@heyramzi/lint 2.13.0 → 2.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -323,7 +323,7 @@ voice. By default each check reports its first hit per file, which settles pass
323
323
  lists every hit of every check with its line (`line` in `--json`), and the exit code doesn't
324
324
  change. A refused push prints that command with this checkout's path: inside a repo, `npx -y -p
325
325
  @heyramzi/lint heyramzi-slop` runs the repo's installed copy, which can be older than the gate's.
326
- Always name the package with `-p`: the bare npm name `heyramzi-slop` belongs to nobody, and the
326
+ Always name the package with `-p`: the bare npm name `heyramzi-slop` is only a placeholder that prints this command and exits 1, and the
327
327
  `npx-bare-bin` repo rule refuses a file that calls it.
328
328
 
329
329
  `--jev` also asks TypeSafe Jev (`jev.js`) to score each sentence and paragraph against the
@@ -78,7 +78,8 @@ export const patternsSubjectVoice = [
78
78
  name: "Every scenario is named by its trigger",
79
79
  // His rule, not a bot tell: 55 of 267 human replies on the Reddit bench use one, against 7 of our 72 bad ones (9 Nov 2026).
80
80
  // A state word passes unless "by" names who did it: "Hive is not connected", "what's broken", "when we're done" (15 of upsys's 78, 10 Nov 2026).
81
- test: /\b(?:is|are|was|were|be|been|being|['’]s|['’]re)\s+(?:not\s+|never\s+|already\s+|also\s+|still\s+|just\s+|then\s+|\w+ly\s+)?(?!(?:interested|based|related|supposed|used\s+to|tired|bored|excited|worried|scared|married|located|involved|impressed|devastated|surprised|confused|annoyed|pleased|stuck|qualified|indeed|need|feed|seed|speed|breed|greed|weed)\b|(?:closed|locked|unlocked|connected|disconnected|archived|enabled|disabled|un[a-z]{2,}ed)\b(?!\s+by\b)|broken\b(?!\s+(?:by|into|down|up|out|off)\b)|caught\s+up\b|done\b(?=\s*(?:[.!?,;:)]|$)))(?:[a-z]{3,}ed|built|made|done|given|taken|known|seen|written|shown|sent|kept|put|found|held|told|paid|brought|bought|caught|taught|chosen|driven|forgotten|hidden|broken|spoken|stolen|frozen|drawn|grown|thrown|worn|torn)\b/i,
81
+ // So does "you're" or "we're": the person is the subject, nobody's hidden ("what you're paid for", a human r/ClaudeCode comment, 15 Nov 2026).
82
+ test: /\b(?:is|are|was|were|be|been|being|['’]s|['’]re)\s+(?:not\s+|never\s+|already\s+|also\s+|still\s+|just\s+|then\s+|\w+ly\s+)?(?!(?:interested|based|related|supposed|used\s+to|tired|bored|excited|worried|scared|married|located|involved|impressed|devastated|surprised|confused|annoyed|pleased|stuck|qualified|indeed|need|feed|seed|speed|breed|greed|weed)\b|(?:closed|locked|unlocked|connected|disconnected|archived|enabled|disabled|un[a-z]{2,}ed)\b(?!\s+by\b)|broken\b(?!\s+(?:by|into|down|up|out|off)\b)|caught\s+up\b|done\b(?=\s*(?:[.!?,;:)]|$)))(?:[a-z]{3,}ed|built|made|done|given|taken|known|seen|written|shown|sent|kept|put|found|held|told|paid|brought|bought|caught|taught|chosen|driven|forgotten|hidden|broken|spoken|stolen|frozen|drawn|grown|thrown|worn|torn)\b(?:(?<!\b(?:you|we)['’]re\s+(?:\w+\s+)?\w+)|(?=\s+by\b))/i,
82
83
  rule: 'A passive: "is named", "was built", "are treated". Nobody does anything in it, so it reads as a report, not a person talking. Name who does it: "we name every scenario by its trigger". Ramzi, 9 Nov 2026, on a Reddit draft: "anything passive tense basically is bad, bad, bad".',
83
84
  example:
84
85
  '"Every scenario we build is named by its trigger" / "anything that comes through chat is treated as an emergency" / "the report was sent on Monday"',
package/jev-core.js CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  PARAGRAPH_SHAPES,
12
12
  SHAPES,
13
13
  } from "#lint/data/jev-shapes.js";
14
+ import { withoutTemplateCode } from "#lint/slop-clean.js";
14
15
 
15
16
  // The questions live in data/jev-shapes.js; callers keep importing them from here.
16
17
  export {
@@ -73,8 +74,8 @@ export function sentences(text) {
73
74
 
74
75
  /** Markup as Jev reads it: a block ends a paragraph, and link text says it's a link. */
75
76
  export function proseOf(html) {
76
- return html
77
- .replace(/<(script|style)[\s\S]*?<\/\1>|<!--[\s\S]*?-->/gi, " ")
77
+ // A Svelte page's `{...}` is code, and the model read it as the writer's sentences.
78
+ return withoutTemplateCode(html.replace(/<(script|style)[\s\S]*?<\/\1>|<!--[\s\S]*?-->/gi, " "))
78
79
  .replace(/<a\b[^>]*>([\s\S]*?)<\/a>/gi, "\n\nLink: $1\n\n")
79
80
  .replace(/<\/(p|li|h[1-6]|div|td|blockquote)>|<br\s*\/?>/gi, "\n\n")
80
81
  .replace(/<[^>]+>/g, " ")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heyramzi/lint",
3
- "version": "2.13.0",
3
+ "version": "2.14.1",
4
4
  "description": "Shared oxlint rules, base config and gates for Studio projects",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -52,6 +52,7 @@
52
52
  "ui-rules-markup.js",
53
53
  "svelte-markup.js",
54
54
  "svelte-template.js",
55
+ "template-braces.js",
55
56
  "register.js",
56
57
  "register.d.ts",
57
58
  "repo-rules.js",
package/register.js CHANGED
@@ -125,7 +125,9 @@ const AI_SIGNALS = {
125
125
  // 49% of ours, 14% of theirs.
126
126
  "no I, hedge or question": (m) => m.speakerMarks === 0,
127
127
  // Our median 12.3 words a sentence, theirs 17.
128
- "short even sentences": (m) => m.meanSentence < 14,
128
+ // Even is a spread under 0.45, between the bench medians (ours 0.40, theirs 0.51), read from 8 sentences up like the lengthVariation band.
129
+ "short even sentences": (m) =>
130
+ m.meanSentence < 14 && (m.sentences < 8 || m.lengthVariation < 0.45),
129
131
  // 35% of ours, 14% of theirs.
130
132
  "orders the reader": (m) => m.sentences >= 3 && m.commandShare > 0,
131
133
  // The 21 Oct paragraph rule overshot: 3 or more paragraphs under 30 words each.
@@ -2,7 +2,10 @@
2
2
 
3
3
  // WHY client id: a Royal Mail export held X-IBM-Client-Id beside its secret, and the pair is the login.
4
4
  const SECRET_NAME =
5
- /secret|token|passw(or)?d|api[-_]?key|apikey|authorization|client[-_]?id|private[-_]?key|access[-_]?key/i;
5
+ /secret|token|passw(or)?d|api[-_]?key|apikey|authorization|client[-_]?id|auth[-_]?id|private[-_]?key|access[-_]?key/i;
6
+ // WHY: Make's sha256(text; encoding; key) is an HMAC, and an Unleashed export typed its live key there.
7
+ const SIGNING_CALL = /\b(sha\d+|md5|hmac|base64)\(/gi;
8
+ const QUOTED_TOKEN = /"([A-Za-z0-9+/=_.~-]{20,})"/g;
6
9
  const INLINE_FIELD =
7
10
  "(password|passwd|secret|client[_-]?secret|api[_-]?key|apikey|access[_-]?token)";
8
11
  const INLINE = [
@@ -19,6 +22,25 @@ function isLiteral(value) {
19
22
  return trimmed.length >= 8 && !trimmed.includes("{{") && !PLACEHOLDER.test(trimmed);
20
23
  }
21
24
 
25
+ /** The text between a call's opening parenthesis and the one that closes it. */
26
+ function argumentsFrom(value, start) {
27
+ let depth = 1;
28
+ for (let at = start; at < value.length; at++) {
29
+ if (value[at] === "(") depth++;
30
+ if (value[at] === ")" && --depth === 0) return value.slice(start, at);
31
+ }
32
+ return value.slice(start);
33
+ }
34
+
35
+ /** A key-shaped quoted literal inside a hashing or encoding call of a Make formula. */
36
+ function hasSigningKey(value) {
37
+ return [...value.matchAll(SIGNING_CALL)].some((call) =>
38
+ [...argumentsFrom(value, call.index + call[0].length).matchAll(QUOTED_TOKEN)].some(
39
+ ([, token]) => /\d/.test(token) && /[A-Za-z]/.test(token),
40
+ ),
41
+ );
42
+ }
43
+
22
44
  /** The scenario object in an export, a `blueprint` wrapper or an API response, or null. */
23
45
  function scenarioOf(json) {
24
46
  for (const candidate of [json, json?.blueprint, json?.response?.blueprint]) {
@@ -47,6 +69,7 @@ function literals(node, trail, found) {
47
69
  const at = `${trail}.${key}`;
48
70
  if (typeof child === "string") {
49
71
  if (SECRET_NAME.test(key) && isLiteral(child)) found.push({ trail: at, field: key });
72
+ if (hasSigningKey(child)) found.push({ trail: at, field: name ?? key });
50
73
  for (const pattern of INLINE) {
51
74
  const match = pattern.exec(child);
52
75
  if (match && isLiteral(match[2])) found.push({ trail: at, field: match[1] });
@@ -0,0 +1,22 @@
1
+ /** A fetch mock that hands every call one Response: its body reads once, so the second call throws "Body is unusable" (Seam, 15 Nov 2026). */
2
+
3
+ const TEST = /\.(test|spec)\.[cm]?[jt]sx?$/;
4
+ const SHARED = /mockResolvedValue\(\s*new Response\(/g;
5
+
6
+ export function sharedMockResponses(tree) {
7
+ const found = [];
8
+ for (const file of tree.touched) {
9
+ if (!TEST.test(file)) continue;
10
+ const text = tree.text(file);
11
+ if (!text) continue;
12
+ for (const match of text.matchAll(SHARED)) {
13
+ const line = text.slice(0, match.index).split("\n").length;
14
+ found.push({
15
+ file,
16
+ rule: "shared-mock-response",
17
+ message: `line ${line} gives every call the same Response, and a body reads once, so a second fetch throws "Body is unusable". Write \`mockImplementation(async () => new Response(...))\` for a fresh one per call, or \`mockResolvedValueOnce\` when exactly one call is expected.`,
18
+ });
19
+ }
20
+ }
21
+ return found;
22
+ }
package/repo-rules/npx.js CHANGED
@@ -1,4 +1,4 @@
1
- /** A registry runner (npx, dlx, bunx) fetching a bare `heyramzi-*` name, which nobody owns on npm. */
1
+ /** A registry runner (npx, dlx, bunx) fetching a bare `heyramzi-*` name, never the linter on npm (`heyramzi-slop` is a placeholder). */
2
2
 
