@nifrajs/cli 5.17.0 → 5.18.0

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.
Files changed (178) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/dist/check-diagnostics.d.ts +7 -0
  3. package/dist/check-diagnostics.d.ts.map +1 -1
  4. package/dist/check-diagnostics.js +3 -0
  5. package/dist/check-diagnostics.js.map +1 -1
  6. package/dist/check-scan-sql.d.ts +95 -0
  7. package/dist/check-scan-sql.d.ts.map +1 -0
  8. package/dist/check-scan-sql.js +1190 -0
  9. package/dist/check-scan-sql.js.map +1 -0
  10. package/dist/check-scan.d.ts +5 -93
  11. package/dist/check-scan.d.ts.map +1 -1
  12. package/dist/check-scan.js +20 -1207
  13. package/dist/check-scan.js.map +1 -1
  14. package/dist/check.d.ts.map +1 -1
  15. package/dist/check.js +9 -0
  16. package/dist/check.js.map +1 -1
  17. package/dist/cli.d.ts +2 -6
  18. package/dist/cli.d.ts.map +1 -1
  19. package/dist/cli.js +249 -80
  20. package/dist/cli.js.map +1 -1
  21. package/dist/command-catalog.d.ts +3 -0
  22. package/dist/command-catalog.d.ts.map +1 -1
  23. package/dist/command-catalog.js +18 -4
  24. package/dist/command-catalog.js.map +1 -1
  25. package/dist/frontend-guidance.js +1 -1
  26. package/dist/frontend-guidance.js.map +1 -1
  27. package/dist/internal/a11y-element.d.ts +33 -0
  28. package/dist/internal/a11y-element.d.ts.map +1 -0
  29. package/dist/internal/a11y-element.js +124 -0
  30. package/dist/internal/a11y-element.js.map +1 -0
  31. package/dist/internal/a11y-jsx.d.ts +12 -0
  32. package/dist/internal/a11y-jsx.d.ts.map +1 -0
  33. package/dist/internal/a11y-jsx.js +42 -0
  34. package/dist/internal/a11y-jsx.js.map +1 -0
  35. package/dist/internal/a11y-template.d.ts +11 -0
  36. package/dist/internal/a11y-template.d.ts.map +1 -0
  37. package/dist/internal/a11y-template.js +56 -0
  38. package/dist/internal/a11y-template.js.map +1 -0
  39. package/dist/internal/aria-data.d.ts +23 -0
  40. package/dist/internal/aria-data.d.ts.map +1 -0
  41. package/dist/internal/aria-data.js +220 -0
  42. package/dist/internal/aria-data.js.map +1 -0
  43. package/dist/internal/edit-distance.d.ts +3 -0
  44. package/dist/internal/edit-distance.d.ts.map +1 -0
  45. package/dist/internal/edit-distance.js +12 -0
  46. package/dist/internal/edit-distance.js.map +1 -0
  47. package/dist/internal/imported-as.d.ts +10 -0
  48. package/dist/internal/imported-as.d.ts.map +1 -0
  49. package/dist/internal/imported-as.js +23 -0
  50. package/dist/internal/imported-as.js.map +1 -0
  51. package/dist/internal/source-facts.d.ts +3 -0
  52. package/dist/internal/source-facts.d.ts.map +1 -1
  53. package/dist/internal/source-facts.js +2 -0
  54. package/dist/internal/source-facts.js.map +1 -1
  55. package/dist/internal/template-markup.d.ts +58 -0
  56. package/dist/internal/template-markup.d.ts.map +1 -0
  57. package/dist/internal/template-markup.js +221 -0
  58. package/dist/internal/template-markup.js.map +1 -0
  59. package/dist/internal/typescript-import.d.ts.map +1 -1
  60. package/dist/internal/typescript-import.js +11 -0
  61. package/dist/internal/typescript-import.js.map +1 -1
  62. package/dist/mcp-exec.d.ts.map +1 -1
  63. package/dist/mcp-exec.js +37 -23
  64. package/dist/mcp-exec.js.map +1 -1
  65. package/dist/mcp-http.js +1 -1
  66. package/dist/mcp-io.d.ts.map +1 -1
  67. package/dist/mcp-io.js +5 -3
  68. package/dist/mcp-io.js.map +1 -1
  69. package/dist/mcp-root.js +1 -1
  70. package/dist/mcp-root.js.map +1 -1
  71. package/dist/mcp-ws.d.ts.map +1 -1
  72. package/dist/mcp-ws.js +3 -2
  73. package/dist/mcp-ws.js.map +1 -1
  74. package/dist/migrate-layout-config.d.ts +63 -0
  75. package/dist/migrate-layout-config.d.ts.map +1 -0
  76. package/dist/migrate-layout-config.js +507 -0
  77. package/dist/migrate-layout-config.js.map +1 -0
  78. package/dist/migrate-layout-split.d.ts +46 -0
  79. package/dist/migrate-layout-split.d.ts.map +1 -0
  80. package/dist/migrate-layout-split.js +687 -0
  81. package/dist/migrate-layout-split.js.map +1 -0
  82. package/dist/migrate-layout.d.ts +4 -24
  83. package/dist/migrate-layout.d.ts.map +1 -1
  84. package/dist/migrate-layout.js +8 -1183
  85. package/dist/migrate-layout.js.map +1 -1
  86. package/dist/output-schemas.d.ts.map +1 -1
  87. package/dist/output-schemas.js +78 -10
  88. package/dist/output-schemas.js.map +1 -1
  89. package/dist/recipes/5.18.0.d.ts +9 -0
  90. package/dist/recipes/5.18.0.d.ts.map +1 -0
  91. package/dist/recipes/5.18.0.js +56 -0
  92. package/dist/recipes/5.18.0.js.map +1 -0
  93. package/dist/recipes/index.d.ts.map +1 -1
  94. package/dist/recipes/index.js +2 -0
  95. package/dist/recipes/index.js.map +1 -1
  96. package/dist/review.d.ts.map +1 -1
  97. package/dist/review.js +6 -0
  98. package/dist/review.js.map +1 -1
  99. package/dist/rules/a11y.d.ts +5 -0
  100. package/dist/rules/a11y.d.ts.map +1 -0
  101. package/dist/rules/a11y.js +78 -0
  102. package/dist/rules/a11y.js.map +1 -0
  103. package/dist/rules/codes.d.ts +6 -0
  104. package/dist/rules/codes.d.ts.map +1 -1
  105. package/dist/rules/codes.js +6 -0
  106. package/dist/rules/codes.js.map +1 -1
  107. package/dist/rules/comment-markers.js +1 -1
  108. package/dist/rules/comment-markers.js.map +1 -1
  109. package/dist/rules/explanations.d.ts.map +1 -1
  110. package/dist/rules/explanations.js +30 -0
  111. package/dist/rules/explanations.js.map +1 -1
  112. package/dist/rules/host-exposure.d.ts +23 -0
  113. package/dist/rules/host-exposure.d.ts.map +1 -0
  114. package/dist/rules/host-exposure.js +380 -0
  115. package/dist/rules/host-exposure.js.map +1 -0
  116. package/dist/rules/internal-links.d.ts.map +1 -1
  117. package/dist/rules/internal-links.js +16 -141
  118. package/dist/rules/internal-links.js.map +1 -1
  119. package/dist/rules/islands.d.ts +54 -0
  120. package/dist/rules/islands.d.ts.map +1 -1
  121. package/dist/rules/islands.js +577 -80
  122. package/dist/rules/islands.js.map +1 -1
  123. package/dist/rules/security.d.ts +1 -0
  124. package/dist/rules/security.d.ts.map +1 -1
  125. package/dist/rules/security.js +34 -7
  126. package/dist/rules/security.js.map +1 -1
  127. package/dist/runtime-differences.js +3 -3
  128. package/dist/runtime-differences.js.map +1 -1
  129. package/dist/scaffold.d.ts +1 -1
  130. package/dist/scaffold.d.ts.map +1 -1
  131. package/dist/scaffold.js +2 -2
  132. package/dist/scaffold.js.map +1 -1
  133. package/dist/source-rewrites.d.ts.map +1 -1
  134. package/dist/source-rewrites.js +2 -19
  135. package/dist/source-rewrites.js.map +1 -1
  136. package/docs/examples.json +4 -4
  137. package/docs/llms-full.txt +422 -42
  138. package/docs/types.json +466 -56
  139. package/package.json +12 -12
  140. package/src/check-diagnostics.ts +11 -0
  141. package/src/check-scan-sql.ts +1746 -0
  142. package/src/check-scan.ts +34 -1754
  143. package/src/check.ts +10 -1
  144. package/src/cli.ts +258 -98
  145. package/src/command-catalog.ts +21 -4
  146. package/src/frontend-guidance.ts +1 -1
  147. package/src/internal/a11y-element.ts +227 -0
  148. package/src/internal/a11y-jsx.ts +54 -0
  149. package/src/internal/a11y-template.ts +74 -0
  150. package/src/internal/aria-data.ts +242 -0
  151. package/src/internal/edit-distance.ts +16 -0
  152. package/src/internal/imported-as.ts +30 -0
  153. package/src/internal/source-facts.ts +4 -0
  154. package/src/internal/template-markup.ts +270 -0
  155. package/src/internal/typescript-import.ts +15 -0
  156. package/src/mcp-exec.ts +43 -22
  157. package/src/mcp-http.ts +1 -1
  158. package/src/mcp-io.ts +5 -3
  159. package/src/mcp-root.ts +1 -1
  160. package/src/mcp-ws.ts +3 -2
  161. package/src/migrate-layout-config.ts +615 -0
  162. package/src/migrate-layout-split.ts +870 -0
  163. package/src/migrate-layout.ts +37 -1468
  164. package/src/output-schemas.ts +85 -17
  165. package/src/recipes/5.18.0.ts +63 -0
  166. package/src/recipes/index.ts +2 -0
  167. package/src/review.ts +6 -0
  168. package/src/rules/a11y.ts +119 -0
  169. package/src/rules/codes.ts +6 -0
  170. package/src/rules/comment-markers.ts +2 -2
  171. package/src/rules/explanations.ts +30 -0
  172. package/src/rules/host-exposure.ts +531 -0
  173. package/src/rules/internal-links.ts +21 -154
  174. package/src/rules/islands.ts +698 -86
  175. package/src/rules/security.ts +48 -7
  176. package/src/runtime-differences.ts +3 -3
  177. package/src/scaffold.ts +3 -3
  178. package/src/source-rewrites.ts +2 -15
@@ -0,0 +1,242 @@
1
+ /**
2
+ * The WAI-ARIA 1.2 vocabulary the accessibility lint judges markup against, read from
3
+ * https://www.w3.org/TR/wai-aria-1.2/ on 2026-11-23. The aria-data test pins every count.
4
+ */
5
+
6
+ /** Roles authors may not use: they exist only to organise the taxonomy. */
7
+ export const ABSTRACT_ROLES: ReadonlySet<string> = new Set([
8
+ "command",
9
+ "composite",
10
+ "input",
11
+ "landmark",
12
+ "range",
13
+ "roletype",
14
+ "section",
15
+ "sectionhead",
16
+ "select",
17
+ "structure",
18
+ "widget",
19
+ "window",
20
+ ])
21
+
22
+ export const CONCRETE_ROLES: ReadonlySet<string> = new Set([
23
+ "alert",
24
+ "alertdialog",
25
+ "application",
26
+ "article",
27
+ "banner",
28
+ "blockquote",
29
+ "button",
30
+ "caption",
31
+ "cell",
32
+ "checkbox",
33
+ "code",
34
+ "columnheader",
35
+ "combobox",
36
+ "complementary",
37
+ "contentinfo",
38
+ "definition",
39
+ "deletion",
40
+ "dialog",
41
+ "directory",
42
+ "document",
43
+ "emphasis",
44
+ "feed",
45
+ "figure",
46
+ "form",
47
+ "generic",
48
+ "grid",
49
+ "gridcell",
50
+ "group",
51
+ "heading",
52
+ "img",
53
+ "insertion",
54
+ "link",
55
+ "list",
56
+ "listbox",
57
+ "listitem",
58
+ "log",
59
+ "main",
60
+ "marquee",
61
+ "math",
62
+ "menu",
63
+ "menubar",
64
+ "menuitem",
65
+ "menuitemcheckbox",
66
+ "menuitemradio",
67
+ "meter",
68
+ "navigation",
69
+ "none",
70
+ "note",
71
+ "option",
72
+ "paragraph",
73
+ "presentation",
74
+ "progressbar",
75
+ "radio",
76
+ "radiogroup",
77
+ "region",
78
+ "row",
79
+ "rowgroup",
80
+ "rowheader",
81
+ "scrollbar",
82
+ "search",
83
+ "searchbox",
84
+ "separator",
85
+ "slider",
86
+ "spinbutton",
87
+ "status",
88
+ "strong",
89
+ "subscript",
90
+ "superscript",
91
+ "switch",
92
+ "tab",
93
+ "table",
94
+ "tablist",
95
+ "tabpanel",
96
+ "term",
97
+ "textbox",
98
+ "time",
99
+ "timer",
100
+ "toolbar",
101
+ "tooltip",
102
+ "tree",
103
+ "treegrid",
104
+ "treeitem",
105
+ ])
106
+
107
+ /** Roles from the DPUB-ARIA and Graphics-ARIA modules; HTML allows both, so neither is judged here. */
108
+ export const MODULE_ROLE_PREFIX = /^(?:doc|graphics)-/
109
+
110
+ /** The 48 states and properties of ARIA 1.2, plus the description and braille attributes browsers ship. */
111
+ export const ARIA_ATTRIBUTES: ReadonlySet<string> = new Set([
112
+ "aria-activedescendant",
113
+ "aria-atomic",
114
+ "aria-autocomplete",
115
+ "aria-braillelabel",
116
+ "aria-brailleroledescription",
117
+ "aria-busy",
118
+ "aria-checked",
119
+ "aria-colcount",
120
+ "aria-colindex",
121
+ "aria-colindextext",
122
+ "aria-colspan",
123
+ "aria-controls",
124
+ "aria-current",
125
+ "aria-describedby",
126
+ "aria-description",
127
+ "aria-details",
128
+ "aria-disabled",
129
+ "aria-dropeffect",
130
+ "aria-errormessage",
131
+ "aria-expanded",
132
+ "aria-flowto",
133
+ "aria-grabbed",
134
+ "aria-haspopup",
135
+ "aria-hidden",
136
+ "aria-invalid",
137
+ "aria-keyshortcuts",
138
+ "aria-label",
139
+ "aria-labelledby",
140
+ "aria-level",
141
+ "aria-live",
142
+ "aria-modal",
143
+ "aria-multiline",
144
+ "aria-multiselectable",
145
+ "aria-orientation",
146
+ "aria-owns",
147
+ "aria-placeholder",
148
+ "aria-posinset",
149
+ "aria-pressed",
150
+ "aria-readonly",
151
+ "aria-relevant",
152
+ "aria-required",
153
+ "aria-roledescription",
154
+ "aria-rowcount",
155
+ "aria-rowindex",
156
+ "aria-rowindextext",
157
+ "aria-rowspan",
158
+ "aria-selected",
159
+ "aria-setsize",
160
+ "aria-sort",
161
+ "aria-valuemax",
162
+ "aria-valuemin",
163
+ "aria-valuenow",
164
+ "aria-valuetext",
165
+ ])
166
+
167
+ /**
168
+ * What a role requires on the element, by the spec. `aria-controls` is left out of `combobox`: it
169
+ * names a popup that need not exist while closed, so its absence is not provably a bug.
170
+ */
171
+ export const ROLE_REQUIRED: ReadonlyMap<string, readonly string[]> = new Map([
172
+ ["checkbox", ["aria-checked"]],
173
+ ["combobox", ["aria-expanded"]],
174
+ ["heading", ["aria-level"]],
175
+ ["menuitemcheckbox", ["aria-checked"]],
176
+ ["menuitemradio", ["aria-checked"]],
177
+ ["meter", ["aria-valuenow"]],
178
+ ["option", ["aria-selected"]],
179
+ ["radio", ["aria-checked"]],
180
+ ["scrollbar", ["aria-controls", "aria-valuenow"]],
181
+ ["slider", ["aria-valuenow"]],
182
+ ["switch", ["aria-checked"]],
183
+ ])
184
+
185
+ const BOOLEAN = ["true", "false"]
186
+ const BOOLEAN_OR_UNDEFINED = ["true", "false", "undefined"]
187
+ const TRISTATE = ["true", "false", "mixed", "undefined"]
188
+
189
+ /** The words each enumerated attribute accepts. A value written as an expression is never judged. */
190
+ export const ARIA_VALUES: ReadonlyMap<string, readonly string[]> = new Map([
191
+ ["aria-atomic", BOOLEAN],
192
+ ["aria-autocomplete", ["inline", "list", "both", "none"]],
193
+ ["aria-busy", BOOLEAN],
194
+ ["aria-checked", TRISTATE],
195
+ ["aria-current", ["page", "step", "location", "date", "time", "true", "false"]],
196
+ ["aria-disabled", BOOLEAN],
197
+ ["aria-expanded", BOOLEAN_OR_UNDEFINED],
198
+ ["aria-grabbed", BOOLEAN_OR_UNDEFINED],
199
+ ["aria-haspopup", ["false", "true", "menu", "listbox", "tree", "grid", "dialog"]],
200
+ ["aria-hidden", BOOLEAN_OR_UNDEFINED],
201
+ ["aria-invalid", ["grammar", "false", "spelling", "true"]],
202
+ ["aria-live", ["off", "polite", "assertive"]],
203
+ ["aria-modal", BOOLEAN],
204
+ ["aria-multiline", BOOLEAN],
205
+ ["aria-multiselectable", BOOLEAN],
206
+ ["aria-orientation", ["horizontal", "vertical", "undefined"]],
207
+ ["aria-pressed", TRISTATE],
208
+ ["aria-readonly", BOOLEAN],
209
+ ["aria-required", BOOLEAN],
210
+ ["aria-selected", BOOLEAN_OR_UNDEFINED],
211
+ ["aria-sort", ["ascending", "descending", "none", "other"]],
212
+ ])
213
+
214
+ /** The roles an element carries with no `role` attribute, for the elements whose role is never in doubt. */
215
+ export const IMPLICIT_ROLES: ReadonlyMap<string, string> = new Map([
216
+ ["article", "article"],
217
+ ["aside", "complementary"],
218
+ ["button", "button"],
219
+ ["dialog", "dialog"],
220
+ ["h1", "heading"],
221
+ ["h2", "heading"],
222
+ ["h3", "heading"],
223
+ ["h4", "heading"],
224
+ ["h5", "heading"],
225
+ ["h6", "heading"],
226
+ ["hr", "separator"],
227
+ ["main", "main"],
228
+ ["nav", "navigation"],
229
+ ["progress", "progressbar"],
230
+ ["textarea", "textbox"],
231
+ ])
232
+
233
+ /** The native element that already does what a `div` or `span` with this role has to be built to do. */
234
+ export const NATIVE_FOR_ROLE: ReadonlyMap<string, string> = new Map([
235
+ ["button", "<button>"],
236
+ ["checkbox", '<input type="checkbox">'],
237
+ ["link", "<a href>"],
238
+ ["main", "<main>"],
239
+ ["navigation", "<nav>"],
240
+ ["radio", '<input type="radio">'],
241
+ ["textbox", "<input> or <textarea>"],
242
+ ])
@@ -0,0 +1,16 @@
1
+ /** The Levenshtein distance between two strings: the fewest single-character edits that turn one into the other. */
2
+ export function distance(a: string, b: string): number {
3
+ let row = Array.from({ length: b.length + 1 }, (_, i) => i)
4
+ for (let i = 1; i <= a.length; i++) {
5
+ const next = [i]
6
+ for (let j = 1; j <= b.length; j++) {
7
+ next[j] = Math.min(
8
+ (row[j] ?? 0) + 1,
9
+ (next[j - 1] ?? 0) + 1,
10
+ (row[j - 1] ?? 0) + (a[i - 1] === b[j - 1] ? 0 : 1),
11
+ )
12
+ }
13
+ row = next
14
+ }
15
+ return row[b.length] ?? 0
16
+ }
@@ -0,0 +1,30 @@
1
+ import type * as TS from "typescript"
2
+
3
+ /**
4
+ * The local names a file imports `exportName` under from the modules `isModule` accepts, and the
5
+ * local names it imports those modules under as a namespace.
6
+ */
7
+ export function importedAs(
8
+ ts: typeof TS,
9
+ tree: TS.SourceFile,
10
+ isModule: (specifier: string) => boolean,
11
+ exportName: string,
12
+ ): { readonly locals: Set<string>; readonly namespaces: Set<string> } {
13
+ const locals = new Set<string>()
14
+ const namespaces = new Set<string>()
15
+ for (const statement of tree.statements) {
16
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteralLike(statement.moduleSpecifier))
17
+ continue
18
+ if (!isModule(statement.moduleSpecifier.text)) continue
19
+ const bindings = statement.importClause?.namedBindings
20
+ if (bindings === undefined) continue
21
+ if (ts.isNamespaceImport(bindings)) namespaces.add(bindings.name.text)
22
+ else {
23
+ for (const element of bindings.elements) {
24
+ if ((element.propertyName ?? element.name).text === exportName)
25
+ locals.add(element.name.text)
26
+ }
27
+ }
28
+ }
29
+ return { locals, namespaces }
30
+ }
@@ -1,4 +1,5 @@
1
1
  import type * as TSApi from "typescript"
