All files / src/compiler state.js

91.66% Statements 55/60
88.88% Branches 8/9
100% Functions 3/3
91.52% Lines 54/59

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 602x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 55x 55x 55x 2x 2x 55x 55x 2x 2x 2x 2x 2x 2x 4948x 4948x 4948x 4490x 4948x 4486x 4486x           4486x 4486x 4486x 4948x 462x 462x 4948x 4948x 4948x 4948x 4948x  
import { getLocator } from 'locate-character';
 
/** @typedef {{ start?: number, end?: number }} NodeLike */
 
/** @type {import('#compiler').Warning[]} */
export let warnings = [];
 
/**
 * The filename (if specified in the compiler options) relative to the rootDir (if specified).
 * This should not be used in the compiler output except in dev mode
 * @type {string | undefined}
 */
export let filename;
 
export let locator = getLocator('', { offsetLine: 1 });
 
/** @type {Set<string>[]} */
export let ignore_stack = [];
 
/**
 * @param {string[]} ignores
 */
export function push_ignore(ignores) {
	const next = new Set([...(ignore_stack.at(-1) || []), ...ignores]);
	ignore_stack.push(next);
}
 
export function pop_ignore() {
	ignore_stack.pop();
}
 
/**
 * @param {string} source
 * @param {{ filename?: string, rootDir?: string }} options
 */
export function reset(source, options) {
	if (
		typeof options.filename === 'string' &&
		typeof options.rootDir === 'string' &&
		options.filename.startsWith(options.rootDir)
	) {
		// temp — just here to debug windows nonsense
		if (!options.filename.startsWith(options.rootDir)) {
			console.error('>>>', {
				filename: options.filename,
				rootDir: options.rootDir
			});
		}
 
		// make filename relative to rootDir
		filename = options.filename.replace(options.rootDir, '').replace(/^[/\\]/, '');
	} else {
		filename = options.filename;
	}
 
	locator = getLocator(source, { offsetLine: 1 });
	warnings = [];
	ignore_stack = [];
}