3
3
  const RUNNER = /(?<![\w-])(?:npx|pnpx|bunx|(?:pnpm|yarn)\s+dlx|npm\s+exec)(?![\w-])/g;
4
4
  const BARE = /^heyramzi-[\w.-]+(@\S*)?$/;
@@ -40,7 +40,7 @@ export function npxBareBins(tree) {
40
40
  found.push({
41
41
  file,
42
42
  rule: "npx-bare-bin",
43
- message: `line ${line} has ${match[0]} fetch the bare npm name ${bin}. Nobody owns that name, so whoever registers it runs code on every machine that follows the line. The bin ships in @heyramzi/lint: write \`npx -y -p @heyramzi/lint ${bin}\`.`,
43
+ message: `line ${line} has ${match[0]} fetch the bare npm name ${bin}, which isn't the linter: heyramzi-slop is a placeholder that exits 1, and an unregistered name runs whoever claims it on every machine that follows the line. The bin ships in @heyramzi/lint: write \`npx -y -p @heyramzi/lint ${bin}\`.`,
44
44
  });
45
45
  }
46
46
  }
package/repo-rules.js CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { blueprintSecrets } from "#lint/repo-rules/blueprints.js";
7
7
  import { untrackedImports } from "#lint/repo-rules/imports.js";
8
+ import { sharedMockResponses } from "#lint/repo-rules/mock-response.js";
8
9
  import { npxBareBins } from "#lint/repo-rules/npx.js";
9
10
  import { composeImages, fossilNames } from "#lint/repo-rules/paths.js";
10
11
  import {
@@ -42,6 +43,7 @@ export const RULES = [
42
43
  untrackedImports,
43
44
  blueprintSecrets,
44
45
  npxBareBins,
46
+ sharedMockResponses,
45
47
  ];
46
48
 
47
49
  /** Every violation in the files the tree says were touched. */
@@ -22,7 +22,7 @@ export default {
22
22
  },
23
23
  messages: {
24
24
  noInlineSvg:
25
- "Inline <svg> at line {{ line }}. Use an icon component (e.g. phosphor-svelte) or extract to a dedicated SVG component file.",
25
+ "Inline <svg> at line {{ line }}. Use an icon component (e.g. phosphor-svelte), or put the SVG component under components/icons/ or a logos/ folder: only those paths may hold inline <svg>.",
26
26
  },
27
27
  schema: [],
28
28
  },
package/slop-clean.js CHANGED
@@ -15,6 +15,8 @@ import {
15
15
  isInvisible,
16
16
  } from "#lint/data/invisibles.js";
17
17
  import { hitLines } from "#lint/slop-lines.js";
18
+ import { looksLikeCopy } from "#lint/slop-views.js";
19
+ import { braceEnd, skipBraces, skipString, skipTemplate } from "#lint/template-braces.js";
18
20
 
19
21
  /**
20
22
  * HTML in, prose out, so an email body and a markdown draft audit the same way.
@@ -27,54 +29,118 @@ export function stripMarkup(raw, { keepLines = false } = {}) {
27
29
  // `keepLines` leaves each removed block's line breaks behind, so a hit's line is the file's line.
28
30
  // The audit itself reads the collapsed text, whose matches every gate run has agreed with.
29
31
  const gap = keepLines ? (m) => ` ${m.replace(/[^\n]/g, "")}` : " ";
30
- const text = raw
31
- .replace(/<(script|style)[\s\S]*?<\/\1>/gi, gap)
32
- // A markup comment is a note to the next developer, not copy.
33
-
34
- // It goes with the script block: the CBAM pages rule their sections with `<!-- name -->` in rows of em dashes, which reported 8 dashes nobody reads.
35
- .replace(/<!--[\s\S]*?-->/g, gap)
32
+ const text = withoutTemplateCode(
33
+ raw
34
+ .replace(/<(script|style)[\s\S]*?<\/\1>/gi, gap)
35
+ // A markup comment is a note to the next developer, not copy.
36
+
37
+ // It goes with the script block: the CBAM pages rule their sections with `<!-- name -->` in rows of em dashes, which reported 8 dashes nobody reads.
38
+ .replace(/<!--[\s\S]*?-->/g, gap),
39
+ { keepLines },
40
+ )
36
41
  .replace(/&[a-z]+;|&#\d+;/gi, " ")
37
42
  .replace(/<[^>]+>/g, gap);
38
- // Svelte and Vue control blocks are code that survives tag stripping, and their loop variables read as prose: `{#each items as row,
39
-
40
- // i (row)}` counted `i` as a first-person pronoun and failed 3 pages on the pronoun ledger.
41
-
42
- // Only `{#`, `{:`, `{/` and `{@` go; a plain `{value}` interpolation is left alone, because the copy it stands for is audited where it is written.
43
- const prose = withoutTemplateTags(text, gap).replace(/[ \t]+/g, " ");
43
+ const prose = text.replace(/[ \t]+/g, " ");
44
44
  return keepLines ? prose : prose.trim();
45
45
  }
46
46
 
47
47
  /**
48
- * Drops every `{#`, `{:`, `{/` and `{@` block up to its balancing brace, skipping braces inside quotes.
48
+ * Drops the code of every Svelte or Vue `{...}` from markup, keeping only the copy strings of a plain interpolation.
49
+ */
50
+
51
+ /*
52
+ * Code read as prose fails the gate. `{#each items as row, i (row)}` counted `i` as a first-person pronoun on 3 pages, a JSON-LD object inside `{@html}` failed
53
+ */
54
+
55
+ /*
56
+ * `comma-run` on a CBAM news page (27 Oct 2026), and `Classer {les(reste, "ligne restante", "lignes restantes")}` failed it on Locameublé (16 Nov 2026).
57
+ */
58
+
59
+ /*
60
+ * It runs before tags go, so `onclick={() => a > b}` no longer ends its tag at the arrow. A block (`{#`, `{:`, `{/`, `{@`) and anything inside a tag go whole.
49
61
  */
