diff --git a/packages/lint/src/linearScans.test.ts b/packages/lint/src/linearScans.test.ts new file mode 100644 index 0000000000..f356f77d07 --- /dev/null +++ b/packages/lint/src/linearScans.test.ts @@ -0,0 +1,156 @@ +import { isDeepStrictEqual } from "node:util"; +import { describe, expect, it } from "vitest"; +import { + blockComments, + emptyStyleBlocks, + hasInvalidScriptClose, + hasScriptWithSrc, + htmlTagTracker, + protectedBlockRanges, + replaceBlockComments, + styleTagTokens, +} from "./linearScans"; + +const PATTERNS = { + blockComment: /\/\*[\s\S]*?\*\//g, + invalidScriptClose: /]*>[\s\S]*?<\s*\/\s*script(?!>)/i, + scriptWithSrc: /]*\bsrc\s*=/i, + styleBlock: /]*>[\s\S]*?<\/style>/gi, + styleTokens: /]*>|/gi, + protectedBlock: + /<(style|script|template|title|noscript|pre|code|textarea|text)\b[^>]*>[\s\S]*?<\/\1(?:\s[^>]*)?>/gi, +}; + +function insideHtmlTag(source: string, index: number): boolean { + let inTag = false; + let quote: string | null = null; + for (let i = 0; i < index; i++) { + const char = source[i]; + if (!inTag) { + if (char === "<") inTag = true; + continue; + } + if (quote) { + if (char === quote) quote = null; + continue; + } + if (char === '"' || char === "'") quote = char; + else if (char === ">") inTag = false; + } + return inTag; +} + +const TOKENS = [ + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "