svelte-ast 0.0.0 → 0.12.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.
Files changed (53) hide show
  1. package/LICENSE +47 -1
  2. package/README.md +561 -2
  3. package/a11y.d.ts +1636 -0
  4. package/a11y.js +36 -0
  5. package/core.d.ts +1800 -0
  6. package/core.js +1 -0
  7. package/entities.d.ts +10 -0
  8. package/entities.js +1 -0
  9. package/index.d.ts +2844 -0
  10. package/index.js +1 -0
  11. package/is-valid-type.js +1 -0
  12. package/lexer.d.ts +224 -0
  13. package/lexer.js +3 -0
  14. package/module.d.ts +1243 -0
  15. package/module.js +1 -0
  16. package/package.json +72 -3
  17. package/parse-imports-exports.js +1 -0
  18. package/parse-module.js +1 -0
  19. package/parse-sections.js +1 -0
  20. package/parse.js +1 -0
  21. package/runes.js +1 -0
  22. package/scope.d.ts +1831 -0
  23. package/scope.js +1 -0
  24. package/shared-2yyqqbp5.js +2 -0
  25. package/shared-3654hw2t.js +2 -0
  26. package/shared-45k6qp45.js +2 -0
  27. package/shared-5tpb3h6x.js +2 -0
  28. package/shared-8598bnrd.js +2 -0
  29. package/shared-8gdz1w3m.js +2 -0
  30. package/shared-97v1a9gx.js +2 -0
  31. package/shared-a23q4q40.js +3 -0
  32. package/shared-bzqbnvee.js +2 -0
  33. package/shared-csw62q5w.js +2 -0
  34. package/shared-dgdrqgdn.js +2 -0
  35. package/shared-drb44hb9.js +2 -0
  36. package/shared-e4gbs4rb.js +3 -0
  37. package/shared-j53a13yb.js +3 -0
  38. package/shared-jqc2xr03.js +2 -0
  39. package/shared-jre53ftf.js +2 -0
  40. package/shared-m0dcdh24.js +5 -0
  41. package/shared-m3dr31c3.js +2 -0
  42. package/shared-n05mksm5.js +2 -0
  43. package/shared-np2e2ssk.js +2 -0
  44. package/shared-s46wfvhw.js +10 -0
  45. package/shared-tqkk8zh6.js +2 -0
  46. package/shared-w9n1rzqm.js +10 -0
  47. package/typescript.d.ts +10 -0
  48. package/typescript.js +1 -0
  49. package/walk.d.ts +2210 -0
  50. package/walk.js +1 -0
  51. package/warnings.d.ts +1680 -0
  52. package/warnings.js +6 -0
  53. package/index.ts +0 -1
