sveast 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts ADDED
@@ -0,0 +1,1156 @@
1
+ /**
2
+ * Parses a Svelte component into svelte's modern AST, the same as
3
+ * `parse(source, { modern: true })` from svelte/compiler. From svelte's
4
+ * `Parser` constructor (`phases/1-parse/index.js`).
5
+ *
6
+ * Throws a {@link ParseError} on a syntax error.
7
+ */
8
+ export declare function parse(source: string, options?: ParseOptions): AST.Root;
9
+
10
+ interface SourceLocation {
11
+ start: Location;
12
+ end: Location;
13
+ }
14
+
15
+ interface Identifier {
16
+ type: "Identifier";
17
+ name: string;
18
+ start: number;
19
+ end: number;
20
+ loc?: SourceLocation;
21
+ }
22
+
23
+ /**
24
+ * Options for {@link parse}. The defaults give svelte's own output, minus
25
+ * `loc` and `name_loc`.
26
+ */
27
+ export interface ParseOptions {
28
+ /**
29
+ * Add `loc` (line/column) to script and expression nodes, and `name_loc`
30
+ * to elements, attributes and directives, as svelte does. Off by default:
31
+ * it makes parsing slower and the AST larger.
32
+ */
33
+ loc?: boolean;
34
+ /**
35
+ * Parse `<style>` into rules and selectors (`css.children`). With `false`,
36
+ * `css` still has its `start`, `end` and `content`, but `children` and
37
+ * `comments` are empty and CSS syntax errors aren't reported. Default `true`.
38
+ */
39
+ css?: boolean;
40
+ }
41
+
42
+ interface Location {
43
+ line: number;
44
+ column: number;
45
+ character: number;
46
+ }
47
+
48
+ type Namespace = "html" | "svg" | "mathml";
49
+
50
+ export declare namespace AST {
51
+ export interface BaseNode {
52
+ type: string;
53
+ start: number;
54
+ end: number;
55
+ }
56
+ export interface Fragment {
57
+ type: "Fragment";
58
+ nodes: Array<Text | Tag | ElementLike | Block | Comment>;
59
+ }
60
+ export interface Root extends BaseNode {
61
+ type: "Root";
62
+ /**
63
+ * Inline options provided by `<svelte:options>` — these override options passed to `compile(...)`
64
+ */
65
+ options: SvelteOptions | null;
66
+ fragment: Fragment;
67
+ /** The parsed `<style>` element, if exists */
68
+ css: AST.CSS.StyleSheet | null;
69
+ /** The parsed `<script>` element, if exists */
70
+ instance?: Script | null;
71
+ /** The parsed `<script module>` element, if exists */
72
+ module?: Script | null;
73
+ /** Comments found in <script> and {expressions} */
74
+ comments: JSComment[];
75
+ }
76
+ export interface SvelteOptions {
77
+ start: number;
78
+ end: number;
79
+ runes?: boolean;
80
+ immutable?: boolean;
81
+ accessors?: boolean;
82
+ preserveWhitespace?: boolean;
83
+ namespace?: Namespace;
84
+ css?: "injected";
85
+ customElement?: {
86
+ tag?: string;
87
+ shadow?: "open" | "none" | ObjectExpression | undefined;
88
+ props?: Record<string, {
89
+ attribute?: string;
90
+ reflect?: boolean;
91
+ type?: "Array" | "Boolean" | "Number" | "Object" | "String";
92
+ }>;
93
+ /**
94
+ * Is of type
95
+ * ```ts
96
+ * (ceClass: new () => HTMLElement) => new () => HTMLElement
97
+ * ```
98
+ */
99
+ extend?: ArrowFunctionExpression | Identifier;
100
+ };
101
+ attributes: Attribute[];
102
+ }
103
+ /** Static text */
104
+ export interface Text extends BaseNode {
105
+ type: "Text";
106
+ /** Text with decoded HTML entities */
107
+ data: string;
108
+ /** The original text, with undecoded HTML entities */
109
+ raw: string;
110
+ }
111
+ /** A (possibly reactive) template expression — `{...}` */
112
+ export interface ExpressionTag extends BaseNode {
113
+ type: "ExpressionTag";
114
+ expression: Expression;
115
+ }
116
+ /** A (possibly reactive) HTML template expression — `{@html ...}` */
117
+ export interface HtmlTag extends BaseNode {
118
+ type: "HtmlTag";
119
+ expression: Expression;
120
+ }
121
+ /** An HTML comment */
122
+ export interface Comment extends BaseNode {
123
+ type: "Comment";
124
+ /** the contents of the comment */
125
+ data: string;
126
+ }
127
+ /** A `{@const ...}` tag */
128
+ export interface ConstTag extends BaseNode {
129
+ type: "ConstTag";
130
+ declaration: VariableDeclaration & {
131
+ declarations: [VariableDeclarator & {
132
+ id: Pattern;
133
+ init: Expression;
134
+ }];
135
+ };
136
+ }
137
+ /** A `{let ...}` or `{const ...}` tag */
138
+ export interface DeclarationTag extends BaseNode {
139
+ type: "DeclarationTag";
140
+ declaration: VariableDeclaration;
141
+ }
142
+ /** A `{@debug ...}` tag */
143
+ export interface DebugTag extends BaseNode {
144
+ type: "DebugTag";
145
+ identifiers: Identifier[];
146
+ }
147
+ /** A `{@render foo(...)} tag */
148
+ export interface RenderTag extends BaseNode {
149
+ type: "RenderTag";
150
+ expression: SimpleCallExpression | (ChainExpression & {
151
+ expression: SimpleCallExpression;
152
+ });
153
+ }
154
+ /** A `{@attach foo(...)} tag */
155
+ export interface AttachTag extends BaseNode {
156
+ type: "AttachTag";
157
+ expression: Expression;
158
+ }
159
+ /** An `animate:` directive */
160
+ export interface AnimateDirective extends BaseAttribute {
161
+ type: "AnimateDirective";
162
+ /** The 'x' in `animate:x` */
163
+ name: string;
164
+ /** The y in `animate:x={y}` */
165
+ expression: null | Expression;
166
+ }
167
+ /** A `bind:` directive */
168
+ export interface BindDirective extends BaseAttribute {
169
+ type: "BindDirective";
170
+ /** The 'x' in `bind:x` */
171
+ name: string;
172
+ /** The y in `bind:x={y}` */
173
+ expression: Identifier | MemberExpression | SequenceExpression;
174
+ }
175
+ /** A `class:` directive */
176
+ export interface ClassDirective extends BaseAttribute {
177
+ type: "ClassDirective";
178
+ /** The 'x' in `class:x` */
179
+ name: "class";
180
+ /** The 'y' in `class:x={y}`, or the `x` in `class:x` */
181
+ expression: Expression;
182
+ }
183
+ /** A `let:` directive */
184
+ export interface LetDirective extends BaseAttribute {
185
+ type: "LetDirective";
186
+ /** The 'x' in `let:x` */
187
+ name: string;
188
+ /** The 'y' in `let:x={y}` */
189
+ expression: null | Identifier | ArrayExpression | ObjectExpression;
190
+ }
191
+ /** An `on:` directive */
192
+ export interface OnDirective extends BaseAttribute {
193
+ type: "OnDirective";
194
+ /** The 'x' in `on:x` */
195
+ name: string;
196
+ /** The 'y' in `on:x={y}` */
197
+ expression: null | Expression;
198
+ modifiers: Array<"capture" | "nonpassive" | "once" | "passive" | "preventDefault" | "self" | "stopImmediatePropagation" | "stopPropagation" | "trusted">;
199
+ }
200
+ /** A `style:` directive */
201
+ export interface StyleDirective extends BaseAttribute {
202
+ type: "StyleDirective";
203
+ /** The 'x' in `style:x` */
204
+ name: string;
205
+ /** The 'y' in `style:x={y}` */
206
+ value: true | ExpressionTag | Array<ExpressionTag | Text>;
207
+ modifiers: Array<"important">;
208
+ }
209
+ /** A `transition:`, `in:` or `out:` directive */
210
+ export interface TransitionDirective extends BaseAttribute {
211
+ type: "TransitionDirective";
212
+ /** The 'x' in `transition:x` */
213
+ name: string;
214
+ /** The 'y' in `transition:x={y}` */
215
+ expression: null | Expression;
216
+ modifiers: Array<"local" | "global">;
217
+ /** True if this is a `transition:` or `in:` directive */
218
+ intro: boolean;
219
+ /** True if this is a `transition:` or `out:` directive */
220
+ outro: boolean;
221
+ }
222
+ /** A `use:` directive */
223
+ export interface UseDirective extends BaseAttribute {
224
+ type: "UseDirective";
225
+ /** The 'x' in `use:x` */
226
+ name: string;
227
+ /** The 'y' in `use:x={y}` */
228
+ expression: null | Expression;
229
+ }
230
+ export interface BaseElement extends BaseNode {
231
+ name: string;
232
+ /** Only with `parse(source, { loc: true })`. */
233
+ name_loc?: SourceLocation;
234
+ attributes: Array<Attribute | SpreadAttribute | Directive | AttachTag>;
235
+ fragment: Fragment;
236
+ }
237
+ export interface Component extends BaseElement {
238
+ type: "Component";
239
+ }
240
+ export interface TitleElement extends BaseElement {
241
+ type: "TitleElement";
242
+ name: "title";
243
+ }
244
+ export interface SlotElement extends BaseElement {
245
+ type: "SlotElement";
246
+ name: "slot";
247
+ }
248
+ export interface RegularElement extends BaseElement {
249
+ type: "RegularElement";
250
+ }
251
+ export interface SvelteBody extends BaseElement {
252
+ type: "SvelteBody";
253
+ name: "svelte:body";
254
+ }
255
+ export interface SvelteComponent extends BaseElement {
256
+ type: "SvelteComponent";
257
+ name: "svelte:component";
258
+ expression: Expression;
259
+ }
260
+ export interface SvelteDocument extends BaseElement {
261
+ type: "SvelteDocument";
262
+ name: "svelte:document";
263
+ }
264
+ export interface SvelteElement extends BaseElement {
265
+ type: "SvelteElement";
266
+ name: "svelte:element";
267
+ tag: Expression;
268
+ }
269
+ export interface SvelteFragment extends BaseElement {
270
+ type: "SvelteFragment";
271
+ name: "svelte:fragment";
272
+ }
273
+ export interface SvelteBoundary extends BaseElement {
274
+ type: "SvelteBoundary";
275
+ name: "svelte:boundary";
276
+ }
277
+ export interface SvelteHead extends BaseElement {
278
+ type: "SvelteHead";
279
+ name: "svelte:head";
280
+ }
281
+ /** This is only an intermediate representation while parsing, it doesn't exist in the final AST */
282
+ export interface SvelteOptionsRaw extends BaseElement {
283
+ type: "SvelteOptions";
284
+ name: "svelte:options";
285
+ }
286
+ export interface SvelteSelf extends BaseElement {
287
+ type: "SvelteSelf";
288
+ name: "svelte:self";
289
+ }
290
+ export interface SvelteWindow extends BaseElement {
291
+ type: "SvelteWindow";
292
+ name: "svelte:window";
293
+ }
294
+ /** An `{#each ...}` block */
295
+ export interface EachBlock extends BaseNode {
296
+ type: "EachBlock";
297
+ expression: Expression;
298
+ /** The `entry` in `{#each item as entry}`. `null` if `as` part is omitted */
299
+ context: Pattern | null;
300
+ body: Fragment;
301
+ fallback?: Fragment;
302
+ index?: string;
303
+ key?: Expression;
304
+ }
305
+ /** An `{#if ...}` block */
306
+ export interface IfBlock extends BaseNode {
307
+ type: "IfBlock";
308
+ elseif: boolean;
309
+ test: Expression;
310
+ consequent: Fragment;
311
+ alternate: Fragment | null;
312
+ }
313
+ /** An `{#await ...}` block */
314
+ export interface AwaitBlock extends BaseNode {
315
+ type: "AwaitBlock";
316
+ expression: Expression;
317
+ /** The resolved value inside the `then` block */
318
+ value: Pattern | null;
319
+ /** The rejection reason inside the `catch` block */
320
+ error: Pattern | null;
321
+ pending: Fragment | null;
322
+ then: Fragment | null;
323
+ catch: Fragment | null;
324
+ }
325
+ export interface KeyBlock extends BaseNode {
326
+ type: "KeyBlock";
327
+ expression: Expression;
328
+ fragment: Fragment;
329
+ }
330
+ export interface SnippetBlock extends BaseNode {
331
+ type: "SnippetBlock";
332
+ expression: Identifier;
333
+ parameters: Pattern[];
334
+ typeParams?: string;
335
+ body: Fragment;
336
+ }
337
+ export interface BaseAttribute extends BaseNode {
338
+ name: string;
339
+ /** Only with `parse(source, { loc: true })`. */
340
+ name_loc?: SourceLocation | null;
341
+ }
342
+ export interface Attribute extends BaseAttribute {
343
+ type: "Attribute";
344
+ /**
345
+ * Quoted/string values are represented by an array, even if they contain a single expression like `"{x}"`
346
+ */
347
+ value: true | ExpressionTag | Array<Text | ExpressionTag>;
348
+ }
349
+ export interface SpreadAttribute extends BaseNode {
350
+ type: "SpreadAttribute";
351
+ expression: Expression;
352
+ }
353
+ export interface Script extends BaseNode {
354
+ type: "Script";
355
+ context: "default" | "module";
356
+ content: Program;
357
+ attributes: Attribute[];
358
+ }
359
+ export interface JSComment {
360
+ type: "Line" | "Block";
361
+ value: string;
362
+ start: number;
363
+ end: number;
364
+ /** Only with `parse(source, { loc: true })`. */
365
+ loc?: {
366
+ start: {
367
+ line: number;
368
+ column: number;
369
+ };
370
+ end: {
371
+ line: number;
372
+ column: number;
373
+ };
374
+ };
375
+ }
376
+ export type AttributeLike = Attribute | SpreadAttribute | Directive;
377
+ export type Directive = AST.AnimateDirective | AST.BindDirective | AST.ClassDirective | AST.LetDirective | AST.OnDirective | AST.StyleDirective | AST.TransitionDirective | AST.UseDirective;
378
+ export type Block = AST.EachBlock | AST.IfBlock | AST.AwaitBlock | AST.KeyBlock | AST.SnippetBlock;
379
+ 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;
380
+ export type Tag = AST.AttachTag | AST.ConstTag | AST.DeclarationTag | AST.DebugTag | AST.ExpressionTag | AST.HtmlTag | AST.RenderTag;
381
+ export type TemplateNode = AST.Root | AST.Text | Tag | ElementLike | AST.Attribute | AST.SpreadAttribute | Directive | AST.AttachTag | AST.Comment | Block;
382
+ export type SvelteNode = Node | TemplateNode | AST.Fragment | _CSS.Node | Script;
383
+ export type { _CSS as CSS };
384
+ }
385
+
386
+ declare namespace _CSS {
387
+ interface BaseNode {
388
+ start: number;
389
+ end: number;
390
+ }
391
+ interface StyleSheetBase extends BaseNode {
392
+ children: Array<Atrule | Rule>;
393
+ /** CSS comments in source order */
394
+ comments: CSSComment[];
395
+ }
396
+ interface CSSComment extends BaseNode {
397
+ type: "CSSComment";
398
+ value: string;
399
+ /** Character offset in a containing declaration value or at-rule prelude */
400
+ position?: number;
401
+ }
402
+ interface StyleSheetFile extends StyleSheetBase {
403
+ type: "StyleSheetFile";
404
+ }
405
+ interface StyleSheet extends StyleSheetBase {
406
+ type: "StyleSheet";
407
+ attributes: any[];
408
+ content: {
409
+ start: number;
410
+ end: number;
411
+ styles: string;
412
+ /** Possible comment atop the style tag */
413
+ comment: AST.Comment | null;
414
+ };
415
+ }
416
+ interface Atrule extends BaseNode {
417
+ type: "Atrule";
418
+ name: string;
419
+ prelude: string;
420
+ block: Block | null;
421
+ }
422
+ interface Rule extends BaseNode {
423
+ type: "Rule";
424
+ prelude: SelectorList;
425
+ block: Block;
426
+ }
427
+ /**
428
+ * A list of selectors, e.g. `a, b, c {}`
429
+ */
430
+ interface SelectorList extends BaseNode {
431
+ type: "SelectorList";
432
+ /**
433
+ * The `a`, `b` and `c` in `a, b, c {}`
434
+ */
435
+ children: ComplexSelector[];
436
+ }
437
+ /**
438
+ * A complex selector, e.g. `a b c {}`
439
+ */
440
+ interface ComplexSelector extends BaseNode {
441
+ type: "ComplexSelector";
442
+ /**
443
+ * The `a`, `b` and `c` in `a b c {}`
444
+ */
445
+ children: RelativeSelector[];
446
+ }
447
+ /**
448
+ * A relative selector, e.g the `a` and `> b` in `a > b {}`
449
+ */
450
+ interface RelativeSelector extends BaseNode {
451
+ type: "RelativeSelector";
452
+ /**
453
+ * In `a > b`, `> b` forms one relative selector, and `>` is the combinator. `null` for the first selector.
454
+ */
455
+ combinator: null | Combinator;
456
+ /**
457
+ * The `b:is(...)` in `> b:is(...)`
458
+ */
459
+ selectors: SimpleSelector[];
460
+ }
461
+ interface TypeSelector extends BaseNode {
462
+ type: "TypeSelector";
463
+ name: string;
464
+ namespace?: string;
465
+ }
466
+ interface IdSelector extends BaseNode {
467
+ type: "IdSelector";
468
+ name: string;
469
+ }
470
+ interface ClassSelector extends BaseNode {
471
+ type: "ClassSelector";
472
+ name: string;
473
+ }
474
+ interface AttributeSelector extends BaseNode {
475
+ type: "AttributeSelector";
476
+ name: string;
477
+ matcher: string | null;
478
+ value: string | null;
479
+ flags: string | null;
480
+ }
481
+ interface PseudoElementSelector extends BaseNode {
482
+ type: "PseudoElementSelector";
483
+ name: string;
484
+ args?: SelectorList;
485
+ }
486
+ interface PseudoClassSelector extends BaseNode {
487
+ type: "PseudoClassSelector";
488
+ name: string;
489
+ args: SelectorList | null;
490
+ }
491
+ interface Percentage extends BaseNode {
492
+ type: "Percentage";
493
+ value: string;
494
+ }
495
+ interface NestingSelector extends BaseNode {
496
+ type: "NestingSelector";
497
+ name: "&";
498
+ }
499
+ interface Nth extends BaseNode {
500
+ type: "Nth";
501
+ value: string;
502
+ }
503
+ type SimpleSelector = TypeSelector | IdSelector | ClassSelector | AttributeSelector | PseudoElementSelector | PseudoClassSelector | Percentage | Nth | NestingSelector;
504
+ interface Combinator extends BaseNode {
505
+ type: "Combinator";
506
+ name: string;
507
+ }
508
+ interface Block extends BaseNode {
509
+ type: "Block";
510
+ children: Array<Declaration | Rule | Atrule>;
511
+ }
512
+ interface Declaration extends BaseNode {
513
+ type: "Declaration";
514
+ property: string;
515
+ value: string;
516
+ }
517
+ type Node = StyleSheet | Rule | Atrule | SelectorList | Block | ComplexSelector | RelativeSelector | Combinator | SimpleSelector | Declaration;
518
+ }
519
+
520
+ interface BaseNodeWithoutComments {
521
+ type: string;
522
+ loc?: SourceLocation | null | undefined;
523
+ range?: [number, number] | undefined;
524
+ }
525
+
526
+ interface BaseNode extends BaseNodeWithoutComments {
527
+ leadingComments?: Comment[] | undefined;
528
+ trailingComments?: Comment[] | undefined;
529
+ }
530
+
531
+ interface NodeMap {
532
+ AssignmentProperty: AssignmentProperty;
533
+ CatchClause: CatchClause;
534
+ Class: Class;
535
+ ClassBody: ClassBody;
536
+ Expression: Expression;
537
+ Function: Function;
538
+ Identifier: Identifier;
539
+ Literal: Literal;
540
+ MethodDefinition: MethodDefinition;
541
+ ModuleDeclaration: ModuleDeclaration;
542
+ ModuleSpecifier: ModuleSpecifier;
543
+ Pattern: Pattern;
544
+ PrivateIdentifier: PrivateIdentifier;
545
+ Program: Program;
546
+ Property: Property;
547
+ PropertyDefinition: PropertyDefinition;
548
+ SpreadElement: SpreadElement;
549
+ Statement: Statement;
550
+ Super: Super;
551
+ SwitchCase: SwitchCase;
552
+ TemplateElement: TemplateElement;
553
+ VariableDeclarator: VariableDeclarator;
554
+ }
555
+
556
+ type Node = NodeMap[keyof NodeMap];
557
+
558
+ interface Comment extends BaseNodeWithoutComments {
559
+ type: "Line" | "Block";
560
+ value: string;
561
+ }
562
+
563
+ interface Program extends BaseNode {
564
+ type: "Program";
565
+ sourceType: "script" | "module";
566
+ body: Array<Directive | Statement | ModuleDeclaration>;
567
+ comments?: Comment[] | undefined;
568
+ }
569
+
570
+ interface Directive extends BaseNode {
571
+ type: "ExpressionStatement";
572
+ expression: Literal;
573
+ directive: string;
574
+ }
575
+
576
+ interface BaseFunction extends BaseNode {
577
+ params: Pattern[];
578
+ generator?: boolean | undefined;
579
+ async?: boolean | undefined;
580
+ body: BlockStatement | Expression;
581
+ }
582
+
583
+ type Function = FunctionDeclaration | FunctionExpression | ArrowFunctionExpression;
584
+
585
+ type Statement = ExpressionStatement | BlockStatement | StaticBlock | EmptyStatement | DebuggerStatement | WithStatement | ReturnStatement | LabeledStatement | BreakStatement | ContinueStatement | IfStatement | SwitchStatement | ThrowStatement | TryStatement | WhileStatement | DoWhileStatement | ForStatement | ForInStatement | ForOfStatement | Declaration;
586
+
587
+ interface BaseStatement extends BaseNode {
588
+ }
589
+
590
+ interface EmptyStatement extends BaseStatement {
591
+ type: "EmptyStatement";
592
+ }
593
+
594
+ interface BlockStatement extends BaseStatement {
595
+ type: "BlockStatement";
596
+ body: Statement[];
597
+ innerComments?: Comment[] | undefined;
598
+ }
599
+
600
+ interface StaticBlock extends Omit<BlockStatement, "type"> {
601
+ type: "StaticBlock";
602
+ }
603
+
604
+ interface ExpressionStatement extends BaseStatement {
605
+ type: "ExpressionStatement";
606
+ expression: Expression;
607
+ }
608
+
609
+ interface IfStatement extends BaseStatement {
610
+ type: "IfStatement";
611
+ test: Expression;
612
+ consequent: Statement;
613
+ alternate?: Statement | null | undefined;
614
+ }
615
+
616
+ interface LabeledStatement extends BaseStatement {
617
+ type: "LabeledStatement";
618
+ label: Identifier;
619
+ body: Statement;
620
+ }
621
+
622
+ interface BreakStatement extends BaseStatement {
623
+ type: "BreakStatement";
624
+ label?: Identifier | null | undefined;
625
+ }
626
+
627
+ interface ContinueStatement extends BaseStatement {
628
+ type: "ContinueStatement";
629
+ label?: Identifier | null | undefined;
630
+ }
631
+
632
+ interface WithStatement extends BaseStatement {
633
+ type: "WithStatement";
634
+ object: Expression;
635
+ body: Statement;
636
+ }
637
+
638
+ interface SwitchStatement extends BaseStatement {
639
+ type: "SwitchStatement";
640
+ discriminant: Expression;
641
+ cases: SwitchCase[];
642
+ }
643
+
644
+ interface ReturnStatement extends BaseStatement {
645
+ type: "ReturnStatement";
646
+ argument?: Expression | null | undefined;
647
+ }
648
+
649
+ interface ThrowStatement extends BaseStatement {
650
+ type: "ThrowStatement";
651
+ argument: Expression;
652
+ }
653
+
654
+ interface TryStatement extends BaseStatement {
655
+ type: "TryStatement";
656
+ block: BlockStatement;
657
+ handler?: CatchClause | null | undefined;
658
+ finalizer?: BlockStatement | null | undefined;
659
+ }
660
+
661
+ interface WhileStatement extends BaseStatement {
662
+ type: "WhileStatement";
663
+ test: Expression;
664
+ body: Statement;
665
+ }
666
+
667
+ interface DoWhileStatement extends BaseStatement {
668
+ type: "DoWhileStatement";
669
+ body: Statement;
670
+ test: Expression;
671
+ }
672
+
673
+ interface ForStatement extends BaseStatement {
674
+ type: "ForStatement";
675
+ init?: VariableDeclaration | Expression | null | undefined;
676
+ test?: Expression | null | undefined;
677
+ update?: Expression | null | undefined;
678
+ body: Statement;
679
+ }
680
+
681
+ interface BaseForXStatement extends BaseStatement {
682
+ left: VariableDeclaration | Pattern;
683
+ right: Expression;
684
+ body: Statement;
685
+ }
686
+
687
+ interface ForInStatement extends BaseForXStatement {
688
+ type: "ForInStatement";
689
+ }
690
+
691
+ interface DebuggerStatement extends BaseStatement {
692
+ type: "DebuggerStatement";
693
+ }
694
+
695
+ type Declaration = FunctionDeclaration | VariableDeclaration | ClassDeclaration;
696
+
697
+ interface BaseDeclaration extends BaseStatement {
698
+ }
699
+
700
+ interface MaybeNamedFunctionDeclaration extends BaseFunction, BaseDeclaration {
701
+ type: "FunctionDeclaration";
702
+ /** It is null when a function declaration is a part of the `export default function` statement */
703
+ id: Identifier | null;
704
+ body: BlockStatement;
705
+ }
706
+
707
+ interface FunctionDeclaration extends MaybeNamedFunctionDeclaration {
708
+ id: Identifier;
709
+ }
710
+
711
+ interface VariableDeclaration extends BaseDeclaration {
712
+ type: "VariableDeclaration";
713
+ declarations: VariableDeclarator[];
714
+ kind: "var" | "let" | "const" | "using" | "await using";
715
+ }
716
+
717
+ interface VariableDeclarator extends BaseNode {
718
+ type: "VariableDeclarator";
719
+ id: Pattern;
720
+ init?: Expression | null | undefined;
721
+ }
722
+
723
+ interface ExpressionMap {
724
+ ArrayExpression: ArrayExpression;
725
+ ArrowFunctionExpression: ArrowFunctionExpression;
726
+ AssignmentExpression: AssignmentExpression;
727
+ AwaitExpression: AwaitExpression;
728
+ BinaryExpression: BinaryExpression;
729
+ CallExpression: CallExpression;
730
+ ChainExpression: ChainExpression;
731
+ ClassExpression: ClassExpression;
732
+ ConditionalExpression: ConditionalExpression;
733
+ FunctionExpression: FunctionExpression;
734
+ Identifier: Identifier;
735
+ ImportExpression: ImportExpression;
736
+ Literal: Literal;
737
+ LogicalExpression: LogicalExpression;
738
+ MemberExpression: MemberExpression;
739
+ MetaProperty: MetaProperty;
740
+ NewExpression: NewExpression;
741
+ ObjectExpression: ObjectExpression;
742
+ SequenceExpression: SequenceExpression;
743
+ TaggedTemplateExpression: TaggedTemplateExpression;
744
+ TemplateLiteral: TemplateLiteral;
745
+ ThisExpression: ThisExpression;
746
+ UnaryExpression: UnaryExpression;
747
+ UpdateExpression: UpdateExpression;
748
+ YieldExpression: YieldExpression;
749
+ }
750
+
751
+ type Expression = ExpressionMap[keyof ExpressionMap];
752
+
753
+ interface BaseExpression extends BaseNode {
754
+ }
755
+
756
+ type ChainElement = SimpleCallExpression | MemberExpression;
757
+
758
+ interface ChainExpression extends BaseExpression {
759
+ type: "ChainExpression";
760
+ expression: ChainElement;
761
+ }
762
+
763
+ interface ThisExpression extends BaseExpression {
764
+ type: "ThisExpression";
765
+ }
766
+
767
+ interface ArrayExpression extends BaseExpression {
768
+ type: "ArrayExpression";
769
+ elements: Array<Expression | SpreadElement | null>;
770
+ }
771
+
772
+ interface ObjectExpression extends BaseExpression {
773
+ type: "ObjectExpression";
774
+ properties: Array<Property | SpreadElement>;
775
+ }
776
+
777
+ interface PrivateIdentifier extends BaseNode {
778
+ type: "PrivateIdentifier";
779
+ name: string;
780
+ }
781
+
782
+ interface Property extends BaseNode {
783
+ type: "Property";
784
+ key: Expression;
785
+ value: Expression | Pattern;
786
+ kind: "init" | "get" | "set";
787
+ method: boolean;
788
+ shorthand: boolean;
789
+ computed: boolean;
790
+ }
791
+
792
+ interface PropertyDefinition extends BaseNode {
793
+ type: "PropertyDefinition";
794
+ key: Expression | PrivateIdentifier;
795
+ value?: Expression | null | undefined;
796
+ computed: boolean;
797
+ static: boolean;
798
+ }
799
+
800
+ interface FunctionExpression extends BaseFunction, BaseExpression {
801
+ id?: Identifier | null | undefined;
802
+ type: "FunctionExpression";
803
+ body: BlockStatement;
804
+ }
805
+
806
+ interface SequenceExpression extends BaseExpression {
807
+ type: "SequenceExpression";
808
+ expressions: Expression[];
809
+ }
810
+
811
+ interface UnaryExpression extends BaseExpression {
812
+ type: "UnaryExpression";
813
+ operator: UnaryOperator;
814
+ prefix: true;
815
+ argument: Expression;
816
+ }
817
+
818
+ interface BinaryExpression extends BaseExpression {
819
+ type: "BinaryExpression";
820
+ operator: BinaryOperator;
821
+ left: Expression | PrivateIdentifier;
822
+ right: Expression;
823
+ }
824
+
825
+ interface AssignmentExpression extends BaseExpression {
826
+ type: "AssignmentExpression";
827
+ operator: AssignmentOperator;
828
+ left: Pattern | MemberExpression;
829
+ right: Expression;
830
+ }
831
+
832
+ interface UpdateExpression extends BaseExpression {
833
+ type: "UpdateExpression";
834
+ operator: UpdateOperator;
835
+ argument: Expression;
836
+ prefix: boolean;
837
+ }
838
+
839
+ interface LogicalExpression extends BaseExpression {
840
+ type: "LogicalExpression";
841
+ operator: LogicalOperator;
842
+ left: Expression;
843
+ right: Expression;
844
+ }
845
+
846
+ interface ConditionalExpression extends BaseExpression {
847
+ type: "ConditionalExpression";
848
+ test: Expression;
849
+ alternate: Expression;
850
+ consequent: Expression;
851
+ }
852
+
853
+ interface BaseCallExpression extends BaseExpression {
854
+ callee: Expression | Super;
855
+ arguments: Array<Expression | SpreadElement>;
856
+ }
857
+
858
+ type CallExpression = SimpleCallExpression | NewExpression;
859
+
860
+ interface SimpleCallExpression extends BaseCallExpression {
861
+ type: "CallExpression";
862
+ optional: boolean;
863
+ }
864
+
865
+ interface NewExpression extends BaseCallExpression {
866
+ type: "NewExpression";
867
+ }
868
+
869
+ interface MemberExpression extends BaseExpression, BasePattern {
870
+ type: "MemberExpression";
871
+ object: Expression | Super;
872
+ property: Expression | PrivateIdentifier;
873
+ computed: boolean;
874
+ optional: boolean;
875
+ }
876
+
877
+ type Pattern = Identifier | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | MemberExpression;
878
+
879
+ interface BasePattern extends BaseNode {
880
+ }
881
+
882
+ interface SwitchCase extends BaseNode {
883
+ type: "SwitchCase";
884
+ test?: Expression | null | undefined;
885
+ consequent: Statement[];
886
+ }
887
+
888
+ interface CatchClause extends BaseNode {
889
+ type: "CatchClause";
890
+ param: Pattern | null;
891
+ body: BlockStatement;
892
+ }
893
+
894
+ type Literal = SimpleLiteral | RegExpLiteral | BigIntLiteral;
895
+
896
+ interface SimpleLiteral extends BaseNode, BaseExpression {
897
+ type: "Literal";
898
+ value: string | boolean | number | null;
899
+ raw?: string | undefined;
900
+ }
901
+
902
+ interface RegExpLiteral extends BaseNode, BaseExpression {
903
+ type: "Literal";
904
+ value?: RegExp | null | undefined;
905
+ regex: {
906
+ pattern: string;
907
+ flags: string;
908
+ };
909
+ raw?: string | undefined;
910
+ }
911
+
912
+ interface BigIntLiteral extends BaseNode, BaseExpression {
913
+ type: "Literal";
914
+ value?: bigint | null | undefined;
915
+ bigint: string;
916
+ raw?: string | undefined;
917
+ }
918
+
919
+ type UnaryOperator = "-" | "+" | "!" | "~" | "typeof" | "void" | "delete";
920
+
921
+ type BinaryOperator = "==" | "!=" | "===" | "!==" | "<" | "<=" | ">" | ">=" | "<<" | ">>" | ">>>" | "+" | "-" | "*" | "/" | "%" | "**" | "|" | "^" | "&" | "in" | "instanceof";
922
+
923
+ type LogicalOperator = "||" | "&&" | "??";
924
+
925
+ type AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "**=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&=" | "||=" | "&&=" | "??=";
926
+
927
+ type UpdateOperator = "++" | "--";
928
+
929
+ interface ForOfStatement extends BaseForXStatement {
930
+ type: "ForOfStatement";
931
+ await: boolean;
932
+ }
933
+
934
+ interface Super extends BaseNode {
935
+ type: "Super";
936
+ }
937
+
938
+ interface SpreadElement extends BaseNode {
939
+ type: "SpreadElement";
940
+ argument: Expression;
941
+ }
942
+
943
+ interface ArrowFunctionExpression extends BaseExpression, BaseFunction {
944
+ type: "ArrowFunctionExpression";
945
+ expression: boolean;
946
+ body: BlockStatement | Expression;
947
+ }
948
+
949
+ interface YieldExpression extends BaseExpression {
950
+ type: "YieldExpression";
951
+ argument?: Expression | null | undefined;
952
+ delegate: boolean;
953
+ }
954
+
955
+ interface TemplateLiteral extends BaseExpression {
956
+ type: "TemplateLiteral";
957
+ quasis: TemplateElement[];
958
+ expressions: Expression[];
959
+ }
960
+
961
+ interface TaggedTemplateExpression extends BaseExpression {
962
+ type: "TaggedTemplateExpression";
963
+ tag: Expression;
964
+ quasi: TemplateLiteral;
965
+ }
966
+
967
+ interface TemplateElement extends BaseNode {
968
+ type: "TemplateElement";
969
+ tail: boolean;
970
+ value: {
971
+ /** It is null when the template literal is tagged and the text has an invalid escape (e.g. - tag`\unicode and \u{55}`) */
972
+ cooked?: string | null | undefined;
973
+ raw: string;
974
+ };
975
+ }
976
+
977
+ interface AssignmentProperty extends Property {
978
+ value: Pattern;
979
+ kind: "init";
980
+ method: boolean;
981
+ }
982
+
983
+ interface ObjectPattern extends BasePattern {
984
+ type: "ObjectPattern";
985
+ properties: Array<AssignmentProperty | RestElement>;
986
+ }
987
+
988
+ interface ArrayPattern extends BasePattern {
989
+ type: "ArrayPattern";
990
+ elements: Array<Pattern | null>;
991
+ }
992
+
993
+ interface RestElement extends BasePattern {
994
+ type: "RestElement";
995
+ argument: Pattern;
996
+ }
997
+
998
+ interface AssignmentPattern extends BasePattern {
999
+ type: "AssignmentPattern";
1000
+ left: Pattern;
1001
+ right: Expression;
1002
+ }
1003
+
1004
+ type Class = ClassDeclaration | ClassExpression;
1005
+
1006
+ interface BaseClass extends BaseNode {
1007
+ superClass?: Expression | null | undefined;
1008
+ body: ClassBody;
1009
+ }
1010
+
1011
+ interface ClassBody extends BaseNode {
1012
+ type: "ClassBody";
1013
+ body: Array<MethodDefinition | PropertyDefinition | StaticBlock>;
1014
+ }
1015
+
1016
+ interface MethodDefinition extends BaseNode {
1017
+ type: "MethodDefinition";
1018
+ key: Expression | PrivateIdentifier;
1019
+ value: FunctionExpression;
1020
+ kind: "constructor" | "method" | "get" | "set";
1021
+ computed: boolean;
1022
+ static: boolean;
1023
+ }
1024
+
1025
+ interface MaybeNamedClassDeclaration extends BaseClass, BaseDeclaration {
1026
+ type: "ClassDeclaration";
1027
+ /** It is null when a class declaration is a part of the `export default class` statement */
1028
+ id: Identifier | null;
1029
+ }
1030
+
1031
+ interface ClassDeclaration extends MaybeNamedClassDeclaration {
1032
+ id: Identifier;
1033
+ }
1034
+
1035
+ interface ClassExpression extends BaseClass, BaseExpression {
1036
+ type: "ClassExpression";
1037
+ id?: Identifier | null | undefined;
1038
+ }
1039
+
1040
+ interface MetaProperty extends BaseExpression {
1041
+ type: "MetaProperty";
1042
+ meta: Identifier;
1043
+ property: Identifier;
1044
+ }
1045
+
1046
+ type ModuleDeclaration = ImportDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration;
1047
+
1048
+ interface BaseModuleDeclaration extends BaseNode {
1049
+ }
1050
+
1051
+ type ModuleSpecifier = ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier;
1052
+
1053
+ interface BaseModuleSpecifier extends BaseNode {
1054
+ local: Identifier;
1055
+ }
1056
+
1057
+ interface ImportDeclaration extends BaseModuleDeclaration {
1058
+ type: "ImportDeclaration";
1059
+ specifiers: Array<ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier>;
1060
+ attributes: ImportAttribute[];
1061
+ source: Literal;
1062
+ }
1063
+
1064
+ interface ImportSpecifier extends BaseModuleSpecifier {
1065
+ type: "ImportSpecifier";
1066
+ imported: Identifier | Literal;
1067
+ }
1068
+
1069
+ interface ImportAttribute extends BaseNode {
1070
+ type: "ImportAttribute";
1071
+ key: Identifier | Literal;
1072
+ value: Literal;
1073
+ }
1074
+
1075
+ interface ImportExpression extends BaseExpression {
1076
+ type: "ImportExpression";
1077
+ source: Expression;
1078
+ options?: Expression | null | undefined;
1079
+ }
1080
+
1081
+ interface ImportDefaultSpecifier extends BaseModuleSpecifier {
1082
+ type: "ImportDefaultSpecifier";
1083
+ }
1084
+
1085
+ interface ImportNamespaceSpecifier extends BaseModuleSpecifier {
1086
+ type: "ImportNamespaceSpecifier";
1087
+ }
1088
+
1089
+ interface ExportNamedDeclaration extends BaseModuleDeclaration {
1090
+ type: "ExportNamedDeclaration";
1091
+ declaration?: Declaration | null | undefined;
1092
+ specifiers: ExportSpecifier[];
1093
+ attributes: ImportAttribute[];
1094
+ source?: Literal | null | undefined;
1095
+ }
1096
+
1097
+ interface ExportSpecifier extends Omit<BaseModuleSpecifier, "local"> {
1098
+ type: "ExportSpecifier";
1099
+ local: Identifier | Literal;
1100
+ exported: Identifier | Literal;
1101
+ }
1102
+
1103
+ interface ExportDefaultDeclaration extends BaseModuleDeclaration {
1104
+ type: "ExportDefaultDeclaration";
1105
+ declaration: MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration | Expression;
1106
+ }
1107
+
1108
+ interface ExportAllDeclaration extends BaseModuleDeclaration {
1109
+ type: "ExportAllDeclaration";
1110
+ exported: Identifier | Literal | null;
1111
+ attributes: ImportAttribute[];
1112
+ source: Literal;
1113
+ }
1114
+
1115
+ interface AwaitExpression extends BaseExpression {
1116
+ type: "AwaitExpression";
1117
+ argument: Expression;
1118
+ }
1119
+
1120
+ type NodeLike = number | {
1121
+ start?: number;
1122
+ end?: number;
1123
+ } | null;
1124
+
1125
+ /**
1126
+ * Thrown for a syntax error. `code`, `message`, `position`, `start`, `end`
1127
+ * and `frame` are what svelte/compiler's `CompileError` has for the same
1128
+ * input.
1129
+ */
1130
+ export declare class ParseError extends Error {
1131
+ name: string;
1132
+ /** svelte's error code, e.g. `"expected_token"` or `"block_unclosed"`. */
1133
+ code: string;
1134
+ /** `[start, end]` offsets into the source. */
1135
+ position?: [number, number];
1136
+ start?: Location;
1137
+ end?: Location;
1138
+ /** A few lines of source around the error, with a `^` under it. */
1139
+ frame?: string;
1140
+ constructor(node: NodeLike, code: string, message: string);
1141
+ }
1142
+
1143
+ /**
1144
+ * Parses a JavaScript or TypeScript module, e.g. a `.ts` file a component
1145
+ * imports, into the same kind of AST as a component's `<script>`:
1146
+ * estree, TypeScript nodes as in `@sveltejs/acorn-typescript`, and
1147
+ * comments attached as `leadingComments`/`trailingComments`.
1148
+ *
1149
+ * Throws a {@link ParseError} (`js_parse_error`) on a syntax error.
1150
+ */
1151
+ export declare function parseModule(source: string, options?: {
1152
+ /** Parse TypeScript. Default `false`. */
1153
+ typescript?: boolean;
1154
+ /** Add `loc` (line/column) to every node. Default `false`. */
1155
+ loc?: boolean;
1156
+ }): Program;