All files / src/compiler/utils extract_svelte_ignore.js

82.6% Statements 38/46
80% Branches 8/10
100% Functions 1/1
82.22% Lines 37/45

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 462x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 610x 610x 98x 98x 98x 98x 98x 98x 98x 312x 105x 105x 105x 105x 105x                 105x 105x 105x 98x 98x 98x  
import * as w from '../warnings.js';
 
const regex_svelte_ignore = /^\s*svelte-ignore\s/;
 
/** @type {Record<string, string>} */
const replacements = {
	'non-top-level-reactive-declaration': 'reactive_declaration_invalid_placement'
};
 
/**
 * @param {number} offset
 * @param {string} text
 * @param {boolean} runes
 * @returns {string[]}
 */
export function extract_svelte_ignore(offset, text, runes) {
	const match = regex_svelte_ignore.exec(text);
	if (!match) return [];
 
	let start = match[0].length;
	offset += start;
 
	/** @type {string[]} */
	const ignores = [];
 
	for (const match of text.slice(start).matchAll(/\S+/gm)) {
		const code = match[0];
 
		console.log({ code, runes, codes: w.codes });
 
		if (runes && !w.codes.includes(code)) {
			const suggestion = replacements[code] || code.replace(/-/g, '_');

			if (w.codes.includes(suggestion)) {
				w.unknown_code({ start: offset, end: offset + code.length }, code, suggestion);
			} else {
				w.unknown_code({ start: offset, end: offset + code.length }, code);
			}
		}
 
		ignores.push(code);
	}
 
	return ignores;
}