package/index.d.ts ADDED
@@ -0,0 +1,2844 @@
1
+ /**
2
+ * Whether `text` is exactly one TypeScript type, e.g. a JSDoc `{"sm" | "lg"}`
3
+ * about to be copied into a `.d.ts`: the type on the right of
4
+ * `type T = ...`, with nothing before or after it but whitespace and
5
+ * comments. Parsed on its own, not wrapped in a statement, so a `;`, a line
6
+ * break or a `}` in `text` can't end the type and start something else.
7
+ */
8
+ export declare function isValidType(text: string, options?: {
9
+ /**
10
+ * `text` will be embedded before more code on the same line, e.g.
11
+ * `CustomEvent<${text}>`: also require every `//` comment in it to end
12
+ * with a line break, so it can't comment out what follows. Default
13
+ * `false`.
14
+ */
15
+ inline?: boolean;
16
+ }): boolean;
17
+
18
+ /** A module specifier: the string after `from`, or after `import` in `import "a"`. */
19
+ export interface LexedSource {
20
+ /** The string's value, with escapes decoded. */
21
+ value: string;
22
+ /** The offset of the opening quote. */
23
+ start: number;
24
+ /** The offset after the closing quote. */
25
+ end: number;
26
+ }
27
+
28
+ /** A name an `import` binds. */
29
+ export interface LexedImportSpecifier {
30
+ /** `"default"` for `a` in `import a from`, `"namespace"` for `* as a`, `"named"` for a name in braces. */
31
+ kind: "default" | "namespace" | "named";
32
+ /** The name in the imported module: `"default"`, `"*"` for a namespace, or the name before `as`, with a string's value for `"a-b" as c`. */
33
+ imported: string;
34
+ /** The name it's bound to in this module. */
35
+ local: string;
36
+ /** Whether it's only a type: in `import type`, or with `type` before it. */
37
+ typeOnly: boolean;
38
+ /** The offset of the name, of `*`, or of `type` before the name. */
39
+ start: number;
40
+ /** The offset after the local name. */
41
+ end: number;
42
+ }
43
+
44
+ /** A name an `export … from` re-exports, or, with `exportLists`, one an `export { … }` without `from` exports. */
45
+ export interface LexedExportSpecifier {
46
+ /** `"all"` for `export *`, `"namespace"` for `export * as a`, `"named"` for a name in braces, `"local"` for a name in an `export { … }` without `from`. */
47
+ kind: "all" | "namespace" | "named" | "local";
48
+ /** The name in the other module: `"*"` for `all` and `namespace`, or the name before `as`, with a string's value for `"a-b" as c`; for `local`, the binding in this module. */
49
+ local: string;
50
+ /** The name it's exported as, or `null` for `export *`. */
51
+ exported: string | null;
52
+ /** Whether it's only a type: in `export type`, or with `type` before it. */
53
+ typeOnly: boolean;
54
+ /** The offset of the name, of `*`, or of `type` before the name. */
55
+ start: number;
56
+ /** The offset after the exported name, or after `*` for `export *`. */
57
+ end: number;
58
+ }
59
+
60
+ interface LexedStatementBase {
61
+ /** The offset of `import` or `export`. */
62
+ start: number;
63
+ /** The offset after the statement's `;`, or its last token without one. */
64
+ end: number;
65
+ /** The module it imports from, or `null` for an `export { … }` without `from`, or a statement the lexer doesn't recognize. */
66
+ source: LexedSource | null;
67
+ /** Whether it's `import type` or `export type`. */
68
+ typeOnly: boolean;
69
+ }
70
+
71
+ /** An `import` statement. */
72
+ export interface LexedImport extends LexedStatementBase {
73
+ kind: "import";
74
+ specifiers: LexedImportSpecifier[];
75
+ }
76
+
77
+ /** An `export … from` statement, or, with `exportLists`, an `export { … }` without `from`. */
78
+ export interface LexedExport extends LexedStatementBase {
79
+ kind: "export";
80
+ specifiers: LexedExportSpecifier[];
81
+ }
82
+
83
+ export type LexedStatement = LexedImport | LexedExport;
84
+
85
+ /** Options for {@link lexImportsExports}. */
86
+ export interface LexImportsExportsOptions {
87
+ /** Also return the module's `export { a, b as c }` statements without `from`, whose specifiers have kind `"local"`. Default `false`. */
88
+ exportLists?: boolean;
89
+ }
90
+
91
+ /** An `import(…)`, a `require(…)` or Vite's `import.meta.glob(…)`. */
92
+ export interface LexedDynamicImport {
93
+ /** `"import"` for `import(…)`, `"require"` for `require(…)`, `"glob"` for `import.meta.glob(…)`. */
94
+ kind: "import" | "require" | "glob";
95
+ /** The first argument, if it's a string or a template without `${…}` followed by `)` or `,`; `null` for a computed one. A template's `start` and `end` include its backticks. */
96
+ source: LexedSource | null;
97
+ /** The offset of `import` or `require`. */
98
+ start: number;
99
+ /** The offset after the closing `)`, or the end of the module without one. */
100
+ end: number;
101
+ }
102
+
103
+ /** A string literal, or the text of a template literal between two of its delimiters. */
104
+ export interface LexedString {
105
+ /** `"string"` for a string literal, where `parseModule` has a `Literal`; `"template"` for a template's text, where it has a `TemplateElement`. */
106
+ kind: "string" | "template";
107
+ /** The value with escapes decoded, as a `Literal`'s `value` or a `TemplateElement`'s `value.cooked`: a template's line breaks read as `\n`. `null` for an escape that acorn rejects in a module, or that leaves a tagged template's `cooked` `null`. */
108
+ value: string | null;
109
+ /** The offset of the opening quote, or of a template's text, after its backtick or `}`. */
110
+ start: number;
111
+ /** The offset after the closing quote, or of the backtick or `${` after a template's text. */
112
+ end: number;
113
+ }
114
+
115
+ /**
116
+ * A module's top-level `import` statements and `export … from`
117
+ * re-exports, read without a parser: each statement's offsets, its
118
+ * source and the names it imports or re-exports. It finds statements as
119
+ * {@link parseImportsExports} does with `localExports: false`, and on
120
+ * every statement that accepts, gives the same offsets, sources and names,
121
+ * but it doesn't check syntax and never throws. A statement it can't read,
122
+ * including TypeScript's `import a = require("a")`, is returned with
123
+ * `source: null` and no specifiers, ending where it stopped reading.
124
+ * TypeScript's `type` forms are always read.
125
+ */
126
+ export declare function lexImportsExports(source: string, options?: LexImportsExportsOptions): LexedStatement[];
127
+
128
+ /**
129
+ * A module's `import(…)` and `require(…)` calls and Vite's
130
+ * `import.meta.glob(…)`, at any depth, in source order, read without a
131
+ * parser: each call's offsets and its first argument, if it's a string or
132
+ * a template without `${…}`. Comments, strings, templates and regular
133
+ * expressions are skipped, as {@link lexStrings} skips them, and it never
134
+ * throws. Where {@link parseModule} accepts the module, they are its
135
+ * `ImportExpression`s, its calls of an identifier `require` and of
136
+ * `import.meta.glob`, and, in TypeScript, its `import("a")` types and
137
+ * `import a = require("a")`. A method named `import` or `require` isn't a
138
+ * call.
139
+ */
140
+ export declare function lexDynamicImports(source: string): LexedDynamicImport[];
141
+
142
+ /**
143
+ * A module's string literals and the text of its template literals, in
144
+ * source order, read without a parser: the offsets and value of each
145
+ * `Literal` with a string value and each `TemplateElement` that
146
+ * {@link parseModule} returns, for a tool that only needs a script's
147
+ * strings, such as one that looks for class names. Comments and regular
148
+ * expressions are skipped, as `parseModule` skips them. It tells a regular
149
+ * expression from a division by the token before it, as acorn's tokenizer
150
+ * does, and doesn't check syntax, so it never throws. A template's raw
151
+ * text is `source.slice(start, end)`, with `\r\n` and `\r` as `\n`.
152
+ */
153
+ export declare function lexStrings(source: string): LexedString[];
154
+
155
+ /** An attribute of a top-level `<script>`, `<style>` or `<svelte:options>`. */
156
+ export interface LexedAttribute {
157
+ name: string;
158
+ /**
159
+ * The value as written, without its quotes: character references
160
+ * aren't decoded, and an expression keeps its braces, as in `"{true}"`
161
+ * for `runes={true}`. `true` for an attribute without a value.
162
+ */
163
+ value: string | true;
164
+ /** The offset of the name. */
165
+ start: number;
166
+ /** The offset after the value, or after the name without one. */
167
+ end: number;
168
+ }
169
+
170
+ /** The text between a top-level element's tags. */
171
+ export interface LexedContent {
172
+ start: number;
173
+ end: number;
174
+ }
175
+
176
+ /** A top-level `<script>`. */
177
+ export interface LexedScript {
178
+ /** The offset of `<script`. */
179
+ start: number;
180
+ /** The offset after `</script>`. */
181
+ end: number;
182
+ /** `"module"` for `<script module>` or `<script context="module">`. */
183
+ context: "default" | "module";
184
+ attributes: LexedAttribute[];
185
+ content: LexedContent;
186
+ }
187
+
188
+ /** The top-level `<style>`. */
189
+ export interface LexedStyle {
190
+ /** The offset of `<style`. */
191
+ start: number;
192
+ /** The offset after `</style>`. */
193
+ end: number;
194
+ attributes: LexedAttribute[];
195
+ content: LexedContent;
196
+ }
197
+
198
+ /** `<svelte:options>`. */
199
+ export interface LexedOptions {
200
+ /** The offset of `<svelte:options`. */
201
+ start: number;
202
+ /** The offset after `/>` or `</svelte:options>`. */
203
+ end: number;
204
+ attributes: LexedAttribute[];
205
+ }
206
+
207
+ /** A component's top-level sections, as {@link lexComponent} finds them. */
208
+ export interface LexedComponent {
209
+ /**
210
+ * Whether `parse` reads the component as TypeScript, which needs the
211
+ * TypeScript plugin: svelte decides it from the first `<script>` with a
212
+ * `lang`, so this is `true` when that one has `lang="ts"`.
213
+ */
214
+ typescript: boolean;
215
+ /** The `<script>` without `module`, as `parse`'s `instance`. */
216
+ instance: LexedScript | null;
217
+ /** The `<script module>`, as `parse`'s `module`. */
218
+ module: LexedScript | null;
219
+ /** The `<style>`, as `parse`'s `css`. */
220
+ css: LexedStyle | null;
221
+ /** `<svelte:options>`, as `parse`'s `options`. */
222
+ options: LexedOptions | null;
223
+ }
224
+
225
+ /**
226
+ * A component's top-level `<script>`, `<script module>`, `<style>` and
227
+ * `<svelte:options>`, with their attributes and the offsets of their tags
228
+ * and content, read without a parser: e.g. to find a component's
229
+ * language or imports, or to rewrite its scripts, without parsing the
230
+ * markup. The offsets are `parse`'s, so they're into the source without
231
+ * a leading byte order mark.
232
+ *
233
+ * The markup is skipped by tracking only tags, attribute values, blocks
234
+ * and the brackets, strings, comments and templates of each `{…}`
235
+ * expression, so a `<script>` inside an element, a block, a string or a
236
+ * comment isn't one. It stops after the last `<script`, `<style` or
237
+ * `<svelte:options`. Where `parse` accepts the component, the sections
238
+ * are the same as its `instance`, `module`, `css` and `options`; it
239
+ * doesn't check syntax and never throws.
240
+ */
241
+ export declare function lexComponent(input: string): LexedComponent;
242
+
243
+ /**
244
+ * Options for {@link parse}. The defaults give svelte's own output, minus
245
+ * `loc` and `name_loc`.
246
+ */
247
+ export interface ParseOptions {
248
+ /**
249
+ * Add `loc` (line/column) to script and expression nodes, and `name_loc`
250
+ * to elements, attributes and directives, as svelte does. Off by default:
251
+ * it makes parsing slower and the AST larger.
252
+ */
253
+ loc?: boolean;
254
+ /**
255
+ * Parse `<style>` into rules and selectors (`css.children`). With `false`,
256
+ * `css` still has its `start`, `end` and `content`, but `children` and
257
+ * `comments` are empty and CSS syntax errors aren't reported. Default `true`.
258
+ */
259
+ css?: boolean;
260
+ /**
261
+ * Parse each `<script>`'s JavaScript or TypeScript. With `false`, scripts
262
+ * keep their attributes and bounds, and `content` is a `Program` with its
263
+ * `start` and `end` but an empty `body`; their comments aren't in
264
+ * `comments`, and their syntax errors aren't reported. Expressions in the
265
+ * markup are still parsed. Default `true`.
266
+ */
267
+ script?: boolean;
268
+ /**
269
+ * Collect JavaScript comments, in scripts, expressions and tags, into
270
+ * `comments` and attach them to nodes as `leadingComments` and
271
+ * `trailingComments`. With `false`, `comments` is empty and no node has
272
+ * either field, including the HTML comment before a `<script>` that
273
+ * svelte copies into its `content.leadingComments`; HTML comments in the
274
+ * markup and CSS comments are kept. Default `true`.
275
+ */
276
+ comments?: boolean;
277
+ }
278
+
279
+ /** Options for {@link parseModule}. */
280
+ export interface ParseModuleOptions {
281
+ /** Parse TypeScript. Default `false`. */
282
+ typescript?: boolean;
283
+ /** Add `loc` (line/column) to every node. Default `false`. */
284
+ loc?: boolean;
285
+ /**
286
+ * Attach comments as `leadingComments`/`trailingComments`. With
287
+ * `false`, no node has either field. Default `true`.
288
+ */
289
+ comments?: boolean;
290
+ }
291
+
292
+ /** Options for {@link parseImportsExports}. */
293
+ export interface ParseImportsExportsOptions {
294
+ /**
295
+ * Parse TypeScript, e.g. `import type`, `export type` and
296
+ * `import a = require("a")`. Default `false`.
297
+ */
298
+ typescript?: boolean;
299
+ /**
300
+ * Return the `export` statements that export the module's own bindings,
301
+ * such as `export let a`, `export function b() {}`, `export { c }` and
302
+ * `export default d`. With `false`, only imports and the exports that
303
+ * have a `from`, such as `export * from "e"` and `export { f } from "f"`,
304
+ * are returned, and the rest is skipped like other code, which is faster
305
+ * when most statements are exported, as in a component's props.
306
+ * Default `true`.
307
+ */
308
+ localExports?: boolean;
309
+ }
310
+
311
+ /**
312
+ * Parses a Svelte component into svelte's modern AST, the same as
313
+ * `parse(source, { modern: true })` from svelte/compiler.
314
+ *
315
+ * Throws a {@link ParseError} on a syntax error.
316
+ */
317
+ export declare function parse(source: string, options?: ParseOptions): AST.Root;
318
+
319
+ type Namespace = "html" | "svg" | "mathml";
320
+
321
+ export declare namespace AST {
322
+ export interface BaseNode {
323
+ type: string;
324
+ start: number;
325
+ end: number;
326
+ }
327
+ export interface Fragment {
328
+ type: "Fragment";
329
+ nodes: Array<Text | Tag | ElementLike | Block | Comment>;
330
+ }
331
+ export interface Root extends BaseNode {
332
+ type: "Root";
333
+ /**
334
+ * Inline options provided by `<svelte:options>` — these override options passed to `compile(...)`
335
+ */
336
+ options: SvelteOptions | null;
337
+ fragment: Fragment;
338
+ /** The parsed `<style>` element, if exists */
339
+ css: AST.CSS.StyleSheet | null;
340
+ /** The parsed `<script>` element, if exists */
341
+ instance?: Script;
342
+ /** The parsed `<script module>` element, if exists */
343
+ module?: Script;
344
+ /** Comments found in <script> and {expressions} */
345
+ comments: JSComment[];
346
+ /** Always empty, as in svelte. */
347
+ js: [];
348
+ }
349
+ export interface SvelteOptions {
350
+ start: number;
351
+ end: number;
352
+ runes?: boolean;
353
+ immutable?: boolean;
354
+ accessors?: boolean;
355
+ preserveWhitespace?: boolean;
356
+ namespace?: Namespace;
357
+ css?: "injected";
358
+ customElement?: {
359
+ tag?: string;
360
+ shadow?: "open" | "none" | ObjectExpression | undefined;
361
+ props?: Record<string, {
362
+ attribute?: string;
363
+ reflect?: boolean;
364
+ type?: "Array" | "Boolean" | "Number" | "Object" | "String";
365
+ }>;
366
+ /**
367
+ * Is of type
368
+ * ```ts
369
+ * (ceClass: new () => HTMLElement) => new () => HTMLElement
370
+ * ```
371
+ */
372
+ extend?: ArrowFunctionExpression | Identifier;
373
+ };
374
+ attributes: Attribute[];
375
+ }
376
+ /** Static text */
377
+ export interface Text extends BaseNode {
378
+ type: "Text";
379
+ /** Text with decoded HTML entities */
380
+ data: string;
381
+ /** The original text, with undecoded HTML entities */
382
+ raw: string;
383
+ }
384
+ /** A (possibly reactive) template expression — `{...}` */
385
+ export interface ExpressionTag extends BaseNode {
386
+ type: "ExpressionTag";
387
+ expression: Expression;
388
+ }
389
+ /** A (possibly reactive) HTML template expression — `{@html ...}` */
390
+ export interface HtmlTag extends BaseNode {
391
+ type: "HtmlTag";
392
+ expression: Expression;
393
+ }
394
+ /** An HTML comment */
395
+ export interface Comment extends BaseNode {
396
+ type: "Comment";
397
+ /** the contents of the comment */
398
+ data: string;
399
+ }
400
+ /** A `{@const ...}` tag */
401
+ export interface ConstTag extends BaseNode {
402
+ type: "ConstTag";
403
+ declaration: VariableDeclaration & {
404
+ declarations: [VariableDeclarator & {
405
+ id: Pattern;
406
+ init: Expression;
407
+ }];
408
+ };
409
+ }
410
+ /** A `{let ...}` or `{const ...}` tag */
411
+ export interface DeclarationTag extends BaseNode {
412
+ type: "DeclarationTag";
413
+ declaration: VariableDeclaration;
414
+ }
415
+ /** A `{@debug ...}` tag */
416
+ export interface DebugTag extends BaseNode {
417
+ type: "DebugTag";
418
+ identifiers: Identifier[];
419
+ }
420
+ /** A `{@render foo(...)} tag */
421
+ export interface RenderTag extends BaseNode {
422
+ type: "RenderTag";
423
+ expression: SimpleCallExpression | (ChainExpression & {
424
+ expression: SimpleCallExpression;
425
+ });
426
+ }
427
+ /** A `{@attach foo(...)} tag */
428
+ export interface AttachTag extends BaseNode {
429
+ type: "AttachTag";
430
+ expression: Expression;
431
+ }
432
+ /** An `animate:` directive */
433
+ export interface AnimateDirective extends BaseAttribute {
434
+ type: "AnimateDirective";
435
+ /** The 'x' in `animate:x` */
436
+ name: string;
437
+ /** The y in `animate:x={y}` */
438
+ expression: null | Expression;
439
+ /** Parsed for every directive, e.g. `use:x|y`; svelte's types declare it only on some. */
440
+ modifiers: string[];
441
+ }
442
+ /** A `bind:` directive */
443
+ export interface BindDirective extends BaseAttribute {
444
+ type: "BindDirective";
445
+ /** The 'x' in `bind:x` */
446
+ name: string;
447
+ /** The y in `bind:x={y}` */
448
+ expression: Identifier | MemberExpression | SequenceExpression;
449
+ /** Parsed for every directive, e.g. `use:x|y`; svelte's types declare it only on some. */
450
+ modifiers: string[];
451
+ }
452
+ /** A `class:` directive */
453
+ export interface ClassDirective extends BaseAttribute {
454
+ type: "ClassDirective";
455
+ /** The 'x' in `class:x` */
456
+ name: "class";
457
+ /** The 'y' in `class:x={y}`, or the `x` in `class:x` */
458
+ expression: Expression;
459
+ /** Parsed for every directive, e.g. `use:x|y`; svelte's types declare it only on some. */
460
+ modifiers: string[];
461
+ }
462
+ /** A `let:` directive */
463
+ export interface LetDirective extends BaseAttribute {
464
+ type: "LetDirective";
465
+ /** The 'x' in `let:x` */
466
+ name: string;
467
+ /** The 'y' in `let:x={y}` */
468
+ expression: null | Identifier | ArrayExpression | ObjectExpression;
469
+ /** Parsed for every directive, e.g. `use:x|y`; svelte's types declare it only on some. */
470
+ modifiers: string[];
471
+ }
472
+ /** An `on:` directive */
473
+ export interface OnDirective extends BaseAttribute {
474
+ type: "OnDirective";
475
+ /** The 'x' in `on:x` */
476
+ name: string;
477
+ /** The 'y' in `on:x={y}` */
478
+ expression: null | Expression;
479
+ modifiers: Array<"capture" | "nonpassive" | "once" | "passive" | "preventDefault" | "self" | "stopImmediatePropagation" | "stopPropagation" | "trusted">;
480
+ }
481
+ /** A `style:` directive */
482
+ export interface StyleDirective extends BaseAttribute {
483
+ type: "StyleDirective";
484
+ /** The 'x' in `style:x` */
485
+ name: string;
486
+ /** The 'y' in `style:x={y}` */
487
+ value: true | ExpressionTag | Array<ExpressionTag | Text>;
488
+ modifiers: Array<"important">;
489
+ }
490
+ /** A `transition:`, `in:` or `out:` directive */
491
+ export interface TransitionDirective extends BaseAttribute {
492
+ type: "TransitionDirective";
493
+ /** The 'x' in `transition:x` */
494
+ name: string;
495
+ /** The 'y' in `transition:x={y}` */
496
+ expression: null | Expression;
497
+ modifiers: Array<"local" | "global">;
498
+ /** True if this is a `transition:` or `in:` directive */
499
+ intro: boolean;
500
+ /** True if this is a `transition:` or `out:` directive */
501
+ outro: boolean;
502
+ }
503
+ /** A `use:` directive */
504
+ export interface UseDirective extends BaseAttribute {
505
+ type: "UseDirective";
506
+ /** The 'x' in `use:x` */
507
+ name: string;
508
+ /** The 'y' in `use:x={y}` */
509
+ expression: null | Expression;
510
+ /** Parsed for every directive, e.g. `use:x|y`; svelte's types declare it only on some. */
511
+ modifiers: string[];
512
+ }
513
+ export interface BaseElement extends BaseNode {
514
+ name: string;
515
+ /** Only with `parse(source, { loc: true })`. */
516
+ name_loc?: SourceLocation;
517
+ attributes: Array<Attribute | SpreadAttribute | Directive | AttachTag>;
518
+ fragment: Fragment;
519
+ }
520
+ export interface Component extends BaseElement {
521
+ type: "Component";
522
+ }
523
+ export interface TitleElement extends BaseElement {
524
+ type: "TitleElement";
525
+ name: "title";
526
+ }
527
+ export interface SlotElement extends BaseElement {
528
+ type: "SlotElement";
529
+ name: "slot";
530
+ }
531
+ export interface RegularElement extends BaseElement {
532
+ type: "RegularElement";
533
+ }
534
+ export interface SvelteBody extends BaseElement {
535
+ type: "SvelteBody";
536
+ name: "svelte:body";
537
+ }
538
+ export interface SvelteComponent extends BaseElement {
539
+ type: "SvelteComponent";
540
+ name: "svelte:component";
541
+ expression: Expression;
542
+ }
543
+ export interface SvelteDocument extends BaseElement {
544
+ type: "SvelteDocument";
545
+ name: "svelte:document";
546
+ }
547
+ export interface SvelteElement extends BaseElement {
548
+ type: "SvelteElement";
549
+ name: "svelte:element";
550
+ tag: Expression;
551
+ }
552
+ export interface SvelteFragment extends BaseElement {
553
+ type: "SvelteFragment";
554
+ name: "svelte:fragment";
555
+ }
556
+ export interface SvelteBoundary extends BaseElement {
557
+ type: "SvelteBoundary";
558
+ name: "svelte:boundary";
559
+ }
560
+ export interface SvelteHead extends BaseElement {
561
+ type: "SvelteHead";
562
+ name: "svelte:head";
563
+ }
564
+ /** This is only an intermediate representation while parsing, it doesn't exist in the final AST */
565
+ export interface SvelteOptionsRaw extends BaseElement {
566
+ type: "SvelteOptions";
567
+ name: "svelte:options";
568
+ }
569
+ export interface SvelteSelf extends BaseElement {
570
+ type: "SvelteSelf";
571
+ name: "svelte:self";
572
+ }
573
+ export interface SvelteWindow extends BaseElement {
574
+ type: "SvelteWindow";
575
+ name: "svelte:window";
576
+ }
577
+ /** An `{#each ...}` block */
578
+ export interface EachBlock extends BaseNode {
579
+ type: "EachBlock";
580
+ expression: Expression;
581
+ /** The `entry` in `{#each item as entry}`. `null` if `as` part is omitted */
582
+ context: Pattern | null;
583
+ body: Fragment;
584
+ fallback?: Fragment;
585
+ index?: string;
586
+ key?: Expression;
587
+ }
588
+ /** An `{#if ...}` block */
589
+ export interface IfBlock extends BaseNode {
590
+ type: "IfBlock";
591
+ elseif: boolean;
592
+ test: Expression;
593
+ consequent: Fragment;
594
+ alternate: Fragment | null;
595
+ }
596
+ /** An `{#await ...}` block */
597
+ export interface AwaitBlock extends BaseNode {
598
+ type: "AwaitBlock";
599
+ expression: Expression;
600
+ /** The resolved value inside the `then` block */
601
+ value: Pattern | null;
602
+ /** The rejection reason inside the `catch` block */
603
+ error: Pattern | null;
604
+ pending: Fragment | null;
605
+ then: Fragment | null;
606
+ catch: Fragment | null;
607
+ }
608
+ export interface KeyBlock extends BaseNode {
609
+ type: "KeyBlock";
610
+ expression: Expression;
611
+ fragment: Fragment;
612
+ }
613
+ export interface SnippetBlock extends BaseNode {
614
+ type: "SnippetBlock";
615
+ expression: Identifier;
616
+ parameters: Pattern[];
617
+ typeParams?: string;
618
+ body: Fragment;
619
+ }
620
+ export interface BaseAttribute extends BaseNode {
621
+ name: string;
622
+ /** Only with `parse(source, { loc: true })`. */
623
+ name_loc?: SourceLocation | null;
624
+ }
625
+ export interface Attribute extends BaseAttribute {
626
+ type: "Attribute";
627
+ /**
628
+ * Quoted/string values are represented by an array, even if they contain a single expression like `"{x}"`
629
+ */
630
+ value: true | ExpressionTag | Array<Text | ExpressionTag>;
631
+ }
632
+ export interface SpreadAttribute extends BaseNode {
633
+ type: "SpreadAttribute";
634
+ expression: Expression;
635
+ }
636
+ export interface Script extends BaseNode {
637
+ type: "Script";
638
+ context: "default" | "module";
639
+ content: Program;
640
+ attributes: Attribute[];
641
+ }
642
+ export interface JSComment {
643
+ type: "Line" | "Block";
644
+ value: string;
645
+ start: number;
646
+ end: number;
647
+ /** Only with `parse(source, { loc: true })`. */
648
+ loc?: {
649
+ start: {
650
+ line: number;
651
+ column: number;
652
+ };
653
+ end: {
654
+ line: number;
655
+ column: number;
656
+ };
657
+ };
658
+ }
659
+ export type AttributeLike = Attribute | SpreadAttribute | Directive;
660
+ export type Directive = AST.AnimateDirective | AST.BindDirective | AST.ClassDirective | AST.LetDirective | AST.OnDirective | AST.StyleDirective | AST.TransitionDirective | AST.UseDirective;
661
+ export type Block = AST.EachBlock | AST.IfBlock | AST.AwaitBlock | AST.KeyBlock | AST.SnippetBlock;
662
+ export type ElementLike = AST.Component | AST.TitleElement | AST.SlotElement | AST.RegularElement | AST.SvelteBody | AST.SvelteBoundary | AST.SvelteComponent | AST.SvelteDocument | AST.SvelteElement | AST.SvelteFragment | AST.SvelteHead | AST.SvelteOptionsRaw | AST.SvelteSelf | AST.SvelteWindow | AST.SvelteBoundary;
663
+ export type Tag = AST.AttachTag | AST.ConstTag | AST.DeclarationTag | AST.DebugTag | AST.ExpressionTag | AST.HtmlTag | AST.RenderTag;
664
+ export type TemplateNode = AST.Root | AST.Text | Tag | ElementLike | AST.Attribute | AST.SpreadAttribute | Directive | AST.AttachTag | AST.Comment | Block;
665
+ export type SvelteNode = Node | TemplateNode | AST.Fragment | _CSS.Node | Script;
666
+ export type { _CSS as CSS };
667
+ }
668
+
669
+ declare namespace _CSS {
670
+ interface BaseNode {
671
+ start: number;
672
+ end: number;
673
+ }
674
+ interface StyleSheetBase extends BaseNode {
675
+ children: Array<Atrule | Rule>;
676
+ /** CSS comments in source order */
677
+ comments: CSSComment[];
678
+ }
679
+ interface CSSComment extends BaseNode {
680
+ type: "CSSComment";
681
+ value: string;
682
+ /** Character offset in a containing declaration value or at-rule prelude */
683
+ position?: number;
684
+ }
685
+ interface StyleSheetFile extends StyleSheetBase {
686
+ type: "StyleSheetFile";
687
+ }
688
+ interface StyleSheet extends StyleSheetBase {
689
+ type: "StyleSheet";
690
+ attributes: any[];
691
+ content: {
692
+ start: number;
693
+ end: number;
694
+ styles: string;
695
+ /** Possible comment atop the style tag */
696
+ comment: AST.Comment | null;
697
+ };
698
+ }
699
+ interface Atrule extends BaseNode {
700
+ type: "Atrule";
701
+ name: string;
702
+ prelude: string;
703
+ block: Block | null;
704
+ }
705
+ interface Rule extends BaseNode {
706
+ type: "Rule";
707
+ prelude: SelectorList;
708
+ block: Block;
709
+ }
710
+ /**
711
+ * A list of selectors, e.g. `a, b, c {}`
712
+ */
713
+ interface SelectorList extends BaseNode {
714
+ type: "SelectorList";
715
+ /**
716
+ * The `a`, `b` and `c` in `a, b, c {}`
717
+ */
718
+ children: ComplexSelector[];
719
+ }
720
+ /**
721
+ * A complex selector, e.g. `a b c {}`
722
+ */
723
+ interface ComplexSelector extends BaseNode {
724
+ type: "ComplexSelector";
725
+ /**
726
+ * The `a`, `b` and `c` in `a b c {}`
727
+ */
728
+ children: RelativeSelector[];
729
+ }
730
+ /**
731
+ * A relative selector, e.g the `a` and `> b` in `a > b {}`
732
+ */
733
+ interface RelativeSelector extends BaseNode {
734
+ type: "RelativeSelector";
735
+ /**
736
+ * In `a > b`, `> b` forms one relative selector, and `>` is the combinator. `null` for the first selector.
737
+ */
738
+ combinator: null | Combinator;
739
+ /**
740
+ * The `b:is(...)` in `> b:is(...)`
741
+ */
742
+ selectors: SimpleSelector[];
743
+ }
744
+ interface TypeSelector extends BaseNode {
745
+ type: "TypeSelector";
746
+ name: string;
747
+ namespace?: string;
748
+ }
749
+ interface IdSelector extends BaseNode {
750
+ type: "IdSelector";
751
+ name: string;
752
+ }
753
+ interface ClassSelector extends BaseNode {
754
+ type: "ClassSelector";
755
+ name: string;
756
+ }
757
+ interface AttributeSelector extends BaseNode {
758
+ type: "AttributeSelector";
759
+ name: string;
760
+ matcher: string | null;
761
+ value: string | null;
762
+ flags: string | null;
763
+ }
764
+ interface PseudoElementSelector extends BaseNode {
765
+ type: "PseudoElementSelector";
766
+ name: string;
767
+ args?: SelectorList;
768
+ }
769
+ interface PseudoClassSelector extends BaseNode {
770
+ type: "PseudoClassSelector";
771
+ name: string;
772
+ args: SelectorList | null;
773
+ }
774
+ interface Percentage extends BaseNode {
775
+ type: "Percentage";
776
+ value: string;
777
+ }
778
+ interface NestingSelector extends BaseNode {
779
+ type: "NestingSelector";
780
+ name: "&";
781
+ }
782
+ interface Nth extends BaseNode {
783
+ type: "Nth";
784
+ value: string;
785
+ }
786
+ type SimpleSelector = TypeSelector | IdSelector | ClassSelector | AttributeSelector | PseudoElementSelector | PseudoClassSelector | Percentage | Nth | NestingSelector;
787
+ interface Combinator extends BaseNode {
788
+ type: "Combinator";
789
+ name: string;
790
+ }
791
+ interface Block extends BaseNode {
792
+ type: "Block";
793
+ children: Array<Declaration | Rule | Atrule>;
794
+ }
795
+ interface Declaration extends BaseNode {
796
+ type: "Declaration";
797
+ property: string;
798
+ value: string;
799
+ }
800
+ type Node = StyleSheet | Rule | Atrule | SelectorList | Block | ComplexSelector | RelativeSelector | Combinator | SimpleSelector | Declaration;
801
+ }
802
+
803
+ export interface BaseNodeWithoutComments {
804
+ type: string;
805
+ start: number;
806
+ end: number;
807
+ loc?: SourceLocation | null | undefined;
808
+ range?: [number, number] | undefined;
809
+ }
810
+
811
+ export interface BaseNode extends BaseNodeWithoutComments {
812
+ leadingComments?: Comment[] | undefined;
813
+ trailingComments?: Comment[] | undefined;
814
+ }
815
+
816
+ export interface NodeMap {
817
+ AssignmentProperty: AssignmentProperty;
818
+ CatchClause: CatchClause;
819
+ Class: Class;
820
+ ClassBody: ClassBody;
821
+ Expression: Expression;
822
+ Function: Function;
823
+ Identifier: Identifier;
824
+ Literal: Literal;
825
+ MethodDefinition: MethodDefinition;
826
+ ModuleDeclaration: ModuleDeclaration;
827
+ ModuleSpecifier: ModuleSpecifier;
828
+ Pattern: Pattern;
829
+ PrivateIdentifier: PrivateIdentifier;
830
+ Program: Program;
831
+ Property: Property;
832
+ PropertyDefinition: PropertyDefinition;
833
+ SpreadElement: SpreadElement;
834
+ Statement: Statement;
835
+ Super: Super;
836
+ SwitchCase: SwitchCase;
837
+ TemplateElement: TemplateElement;
838
+ VariableDeclarator: VariableDeclarator;
839
+ ImportAttribute: ImportAttribute;
840
+ TSNode: TSNode;
841
+ }
842
+
843
+ export type Node = NodeMap[keyof NodeMap];
844
+
845
+ export interface Comment extends BaseNodeWithoutComments {
846
+ type: "Line" | "Block";
847
+ value: string;
848
+ }
849
+
850
+ export interface SourceLocation {
851
+ source?: string | null | undefined;
852
+ start: Position;
853
+ end: Position;
854
+ }
855
+
856
+ export interface Position {
857
+ /** >= 1 */
858
+ line: number;
859
+ /** >= 0 */
860
+ column: number;
861
+ }
862
+
863
+ export interface Program extends Omit<BaseNode, "leadingComments"> {
864
+ type: "Program";
865
+ sourceType: "script" | "module";
866
+ body: Array<Directive | Statement | ModuleDeclaration>;
867
+ comments?: Comment[] | undefined;
868
+ /** In a component's `<script>`, an HTML comment right before the tag becomes `{ type: "Line", value }`, without offsets, as in svelte. */
869
+ leadingComments?: Array<Comment | {
870
+ type: "Line";
871
+ value: string;
872
+ }> | undefined;
873
+ }
874
+
875
+ export interface Directive extends BaseNode {
876
+ type: "ExpressionStatement";
877
+ expression: Literal;
878
+ directive: string;
879
+ }
880
+
881
+ export interface BaseFunction extends BaseNode, TSFunctionFields {
882
+ params: Array<Pattern | TSParameterProperty>;
883
+ generator?: boolean | undefined;
884
+ async?: boolean | undefined;
885
+ body: BlockStatement | Expression;
886
+ }
887
+
888
+ export type Function = FunctionDeclaration | FunctionExpression | ArrowFunctionExpression;
889
+
890
+ export type Statement = ExpressionStatement | BlockStatement | StaticBlock | EmptyStatement | DebuggerStatement | WithStatement | ReturnStatement | LabeledStatement | BreakStatement | ContinueStatement | IfStatement | SwitchStatement | ThrowStatement | TryStatement | WhileStatement | DoWhileStatement | ForStatement | ForInStatement | ForOfStatement | Declaration;
891
+
892
+ export interface BaseStatement extends BaseNode {
893
+ }
894
+
895
+ export interface EmptyStatement extends BaseStatement {
896
+ type: "EmptyStatement";
897
+ }
898
+
899
+ export interface BlockStatement extends BaseStatement {
900
+ type: "BlockStatement";
901
+ body: Statement[];
902
+ innerComments?: Comment[] | undefined;
903
+ }
904
+
905
+ export interface StaticBlock extends Omit<BlockStatement, "type"> {
906
+ type: "StaticBlock";
907
+ }
908
+
909
+ export interface ExpressionStatement extends BaseStatement {
910
+ type: "ExpressionStatement";
911
+ expression: Expression;
912
+ }
913
+
914
+ export interface IfStatement extends BaseStatement {
915
+ type: "IfStatement";
916
+ test: Expression;
917
+ consequent: Statement;
918
+ alternate?: Statement | null | undefined;
919
+ }
920
+
921
+ export interface LabeledStatement extends BaseStatement {
922
+ type: "LabeledStatement";
923
+ label: Identifier;
924
+ body: Statement;
925
+ }
926
+
927
+ export interface BreakStatement extends BaseStatement {
928
+ type: "BreakStatement";
929
+ label?: Identifier | null | undefined;
930
+ }
931
+
932
+ export interface ContinueStatement extends BaseStatement {
933
+ type: "ContinueStatement";
934
+ label?: Identifier | null | undefined;
935
+ }
936
+
937
+ export interface WithStatement extends BaseStatement {
938
+ type: "WithStatement";
939
+ object: Expression;
940
+ body: Statement;
941
+ }
942
+
943
+ export interface SwitchStatement extends BaseStatement {
944
+ type: "SwitchStatement";
945
+ discriminant: Expression;
946
+ cases: SwitchCase[];
947
+ }
948
+
949
+ export interface ReturnStatement extends BaseStatement {
950
+ type: "ReturnStatement";
951
+ argument?: Expression | null | undefined;
952
+ }
953
+
954
+ export interface ThrowStatement extends BaseStatement {
955
+ type: "ThrowStatement";
956
+ argument: Expression;
957
+ }
958
+
959
+ export interface TryStatement extends BaseStatement {
960
+ type: "TryStatement";
961
+ block: BlockStatement;
962
+ handler?: CatchClause | null | undefined;
963
+ finalizer?: BlockStatement | null | undefined;
964
+ }
965
+
966
+ export interface WhileStatement extends BaseStatement {
967
+ type: "WhileStatement";
968
+ test: Expression;
969
+ body: Statement;
970
+ }
971
+
972
+ export interface DoWhileStatement extends BaseStatement {
973
+ type: "DoWhileStatement";
974
+ body: Statement;
975
+ test: Expression;
976
+ }
977
+
978
+ export interface ForStatement extends BaseStatement {
979
+ type: "ForStatement";
980
+ init?: VariableDeclaration | Expression | null | undefined;
981
+ test?: Expression | null | undefined;
982
+ update?: Expression | null | undefined;
983
+ body: Statement;
984
+ }
985
+
986
+ export interface BaseForXStatement extends BaseStatement {
987
+ left: VariableDeclaration | Pattern;
988
+ right: Expression;
989
+ body: Statement;
990
+ }
991
+
992
+ export interface ForInStatement extends BaseForXStatement {
993
+ type: "ForInStatement";
994
+ }
995
+
996
+ export interface DebuggerStatement extends BaseStatement {
997
+ type: "DebuggerStatement";
998
+ }
999
+
1000
+ export type Declaration = FunctionDeclaration | VariableDeclaration | ClassDeclaration | TSDeclaration;
1001
+
1002
+ export interface BaseDeclaration extends BaseStatement {
1003
+ }
1004
+
1005
+ export interface MaybeNamedFunctionDeclaration extends BaseFunction, BaseDeclaration {
1006
+ type: "FunctionDeclaration";
1007
+ /** It is null when a function declaration is a part of the `export default function` statement */
1008
+ id: Identifier | null;
1009
+ body: BlockStatement;
1010
+ expression: false;
1011
+ /** No `TSParameterProperty`: `private x` only parses in a class constructor, a `FunctionExpression`. */
1012
+ params: Pattern[];
1013
+ }
1014
+
1015
+ export interface FunctionDeclaration extends MaybeNamedFunctionDeclaration {
1016
+ id: Identifier;
1017
+ }
1018
+
1019
+ export interface VariableDeclaration extends BaseDeclaration {
1020
+ type: "VariableDeclaration";
1021
+ declarations: VariableDeclarator[];
1022
+ kind: "var" | "let" | "const" | "using" | "await using";
1023
+ declare?: boolean;
1024
+ }
1025
+
1026
+ export interface VariableDeclarator extends BaseNode {
1027
+ type: "VariableDeclarator";
1028
+ id: Pattern;
1029
+ init?: Expression | null | undefined;
1030
+ definite?: boolean;
1031
+ }
1032
+
1033
+ export interface ExpressionMap {
1034
+ ArrayExpression: ArrayExpression;
1035
+ ArrowFunctionExpression: ArrowFunctionExpression;
1036
+ AssignmentExpression: AssignmentExpression;
1037
+ AwaitExpression: AwaitExpression;
1038
+ BinaryExpression: BinaryExpression;
1039
+ CallExpression: CallExpression;
1040
+ ChainExpression: ChainExpression;
1041
+ ClassExpression: ClassExpression;
1042
+ ConditionalExpression: ConditionalExpression;
1043
+ FunctionExpression: FunctionExpression;
1044
+ Identifier: Identifier;
1045
+ ImportExpression: ImportExpression;
1046
+ Literal: Literal;
1047
+ LogicalExpression: LogicalExpression;
1048
+ MemberExpression: MemberExpression;
1049
+ MetaProperty: MetaProperty;
1050
+ NewExpression: NewExpression;
1051
+ ObjectExpression: ObjectExpression;
1052
+ SequenceExpression: SequenceExpression;
1053
+ TaggedTemplateExpression: TaggedTemplateExpression;
1054
+ TemplateLiteral: TemplateLiteral;
1055
+ ThisExpression: ThisExpression;
1056
+ UnaryExpression: UnaryExpression;
1057
+ UpdateExpression: UpdateExpression;
1058
+ YieldExpression: YieldExpression;
1059
+ TSExpression: TSExpression;
1060
+ }
1061
+
1062
+ export type Expression = ExpressionMap[keyof ExpressionMap];
1063
+
1064
+ export interface BaseExpression extends BaseNode {
1065
+ }
1066
+
1067
+ export type ChainElement = SimpleCallExpression | MemberExpression;
1068
+
1069
+ export interface ChainExpression extends BaseExpression {
1070
+ type: "ChainExpression";
1071
+ expression: ChainElement;
1072
+ }
1073
+
1074
+ export interface ThisExpression extends BaseExpression {
1075
+ type: "ThisExpression";
1076
+ }
1077
+
1078
+ export interface ArrayExpression extends BaseExpression {
1079
+ type: "ArrayExpression";
1080
+ elements: Array<Expression | SpreadElement | null>;
1081
+ }
1082
+
1083
+ export interface ObjectExpression extends BaseExpression {
1084
+ type: "ObjectExpression";
1085
+ properties: Array<Property | SpreadElement>;
1086
+ }
1087
+
1088
+ export interface PrivateIdentifier extends BaseNode {
1089
+ type: "PrivateIdentifier";
1090
+ name: string;
1091
+ }
1092
+
1093
+ export interface Property extends BaseNode {
1094
+ type: "Property";
1095
+ key: Expression;
1096
+ value: Expression | Pattern;
1097
+ kind: "init" | "get" | "set";
1098
+ method: boolean;
1099
+ shorthand: boolean;
1100
+ computed: boolean;
1101
+ decorators?: Decorator[];
1102
+ }
1103
+
1104
+ export interface PropertyDefinition extends BaseNode, TSClassMemberFields {
1105
+ type: "PropertyDefinition";
1106
+ key: Expression | PrivateIdentifier;
1107
+ value?: Expression | null | undefined;
1108
+ computed: boolean;
1109
+ static: boolean;
1110
+ typeAnnotation?: TSTypeAnnotation;
1111
+ definite?: boolean;
1112
+ }
1113
+
1114
+ export interface FunctionExpression extends BaseFunction, BaseExpression {
1115
+ id?: Identifier | null | undefined;
1116
+ type: "FunctionExpression";
1117
+ body: BlockStatement;
1118
+ expression: false;
1119
+ }
1120
+
1121
+ export interface SequenceExpression extends BaseExpression {
1122
+ type: "SequenceExpression";
1123
+ expressions: Expression[];
1124
+ }
1125
+
1126
+ export interface UnaryExpression extends BaseExpression {
1127
+ type: "UnaryExpression";
1128
+ operator: UnaryOperator;
1129
+ prefix: true;
1130
+ argument: Expression;
1131
+ }
1132
+
1133
+ export interface BinaryExpression extends BaseExpression {
1134
+ type: "BinaryExpression";
1135
+ operator: BinaryOperator;
1136
+ left: Expression | PrivateIdentifier;
1137
+ right: Expression;
1138
+ }
1139
+
1140
+ export interface AssignmentExpression extends BaseExpression {
1141
+ type: "AssignmentExpression";
1142
+ operator: AssignmentOperator;
1143
+ left: Pattern | MemberExpression | TSAsExpression | TSNonNullExpression | TSSatisfiesExpression | TSTypeAssertion;
1144
+ right: Expression;
1145
+ }
1146
+
1147
+ export interface UpdateExpression extends BaseExpression {
1148
+ type: "UpdateExpression";
1149
+ operator: UpdateOperator;
1150
+ argument: Expression;
1151
+ prefix: boolean;
1152
+ }
1153
+
1154
+ export interface LogicalExpression extends BaseExpression {
1155
+ type: "LogicalExpression";
1156
+ operator: LogicalOperator;
1157
+ left: Expression;
1158
+ right: Expression;
1159
+ }
1160
+
1161
+ export interface ConditionalExpression extends BaseExpression {
1162
+ type: "ConditionalExpression";
1163
+ test: Expression;
1164
+ alternate: Expression;
1165
+ consequent: Expression;
1166
+ }
1167
+
1168
+ export interface BaseCallExpression extends BaseExpression {
1169
+ callee: Expression | Super;
1170
+ arguments: Array<Expression | SpreadElement>;
1171
+ typeArguments?: TSTypeParameterInstantiation;
1172
+ }
1173
+
1174
+ export type CallExpression = SimpleCallExpression | NewExpression;
1175
+
1176
+ export interface SimpleCallExpression extends BaseCallExpression {
1177
+ type: "CallExpression";
1178
+ /** Absent in a decorator, and on a call with type arguments, as in acorn-typescript. */
1179
+ optional?: boolean;
1180
+ }
1181
+
1182
+ export interface NewExpression extends BaseCallExpression {
1183
+ type: "NewExpression";
1184
+ }
1185
+
1186
+ export interface MemberExpression extends BaseExpression, BasePattern {
1187
+ type: "MemberExpression";
1188
+ object: Expression | Super;
1189
+ property: Expression | PrivateIdentifier;
1190
+ computed: boolean;
1191
+ /** Absent in a decorator, and on a call with type arguments, as in acorn-typescript. */
1192
+ optional?: boolean;
1193
+ }
1194
+
1195
+ export type Pattern = Identifier | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | MemberExpression;
1196
+
1197
+ export interface BasePattern extends BaseNode {
1198
+ }
1199
+
1200
+ export interface SwitchCase extends BaseNode {
1201
+ type: "SwitchCase";
1202
+ test?: Expression | null | undefined;
1203
+ consequent: Statement[];
1204
+ }
1205
+
1206
+ export interface CatchClause extends BaseNode {
1207
+ type: "CatchClause";
1208
+ param: Pattern | null;
1209
+ body: BlockStatement;
1210
+ }
1211
+
1212
+ export interface Identifier extends BaseNode, BaseExpression, BasePattern, TSBindingFields {
1213
+ type: "Identifier";
1214
+ name: string;
1215
+ }
1216
+
1217
+ export type Literal = SimpleLiteral | RegExpLiteral | BigIntLiteral;
1218
+
1219
+ export interface SimpleLiteral extends BaseNode, BaseExpression {
1220
+ type: "Literal";
1221
+ value: string | boolean | number | null;
1222
+ raw?: string | undefined;
1223
+ }
1224
+
1225
+ /** A string `Literal`: a module specifier, an import attribute, or a quoted module export name. */
1226
+ export interface StringLiteral extends SimpleLiteral {
1227
+ value: string;
1228
+ }
1229
+
1230
+ export interface RegExpLiteral extends BaseNode, BaseExpression {
1231
+ type: "Literal";
1232
+ value?: RegExp | null | undefined;
1233
+ regex: {
1234
+ pattern: string;
1235
+ flags: string;
1236
+ };
1237
+ raw?: string | undefined;
1238
+ }
1239
+
1240
+ export interface BigIntLiteral extends BaseNode, BaseExpression {
1241
+ type: "Literal";
1242
+ value?: bigint | null | undefined;
1243
+ bigint: string;
1244
+ raw?: string | undefined;
1245
+ }
1246
+
1247
+ export type UnaryOperator = "-" | "+" | "!" | "~" | "typeof" | "void" | "delete";
1248
+
1249
+ export type BinaryOperator = "==" | "!=" | "===" | "!==" | "<" | "<=" | ">" | ">=" | "<<" | ">>" | ">>>" | "+" | "-" | "*" | "/" | "%" | "**" | "|" | "^" | "&" | "in" | "instanceof";
1250
+
1251
+ export type LogicalOperator = "||" | "&&" | "??";
1252
+
1253
+ export type AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "**=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&=" | "||=" | "&&=" | "??=";
1254
+
1255
+ export type UpdateOperator = "++" | "--";
1256
+
1257
+ export interface ForOfStatement extends BaseForXStatement {
1258
+ type: "ForOfStatement";
1259
+ await: boolean;
1260
+ }
1261
+
1262
+ export interface Super extends BaseNode {
1263
+ type: "Super";
1264
+ }
1265
+
1266
+ export interface SpreadElement extends BaseNode {
1267
+ type: "SpreadElement";
1268
+ argument: Expression;
1269
+ }
1270
+
1271
+ export interface ArrowFunctionExpression extends BaseExpression, BaseFunction {
1272
+ type: "ArrowFunctionExpression";
1273
+ expression: boolean;
1274
+ body: BlockStatement | Expression;
1275
+ id: null;
1276
+ /** No `TSParameterProperty`: `private x` only parses in a class constructor, a `FunctionExpression`. */
1277
+ params: Pattern[];
1278
+ }
1279
+
1280
+ export interface YieldExpression extends BaseExpression {
1281
+ type: "YieldExpression";
1282
+ argument?: Expression | null | undefined;
1283
+ delegate: boolean;
1284
+ }
1285
+
1286
+ export interface TemplateLiteral extends BaseExpression {
1287
+ type: "TemplateLiteral";
1288
+ quasis: TemplateElement[];
1289
+ expressions: Expression[];
1290
+ }
1291
+
1292
+ export interface TaggedTemplateExpression extends BaseExpression {
1293
+ type: "TaggedTemplateExpression";
1294
+ tag: Expression;
1295
+ quasi: TemplateLiteral;
1296
+ typeArguments?: TSTypeParameterInstantiation;
1297
+ }
1298
+
1299
+ export interface TemplateElement extends BaseNode {
1300
+ type: "TemplateElement";
1301
+ tail: boolean;
1302
+ value: {
1303
+ /** It is null when the template literal is tagged and the text has an invalid escape (e.g. - tag`\unicode and \u{55}`) */
1304
+ cooked?: string | null | undefined;
1305
+ raw: string;
1306
+ };
1307
+ }
1308
+
1309
+ export interface AssignmentProperty extends Property {
1310
+ value: Pattern;
1311
+ kind: "init";
1312
+ method: boolean;
1313
+ }
1314
+
1315
+ export interface ObjectPattern extends BasePattern, TSBindingFields {
1316
+ type: "ObjectPattern";
1317
+ properties: Array<AssignmentProperty | RestElement>;
1318
+ }
1319
+
1320
+ export interface ArrayPattern extends BasePattern, TSBindingFields {
1321
+ type: "ArrayPattern";
1322
+ elements: Array<Pattern | null>;
1323
+ }
1324
+
1325
+ export interface RestElement extends BasePattern, TSBindingFields {
1326
+ type: "RestElement";
1327
+ argument: Pattern;
1328
+ }
1329
+
1330
+ export interface AssignmentPattern extends BasePattern {
1331
+ type: "AssignmentPattern";
1332
+ left: Pattern;
1333
+ right: Expression;
1334
+ decorators?: Decorator[];
1335
+ }
1336
+
1337
+ export type Class = ClassDeclaration | ClassExpression;
1338
+
1339
+ export interface BaseClass extends BaseNode, TSClassFields {
1340
+ superClass?: Expression | null | undefined;
1341
+ body: ClassBody;
1342
+ }
1343
+
1344
+ export interface ClassBody extends BaseNode {
1345
+ type: "ClassBody";
1346
+ body: Array<MethodDefinition | PropertyDefinition | StaticBlock | TSIndexSignature>;
1347
+ }
1348
+
1349
+ export interface MethodDefinition extends BaseNode, TSClassMemberFields {
1350
+ type: "MethodDefinition";
1351
+ key: Expression | PrivateIdentifier;
1352
+ value: FunctionExpression | TSDeclareMethod;
1353
+ kind: "constructor" | "method" | "get" | "set";
1354
+ computed: boolean;
1355
+ static: boolean;
1356
+ typeParameters?: TSTypeParameterDeclaration;
1357
+ }
1358
+
1359
+ export interface MaybeNamedClassDeclaration extends BaseClass, BaseDeclaration {
1360
+ type: "ClassDeclaration";
1361
+ /** It is null when a class declaration is a part of the `export default class` statement */
1362
+ id: Identifier | null;
1363
+ }
1364
+
1365
+ export interface ClassDeclaration extends MaybeNamedClassDeclaration {
1366
+ id: Identifier;
1367
+ }
1368
+
1369
+ export interface ClassExpression extends BaseClass, BaseExpression {
1370
+ type: "ClassExpression";
1371
+ id?: Identifier | null | undefined;
1372
+ }
1373
+
1374
+ export interface MetaProperty extends BaseExpression {
1375
+ type: "MetaProperty";
1376
+ meta: Identifier;
1377
+ property: Identifier;
1378
+ }
1379
+
1380
+ export type ModuleDeclaration = ImportDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration | TSModuleDeclarationStatement;
1381
+
1382
+ export interface BaseModuleDeclaration extends BaseNode {
1383
+ }
1384
+
1385
+ export type ModuleSpecifier = ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier;
1386
+
1387
+ export interface BaseModuleSpecifier extends BaseNode {
1388
+ local: Identifier;
1389
+ }
1390
+
1391
+ export interface ImportDeclaration extends BaseModuleDeclaration {
1392
+ type: "ImportDeclaration";
1393
+ specifiers: Array<ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier>;
1394
+ /** Absent with `typescript: true` unless there's a `with` clause, as in acorn-typescript. */
1395
+ attributes?: ImportAttribute[] | undefined;
1396
+ source: StringLiteral;
1397
+ importKind?: "type" | "value";
1398
+ }
1399
+
1400
+ export interface ImportSpecifier extends BaseModuleSpecifier {
1401
+ type: "ImportSpecifier";
1402
+ imported: Identifier | StringLiteral;
1403
+ importKind?: "type" | "value";
1404
+ }
1405
+
1406
+ export interface ImportAttribute extends BaseNode {
1407
+ type: "ImportAttribute";
1408
+ key: Identifier | StringLiteral;
1409
+ value: StringLiteral;
1410
+ }
1411
+
1412
+ export interface ImportExpression extends BaseExpression {
1413
+ type: "ImportExpression";
1414
+ source: Expression;
1415
+ options?: Expression | null | undefined;
1416
+ /** The import attributes, with `typescript: true`; `options` otherwise. */
1417
+ arguments?: Expression[];
1418
+ }
1419
+
1420
+ export interface ImportDefaultSpecifier extends BaseModuleSpecifier {
1421
+ type: "ImportDefaultSpecifier";
1422
+ }
1423
+
1424
+ export interface ImportNamespaceSpecifier extends BaseModuleSpecifier {
1425
+ type: "ImportNamespaceSpecifier";
1426
+ }
1427
+
1428
+ export interface ExportNamedDeclaration extends BaseModuleDeclaration {
1429
+ type: "ExportNamedDeclaration";
1430
+ declaration?: Declaration | null | undefined;
1431
+ specifiers: ExportSpecifier[];
1432
+ /** Absent with `typescript: true` unless there's a `with` clause, as in acorn-typescript. */
1433
+ attributes?: ImportAttribute[] | undefined;
1434
+ source?: StringLiteral | null | undefined;
1435
+ exportKind?: "type" | "value";
1436
+ }
1437
+
1438
+ export interface ExportSpecifier extends Omit<BaseModuleSpecifier, "local"> {
1439
+ type: "ExportSpecifier";
1440
+ local: Identifier | StringLiteral;
1441
+ exported: Identifier | StringLiteral;
1442
+ exportKind?: "type" | "value";
1443
+ }
1444
+
1445
+ export interface ExportDefaultDeclaration extends BaseModuleDeclaration {
1446
+ type: "ExportDefaultDeclaration";
1447
+ declaration: MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration | Expression | TSDeclareFunction | TSInterfaceDeclaration;
1448
+ exportKind?: "type" | "value";
1449
+ }
1450
+
1451
+ export interface ExportAllDeclaration extends BaseModuleDeclaration {
1452
+ type: "ExportAllDeclaration";
1453
+ exported: Identifier | StringLiteral | null;
1454
+ /** Absent with `typescript: true` unless there's a `with` clause, as in acorn-typescript. */
1455
+ attributes?: ImportAttribute[] | undefined;
1456
+ source: StringLiteral;
1457
+ exportKind?: "type" | "value";
1458
+ }
1459
+
1460
+ export interface AwaitExpression extends BaseExpression {
1461
+ type: "AwaitExpression";
1462
+ argument: Expression;
1463
+ }
1464
+
1465
+ export type TSNode = Decorator | TSTypeAnnotation | TypeNode | TSTypePredicate | TSNamedTupleMember | TSOptionalType | TSRestType | TemplateLiteralType | TSTypeParameter | TSTypeParameterDeclaration | TSTypeParameterInstantiation | TSQualifiedName | TypeElement | TSInterfaceBody | TSExpressionWithTypeArguments | TSEnumMember | TSModuleBlock | TSExternalModuleReference | TSParameterProperty | TSDeclareMethod | TSDeclaration | TSModuleDeclarationStatement | TSExpression;
1466
+
1467
+ /** Declarations; in estree's `Declaration` union. */
1468
+ export type TSDeclaration = TSDeclareFunction | TSEnumDeclaration | TSInterfaceDeclaration | TSModuleDeclaration | TSTypeAliasDeclaration;
1469
+
1470
+ /** Module-level statements; in estree's `ModuleDeclaration` union. */
1471
+ export type TSModuleDeclarationStatement = TSExportAssignment | TSImportEqualsDeclaration | TSNamespaceExportDeclaration;
1472
+
1473
+ /** Expressions; in estree's `Expression` union. */
1474
+ export type TSExpression = TSAsExpression | TSInstantiationExpression | TSNonNullExpression | TSSatisfiesExpression | TSTypeAssertion;
1475
+
1476
+ export type TypeNode = TSAnyKeyword | TSBigIntKeyword | TSBooleanKeyword | TSNeverKeyword | TSNullKeyword | TSNumberKeyword | TSObjectKeyword | TSStringKeyword | TSSymbolKeyword | TSUndefinedKeyword | TSUnknownKeyword | TSVoidKeyword | TSArrayType | TSConditionalType | TSConstructorType | TSFunctionType | TSImportType | TSIndexedAccessType | TSInferType | TSIntersectionType | TSLiteralType | TSMappedType | TSParenthesizedType | TSThisType | TSTupleType | TSTypeLiteral | TSTypeOperator | TSTypeQuery | TSTypeReference | TSUnionType;
1477
+
1478
+ export type TypeElement = TSCallSignatureDeclaration | TSConstructSignatureDeclaration | TSIndexSignature | TSMethodSignature | TSPropertySignature;
1479
+
1480
+ export type EntityName = Identifier | TSQualifiedName;
1481
+
1482
+ export type Accessibility = "public" | "private" | "protected";
1483
+
1484
+ /** A parameter of a function type, method signature or declared function. */
1485
+ export type SignatureParameter = Identifier | ObjectPattern | ArrayPattern | RestElement;
1486
+
1487
+ /** Fields the plugin adds to `Identifier`, `ObjectPattern`, `ArrayPattern` and `RestElement`. */
1488
+ export interface TSBindingFields {
1489
+ typeAnnotation?: TSTypeAnnotation | undefined;
1490
+ /** `a?` in a parameter list. */
1491
+ optional?: boolean;
1492
+ decorators?: Decorator[];
1493
+ }
1494
+
1495
+ /** Fields the plugin adds to functions. */
1496
+ export interface TSFunctionFields {
1497
+ typeParameters?: TSTypeParameterDeclaration;
1498
+ returnType?: TSTypeAnnotation;
1499
+ }
1500
+
1501
+ /** Fields the plugin adds to classes. */
1502
+ export interface TSClassFields {
1503
+ typeParameters?: TSTypeParameterDeclaration;
1504
+ superTypeParameters?: TSTypeParameterInstantiation;
1505
+ implements?: TSExpressionWithTypeArguments[];
1506
+ abstract?: boolean;
1507
+ declare?: boolean;
1508
+ decorators?: Decorator[];
1509
+ }
1510
+
1511
+ /** Modifiers the plugin adds to class members. */
1512
+ export interface TSClassMemberFields {
1513
+ accessibility?: Accessibility;
1514
+ abstract?: boolean;
1515
+ override?: boolean;
1516
+ readonly?: boolean;
1517
+ declare?: boolean;
1518
+ accessor?: boolean;
1519
+ optional?: boolean;
1520
+ decorators?: Decorator[];
1521
+ }
1522
+
1523
+ export interface Decorator extends BaseNode {
1524
+ type: "Decorator";
1525
+ expression: Expression;
1526
+ }
1527
+
1528
+ export interface TSTypeAnnotation extends BaseNode {
1529
+ type: "TSTypeAnnotation";
1530
+ /** A predicate (`x is T`, `asserts x`) only in a return type. */
1531
+ typeAnnotation: TypeNode | TSTypePredicate;
1532
+ }
1533
+
1534
+ export interface TSTypePredicate extends BaseNode {
1535
+ type: "TSTypePredicate";
1536
+ parameterName: Identifier | TSThisType;
1537
+ asserts: boolean;
1538
+ /** `null` for `asserts x` without `is`. */
1539
+ typeAnnotation: TSTypeAnnotation | null;
1540
+ }
1541
+
1542
+ export interface TSAnyKeyword extends BaseNode {
1543
+ type: "TSAnyKeyword";
1544
+ }
1545
+
1546
+ export interface TSBigIntKeyword extends BaseNode {
1547
+ type: "TSBigIntKeyword";
1548
+ }
1549
+
1550
+ export interface TSBooleanKeyword extends BaseNode {
1551
+ type: "TSBooleanKeyword";
1552
+ }
1553
+
1554
+ export interface TSNeverKeyword extends BaseNode {
1555
+ type: "TSNeverKeyword";
1556
+ }
1557
+
1558
+ export interface TSNullKeyword extends BaseNode {
1559
+ type: "TSNullKeyword";
1560
+ }
1561
+
1562
+ export interface TSNumberKeyword extends BaseNode {
1563
+ type: "TSNumberKeyword";
1564
+ }
1565
+
1566
+ export interface TSObjectKeyword extends BaseNode {
1567
+ type: "TSObjectKeyword";
1568
+ }
1569
+
1570
+ export interface TSStringKeyword extends BaseNode {
1571
+ type: "TSStringKeyword";
1572
+ }
1573
+
1574
+ export interface TSSymbolKeyword extends BaseNode {
1575
+ type: "TSSymbolKeyword";
1576
+ }
1577
+
1578
+ export interface TSUndefinedKeyword extends BaseNode {
1579
+ type: "TSUndefinedKeyword";
1580
+ }
1581
+
1582
+ export interface TSUnknownKeyword extends BaseNode {
1583
+ type: "TSUnknownKeyword";
1584
+ }
1585
+
1586
+ export interface TSVoidKeyword extends BaseNode {
1587
+ type: "TSVoidKeyword";
1588
+ }
1589
+
1590
+ export interface TSThisType extends BaseNode {
1591
+ type: "TSThisType";
1592
+ }
1593
+
1594
+ export interface TSArrayType extends BaseNode {
1595
+ type: "TSArrayType";
1596
+ elementType: TypeNode;
1597
+ }
1598
+
1599
+ export interface TSConditionalType extends BaseNode {
1600
+ type: "TSConditionalType";
1601
+ checkType: TypeNode;
1602
+ extendsType: TypeNode;
1603
+ trueType: TypeNode;
1604
+ falseType: TypeNode;
1605
+ }
1606
+
1607
+ export interface TSFunctionType extends BaseNode {
1608
+ type: "TSFunctionType";
1609
+ typeParameters?: TSTypeParameterDeclaration;
1610
+ parameters: SignatureParameter[];
1611
+ typeAnnotation: TSTypeAnnotation;
1612
+ }
1613
+
1614
+ export interface TSConstructorType extends BaseNode {
1615
+ type: "TSConstructorType";
1616
+ abstract: boolean;
1617
+ typeParameters?: TSTypeParameterDeclaration;
1618
+ parameters: SignatureParameter[];
1619
+ typeAnnotation: TSTypeAnnotation;
1620
+ }
1621
+
1622
+ export interface TSImportType extends BaseNode {
1623
+ type: "TSImportType";
1624
+ argument: StringLiteral;
1625
+ qualifier?: EntityName;
1626
+ typeArguments?: TSTypeParameterInstantiation;
1627
+ }
1628
+
1629
+ export interface TSIndexedAccessType extends BaseNode {
1630
+ type: "TSIndexedAccessType";
1631
+ objectType: TypeNode;
1632
+ indexType: TypeNode;
1633
+ }
1634
+
1635
+ export interface TSInferType extends BaseNode {
1636
+ type: "TSInferType";
1637
+ typeParameter: TSTypeParameter;
1638
+ }
1639
+
1640
+ export interface TSIntersectionType extends BaseNode {
1641
+ type: "TSIntersectionType";
1642
+ types: TypeNode[];
1643
+ }
1644
+
1645
+ export interface TSUnionType extends BaseNode {
1646
+ type: "TSUnionType";
1647
+ types: TypeNode[];
1648
+ }
1649
+
1650
+ export interface TSLiteralType extends BaseNode {
1651
+ type: "TSLiteralType";
1652
+ /** `UnaryExpression` for a negative number, e.g. `-1`. */
1653
+ literal: Literal | UnaryExpression | TemplateLiteralType;
1654
+ }
1655
+
1656
+ /** A template literal type, `` `prefix-${T}` ``: a `TemplateLiteral` whose expressions are types. */
1657
+ export interface TemplateLiteralType extends BaseNode {
1658
+ type: "TemplateLiteral";
1659
+ quasis: TemplateElement[];
1660
+ expressions: TypeNode[];
1661
+ }
1662
+
1663
+ export interface TSMappedType extends BaseNode {
1664
+ type: "TSMappedType";
1665
+ readonly?: true | "+" | "-";
1666
+ typeParameter: TSTypeParameter;
1667
+ /** The `as` clause. */
1668
+ nameType: TypeNode | null;
1669
+ optional?: true | "+" | "-";
1670
+ typeAnnotation?: TypeNode;
1671
+ }
1672
+
1673
+ export interface TSParenthesizedType extends BaseNode {
1674
+ type: "TSParenthesizedType";
1675
+ typeAnnotation: TypeNode;
1676
+ }
1677
+
1678
+ export interface TSTupleType extends BaseNode {
1679
+ type: "TSTupleType";
1680
+ elementTypes: Array<TypeNode | TSNamedTupleMember | TSOptionalType | TSRestType>;
1681
+ }
1682
+
1683
+ export interface TSNamedTupleMember extends BaseNode {
1684
+ type: "TSNamedTupleMember";
1685
+ label: Identifier;
1686
+ optional: boolean;
1687
+ elementType: TypeNode;
1688
+ }
1689
+
1690
+ export interface TSOptionalType extends BaseNode {
1691
+ type: "TSOptionalType";
1692
+ typeAnnotation: TypeNode;
1693
+ }
1694
+
1695
+ export interface TSRestType extends BaseNode {
1696
+ type: "TSRestType";
1697
+ typeAnnotation: TypeNode | TSNamedTupleMember;
1698
+ }
1699
+
1700
+ export interface TSTypeLiteral extends BaseNode {
1701
+ type: "TSTypeLiteral";
1702
+ members: TypeElement[];
1703
+ }
1704
+
1705
+ export interface TSTypeOperator extends BaseNode {
1706
+ type: "TSTypeOperator";
1707
+ operator: "keyof" | "unique" | "readonly";
1708
+ typeAnnotation: TypeNode;
1709
+ }
1710
+
1711
+ export interface TSTypeQuery extends BaseNode {
1712
+ type: "TSTypeQuery";
1713
+ exprName: EntityName | TSImportType;
1714
+ typeArguments?: TSTypeParameterInstantiation;
1715
+ }
1716
+
1717
+ export interface TSTypeReference extends BaseNode {
1718
+ type: "TSTypeReference";
1719
+ typeName: EntityName;
1720
+ typeArguments?: TSTypeParameterInstantiation;
1721
+ }
1722
+
1723
+ export interface TSQualifiedName extends BaseNode {
1724
+ type: "TSQualifiedName";
1725
+ left: EntityName;
1726
+ right: Identifier;
1727
+ }
1728
+
1729
+ export interface TSTypeParameterDeclaration extends BaseNode {
1730
+ type: "TSTypeParameterDeclaration";
1731
+ params: TSTypeParameter[];
1732
+ /** With a trailing comma, its offset. */
1733
+ extra?: {
1734
+ trailingComma: number;
1735
+ };
1736
+ }
1737
+
1738
+ export interface TSTypeParameter extends BaseNode {
1739
+ type: "TSTypeParameter";
1740
+ name: string;
1741
+ constraint?: TypeNode;
1742
+ default?: TypeNode;
1743
+ const?: true;
1744
+ in?: true;
1745
+ out?: true;
1746
+ }
1747
+
1748
+ export interface TSTypeParameterInstantiation extends BaseNode {
1749
+ type: "TSTypeParameterInstantiation";
1750
+ params: TypeNode[];
1751
+ }
1752
+
1753
+ export interface TSPropertySignature extends BaseNode {
1754
+ type: "TSPropertySignature";
1755
+ key: Expression;
1756
+ computed?: boolean;
1757
+ optional?: boolean;
1758
+ readonly?: boolean;
1759
+ typeAnnotation?: TSTypeAnnotation;
1760
+ }
1761
+
1762
+ export interface TSMethodSignature extends BaseNode {
1763
+ type: "TSMethodSignature";
1764
+ key: Expression;
1765
+ computed?: boolean;
1766
+ optional?: boolean;
1767
+ kind: "method" | "get" | "set";
1768
+ typeParameters?: TSTypeParameterDeclaration;
1769
+ parameters: SignatureParameter[];
1770
+ /** The return type. */
1771
+ typeAnnotation?: TSTypeAnnotation;
1772
+ }
1773
+
1774
+ /** In an interface, a type literal, or a class body (with the class member modifiers). */
1775
+ export interface TSIndexSignature extends BaseNode, TSClassMemberFields {
1776
+ type: "TSIndexSignature";
1777
+ parameters: Identifier[];
1778
+ typeAnnotation?: TSTypeAnnotation;
1779
+ static?: boolean;
1780
+ }
1781
+
1782
+ export interface TSCallSignatureDeclaration extends BaseNode {
1783
+ type: "TSCallSignatureDeclaration";
1784
+ typeParameters?: TSTypeParameterDeclaration;
1785
+ parameters: SignatureParameter[];
1786
+ typeAnnotation?: TSTypeAnnotation;
1787
+ }
1788
+
1789
+ export interface TSConstructSignatureDeclaration extends BaseNode {
1790
+ type: "TSConstructSignatureDeclaration";
1791
+ typeParameters?: TSTypeParameterDeclaration;
1792
+ parameters: SignatureParameter[];
1793
+ typeAnnotation?: TSTypeAnnotation;
1794
+ }
1795
+
1796
+ export interface TSInterfaceDeclaration extends BaseNode {
1797
+ type: "TSInterfaceDeclaration";
1798
+ id: Identifier;
1799
+ typeParameters?: TSTypeParameterDeclaration;
1800
+ extends?: TSExpressionWithTypeArguments[];
1801
+ body: TSInterfaceBody;
1802
+ declare?: boolean;
1803
+ }
1804
+
1805
+ export interface TSInterfaceBody extends BaseNode {
1806
+ type: "TSInterfaceBody";
1807
+ body: TypeElement[];
1808
+ }
1809
+
1810
+ /** An interface's `extends` or a class's `implements` entry. */
1811
+ export interface TSExpressionWithTypeArguments extends BaseNode {
1812
+ type: "TSExpressionWithTypeArguments";
1813
+ expression: EntityName;
1814
+ /** The type arguments, named `typeParameters` as in acorn-typescript. */
1815
+ typeParameters?: TSTypeParameterInstantiation;
1816
+ }
1817
+
1818
+ export interface TSTypeAliasDeclaration extends BaseNode {
1819
+ type: "TSTypeAliasDeclaration";
1820
+ id: Identifier;
1821
+ typeParameters?: TSTypeParameterDeclaration;
1822
+ typeAnnotation: TypeNode;
1823
+ declare?: boolean;
1824
+ }
1825
+
1826
+ export interface TSEnumDeclaration extends BaseNode {
1827
+ type: "TSEnumDeclaration";
1828
+ id: Identifier;
1829
+ members: TSEnumMember[];
1830
+ const?: boolean;
1831
+ declare?: boolean;
1832
+ }
1833
+
1834
+ export interface TSEnumMember extends BaseNode {
1835
+ type: "TSEnumMember";
1836
+ id: Identifier | StringLiteral;
1837
+ initializer?: Expression;
1838
+ }
1839
+
1840
+ /** `namespace A {}`, `module "a" {}`, `declare global {}`; `namespace A.B {}` nests through `body`. */
1841
+ export interface TSModuleDeclaration extends BaseNode {
1842
+ type: "TSModuleDeclaration";
1843
+ id: Identifier | StringLiteral;
1844
+ /** Absent for `declare module "a";`. */
1845
+ body?: TSModuleBlock | TSModuleDeclaration;
1846
+ declare?: boolean;
1847
+ global?: boolean;
1848
+ }
1849
+
1850
+ export interface TSModuleBlock extends BaseNode {
1851
+ type: "TSModuleBlock";
1852
+ body: Array<Statement | ModuleDeclaration>;
1853
+ }
1854
+
1855
+ /** A function declaration without a body: an overload or `declare function`. */
1856
+ export interface TSDeclareFunction extends BaseNode, TSFunctionFields {
1857
+ type: "TSDeclareFunction";
1858
+ /** `null` in `export default function (): void;`. */
1859
+ id: Identifier | null;
1860
+ params: Pattern[];
1861
+ expression: boolean;
1862
+ generator: boolean;
1863
+ async: boolean;
1864
+ declare?: boolean;
1865
+ }
1866
+
1867
+ /** A `MethodDefinition`'s value when the method has no body: an overload or an abstract method. */
1868
+ export interface TSDeclareMethod extends BaseNode, TSFunctionFields {
1869
+ type: "TSDeclareMethod";
1870
+ id: null;
1871
+ params: Array<Pattern | TSParameterProperty>;
1872
+ expression: boolean;
1873
+ generator: boolean;
1874
+ async: boolean;
1875
+ }
1876
+
1877
+ /** `constructor(private a: T)`: a constructor parameter with a modifier. */
1878
+ export interface TSParameterProperty extends BaseNode {
1879
+ type: "TSParameterProperty";
1880
+ accessibility?: Accessibility;
1881
+ readonly?: boolean;
1882
+ override?: boolean;
1883
+ parameter: Identifier | AssignmentPattern;
1884
+ }
1885
+
1886
+ /** `import a = require("a")`, `import a = B.C`, `export import a = B.C`. */
1887
+ export interface TSImportEqualsDeclaration extends BaseNode {
1888
+ type: "TSImportEqualsDeclaration";
1889
+ importKind: "type" | "value";
1890
+ isExport: boolean;
1891
+ id: Identifier;
1892
+ moduleReference: EntityName | TSExternalModuleReference;
1893
+ }
1894
+
1895
+ export interface TSExternalModuleReference extends BaseNode {
1896
+ type: "TSExternalModuleReference";
1897
+ expression: StringLiteral;
1898
+ }
1899
+
1900
+ /** `export = a`. */
1901
+ export interface TSExportAssignment extends BaseNode {
1902
+ type: "TSExportAssignment";
1903
+ expression: Expression;
1904
+ }
1905
+
1906
+ /** `export as namespace A`. */
1907
+ export interface TSNamespaceExportDeclaration extends BaseNode {
1908
+ type: "TSNamespaceExportDeclaration";
1909
+ id: Identifier;
1910
+ }
1911
+
1912
+ export interface TSAsExpression extends BaseNode {
1913
+ type: "TSAsExpression";
1914
+ expression: Expression;
1915
+ typeAnnotation: TypeNode;
1916
+ }
1917
+
1918
+ export interface TSSatisfiesExpression extends BaseNode {
1919
+ type: "TSSatisfiesExpression";
1920
+ expression: Expression;
1921
+ typeAnnotation: TypeNode;
1922
+ }
1923
+
1924
+ /** `<T>a`. */
1925
+ export interface TSTypeAssertion extends BaseNode {
1926
+ type: "TSTypeAssertion";
1927
+ typeAnnotation: TypeNode;
1928
+ expression: Expression;
1929
+ }
1930
+
1931
+ export interface TSNonNullExpression extends BaseNode {
1932
+ type: "TSNonNullExpression";
1933
+ expression: Expression;
1934
+ }
1935
+
1936
+ /** `f<T>` without a call. */
1937
+ export interface TSInstantiationExpression extends BaseNode {
1938
+ type: "TSInstantiationExpression";
1939
+ expression: Expression;
1940
+ typeArguments: TSTypeParameterInstantiation;
1941
+ }
1942
+
1943
+ /**
1944
+ * Parses only a module's top-level `import` and `export` statements, e.g.
1945
+ * to rewrite or follow its imports, and skips the rest without building
1946
+ * it. Each node is the one {@link parseModule} returns for the statement
1947
+ * with `comments: false`: `ImportDeclaration`, `ExportNamedDeclaration`,
1948
+ * `ExportDefaultDeclaration` and `ExportAllDeclaration`, plus, with
1949
+ * `typescript: true`, `TSImportEqualsDeclaration`, `TSExportAssignment`
1950
+ * and `TSNamespaceExportDeclaration`. `import(...)` and `import.meta`
1951
+ * aren't statements, so they aren't returned.
1952
+ *
1953
+ * Throws a {@link ParseError} (`js_parse_error`) on a syntax error in one
1954
+ * of those statements. Syntax errors in the rest aren't reported.
1955
+ */
1956
+ export declare function parseImportsExports(source: string, options?: ParseImportsExportsOptions): ModuleDeclaration[];
1957
+
1958
+ /**
1959
+ * Parses a JavaScript or TypeScript module, e.g. a `.ts` file a component
1960
+ * imports, into the same kind of AST as a component's `<script>`:
1961
+ * estree, TypeScript nodes as in `@sveltejs/acorn-typescript`, and
1962
+ * comments attached as `leadingComments`/`trailingComments`.
1963
+ *
1964
+ * Throws a {@link ParseError} (`js_parse_error`) on a syntax error.
1965
+ */
1966
+ export declare function parseModule(source: string, options?: ParseModuleOptions): Program;
1967
+
1968
+ type NodeLike = number | {
1969
+ start?: number;
1970
+ end?: number;
1971
+ } | null;
1972
+
1973
+ /**
1974
+ * Thrown for a syntax error. `code`, `message`, `position`, `start`, `end`
1975
+ * and `frame` are what svelte/compiler's `CompileError` has for the same
1976
+ * input.
1977
+ */
1978
+ export declare class ParseError extends Error {
1979
+ name: string;
1980
+ /** svelte's error code, e.g. `"expected_token"` or `"block_unclosed"`. */
1981
+ code: string;
1982
+ /**
1983
+ * The message without svelte's link to the error's docs, e.g.
1984
+ * `"Unexpected token"`. `message` is always `reason`, a line break, then
1985
+ * the link, `https://svelte.dev/e/${code}`.
1986
+ */
1987
+ reason: string;
1988
+ /** `[start, end]` offsets into the source. */
1989
+ position?: [number, number];
1990
+ start?: Location;
1991
+ end?: Location;
1992
+ /** A few lines of source around the error, with a `^` under it. */
1993
+ frame?: string;
1994
+ constructor(node: NodeLike, code: string, reason: string);
1995
+ }
1996
+
1997
+ interface Location {
1998
+ line: number;
1999
+ column: number;
2000
+ character: number;
2001
+ }
2002
+
2003
+ /**
2004
+ * A function from an offset in `text` to its line, from 1, and column,
2005
+ * from 0, in UTF-16 code units: what `loc: true` gives the node that
2006
+ * starts there, without parsing with `loc`. Lines end at `\n`, as in
2007
+ * svelte's markup `loc` and in `ParseError`; acorn's `loc` in
2008
+ * scripts and modules also ends them at a `\r` not followed by `\n`, at
2009
+ * U+2028 and at U+2029. `parse` drops a leading byte order mark, so pass
2010
+ * the text without it. Lines are found on the first call; lookups in
2011
+ * source order are fastest.
2012
+ *
2013
+ * ```ts
2014
+ * import { createLocator, parse, walk } from "svelte-ast";
2015
+ *
2016
+ * const locate = createLocator(source);
2017
+ * walk(parse(source), {
2018
+ * enter(node) {
2019
+ * if (node.type === "Component") console.log(node.name, locate(node.start).line);
2020
+ * },
2021
+ * });
2022
+ * ```
2023
+ */
2024
+ export declare function createLocator(text: string): (offset: number) => Position;
2025
+
2026
+ /**
2027
+ * Parses a component's top-level `<script>`s, `<style>` and
2028
+ * `<svelte:options>` as {@link parse} does, and skips the markup between
2029
+ * them as `lexComponent` skips it: `fragment` has no nodes, `comments`
2030
+ * only the scripts' comments, and errors in the markup aren't reported.
2031
+ * The rest is `parse`'s, offsets included. For a pass that only reads the
2032
+ * scripts, such as a component's props or its module script's exports.
2033
+ *
2034
+ * Throws a {@link ParseError} on a syntax error in a section.
2035
+ */
2036
+ export declare function parseSections(source: string, options?: ParseOptions): AST.Root;
2037
+
2038
+ /**
2039
+ * Whether svelte compiles the component in runes mode, as
2040
+ * `compile(source).metadata.runes` says: `<svelte:options runes>` if it
2041
+ * has one, otherwise whether it uses a rune, such as `$state` or
2042
+ * `$props`, or `await` outside a function in its instance script or
2043
+ * markup. A `$state` that subscribes to a store named `state` isn't a
2044
+ * rune, as in svelte.
2045
+ *
2046
+ * It reads `<svelte:options>` without parsing, and a component that has
2047
+ * no rune's name and no `await` isn't parsed either. Otherwise it parses
2048
+ * the scripts, and the markup only if one of them is in it, and throws a
2049
+ * `ParseError` on a syntax error there.
2050
+ */
2051
+ export declare function isRunesMode(source: string): boolean;
2052
+
2053
+ /** How a {@link Binding} is declared. */
2054
+ export type BindingKind = "import" | "var" | "let" | "const" | "using" | "function" | "class" | "enum" | "enum-member" | "namespace" | "param" | "catch" | "reactive" | "each" | "each-index" | "let-directive" | "snippet" | "snippet-param" | "const-tag" | "await-value" | "await-error" | "type" | "interface" | "type-param";
2055
+
2056
+ /** Options for {@link analyzeScopes}. */
2057
+ export interface AnalyzeScopesOptions {
2058
+ /**
2059
+ * Resolve the names in TypeScript's types too: `type`, `interface` and
2060
+ * type parameters declare bindings, in a scope's `types`, and a name in
2061
+ * a type is a {@link Reference} with `type: true`. Defaults to `false`,
2062
+ * which resolves values only, as svelte's analyzer does.
2063
+ */
2064
+ types?: boolean;
2065
+ }
2066
+
2067
+ /** A name declared in a {@link Scope}. */
2068
+ export interface Binding {
2069
+ readonly name: string;
2070
+ /**
2071
+ * What declares it: `"import"`, `"var"`, `"let"`, `"const"` (`{let}`
2072
+ * and `{const}` tags included), `"using"`, `"function"`, `"class"`,
2073
+ * `"enum"`, `"enum-member"`, `"namespace"`, `"param"`, `"catch"`,
2074
+ * `"reactive"` (`x` in `$: x = ...` without a declaration of `x`),
2075
+ * `"each"` and `"each-index"` (`item` and `i` in `{#each items as item,
2076
+ * i}`), `"let-directive"`, `"snippet"` (its name), `"snippet-param"`,
2077
+ * `"const-tag"` (`{@const}`), `"await-value"` and `"await-error"` (`{:then
2078
+ * value}` and `{:catch error}`). With `{ types: true }`, `"type"`,
2079
+ * `"interface"` and `"type-param"` (a type parameter or `infer U`), which
2080
+ * are in a scope's `types`, not its `declarations`, and `"param"` for a
2081
+ * parameter of a function type or signature too.
2082
+ */
2083
+ readonly kind: BindingKind;
2084
+ /**
2085
+ * The `Identifier` that declares it; `null` for an each block's index,
2086
+ * `let:x` without a value and a type parameter, whose names are strings.
2087
+ */
2088
+ readonly node: Identifier | null;
2089
+ /**
2090
+ * The node that declares it: the import specifier, the
2091
+ * `VariableDeclarator`, the function or class, the function a
2092
+ * parameter belongs to, the `CatchClause`, the `LabeledStatement` of
2093
+ * `$:`, the `EachBlock`, `LetDirective`, `SnippetBlock` or `AwaitBlock`,
2094
+ * the enum, enum member or namespace, or `import a = b`; the type
2095
+ * alias, interface or `TSTypeParameter`, or the function type or
2096
+ * signature a parameter belongs to.
2097
+ */
2098
+ readonly declaration: AST.SvelteNode;
2099
+ /**
2100
+ * What it starts as, as svelte's analyzer has it: a variable's
2101
+ * initializer, the function or class, the `ImportDeclaration`, the
2102
+ * `SnippetBlock` for a snippet's name, the `EachBlock` for an index,
2103
+ * the right side of `$: x = ...`, an enum member's initializer, the type
2104
+ * alias or interface. For a
2105
+ * prop destructured from `$props()`, its default, without `$bindable`:
2106
+ * `"md"` in `let { size = "md" } = $props()` or in `let { size =
2107
+ * $bindable("md") } = $props()`. `null` otherwise.
2108
+ */
2109
+ readonly initial: AST.SvelteNode | null;
2110
+ readonly scope: Scope;
2111
+ /**
2112
+ * Every use of it, in source order: reads, writes, and `$name`
2113
+ * subscriptions if it's a store. Not the identifiers that declare it,
2114
+ * but for `x` in `$: x = ...`, which declares `x` and writes it each
2115
+ * time the statement runs.
2116
+ */
2117
+ readonly references: readonly Reference[];
2118
+ /**
2119
+ * The rune its declarator's initializer calls, such as `"$state"`,
2120
+ * `"$state.raw"`, `"$derived"`, `"$derived.by"` or `"$props"`, unless
2121
+ * a binding or a store shadows it; `null` otherwise.
2122
+ */
2123
+ readonly rune: string | null;
2124
+ /**
2125
+ * The name a parent passes it as, for a prop: `"class"` for `klass` in
2126
+ * `let { class: klass } = $props()` and in `export { klass as class }`,
2127
+ * `"size"` in `export let size`. `null` otherwise, including for `rest`
2128
+ * in `let { a, ...rest } = $props()`.
2129
+ */
2130
+ readonly prop: string | null;
2131
+ }
2132
+
2133
+ /** A use of a name. */
2134
+ export interface Reference {
2135
+ /**
2136
+ * The `Identifier`. For a name the AST holds only as a string, such as
2137
+ * `Foo` in `<Foo.Bar>`, `a` in `use:a`, `transition:a`, `in:a`,
2138
+ * `out:a` and `animate:a`, and `color` in `style:color`, a new
2139
+ * `Identifier` with the name's `start` and `end`.
2140
+ */
2141
+ readonly node: Identifier;
2142
+ /** The node that holds it. */
2143
+ readonly parent: AST.SvelteNode;
2144
+ /** The scope it's in. */
2145
+ readonly scope: Scope;
2146
+ /** What it refers to; `null` for a global, such as `window` or a rune. */
2147
+ readonly binding: Binding | null;
2148
+ /**
2149
+ * Whether it reads the value: all but the target of a plain `=`, and
2150
+ * every store subscription.
2151
+ */
2152
+ readonly reads: boolean;
2153
+ /**
2154
+ * Whether it assigns a new value: the target of `=`, `+=` and the like,
2155
+ * `++` and `--`, `bind:`, or `for (a of b)`.
2156
+ */
2157
+ readonly writes: boolean;
2158
+ /**
2159
+ * Whether it changes a property of the value: `a` in `a.b = c`,
2160
+ * `a.b++` and `bind:value={a.b}`.
2161
+ */
2162
+ readonly mutates: boolean;
2163
+ /**
2164
+ * Whether it's a store subscription: `$count` refers to `count`, and
2165
+ * `$count = 1` mutates it.
2166
+ */
2167
+ readonly store: boolean;
2168
+ /**
2169
+ * Whether it's in a type, or in `export type { a }`, where it neither
2170
+ * reads, writes nor mutates. Only with `{ types: true }`: `A` in `let
2171
+ * a: A`, `a` in `typeof a`, `I` in `implements I`, `N` in `N.T`.
2172
+ */
2173
+ readonly type: boolean;
2174
+ }
2175
+
2176
+ /**
2177
+ * The names a function, block, element or other node declares, and the
2178
+ * scopes around it.
2179
+ */
2180
+ export interface Scope {
2181
+ /**
2182
+ * The node that makes it, or `null` for a component's `<script>` or
2183
+ * `<script module>` that isn't there.
2184
+ */
2185
+ readonly node: AST.SvelteNode | null;
2186
+ readonly parent: Scope | null;
2187
+ /**
2188
+ * Its own bindings, by name, in the order they're declared: the values,
2189
+ * including imports, classes, enums and namespaces, which are types too.
2190
+ */
2191
+ readonly declarations: ReadonlyMap<string, Binding>;
2192
+ /**
2193
+ * Its own type-only bindings, by name: `type`, `interface` and type
2194
+ * parameters. Empty unless `{ types: true }`.
2195
+ */
2196
+ readonly types: ReadonlyMap<string, Binding>;
2197
+ /**
2198
+ * The binding `name` refers to here as a value, declared in this scope
2199
+ * or one around it; `null` if none does.
2200
+ */
2201
+ get(name: string): Binding | null;
2202
+ /**
2203
+ * The binding `name` refers to here as a type: a `type`, `interface` or
2204
+ * type parameter, or an import, class or enum; `null` if none does.
2205
+ */
2206
+ getType(name: string): Binding | null;
2207
+ }
2208
+
2209
+ /** What {@link analyzeScopes} found. */
2210
+ export interface Scopes {
2211
+ /** The `<script module>`'s scope, or a module's. */
2212
+ readonly module: Scope;
2213
+ /** The `<script>`'s scope, inside `module`; a module's, for a module. */
2214
+ readonly instance: Scope;
2215
+ /**
2216
+ * The scope `node` is in: for a function, the scope around it, while
2217
+ * its parameters are in its own. `null` for a node in a type, in the
2218
+ * `<style>` or outside the AST. The first call walks the AST again to
2219
+ * record every node's scope, which the rest of the analysis doesn't
2220
+ * need.
2221
+ */
2222
+ scopeOf(node: AST.SvelteNode): Scope | null;
2223
+ /**
2224
+ * The binding an `Identifier` declares or refers to; `null` for a
2225
+ * global, and for a name that isn't a reference, such as a property
2226
+ * key or a name in a type.
2227
+ */
2228
+ bindingOf(node: Identifier): Binding | null;
2229
+ /**
2230
+ * The use an `Identifier` is, with whether it reads, writes or
2231
+ * mutates its binding or subscribes to it as a store; `null` for an
2232
+ * `Identifier` that declares a binding or isn't a reference. A global's
2233
+ * use has no binding.
2234
+ */
2235
+ referenceOf(node: Identifier): Reference | null;
2236
+ /**
2237
+ * The bindings of the scope `node` makes, by name; empty if it makes
2238
+ * none. A function's are its parameters, and a function expression's
2239
+ * name; its body's declarations are its body's.
2240
+ */
2241
+ declaredIn(node: AST.SvelteNode): ReadonlyMap<string, Binding>;
2242
+ }
2243
+
2244
+ /**
2245
+ * Finds every scope, binding and reference in a component, its scripts
2246
+ * and its markup together, or in a module, as svelte's analyzer does:
2247
+ * which declaration each name refers to, and where each binding is read,
2248
+ * written or subscribed to.
2249
+ *
2250
+ * Besides JavaScript's scopes, it knows the markup's: `{#each items as
2251
+ * item, i (key)}` declares `item` and `i` for the key and the body, a
2252
+ * snippet its parameters, `{:then value}` and `{:catch error}` their
2253
+ * names, `{@const}` a name for its whole fragment, and `let:` a name for
2254
+ * the element, or for a component's default or named slot (`let:a={b}`
2255
+ * declares `b`). Store subscriptions such as `$count` are uses of
2256
+ * `count`, unless they're runes. `bind:` writes its target, and
2257
+ * `$: x = ...` declares `x` if nothing else does. A binding records the
2258
+ * rune that initializes it, such as `$state` or `$props`, and the name a
2259
+ * prop is passed as.
2260
+ *
2261
+ * Names in TypeScript types aren't references, and types aren't
2262
+ * declarations: `interface` and `type` declare nothing, unless `{ types:
2263
+ * true }`, which resolves the names in types too. A top-level
2264
+ * snippet is declared in the markup's scope, as in svelte's analyzer, so
2265
+ * a `<script>` that uses it refers to a global.
2266
+ *
2267
+ * ```ts
2268
+ * import { parse } from "svelte-ast";
2269
+ * import { analyzeScopes } from "svelte-ast/scope";
2270
+ *
2271
+ * const ast = parse(source);
2272
+ * const scopes = analyzeScopes(ast);
2273
+ * const size = scopes.instance.get("size");
2274
+ * size?.prop; // "size", for `let { size } = $props()`
2275
+ * size?.references.some((reference) => reference.writes || reference.mutates);
2276
+ * ```
2277
+ *
2278
+ * It reads the AST but doesn't change it.
2279
+ */
2280
+ export declare function analyzeScopes(ast: AST.Root | Program, options?: AnalyzeScopesOptions): Scopes;
2281
+
2282
+ /** The fields of each node type that hold child nodes, in source order. */
2283
+ export declare const visitorKeys: {
2284
+ readonly Root: readonly ["module", "instance", "fragment", "css"];
2285
+ readonly Script: readonly ["attributes", "content"];
2286
+ readonly Fragment: readonly ["nodes"];
2287
+ readonly Text: readonly [];
2288
+ readonly Comment: readonly [];
2289
+ readonly ExpressionTag: readonly ["expression"];
2290
+ readonly HtmlTag: readonly ["expression"];
2291
+ readonly ConstTag: readonly ["declaration"];
2292
+ readonly DeclarationTag: readonly ["declaration"];
2293
+ readonly DebugTag: readonly ["identifiers"];
2294
+ readonly RenderTag: readonly ["expression"];
2295
+ readonly AttachTag: readonly ["expression"];
2296
+ readonly Attribute: readonly ["value"];
2297
+ readonly SpreadAttribute: readonly ["expression"];
2298
+ readonly AnimateDirective: readonly ["expression"];
2299
+ readonly BindDirective: readonly ["expression"];
2300
+ readonly ClassDirective: readonly ["expression"];
2301
+ readonly LetDirective: readonly ["expression"];
2302
+ readonly OnDirective: readonly ["expression"];
2303
+ readonly StyleDirective: readonly ["value"];
2304
+ readonly TransitionDirective: readonly ["expression"];
2305
+ readonly UseDirective: readonly ["expression"];
2306
+ readonly Component: readonly ["attributes", "fragment"];
2307
+ readonly TitleElement: readonly ["attributes", "fragment"];
2308
+ readonly SlotElement: readonly ["attributes", "fragment"];
2309
+ readonly RegularElement: readonly ["attributes", "fragment"];
2310
+ readonly SvelteBody: readonly ["attributes", "fragment"];
2311
+ readonly SvelteBoundary: readonly ["attributes", "fragment"];
2312
+ readonly SvelteComponent: readonly ["expression", "attributes", "fragment"];
2313
+ readonly SvelteDocument: readonly ["attributes", "fragment"];
2314
+ readonly SvelteElement: readonly ["tag", "attributes", "fragment"];
2315
+ readonly SvelteFragment: readonly ["attributes", "fragment"];
2316
+ readonly SvelteHead: readonly ["attributes", "fragment"];
2317
+ readonly SvelteOptions: readonly ["attributes", "fragment"];
2318
+ readonly SvelteSelf: readonly ["attributes", "fragment"];
2319
+ readonly SvelteWindow: readonly ["attributes", "fragment"];
2320
+ readonly IfBlock: readonly ["test", "consequent", "alternate"];
2321
+ readonly EachBlock: readonly ["expression", "context", "key", "body", "fallback"];
2322
+ readonly AwaitBlock: readonly ["expression", "pending", "value", "then", "error", "catch"];
2323
+ readonly KeyBlock: readonly ["expression", "fragment"];
2324
+ readonly SnippetBlock: readonly ["expression", "parameters", "body"];
2325
+ readonly StyleSheet: readonly ["attributes", "children"];
2326
+ readonly Rule: readonly ["prelude", "block"];
2327
+ readonly Atrule: readonly ["block"];
2328
+ readonly SelectorList: readonly ["children"];
2329
+ readonly ComplexSelector: readonly ["children"];
2330
+ readonly RelativeSelector: readonly ["combinator", "selectors"];
2331
+ readonly Combinator: readonly [];
2332
+ readonly TypeSelector: readonly [];
2333
+ readonly IdSelector: readonly [];
2334
+ readonly ClassSelector: readonly [];
2335
+ readonly AttributeSelector: readonly [];
2336
+ readonly PseudoElementSelector: readonly ["args"];
2337
+ readonly PseudoClassSelector: readonly ["args"];
2338
+ readonly Percentage: readonly [];
2339
+ readonly Nth: readonly [];
2340
+ readonly NestingSelector: readonly [];
2341
+ readonly Block: readonly ["children"];
2342
+ readonly Declaration: readonly [];
2343
+ readonly Program: readonly ["body"];
2344
+ readonly ExpressionStatement: readonly ["expression"];
2345
+ readonly BlockStatement: readonly ["body"];
2346
+ readonly StaticBlock: readonly ["body"];
2347
+ readonly EmptyStatement: readonly [];
2348
+ readonly DebuggerStatement: readonly [];
2349
+ readonly WithStatement: readonly ["object", "body"];
2350
+ readonly ReturnStatement: readonly ["argument"];
2351
+ readonly LabeledStatement: readonly ["label", "body"];
2352
+ readonly BreakStatement: readonly ["label"];
2353
+ readonly ContinueStatement: readonly ["label"];
2354
+ readonly IfStatement: readonly ["test", "consequent", "alternate"];
2355
+ readonly SwitchStatement: readonly ["discriminant", "cases"];
2356
+ readonly SwitchCase: readonly ["test", "consequent"];
2357
+ readonly ThrowStatement: readonly ["argument"];
2358
+ readonly TryStatement: readonly ["block", "handler", "finalizer"];
2359
+ readonly CatchClause: readonly ["param", "body"];
2360
+ readonly WhileStatement: readonly ["test", "body"];
2361
+ readonly DoWhileStatement: readonly ["body", "test"];
2362
+ readonly ForStatement: readonly ["init", "test", "update", "body"];
2363
+ readonly ForInStatement: readonly ["left", "right", "body"];
2364
+ readonly ForOfStatement: readonly ["left", "right", "body"];
2365
+ readonly FunctionDeclaration: readonly ["id", "typeParameters", "params", "returnType", "body"];
2366
+ readonly FunctionExpression: readonly ["id", "typeParameters", "params", "returnType", "body"];
2367
+ readonly ArrowFunctionExpression: readonly ["typeParameters", "params", "returnType", "body"];
2368
+ readonly VariableDeclaration: readonly ["declarations"];
2369
+ readonly VariableDeclarator: readonly ["id", "init"];
2370
+ readonly ClassDeclaration: readonly ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "implements", "body"];
2371
+ readonly ClassExpression: readonly ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "implements", "body"];
2372
+ readonly ClassBody: readonly ["body"];
2373
+ readonly MethodDefinition: readonly ["decorators", "key", "typeParameters", "value"];
2374
+ readonly PropertyDefinition: readonly ["decorators", "key", "typeAnnotation", "value"];
2375
+ readonly Property: readonly ["decorators", "key", "value"];
2376
+ readonly ThisExpression: readonly [];
2377
+ readonly Super: readonly [];
2378
+ readonly Literal: readonly [];
2379
+ readonly Identifier: readonly ["decorators", "typeAnnotation"];
2380
+ readonly PrivateIdentifier: readonly [];
2381
+ readonly ArrayExpression: readonly ["elements"];
2382
+ readonly ObjectExpression: readonly ["properties"];
2383
+ readonly UnaryExpression: readonly ["argument"];
2384
+ readonly UpdateExpression: readonly ["argument"];
2385
+ readonly BinaryExpression: readonly ["left", "right"];
2386
+ readonly LogicalExpression: readonly ["left", "right"];
2387
+ readonly AssignmentExpression: readonly ["left", "right"];
2388
+ readonly MemberExpression: readonly ["object", "property"];
2389
+ readonly ConditionalExpression: readonly ["test", "consequent", "alternate"];
2390
+ readonly CallExpression: readonly ["callee", "typeArguments", "arguments"];
2391
+ readonly NewExpression: readonly ["callee", "typeArguments", "arguments"];
2392
+ readonly SequenceExpression: readonly ["expressions"];
2393
+ readonly TemplateLiteral: readonly ["quasis", "expressions"];
2394
+ readonly TaggedTemplateExpression: readonly ["tag", "typeArguments", "quasi"];
2395
+ readonly TemplateElement: readonly [];
2396
+ readonly SpreadElement: readonly ["argument"];
2397
+ readonly RestElement: readonly ["decorators", "argument", "typeAnnotation"];
2398
+ readonly YieldExpression: readonly ["argument"];
2399
+ readonly AwaitExpression: readonly ["argument"];
2400
+ readonly ImportExpression: readonly ["source", "options", "arguments"];
2401
+ readonly ChainExpression: readonly ["expression"];
2402
+ readonly ParenthesizedExpression: readonly ["expression"];
2403
+ readonly MetaProperty: readonly ["meta", "property"];
2404
+ readonly ObjectPattern: readonly ["decorators", "properties", "typeAnnotation"];
2405
+ readonly ArrayPattern: readonly ["decorators", "elements", "typeAnnotation"];
2406
+ readonly AssignmentPattern: readonly ["decorators", "left", "right"];
2407
+ readonly ImportDeclaration: readonly ["specifiers", "source", "attributes"];
2408
+ readonly ImportSpecifier: readonly ["imported", "local"];
2409
+ readonly ImportDefaultSpecifier: readonly ["local"];
2410
+ readonly ImportNamespaceSpecifier: readonly ["local"];
2411
+ readonly ImportAttribute: readonly ["key", "value"];
2412
+ readonly ExportNamedDeclaration: readonly ["declaration", "specifiers", "source", "attributes"];
2413
+ readonly ExportSpecifier: readonly ["local", "exported"];
2414
+ readonly ExportDefaultDeclaration: readonly ["declaration"];
2415
+ readonly ExportAllDeclaration: readonly ["exported", "source", "attributes"];
2416
+ readonly Decorator: readonly ["expression"];
2417
+ readonly TSTypeAnnotation: readonly ["typeAnnotation"];
2418
+ readonly TSTypeParameterDeclaration: readonly ["params"];
2419
+ readonly TSTypeParameterInstantiation: readonly ["params"];
2420
+ readonly TSTypeParameter: readonly ["constraint", "default"];
2421
+ readonly TSAnyKeyword: readonly [];
2422
+ readonly TSBigIntKeyword: readonly [];
2423
+ readonly TSBooleanKeyword: readonly [];
2424
+ readonly TSNeverKeyword: readonly [];
2425
+ readonly TSNullKeyword: readonly [];
2426
+ readonly TSNumberKeyword: readonly [];
2427
+ readonly TSObjectKeyword: readonly [];
2428
+ readonly TSStringKeyword: readonly [];
2429
+ readonly TSSymbolKeyword: readonly [];
2430
+ readonly TSUndefinedKeyword: readonly [];
2431
+ readonly TSUnknownKeyword: readonly [];
2432
+ readonly TSVoidKeyword: readonly [];
2433
+ readonly TSThisType: readonly [];
2434
+ readonly TSArrayType: readonly ["elementType"];
2435
+ readonly TSTupleType: readonly ["elementTypes"];
2436
+ readonly TSNamedTupleMember: readonly ["label", "elementType"];
2437
+ readonly TSOptionalType: readonly ["typeAnnotation"];
2438
+ readonly TSRestType: readonly ["typeAnnotation"];
2439
+ readonly TSUnionType: readonly ["types"];
2440
+ readonly TSIntersectionType: readonly ["types"];
2441
+ readonly TSConditionalType: readonly ["checkType", "extendsType", "trueType", "falseType"];
2442
+ readonly TSInferType: readonly ["typeParameter"];
2443
+ readonly TSParenthesizedType: readonly ["typeAnnotation"];
2444
+ readonly TSTypeOperator: readonly ["typeAnnotation"];
2445
+ readonly TSIndexedAccessType: readonly ["objectType", "indexType"];
2446
+ readonly TSMappedType: readonly ["typeParameter", "nameType", "typeAnnotation"];
2447
+ readonly TSLiteralType: readonly ["literal"];
2448
+ readonly TSTypeReference: readonly ["typeName", "typeArguments"];
2449
+ readonly TSQualifiedName: readonly ["left", "right"];
2450
+ readonly TSTypeQuery: readonly ["exprName", "typeArguments"];
2451
+ readonly TSImportType: readonly ["argument", "qualifier", "typeArguments"];
2452
+ readonly TSTypeLiteral: readonly ["members"];
2453
+ readonly TSPropertySignature: readonly ["key", "typeAnnotation"];
2454
+ readonly TSMethodSignature: readonly ["key", "typeParameters", "parameters", "typeAnnotation"];
2455
+ readonly TSCallSignatureDeclaration: readonly ["typeParameters", "parameters", "typeAnnotation"];
2456
+ readonly TSConstructSignatureDeclaration: readonly ["typeParameters", "parameters", "typeAnnotation"];
2457
+ readonly TSFunctionType: readonly ["typeParameters", "parameters", "typeAnnotation"];
2458
+ readonly TSConstructorType: readonly ["typeParameters", "parameters", "typeAnnotation"];
2459
+ readonly TSIndexSignature: readonly ["decorators", "parameters", "typeAnnotation"];
2460
+ readonly TSTypePredicate: readonly ["parameterName", "typeAnnotation"];
2461
+ readonly TSInterfaceDeclaration: readonly ["id", "typeParameters", "extends", "body"];
2462
+ readonly TSInterfaceBody: readonly ["body"];
2463
+ readonly TSExpressionWithTypeArguments: readonly ["expression", "typeParameters"];
2464
+ readonly TSTypeAliasDeclaration: readonly ["id", "typeParameters", "typeAnnotation"];
2465
+ readonly TSEnumDeclaration: readonly ["id", "members"];
2466
+ readonly TSEnumMember: readonly ["id", "initializer"];
2467
+ readonly TSModuleDeclaration: readonly ["id", "body"];
2468
+ readonly TSModuleBlock: readonly ["body"];
2469
+ readonly TSImportEqualsDeclaration: readonly ["id", "moduleReference"];
2470
+ readonly TSExternalModuleReference: readonly ["expression"];
2471
+ readonly TSExportAssignment: readonly ["expression"];
2472
+ readonly TSNamespaceExportDeclaration: readonly ["id"];
2473
+ readonly TSDeclareFunction: readonly ["id", "typeParameters", "params", "returnType"];
2474
+ readonly TSDeclareMethod: readonly ["typeParameters", "params", "returnType"];
2475
+ readonly TSParameterProperty: readonly ["parameter"];
2476
+ readonly TSAsExpression: readonly ["expression", "typeAnnotation"];
2477
+ readonly TSSatisfiesExpression: readonly ["expression", "typeAnnotation"];
2478
+ readonly TSTypeAssertion: readonly ["typeAnnotation", "expression"];
2479
+ readonly TSNonNullExpression: readonly ["expression"];
2480
+ readonly TSInstantiationExpression: readonly ["expression", "typeArguments"];
2481
+ };
2482
+
2483
+ /** A table of the fields of each node type that {@link walk} visits, such as {@link visitorKeys} or {@link markupVisitorKeys}. */
2484
+ export type VisitorKeys = Readonly<Partial<Record<string, readonly string[]>>>;
2485
+
2486
+ /**
2487
+ * The fields of the markup's nodes that hold other markup nodes, for a
2488
+ * {@link walk} that never enters the scripts, the styles or the
2489
+ * expressions: `Root` holds only its `fragment`, an `ExpressionTag` or a
2490
+ * directive has no children, and a block holds only its fragments.
2491
+ */
2492
+ export declare const markupVisitorKeys: {
2493
+ readonly Root: readonly ["fragment"];
2494
+ readonly Fragment: readonly ["nodes"];
2495
+ readonly Text: readonly [];
2496
+ readonly Comment: readonly [];
2497
+ readonly ExpressionTag: readonly [];
2498
+ readonly HtmlTag: readonly [];
2499
+ readonly ConstTag: readonly [];
2500
+ readonly DeclarationTag: readonly [];
2501
+ readonly DebugTag: readonly [];
2502
+ readonly RenderTag: readonly [];
2503
+ readonly AttachTag: readonly [];
2504
+ readonly Attribute: readonly ["value"];
2505
+ readonly SpreadAttribute: readonly [];
2506
+ readonly AnimateDirective: readonly [];
2507
+ readonly BindDirective: readonly [];
2508
+ readonly ClassDirective: readonly [];
2509
+ readonly LetDirective: readonly [];
2510
+ readonly OnDirective: readonly [];
2511
+ readonly StyleDirective: readonly ["value"];
2512
+ readonly TransitionDirective: readonly [];
2513
+ readonly UseDirective: readonly [];
2514
+ readonly Component: readonly ["attributes", "fragment"];
2515
+ readonly TitleElement: readonly ["attributes", "fragment"];
2516
+ readonly SlotElement: readonly ["attributes", "fragment"];
2517
+ readonly RegularElement: readonly ["attributes", "fragment"];
2518
+ readonly SvelteBody: readonly ["attributes", "fragment"];
2519
+ readonly SvelteBoundary: readonly ["attributes", "fragment"];
2520
+ readonly SvelteComponent: readonly ["attributes", "fragment"];
2521
+ readonly SvelteDocument: readonly ["attributes", "fragment"];
2522
+ readonly SvelteElement: readonly ["attributes", "fragment"];
2523
+ readonly SvelteFragment: readonly ["attributes", "fragment"];
2524
+ readonly SvelteHead: readonly ["attributes", "fragment"];
2525
+ readonly SvelteOptions: readonly ["attributes", "fragment"];
2526
+ readonly SvelteSelf: readonly ["attributes", "fragment"];
2527
+ readonly SvelteWindow: readonly ["attributes", "fragment"];
2528
+ readonly IfBlock: readonly ["consequent", "alternate"];
2529
+ readonly EachBlock: readonly ["body", "fallback"];
2530
+ readonly AwaitBlock: readonly ["pending", "then", "catch"];
2531
+ readonly KeyBlock: readonly ["fragment"];
2532
+ readonly SnippetBlock: readonly ["body"];
2533
+ };
2534
+
2535
+ /**
2536
+ * {@link visitorKeys} without TypeScript's types: a {@link walk} with it
2537
+ * reaches every value and binding but no type annotation, type
2538
+ * parameter, type argument, `implements` clause or type in `as` and
2539
+ * `satisfies`, so an `Identifier` it reaches in a TypeScript node is
2540
+ * never a type's name. It still enters a declaration that holds only
2541
+ * types, such as `type T = ...`, `interface I {}` or an index signature,
2542
+ * but not its children, and of `declare function f(): void` it visits
2543
+ * only the name. The
2544
+ * TypeScript nodes it enters children of hold values: `as`,
2545
+ * `satisfies`, `<T>a`, `a!` and `a<T>` hold their expression, an enum
2546
+ * its members, a namespace its body, `import a = b` and `export =` their
2547
+ * value, and a parameter property its parameter.
2548
+ */
2549
+ export declare const valueVisitorKeys: {
2550
+ readonly FunctionDeclaration: readonly ["id", "params", "body"];
2551
+ readonly FunctionExpression: readonly ["id", "params", "body"];
2552
+ readonly ArrowFunctionExpression: readonly ["params", "body"];
2553
+ readonly ClassDeclaration: readonly ["decorators", "id", "superClass", "body"];
2554
+ readonly ClassExpression: readonly ["decorators", "id", "superClass", "body"];
2555
+ readonly MethodDefinition: readonly ["decorators", "key", "value"];
2556
+ readonly PropertyDefinition: readonly ["decorators", "key", "value"];
2557
+ readonly Identifier: readonly ["decorators"];
2558
+ readonly CallExpression: readonly ["callee", "arguments"];
2559
+ readonly NewExpression: readonly ["callee", "arguments"];
2560
+ readonly TaggedTemplateExpression: readonly ["tag", "quasi"];
2561
+ readonly RestElement: readonly ["decorators", "argument"];
2562
+ readonly ObjectPattern: readonly ["decorators", "properties"];
2563
+ readonly ArrayPattern: readonly ["decorators", "elements"];
2564
+ readonly TSTypeAnnotation: readonly [];
2565
+ readonly TSTypeParameterDeclaration: readonly [];
2566
+ readonly TSTypeParameterInstantiation: readonly [];
2567
+ readonly TSTypeParameter: readonly [];
2568
+ readonly TSArrayType: readonly [];
2569
+ readonly TSTupleType: readonly [];
2570
+ readonly TSNamedTupleMember: readonly [];
2571
+ readonly TSOptionalType: readonly [];
2572
+ readonly TSRestType: readonly [];
2573
+ readonly TSUnionType: readonly [];
2574
+ readonly TSIntersectionType: readonly [];
2575
+ readonly TSConditionalType: readonly [];
2576
+ readonly TSInferType: readonly [];
2577
+ readonly TSParenthesizedType: readonly [];
2578
+ readonly TSTypeOperator: readonly [];
2579
+ readonly TSIndexedAccessType: readonly [];
2580
+ readonly TSMappedType: readonly [];
2581
+ readonly TSLiteralType: readonly [];
2582
+ readonly TSTypeReference: readonly [];
2583
+ readonly TSTypeQuery: readonly [];
2584
+ readonly TSImportType: readonly [];
2585
+ readonly TSTypeLiteral: readonly [];
2586
+ readonly TSPropertySignature: readonly [];
2587
+ readonly TSMethodSignature: readonly [];
2588
+ readonly TSCallSignatureDeclaration: readonly [];
2589
+ readonly TSConstructSignatureDeclaration: readonly [];
2590
+ readonly TSFunctionType: readonly [];
2591
+ readonly TSConstructorType: readonly [];
2592
+ readonly TSIndexSignature: readonly [];
2593
+ readonly TSTypePredicate: readonly [];
2594
+ readonly TSInterfaceDeclaration: readonly [];
2595
+ readonly TSInterfaceBody: readonly [];
2596
+ readonly TSExpressionWithTypeArguments: readonly [];
2597
+ readonly TSTypeAliasDeclaration: readonly [];
2598
+ readonly TSNamespaceExportDeclaration: readonly [];
2599
+ readonly TSDeclareFunction: readonly ["id"];
2600
+ readonly TSDeclareMethod: readonly [];
2601
+ readonly TSAsExpression: readonly ["expression"];
2602
+ readonly TSSatisfiesExpression: readonly ["expression"];
2603
+ readonly TSTypeAssertion: readonly ["expression"];
2604
+ readonly TSInstantiationExpression: readonly ["expression"];
2605
+ readonly Root: readonly ["module", "instance", "fragment", "css"];
2606
+ readonly Script: readonly ["attributes", "content"];
2607
+ readonly Fragment: readonly ["nodes"];
2608
+ readonly Text: readonly [];
2609
+ readonly Comment: readonly [];
2610
+ readonly ExpressionTag: readonly ["expression"];
2611
+ readonly HtmlTag: readonly ["expression"];
2612
+ readonly ConstTag: readonly ["declaration"];
2613
+ readonly DeclarationTag: readonly ["declaration"];
2614
+ readonly DebugTag: readonly ["identifiers"];
2615
+ readonly RenderTag: readonly ["expression"];
2616
+ readonly AttachTag: readonly ["expression"];
2617
+ readonly Attribute: readonly ["value"];
2618
+ readonly SpreadAttribute: readonly ["expression"];
2619
+ readonly AnimateDirective: readonly ["expression"];
2620
+ readonly BindDirective: readonly ["expression"];
2621
+ readonly ClassDirective: readonly ["expression"];
2622
+ readonly LetDirective: readonly ["expression"];
2623
+ readonly OnDirective: readonly ["expression"];
2624
+ readonly StyleDirective: readonly ["value"];
2625
+ readonly TransitionDirective: readonly ["expression"];
2626
+ readonly UseDirective: readonly ["expression"];
2627
+ readonly Component: readonly ["attributes", "fragment"];
2628
+ readonly TitleElement: readonly ["attributes", "fragment"];
2629
+ readonly SlotElement: readonly ["attributes", "fragment"];
2630
+ readonly RegularElement: readonly ["attributes", "fragment"];
2631
+ readonly SvelteBody: readonly ["attributes", "fragment"];
2632
+ readonly SvelteBoundary: readonly ["attributes", "fragment"];
2633
+ readonly SvelteComponent: readonly ["expression", "attributes", "fragment"];
2634
+ readonly SvelteDocument: readonly ["attributes", "fragment"];
2635
+ readonly SvelteElement: readonly ["tag", "attributes", "fragment"];
2636
+ readonly SvelteFragment: readonly ["attributes", "fragment"];
2637
+ readonly SvelteHead: readonly ["attributes", "fragment"];
2638
+ readonly SvelteOptions: readonly ["attributes", "fragment"];
2639
+ readonly SvelteSelf: readonly ["attributes", "fragment"];
2640
+ readonly SvelteWindow: readonly ["attributes", "fragment"];
2641
+ readonly IfBlock: readonly ["test", "consequent", "alternate"];
2642
+ readonly EachBlock: readonly ["expression", "context", "key", "body", "fallback"];
2643
+ readonly AwaitBlock: readonly ["expression", "pending", "value", "then", "error", "catch"];
2644
+ readonly KeyBlock: readonly ["expression", "fragment"];
2645
+ readonly SnippetBlock: readonly ["expression", "parameters", "body"];
2646
+ readonly StyleSheet: readonly ["attributes", "children"];
2647
+ readonly Rule: readonly ["prelude", "block"];
2648
+ readonly Atrule: readonly ["block"];
2649
+ readonly SelectorList: readonly ["children"];
2650
+ readonly ComplexSelector: readonly ["children"];
2651
+ readonly RelativeSelector: readonly ["combinator", "selectors"];
2652
+ readonly Combinator: readonly [];
2653
+ readonly TypeSelector: readonly [];
2654
+ readonly IdSelector: readonly [];
2655
+ readonly ClassSelector: readonly [];
2656
+ readonly AttributeSelector: readonly [];
2657
+ readonly PseudoElementSelector: readonly ["args"];
2658
+ readonly PseudoClassSelector: readonly ["args"];
2659
+ readonly Percentage: readonly [];
2660
+ readonly Nth: readonly [];
2661
+ readonly NestingSelector: readonly [];
2662
+ readonly Block: readonly ["children"];
2663
+ readonly Declaration: readonly [];
2664
+ readonly Program: readonly ["body"];
2665
+ readonly ExpressionStatement: readonly ["expression"];
2666
+ readonly BlockStatement: readonly ["body"];
2667
+ readonly StaticBlock: readonly ["body"];
2668
+ readonly EmptyStatement: readonly [];
2669
+ readonly DebuggerStatement: readonly [];
2670
+ readonly WithStatement: readonly ["object", "body"];
2671
+ readonly ReturnStatement: readonly ["argument"];
2672
+ readonly LabeledStatement: readonly ["label", "body"];
2673
+ readonly BreakStatement: readonly ["label"];
2674
+ readonly ContinueStatement: readonly ["label"];
2675
+ readonly IfStatement: readonly ["test", "consequent", "alternate"];
2676
+ readonly SwitchStatement: readonly ["discriminant", "cases"];
2677
+ readonly SwitchCase: readonly ["test", "consequent"];
2678
+ readonly ThrowStatement: readonly ["argument"];
2679
+ readonly TryStatement: readonly ["block", "handler", "finalizer"];
2680
+ readonly CatchClause: readonly ["param", "body"];
2681
+ readonly WhileStatement: readonly ["test", "body"];
2682
+ readonly DoWhileStatement: readonly ["body", "test"];
2683
+ readonly ForStatement: readonly ["init", "test", "update", "body"];
2684
+ readonly ForInStatement: readonly ["left", "right", "body"];
2685
+ readonly ForOfStatement: readonly ["left", "right", "body"];
2686
+ readonly VariableDeclaration: readonly ["declarations"];
2687
+ readonly VariableDeclarator: readonly ["id", "init"];
2688
+ readonly ClassBody: readonly ["body"];
2689
+ readonly Property: readonly ["decorators", "key", "value"];
2690
+ readonly ThisExpression: readonly [];
2691
+ readonly Super: readonly [];
2692
+ readonly Literal: readonly [];
2693
+ readonly PrivateIdentifier: readonly [];
2694
+ readonly ArrayExpression: readonly ["elements"];
2695
+ readonly ObjectExpression: readonly ["properties"];
2696
+ readonly UnaryExpression: readonly ["argument"];
2697
+ readonly UpdateExpression: readonly ["argument"];
2698
+ readonly BinaryExpression: readonly ["left", "right"];
2699
+ readonly LogicalExpression: readonly ["left", "right"];
2700
+ readonly AssignmentExpression: readonly ["left", "right"];
2701
+ readonly MemberExpression: readonly ["object", "property"];
2702
+ readonly ConditionalExpression: readonly ["test", "consequent", "alternate"];
2703
+ readonly SequenceExpression: readonly ["expressions"];
2704
+ readonly TemplateLiteral: readonly ["quasis", "expressions"];
2705
+ readonly TemplateElement: readonly [];
2706
+ readonly SpreadElement: readonly ["argument"];
2707
+ readonly YieldExpression: readonly ["argument"];
2708
+ readonly AwaitExpression: readonly ["argument"];
2709
+ readonly ImportExpression: readonly ["source", "options", "arguments"];
2710
+ readonly ChainExpression: readonly ["expression"];
2711
+ readonly ParenthesizedExpression: readonly ["expression"];
2712
+ readonly MetaProperty: readonly ["meta", "property"];
2713
+ readonly AssignmentPattern: readonly ["decorators", "left", "right"];
2714
+ readonly ImportDeclaration: readonly ["specifiers", "source", "attributes"];
2715
+ readonly ImportSpecifier: readonly ["imported", "local"];
2716
+ readonly ImportDefaultSpecifier: readonly ["local"];
2717
+ readonly ImportNamespaceSpecifier: readonly ["local"];
2718
+ readonly ImportAttribute: readonly ["key", "value"];
2719
+ readonly ExportNamedDeclaration: readonly ["declaration", "specifiers", "source", "attributes"];
2720
+ readonly ExportSpecifier: readonly ["local", "exported"];
2721
+ readonly ExportDefaultDeclaration: readonly ["declaration"];
2722
+ readonly ExportAllDeclaration: readonly ["exported", "source", "attributes"];
2723
+ readonly Decorator: readonly ["expression"];
2724
+ readonly TSAnyKeyword: readonly [];
2725
+ readonly TSBigIntKeyword: readonly [];
2726
+ readonly TSBooleanKeyword: readonly [];
2727
+ readonly TSNeverKeyword: readonly [];
2728
+ readonly TSNullKeyword: readonly [];
2729
+ readonly TSNumberKeyword: readonly [];
2730
+ readonly TSObjectKeyword: readonly [];
2731
+ readonly TSStringKeyword: readonly [];
2732
+ readonly TSSymbolKeyword: readonly [];
2733
+ readonly TSUndefinedKeyword: readonly [];
2734
+ readonly TSUnknownKeyword: readonly [];
2735
+ readonly TSVoidKeyword: readonly [];
2736
+ readonly TSThisType: readonly [];
2737
+ readonly TSQualifiedName: readonly ["left", "right"];
2738
+ readonly TSEnumDeclaration: readonly ["id", "members"];
2739
+ readonly TSEnumMember: readonly ["id", "initializer"];
2740
+ readonly TSModuleDeclaration: readonly ["id", "body"];
2741
+ readonly TSModuleBlock: readonly ["body"];
2742
+ readonly TSImportEqualsDeclaration: readonly ["id", "moduleReference"];
2743
+ readonly TSExternalModuleReference: readonly ["expression"];
2744
+ readonly TSExportAssignment: readonly ["expression"];
2745
+ readonly TSParameterProperty: readonly ["parameter"];
2746
+ readonly TSNonNullExpression: readonly ["expression"];
2747
+ };
2748
+
2749
+ /**
2750
+ * Return it from `enter` or `leave` to end the walk: no further `enter` or
2751
+ * `leave` calls, including `leave` on the node's ancestors.
2752
+ */
2753
+ export declare const STOP: unique symbol;
2754
+
2755
+ /**
2756
+ * Return it from `enter` to skip the node's children; `leave` is still
2757
+ * called on the node.
2758
+ */
2759
+ export declare const SKIP: unique symbol;
2760
+
2761
+ /** The callbacks {@link walk} calls for each node. */
2762
+ export interface Visitor {
2763
+ /**
2764
+ * Called before the node's children. Return {@link SKIP} to skip them;
2765
+ * `leave` is still called, so the two stay paired. Return {@link STOP} to
2766
+ * end the walk. Return another node to put it in this one's place: `walk`
2767
+ * writes it to `parent[key]` (or `parent[key][index]`), then calls `enter`
2768
+ * on it and visits its children instead. Any other value, `false`
2769
+ * included, is ignored, so `(node) => node.type === "Component" &&
2770
+ * names.add(node.name)` visits every node.
2771
+ */
2772
+ enter?(node: AST.SvelteNode, parent: AST.SvelteNode | null, key: string | null, index: number | null): unknown;
2773
+ /** Called after the node's children. Return {@link STOP} to end the walk. */
2774
+ leave?(node: AST.SvelteNode, parent: AST.SvelteNode | null, key: string | null, index: number | null): unknown;
2775
+ }
2776
+
2777
+ /**
2778
+ * Visits `node` and its descendants depth-first, in source order, calling
2779
+ * `visitor.enter` before a node's children and `visitor.leave` after them.
2780
+ * `parent[key]` is the node, or `parent[key][index]` when the field is an
2781
+ * array; all three are `null` for `node` itself. `keys` says which fields
2782
+ * of each node type to visit, {@link visitorKeys} by default; with
2783
+ * {@link markupVisitorKeys}, only the markup is visited. A node whose
2784
+ * type it has no entry for throws.
2785
+ */
2786
+ export declare function walk(node: AST.SvelteNode, visitor: Visitor, keys?: VisitorKeys): void;
2787
+
2788
+ /**
2789
+ * Calls `callback` with each of `node`'s child nodes in source order, as
2790
+ * {@link walk} would visit them, with the field that holds the child and
2791
+ * its index when the field is an array. Allocates nothing. `keys` is as
2792
+ * in {@link walk}.
2793
+ */
2794
+ export declare function forEachChild(node: AST.SvelteNode, callback: (child: AST.SvelteNode, key: string, index: number | null) => void, keys?: VisitorKeys): void;
2795
+
2796
+ /**
2797
+ * `node`'s child nodes in source order, as {@link walk} would visit them.
2798
+ * The array is made on the first call for each node and `keys`, and the
2799
+ * same one is returned after, so don't change it; a node that
2800
+ * {@link walk} replaces later isn't in it. `keys` is as in {@link walk}.
2801
+ */
2802
+ export declare function children(node: AST.SvelteNode, keys?: VisitorKeys): readonly AST.SvelteNode[];
2803
+
2804
+ /**
2805
+ * The `Identifier` nodes a pattern binds, in source order: `a`, `c`, `d`,
2806
+ * `e` and `f` in `{ a, b: [c, ...d], e = 1, ...f }`. Not the property
2807
+ * keys, defaults or type annotations. A member expression, which an
2808
+ * assignment's pattern can hold, as in `[a.b] = c`, binds nothing, so it
2809
+ * yields no identifiers, as in svelte's `extract_identifiers`. Also takes
2810
+ * a function's params as they are, parameter properties included, and an
2811
+ * assignment's `left`, where `a!`, `a as T`, `a satisfies T` and `<T>a`
2812
+ * yield `a`.
2813
+ */
2814
+ export declare function extractIdentifiers(pattern: Pattern | TSParameterProperty | AssignmentExpression["left"]): Identifier[];
2815
+
2816
+ /**
2817
+ * Whether `node` is an `Identifier` that names a binding in the value
2818
+ * namespace, where it's declared or where it's used, given its `parent`
2819
+ * from `walk`. `false` for a property, method or label name, the
2820
+ * renamed side of an import or export specifier, `import.meta`'s and
2821
+ * `new.target`'s names, an import attribute's key, and every name in a
2822
+ * type. The check svelte's analyzer makes, from the `is-reference` package,
2823
+ * plus TypeScript: an `Identifier` whose parent is a TypeScript node is a
2824
+ * reference only as the expression of `as`, `satisfies`, `<T>x`, `x!`,
2825
+ * `f<T>` or `export =`, an enum member's initializer, a parameter
2826
+ * property, an enum's name, or the name or target of `import a = b`.
2827
+ */
2828
+ export declare function isReference(node: AST.SvelteNode, parent: AST.SvelteNode | null): boolean;
2829
+
2830
+ /**
2831
+ * The `{ line, column }` of `offset` in `text`, line from 1 and column
2832
+ * from 0, as {@link createLocator}'s function gives it, without keeping
2833
+ * a locator: the lines of the last 64 texts are kept, so calls for
2834
+ * several files in any order cost a lookup each after the first.
2835
+ *
2836
+ * ```ts
2837
+ * import { locate } from "svelte-ast";
2838
+ *
2839
+ * `${file}:${locate(source, node.start).line}`;
2840
+ * ```
2841
+ */
2842
+ export declare function locate(text: string, offset: number): Position;
2843
+
2844
+ export declare function skipTypeWrappers(node: AST.SvelteNode): AST.SvelteNode;