2
+ import { type A11yFinding, a11yFindings } from "./a11y-jsx.ts"
2
3
  import { importedNames } from "./named-imports.ts"
3
4
  import { scriptKindOf } from "./script-kind.ts"
4
5
  import type { TypeScriptApi } from "./typescript-import.ts"
@@ -166,6 +167,8 @@ export interface SourceFacts {
166
167
  routeHookCalls(source: TSApi.SourceFile): readonly RouteHookCall[]
167
168
  /** The casts of a value to `Href`, imported from `@nifrajs/web` or a `@nifrajs/web-<framework>` package. */
168
169
  hrefCasts(source: TSApi.SourceFile): readonly HrefCast[]
170
+ /** The accessibility findings in the JSX of `source`: roles, `aria-*` attributes, `alt`, `tabindex`, `<html lang>`. */
171
+ a11yFindings(source: TSApi.SourceFile): readonly A11yFinding[]
169
172
  /** Whether the function `source` exports as `name` returns a raw `Response` on some path. */
170
173
  exportReturnsResponse(source: TSApi.SourceFile, name: string): boolean
171
174
  /** Whether the `import` keyword at `position` starts a runtime `import(specifier)` call (true) or a
@@ -1175,6 +1178,7 @@ export function createSourceFacts(
1175
1178
  internalAnchors,
1176
1179
  routeHookCalls,
1177
1180
  hrefCasts,
1181
+ a11yFindings: (source) => a11yFindings(ts, source),
1178
1182
  serverFunctionMounts,
1179
1183
  exportReturnsResponse,
1180
1184
  isDynamicImportAt,
@@ -0,0 +1,270 @@
1
+ import { Glob } from "bun"
2
+ import { IGNORED } from "../check-scan.ts"
3
+ import { toPosix } from "./posix-path.ts"
4
+
5
+ /**
6
+ * A reader for the markup of a `.vue` or `.svelte` file. The source index holds only a component's
7
+ * script blocks, so a rule that judges what a template renders reads the raw file with this.
8
+ */
9
+
10
+ export interface HtmlComment {
11
+ readonly start: number
12
+ /** Where the text after `<!--` stops: before the closing delimiter. */
13
+ readonly bodyEnd: number
14
+ readonly end: number
15
+ }
16
+
17
+ // A comment ends at `-->` or `--!>`.
18
+ const COMMENT_END = /--!?>/g
19
+
20
+ /** The comment opened at `start`, which HTML ends at `-->` or `--!>`; `<!-->` and `<!--->` are empty. */
21
+ function commentAt(text: string, start: number): HtmlComment {
22
+ const body = start + 4
23
+ if (text.startsWith(">", body)) return { start, bodyEnd: body, end: body + 1 }
24
+ if (text.startsWith("->", body)) return { start, bodyEnd: body, end: body + 2 }
25
+ COMMENT_END.lastIndex = body
26
+ const close = COMMENT_END.exec(text)
27
+ return close === null
28
+ ? { start, bodyEnd: text.length, end: text.length }
29
+ : { start, bodyEnd: close.index, end: close.index + close[0].length }
30
+ }
31
+
32
+ const SPACE = /\s/
33
+ // A `/` after one of these starts a regex literal rather than dividing.
34
+ const BEFORE_REGEX =
35
+ /(?:^|[({[,;:=!&|?+\-*%^~>]|\b(?:await|case|const|delete|do|else|html|if|in|instanceof|new|of|return|throw|typeof|void|yield))\s*$/
36
+ // A Svelte `{/if}` closes a block; it opens no regex.
37
+ const BLOCK_CLOSE = /\/(?:if|each|await|key|snippet)\s*\}/y
38
+ // One line, with `/` allowed unescaped inside a character class.
39
+ const REGEX_LITERAL = /\/(?![*/])(?:\\.|\[(?:\\.|[^\]\\\n])*\]|[^/[\\\n])+\//y
40
+
41
+ /** The offset just past the JavaScript comment or regex literal opening at the `/` at `at`, or past
42
+ * that `/` alone when it divides: a brace or quote inside either literal is not code. */
43
+ function pastSlash(text: string, at: number, from: number): number {
44
+ if (text[at + 1] === "/") {
45
+ const newline = text.indexOf("\n", at)
46
+ return newline === -1 ? text.length : newline
47
+ }
48
+ if (text[at + 1] === "*") {
49
+ const close = text.indexOf("*/", at + 2)
50
+ return close === -1 ? text.length : close + 2
51
+ }
52
+ let code = at
53
+ while (code > 0 && SPACE.test(text[code - 1] ?? "")) code--
54
+ BLOCK_CLOSE.lastIndex = at
55
+ if (text[code - 1] === "{" && BLOCK_CLOSE.test(text)) return at + 1
56
+ if (!BEFORE_REGEX.test(text.slice(Math.max(from, code - 16), code))) return at + 1
57
+ REGEX_LITERAL.lastIndex = at
58
+ return REGEX_LITERAL.test(text) ? REGEX_LITERAL.lastIndex : at + 1
59
+ }
60
+
61
+ /** The end of a markup tag or `{expression}`, ignoring `>`/braces inside quoted values and inside an
62
+ * expression's comments and regex literals. */
63
+ function markupEnd(text: string, start: number, expression = false): number {
64
+ let quote: string | undefined
65
+ let braces = expression ? 1 : 0
66
+ for (let at = start; at < text.length; at++) {
67
+ const char = text[at]
68
+ if (quote !== undefined) {
69
+ if (braces > 0 && char === "\\") at++
70
+ else if (char === quote) quote = undefined
71
+ } else if (braces > 0 && char === "/") at = pastSlash(text, at, start) - 1
72
+ else if (char === '"' || char === "'" || (braces > 0 && char === "`")) quote = char
73
+ else if (char === "{") braces++
74
+ else if (char === "}") {
75
+ braces--
76
+ if (expression && braces === 0) return at + 1
77
+ } else if (!expression && braces === 0 && char === ">") return at + 1
78
+ }
79
+ return text.length
80
+ }
81
+
82
+ /** An opening tag of a template, from {@link scanTemplate}. */
83
+ export interface TemplateTag {
84
+ /** The tag name, lowercased. */
85
+ readonly name: string
86
+ /** The tag name as written: a component is capitalised, an intrinsic element is not. */
87
+ readonly written: string
88
+ /** The offset of the `<`. */
89
+ readonly at: number
90
+ /** The offset just after the tag name, where its attributes start. */
91
+ readonly attributesAt: number
92
+ /** Whether the tag is markup: always for Svelte, and for Vue inside a `<template>`. */
93
+ readonly inTemplate: boolean
94
+ }
95
+
96
+ export interface TemplateScan {
97
+ readonly tags: readonly TemplateTag[]
98
+ /**
99
+ * The file with its HTML comments turned into `//` lines and every other character blanked, line
100
+ * counts unchanged, for the shared `nifra-expect` reader. A marker in quoted text suppresses nothing.
101
+ */
102
+ readonly expectationLines: readonly string[]
103
+ }
104
+
105
+ /** The opening tags of `text`, not those inside a script or style block, an HTML comment or an expression. */
106
+ export function scanTemplate(text: string, vue: boolean): TemplateScan {
107
+ const tags: TemplateTag[] = []
108
+ const comments: HtmlComment[] = []
109
+ let templateDepth = 0
110
+ for (let at = 0; at < text.length; ) {
111
+ if (text.startsWith("<!--", at)) {
112
+ const comment = commentAt(text, at)
113
+ comments.push(comment)
114
+ at = comment.end
115
+ continue
116
+ }
117
+ if (text[at] === "{" && (!vue || text.startsWith("{{", at))) {
118
+ at = markupEnd(text, at + 1, true)
119
+ continue
120
+ }
121
+ if (text[at] !== "<") {
122
+ at++
123
+ continue
124
+ }
125
+ const tag = /^<(\/?)([\w-]+)(?=[\s/>])/.exec(text.slice(at))
126
+ if (tag === null) {
127
+ at++
128
+ continue
129
+ }
130
+ const tagAt = at
131
+ const end = markupEnd(text, at + tag[0].length)
132
+ const name = tag[2]?.toLowerCase() ?? ""
133
+ const closing = tag[1] === "/"
134
+ at = end
135
+ if (!closing && (name === "script" || name === "style")) {
136
+ const close = name === "script" ? /<\/script\s*>/gi : /<\/style\s*>/gi
137
+ close.lastIndex = end
138
+ const match = close.exec(text)
139
+ at = match === null ? text.length : close.lastIndex
140
+ continue
141
+ }
142
+ if (name === "template") templateDepth += closing ? -1 : 1
143
+ if (closing) continue
144
+ tags.push({
145
+ name,
146
+ written: tag[2] ?? name,
147
+ at: tagAt,
148
+ attributesAt: tagAt + tag[0].length,
149
+ inTemplate: !vue || templateDepth > 0,
150
+ })
151
+ }
152
+ // Adapt only real HTML comments to the shared directive parser. Non-comment code stays a block
153
+ // boundary. Line counts are unchanged.
154
+ const code = (part: string): string => part.replace(/[^\s]/g, "x")
155
+ let expectations = ""
156
+ let previous = 0
157
+ for (const comment of comments) {
158
+ expectations += code(text.slice(previous, comment.start))
159
+ expectations += text
160
+ .slice(comment.start + 4, comment.bodyEnd)
161
+ .split("\n")
162
+ .map((line) => `// ${line}`)
163
+ .join("\n")
164
+ previous = comment.end
165
+ }
166
+ expectations += code(text.slice(previous))
167
+ return { tags, expectationLines: expectations.split("\n") }
168
+ }
169
+
170
+ /** One attribute of a template tag, as written. */
171
+ export interface TemplateAttribute {
172
+ readonly name: string
173
+ /** The offset of the attribute's name. */
174
+ readonly at: number
175
+ /** The text between the quotes of `name="…"` or `name='…'`. */
176
+ readonly quoted: string | undefined
177
+ /** The string of `name={"…"}`, `name={'…'}` or a template literal in braces. */
178
+ readonly braceString: string | undefined
179
+ /** What stands between the braces of any other `name={…}`. */
180
+ readonly braced: string | undefined
181
+ /** The value of `name=value`. */
182
+ readonly bare: string | undefined
183
+ }
184
+
185
+ const NAME_END = /[\s=>/]/
186
+ const STRING_IN_BRACES = /^(?:"([^"]*)"|'([^']*)'|`([^`]*)`)$/
187
+
188
+ /**
189
+ * The attributes of `tag`, up to the first thing that is not one (`>` or `/>`). A value is read as
190
+ * `name="x"`, `name='x'`, `name={…}` (balanced, so `on:click={() => {}}` is one attribute) or an
191
+ * unquoted `name=x`; a Svelte `{...props}` or `{id}` is an attribute named by its braces.
192
+ */
193
+ export function readAttributes(text: string, tag: TemplateTag): TemplateAttribute[] {
194
+ const attributes: TemplateAttribute[] = []
195
+ const skipSpace = (from: number): number => {
196
+ let at = from
197
+ while (at < text.length && SPACE.test(text[at] ?? "")) at++
198
+ return at
199
+ }
200
+ let at = tag.attributesAt
201
+ for (;;) {
202
+ const start = skipSpace(at)
203
+ if (start === at || start >= text.length) break
204
+ const first = text[start]
205
+ if (first === ">" || first === "/" || first === "=") break
206
+ let end = start
207
+ if (first === "{") end = markupEnd(text, start + 1, true)
208
+ else while (end < text.length && !NAME_END.test(text[end] ?? "")) end++
209
+ const name = text.slice(start, end)
210
+ at = end
211
+ let quoted: string | undefined
212
+ let braceString: string | undefined
213
+ let braced: string | undefined
214
+ let bare: string | undefined
215
+ const equals = skipSpace(end)
216
+ if (text[equals] === "=") {
217
+ const value = skipSpace(equals + 1)
218
+ const open = text[value]
219
+ if (open === '"' || open === "'") {
220
+ const close = text.indexOf(open, value + 1)
221
+ const stop = close === -1 ? text.length : close
222
+ quoted = text.slice(value + 1, stop)
223
+ at = Math.min(stop + 1, text.length)
224
+ } else if (open === "{") {
225
+ const stop = markupEnd(text, value + 1, true)
226
+ const inner = text.slice(value + 1, Math.max(value + 1, stop - 1))
227
+ const literal = STRING_IN_BRACES.exec(inner.trim())
228
+ if (literal === null) braced = inner
229
+ else braceString = literal[1] ?? literal[2] ?? literal[3]
230
+ at = stop
231
+ } else {
232
+ let stop = value
233
+ while (stop < text.length && !/[\s"'<>`{}]/.test(text[stop] ?? "")) stop++
234
+ if (stop > value) bare = text.slice(value, stop)
235
+ at = Math.max(stop, equals + 1)
236
+ }
237
+ }
238
+ attributes.push({ name, at: start, quoted, braceString, braced, bare })
239
+ }
240
+ return attributes
241
+ }
242
+
243
+ /** The 1-based line of an offset in `text`: a search over the line starts, so a file with thousands of links is not re-split for each. */
244
+ export function lineLookup(text: string): (offset: number) => number {
245
+ const starts = [0]
246
+ for (let at = text.indexOf("\n"); at !== -1; at = text.indexOf("\n", at + 1)) starts.push(at + 1)
247
+ return (offset) => {
248
+ let low = 0
249
+ let high = starts.length - 1
250
+ while (low < high) {
251
+ const mid = (low + high + 1) >> 1
252
+ if ((starts[mid] ?? 0) <= offset) low = mid
253
+ else high = mid - 1
254
+ }
255
+ return low + 1
256
+ }
257
+ }
258
+
259
+ const TEST_DIR = /(?:^|\/)(?:tests?|__tests__)\//
260
+
261
+ /** The `.vue` and `.svelte` files under `root` that a lint reads, sorted, as `/` paths. */
262
+ export async function templateFiles(root: string): Promise<string[]> {
263
+ const files: string[] = []
264
+ for await (const entry of new Glob("**/*.{vue,svelte}").scan({ cwd: root, dot: false })) {
265
+ // Bun yields `\` paths on Windows, which IGNORED and TEST_DIR (and the reported location) expect as `/`.
266
+ const file = toPosix(entry)
267
+ if (!IGNORED.test(file) && !TEST_DIR.test(file)) files.push(file)
268
+ }
269
+ return files.sort()
270
+ }
@@ -553,8 +553,23 @@ async function createTypeScript7Session(
553
553
  const isParameter = (node: unknown): boolean => hasNodeKind(node, parameterKinds)
554
554
  const isStringLiteralLike = (node: unknown): boolean => hasNodeKind(node, stringLiteralKinds)
555
555
 
556
+ // TypeScript 7 renamed some guards and dropped the modifier helpers; the scanners use the 5/6 names.
557
+ // A missing one is a TypeError only on the input that reaches it, so each is listed here.
558
+ const isModifier = (node: unknown): boolean =>
559
+ typeof astModule.isModifier === "function" && astModule.isModifier(node) === true
560
+ const canHaveModifiers = (node: unknown): boolean => typeof node === "object" && node !== null
561
+ const getModifiers = (node: { readonly modifiers?: Iterable<unknown> }) => {
562
+ const modifiers = Array.from(node.modifiers ?? []).filter(isModifier)
563
+ return modifiers.length === 0 ? undefined : modifiers
564
+ }
565
+
556
566
  const facade: UnknownRecord = {
557
567
  ...astModule,
568
+ isTypeAssertionExpression: astModule.isTypeAssertion,
569
+ isMethodSignature: astModule.isMethodSignatureDeclaration,
570
+ isPropertySignature: astModule.isPropertySignatureDeclaration,
571
+ canHaveModifiers,
572
+ getModifiers,
558
573
  version,
559
574
  createSourceFile,
560
575
  forEachChild,