50
62
 
51
63
  /*
52
- * A `[^}]*` regex stopped at the first nested brace, so a JSON-LD object inside `{@html}` read as copy and failed `comma-run` on a CBAM news page, 27 Oct 2026.
64
+ * A plain `{value}` in text becomes `0`, so "Code sent to {email}" keeps an object and doesn't end on its preposition. Glued to a word, as in `ligne{s(n)}`,
53
65
  */
54
- export function withoutTemplateTags(text, gap = " ") {
66
+
67
+ /*
68
+ * it's a suffix and leaves nothing. Its literals of 2+ words wait for the end of the line, each on a line of their own, so arguments never join a sentence.
69
+ */
70
+ export function withoutTemplateCode(text, { keepLines = false } = {}) {
55
71
  let out = "";
56
- let i = 0;
57
- while (i < text.length) {
58
- if (text[i] !== "{" || !"#:/@".includes(text[i + 1] ?? "")) {
59
- out += text[i++];
72
+ let waiting = [];
73
+ let inTag = false;
74
+ for (let i = 0; i < text.length; i++) {
75
+ const c = text[i];
76
+ if (c === "\n" && waiting.length) {
77
+ out += `\n${waiting.join("\n")}`;
78
+ waiting = [];
79
+ }
80
+ const end = c === "{" ? braceEnd(text, i) : -1;
81
+ if (end < 0) {
82
+ if (c === "<" && /[A-Za-z/]/.test(text[i + 1] ?? "")) inTag = true;
83
+ else if (c === ">") inTag = false;
84
+ out += c;
60
85
  continue;
61
86
  }
62
- let depth = 0;
63
- let quote = "";
64
- let j = i;
65
- for (; j < text.length; j++) {
66
- const c = text[j];
67
- if (quote) {
68
- if (c === "\\") j++;
69
- else if (c === quote) quote = "";
70
- } else if (c === '"' || c === "'" || c === "`") quote = c;
71
- else if (c === "{") depth++;
72
- else if (c === "}" && --depth === 0) break;
87
+ const code = text.slice(i, end + 1);
88
+ if (inTag || "#:/@".includes(code[1])) out += ` ${keepLines ? newlinesIn(code) : ""}`;
89
+ else {
90
+ const copy = copyLiterals(code);
91
+ out += placeholder(text[i - 1]);
92
+ if (keepLines) out += keptLines(code, copy);
93
+ else waiting.push(...copy.map((l) => l.text));
94
+ }
95
+ i = end;
96
+ }
97
+ return waiting.length ? `${out}\n${waiting.join("\n")}` : out;
98
+ }
99
+
100
+ /** What a value stands in for in a sentence: `0`, or nothing when it is a word's ending. */
101
+ const placeholder = (before = "") => (/\p{L}/u.test(before) ? "" : "x");
102
+
103
+ const newlinesIn = (code) => code.replace(/[^\n]/g, "");
104
+
105
+ /** An expression's literals where they sit, between the line breaks it spanned, so a hit's line is the file's. */
106
+ function keptLines(code, copy) {
107
+ let out = "";
108
+ let from = 0;
109
+ for (const l of copy) {
110
+ out += `${newlinesIn(code.slice(from, Math.max(from, l.index)))} ${l.text} `;
111
+ from = Math.max(from, l.end);
112
+ }
113
+ return out + newlinesIn(code.slice(from));
114
+ }
115
+
116
+ /**
117
+ * The string literals of an expression that read as copy, each with where it sits in `code`.
118
+ */
119
+
120
+ /*
121
+ * A template literal's `${...}` reads as a value does in markup, and the literals inside it count on their own.
122
+ */
123
+ function copyLiterals(code) {
124
+ const found = [];
125
+ for (let i = 0; i < code.length; i++) {
126
+ const q = code[i];
127
+ if (q !== '"' && q !== "'" && q !== "`") continue;
128
+ const end = q === "`" ? skipTemplate(code, i) : skipString(code, i, q);
129
+ let text = "";
130
+ for (let j = i + 1; j < end; j++) {
131
+ if (code[j] === "\\") text += code[++j] ?? "";
132
+ else if (q === "`" && code[j] === "$" && code[j + 1] === "{") {
133
+ const close = skipBraces(code, j + 1) - 1;
134
+ const inner = copyLiterals(code.slice(j + 1, close + 1));
135
+ found.push(...inner.map((l) => ({ ...l, index: l.index + j + 1, end: l.end + j + 1 })));
136
+ text += placeholder(code[j - 1]);
137
+ j = close;
138
+ } else text += code[j];
73
139
  }
74
- out += typeof gap === "function" ? gap(text.slice(i, j + 1)) : gap;
75
- i = j + 1;
140
+ if (looksLikeCopy(text)) found.push({ text: text.trim(), index: i, end: end + 1 });
141
+ i = end;
76
142
  }
77
- return out;
143
+ return found.toSorted((a, b) => a.index - b.index);
78
144
  }
79
145
 
80
146
  const isPictographic = (ch) => /\p{Extended_Pictographic}/u.test(ch);
package/slop-views.js CHANGED
@@ -41,9 +41,12 @@ export function withoutComments(text) {
41
41
  export function copyStrings(text) {
42
42
  const literals =
43
43
  withoutComments(text).match(/"(?:[^"\\\n]|\\.)*"|`(?:[^`\\]|\\.)*`|'(?:[^'\\\n]|\\.)*'/g) ?? [];
44
- return literals.filter((s) => /\p{L}{2,}\s+\p{L}{2,}/u.test(s)).join("\n");
44
+ return literals.filter(looksLikeCopy).join("\n");
45
45
  }
46
46
 
47
+ /** A string of 2 words or more. A lone word is a key, a class or a flag, not a sentence anyone wrote. */
48
+ export const looksLikeCopy = (s) => /\p{L}{2,}\s+\p{L}{2,}/u.test(s);
49
+
47
50
  /**
48
51
  * A string literal's first sentence is sentence-initial, and every anchored pattern used to miss it.
49
52
  */
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  import { readFileSync } from "node:fs";
14
+ import { skipBraces } from "#lint/template-braces.js";
14
15
 
15
16
  export const VOID_ELEMENTS = new Set([
16
17
  "area",
@@ -46,50 +47,6 @@ export const MATHML_ELEMENTS = new Set(
46
47
 
47
48
  const RAW_TEXT = new Set(["script", "style"]);
48
49
 
49
- /** The index just past the `}` that closes the `{` at `start`, honouring strings and comments. */
50
- function skipBraces(source, start) {
51
- let depth = 0;
52
- for (let i = start; i < source.length; i++) {
53
- const c = source[i];
54
- if (c === "'" || c === '"') {
55
- i = skipString(source, i, c);
56
- } else if (c === "`") {
57
- i = skipTemplate(source, i);
58
- } else if (c === "/" && source[i + 1] === "*") {
59
- const end = source.indexOf("*/", i + 2);
60
- if (end === -1) return source.length;
61
- i = end + 1;
62
- } else if (c === "/" && source[i + 1] === "/" && source[i - 1] !== ":") {
63
- const end = source.indexOf("\n", i);
64
- if (end === -1) return source.length;
65
- i = end;
66
- } else if (c === "{") {
67
- depth++;
68
- } else if (c === "}") {
69
- depth--;
70
- if (depth === 0) return i + 1;
71
- }
72
- }
73
- return source.length;
74
- }
75
-
76
- function skipString(source, start, quote) {
77
- for (let i = start + 1; i < source.length; i++) {
78
- if (source[i] === "\\") i++;
79
- else if (source[i] === quote || source[i] === "\n") return i;
80
- }
81
- return source.length;
82
- }
83
-
84
- function skipTemplate(source, start) {
85
- for (let i = start + 1; i < source.length; i++) {
86
- if (source[i] === "\\") i++;
87
- else if (source[i] === "`") return i;
88
- else if (source[i] === "$" && source[i + 1] === "{") i = skipBraces(source, i + 1) - 1;
89
- }
90
- return source.length;
91
- }
92
-
93
50
  /**
94
51
  * Scan a whole .svelte source.
95
52
  * @returns {{ tags: Tag[], expressions: Expression[], blocks: Block[] }}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Where a Svelte or Vue `{...}` ends, honouring strings, template literals and comments. No Node import, so `jev-core` can use it in a Worker.
3
+ */
4
+
5
+ /*
6
+ * A flat scan that treats a backtick as a quote ends a template literal at the first nested one: `${a ? `b` : "c"}` lost the rest of a
7
+ */
8
+
9
+ /*
10
+ * Locameublé page to one `{@render}` that never closed, so no copy after it was read (16 Nov 2026).
11
+ */
12
+
13
+ /** The index of the `}` that closes the `{` at `start`, or -1 when nothing balances it. */
14
+ export function braceEnd(source, start) {
15
+ let depth = 0;
16
+ for (let i = start; i < source.length; i++) {
17
+ const c = source[i];
18
+ if (c === "'" || c === '"') {
19
+ i = skipString(source, i, c);
20
+ } else if (c === "`") {
21
+ i = skipTemplate(source, i);
22
+ } else if (c === "/" && source[i + 1] === "*") {
23
+ const end = source.indexOf("*/", i + 2);
24
+ if (end === -1) return -1;
25
+ i = end + 1;
26
+ } else if (c === "/" && source[i + 1] === "/" && source[i - 1] !== ":") {
27
+ const end = source.indexOf("\n", i);
28
+ if (end === -1) return -1;
29
+ i = end;
30
+ } else if (c === "{") {
31
+ depth++;
32
+ } else if (c === "}") {
33
+ depth--;
34
+ if (depth === 0) return i;
35
+ }
36
+ }
37
+ return -1;
38
+ }
39
+
40
+ /** The index just past the `}` that closes the `{` at `start`, or the source's length. */
41
+ export function skipBraces(source, start) {
42
+ const end = braceEnd(source, start);
43
+ return end < 0 ? source.length : end + 1;
44
+ }
45
+
46
+ /** The index of the quote closing the string at `start`. A line break ends an unclosed one. */
47
+ export function skipString(source, start, quote) {
48
+ for (let i = start + 1; i < source.length; i++) {
49
+ if (source[i] === "\\") i++;
50
+ else if (source[i] === quote || source[i] === "\n") return i;
51
+ }
52
+ return source.length;
53
+ }
54
+
55
+ /** The index of the backtick closing the template literal at `start`, past every `${...}`. */
56
+ export function skipTemplate(source, start) {
57
+ for (let i = start + 1; i < source.length; i++) {
58
+ if (source[i] === "\\") i++;
59
+ else if (source[i] === "`") return i;
60
+ else if (source[i] === "$" && source[i + 1] === "{") i = skipBraces(source, i + 1) - 1;
61
+ }
62
+ return source.length;
63
+ }