ripple 0.2.180 → 0.2.183

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.
@@ -0,0 +1,1580 @@
1
+ /**
2
+ * Type definitions for Ripple's extended Acorn parser
3
+ *
4
+ * These types cover internal properties and static class members that aren't
5
+ * included in Acorn's official type definitions but are used by Ripple's parser.
6
+ *
7
+ * Based on acorn source code: https://github.com/acornjs/acorn
8
+ * and @sveltejs/acorn-typescript: https://github.com/sveltejs/acorn-typescript
9
+ *
10
+ * Usage in JSDoc: @type {Parse.Parser}
11
+ */
12
+
13
+ import type * as acorn from 'acorn';
14
+ import type * as AST from 'estree';
15
+ import type * as ESTreeJSX from 'estree-jsx';
16
+
17
+ type ForInit = boolean | 'await';
18
+
19
+ declare module 'acorn' {
20
+ // Helper type for readToken method
21
+ type ReadToken = Parse.Parser['readToken'];
22
+
23
+ const tokContexts: Parse.TokContexts;
24
+ class Position implements AST.Position {
25
+ line: number;
26
+ column: number;
27
+ constructor(line: number, column: number);
28
+ }
29
+ function isNewLine(code: number): boolean;
30
+
31
+ interface Parser {
32
+ readToken(...args: Parameters<ReadToken>): ReturnType<ReadToken>;
33
+ }
34
+ }
35
+
36
+ export namespace Parse {
37
+ /**
38
+ * Destructuring errors object used during expression parsing
39
+ * See: https://github.com/acornjs/acorn/blob/main/acorn/src/parseutil.js
40
+ */
41
+ export interface DestructuringErrors {
42
+ shorthandAssign: number;
43
+ trailingComma: number;
44
+ parenthesizedAssign: number;
45
+ parenthesizedBind: number;
46
+ doubleProto: number;
47
+ }
48
+
49
+ /**
50
+ * Binding type constants used in checkLVal* and declareName
51
+ * to determine the type of a binding
52
+ */
53
+ export interface BindingType {
54
+ /** Not a binding */
55
+ BIND_NONE: 0;
56
+ /** Var-style binding */
57
+ BIND_VAR: 1;
58
+ /** Let- or const-style binding */
59
+ BIND_LEXICAL: 2;
60
+ /** Function declaration */
61
+ BIND_FUNCTION: 3;
62
+ /** Simple (identifier pattern) catch binding */
63
+ BIND_SIMPLE_CATCH: 4;
64
+ /** Special case for function names as bound inside the function */
65
+ BIND_OUTSIDE: 5;
66
+ }
67
+
68
+ export interface Options extends Omit<acorn.Options, 'onComment' | 'ecmaVersion'> {
69
+ rippleOptions: {
70
+ loose: boolean;
71
+ };
72
+ // The type has "latest" but it's converted to 1e8 at runtime
73
+ // and if (ecmaVersion >= 2015) { ecmaVersion -= 2009 }
74
+ // so we're making it always a number to reflect the runtime values
75
+ ecmaVersion: number;
76
+ onComment(
77
+ block: boolean,
78
+ value: string,
79
+ start: number,
80
+ end: number,
81
+ start_loc: AST.Position,
82
+ end_loc: AST.Position,
83
+ metadata?: CommentMetaData | null,
84
+ ): void;
85
+ }
86
+
87
+ export interface CommentMetaData {
88
+ containerId: number;
89
+ childIndex: number;
90
+ beforeMeaningfulChild: boolean;
91
+ }
92
+
93
+ /**
94
+ * Token context - controls how tokens are interpreted in different syntactic contexts
95
+ */
96
+ export interface TokContext {
97
+ token: string;
98
+ isExpr: boolean;
99
+ preserveSpace?: boolean;
100
+ override?: ((parser: Parser) => acorn.Token) | null;
101
+ }
102
+
103
+ /**
104
+ * Token type definition
105
+ */
106
+ export interface TokenType {
107
+ label: string;
108
+ keyword: string | undefined;
109
+ beforeExpr?: boolean;
110
+ startsExpr?: boolean;
111
+ isLoop?: boolean;
112
+ isAssign?: boolean;
113
+ prefix?: boolean;
114
+ postfix?: boolean;
115
+ binop?: number | null;
116
+ updateContext?: ((prevType: TokenType) => void) | null;
117
+ }
118
+
119
+ /**
120
+ * Acorn's built-in token contexts
121
+ */
122
+ export interface TokContexts {
123
+ /** Block statement context - `{` in statement position */
124
+ b_stat: TokContext & { token: '{' };
125
+ /** Block expression context - `{` in expression position (object literals) */
126
+ b_expr: TokContext & { token: '{' };
127
+ /** Template literal context - `${` inside template */
128
+ b_tmpl: TokContext & { token: '${' };
129
+ /** Parenthesized statement context - `(` in statement position */
130
+ p_stat: TokContext & { token: '(' };
131
+ /** Parenthesized expression context - `(` in expression position */
132
+ p_expr: TokContext & { token: '(' };
133
+ /** Quasi/template context - `` ` `` backtick */
134
+ q_tmpl: TokContext & { token: '`' };
135
+ /** Function statement context - `function` keyword in statement */
136
+ f_stat: TokContext & { token: 'function' };
137
+ /** Function expression context - `function` keyword in expression */
138
+ f_expr: TokContext & { token: 'function' };
139
+ /** Generator function expression context - `function*` in expression */
140
+ f_expr_gen: TokContext & { token: 'function' };
141
+ /** Generator function context - `function*` in statement */
142
+ f_gen: TokContext & { token: 'function' };
143
+ }
144
+
145
+ /**
146
+ * Acorn's built-in token types
147
+ */
148
+ export interface TokTypes {
149
+ // Literal tokens
150
+ num: TokenType & { label: 'num' };
151
+ regexp: TokenType & { label: 'regexp' };
152
+ string: TokenType & { label: 'string' };
153
+ name: TokenType & { label: 'name' };
154
+ privateId: TokenType & { label: 'privateId' };
155
+ eof: TokenType & { label: 'eof' };
156
+
157
+ // Punctuation tokens
158
+ bracketL: TokenType & { label: '[' };
159
+ bracketR: TokenType & { label: ']' };
160
+ braceL: TokenType & { label: '{' };
161
+ braceR: TokenType & { label: '}' };
162
+ parenL: TokenType & { label: '(' };
163
+ parenR: TokenType & { label: ')' };
164
+ comma: TokenType & { label: ',' };
165
+ semi: TokenType & { label: ';' };
166
+ colon: TokenType & { label: ':' };
167
+ dot: TokenType & { label: '.' };
168
+ question: TokenType & { label: '?' };
169
+ questionDot: TokenType & { label: '?.' };
170
+ arrow: TokenType & { label: '=>' };
171
+ template: TokenType & { label: 'template' };
172
+ invalidTemplate: TokenType & { label: 'invalidTemplate' };
173
+ ellipsis: TokenType & { label: '...' };
174
+ backQuote: TokenType & { label: '`' };
175
+ dollarBraceL: TokenType & { label: '${' };
176
+
177
+ // Operators
178
+ eq: TokenType & { label: '='; isAssign: true };
179
+ assign: TokenType & { label: '_='; isAssign: true };
180
+ incDec: TokenType & { label: '++/--'; prefix: true; postfix: true };
181
+ prefix: TokenType & { label: '!/~'; prefix: true };
182
+ logicalOR: TokenType & { label: '||'; binop: 1 };
183
+ logicalAND: TokenType & { label: '&&'; binop: 2 };
184
+ bitwiseOR: TokenType & { label: '|'; binop: 3 };
185
+ bitwiseXOR: TokenType & { label: '^'; binop: 4 };
186
+ bitwiseAND: TokenType & { label: '&'; binop: 5 };
187
+ equality: TokenType & { label: '==/!=/===/!=='; binop: 6 };
188
+ relational: TokenType & { label: '</>/<=/>='; binop: 7 };
189
+ bitShift: TokenType & { label: '<</>>/>>>'; binop: 8 };
190
+ plusMin: TokenType & { label: '+/-'; binop: 9; prefix: true };
191
+ modulo: TokenType & { label: '%'; binop: 10 };
192
+ star: TokenType & { label: '*'; binop: 10 };
193
+ slash: TokenType & { label: '/'; binop: 10 };
194
+ starstar: TokenType & { label: '**' };
195
+ coalesce: TokenType & { label: '??'; binop: 1 };
196
+
197
+ // Keywords (label matches keyword name)
198
+ _break: TokenType & { label: 'break'; keyword: 'break' };
199
+ _case: TokenType & { label: 'case'; keyword: 'case' };
200
+ _catch: TokenType & { label: 'catch'; keyword: 'catch' };
201
+ _continue: TokenType & { label: 'continue'; keyword: 'continue' };
202
+ _debugger: TokenType & { label: 'debugger'; keyword: 'debugger' };
203
+ _default: TokenType & { label: 'default'; keyword: 'default' };
204
+ _do: TokenType & { label: 'do'; keyword: 'do'; isLoop: true };
205
+ _else: TokenType & { label: 'else'; keyword: 'else' };
206
+ _finally: TokenType & { label: 'finally'; keyword: 'finally' };
207
+ _for: TokenType & { label: 'for'; keyword: 'for'; isLoop: true };
208
+ _function: TokenType & { label: 'function'; keyword: 'function' };
209
+ _if: TokenType & { label: 'if'; keyword: 'if' };
210
+ _return: TokenType & { label: 'return'; keyword: 'return' };
211
+ _switch: TokenType & { label: 'switch'; keyword: 'switch' };
212
+ _throw: TokenType & { label: 'throw'; keyword: 'throw' };
213
+ _try: TokenType & { label: 'try'; keyword: 'try' };
214
+ _var: TokenType & { label: 'var'; keyword: 'var' };
215
+ _const: TokenType & { label: 'const'; keyword: 'const' };
216
+ _while: TokenType & { label: 'while'; keyword: 'while'; isLoop: true };
217
+ _with: TokenType & { label: 'with'; keyword: 'with' };
218
+ _new: TokenType & { label: 'new'; keyword: 'new' };
219
+ _this: TokenType & { label: 'this'; keyword: 'this' };
220
+ _super: TokenType & { label: 'super'; keyword: 'super' };
221
+ _class: TokenType & { label: 'class'; keyword: 'class' };
222
+ _extends: TokenType & { label: 'extends'; keyword: 'extends' };
223
+ _export: TokenType & { label: 'export'; keyword: 'export' };
224
+ _import: TokenType & { label: 'import'; keyword: 'import' };
225
+ _null: TokenType & { label: 'null'; keyword: 'null' };
226
+ _true: TokenType & { label: 'true'; keyword: 'true' };
227
+ _false: TokenType & { label: 'false'; keyword: 'false' };
228
+ _in: TokenType & { label: 'in'; keyword: 'in'; binop: 7 };
229
+ _instanceof: TokenType & { label: 'instanceof'; keyword: 'instanceof'; binop: 7 };
230
+ _typeof: TokenType & { label: 'typeof'; keyword: 'typeof'; prefix: true };
231
+ _void: TokenType & { label: 'void'; keyword: 'void'; prefix: true };
232
+ _delete: TokenType & { label: 'delete'; keyword: 'delete'; prefix: true };
233
+ }
234
+
235
+ /**
236
+ * TypeScript-specific token types added by @sveltejs/acorn-typescript
237
+ */
238
+ export interface AcornTypeScriptTokTypes {
239
+ // JSX tokens
240
+ jsxTagStart: TokenType & { label: 'jsxTagStart' };
241
+ jsxTagEnd: TokenType & { label: 'jsxTagEnd' };
242
+ jsxText: TokenType & { label: 'jsxText' };
243
+ jsxName: TokenType & { label: 'jsxName' };
244
+
245
+ // Decorator token
246
+ at: TokenType & { label: '@' };
247
+
248
+ // TypeScript keyword tokens
249
+ abstract: TokenType & { label: 'abstract' };
250
+ as: TokenType & { label: 'as' };
251
+ asserts: TokenType & { label: 'asserts' };
252
+ assert: TokenType & { label: 'assert' };
253
+ bigint: TokenType & { label: 'bigint' };
254
+ declare: TokenType & { label: 'declare' };
255
+ enum: TokenType & { label: 'enum' };
256
+ global: TokenType & { label: 'global' };
257
+ implements: TokenType & { label: 'implements' };
258
+ infer: TokenType & { label: 'infer' };
259
+ interface: TokenType & { label: 'interface' };
260
+ intrinsic: TokenType & { label: 'intrinsic' };
261
+ is: TokenType & { label: 'is' };
262
+ keyof: TokenType & { label: 'keyof' };
263
+ module: TokenType & { label: 'module' };
264
+ namespace: TokenType & { label: 'namespace' };
265
+ never: TokenType & { label: 'never' };
266
+ out: TokenType & { label: 'out' };
267
+ override: TokenType & { label: 'override' };
268
+ private: TokenType & { label: 'private' };
269
+ protected: TokenType & { label: 'protected' };
270
+ public: TokenType & { label: 'public' };
271
+ readonly: TokenType & { label: 'readonly' };
272
+ require: TokenType & { label: 'require' };
273
+ satisfies: TokenType & { label: 'satisfies' };
274
+ symbol: TokenType & { label: 'symbol' };
275
+ type: TokenType & { label: 'type' };
276
+ unique: TokenType & { label: 'unique' };
277
+ unknown: TokenType & { label: 'unknown' };
278
+ }
279
+
280
+ /**
281
+ * TypeScript-specific token contexts added by @sveltejs/acorn-typescript
282
+ */
283
+ export interface AcornTypeScriptTokContexts {
284
+ /** JSX opening tag context - `<` starting a JSX tag */
285
+ tc_oTag: TokContext & { token: '<' };
286
+ /** JSX closing tag context - `</` closing a JSX tag */
287
+ tc_cTag: TokContext & { token: '</' };
288
+ /** JSX expression context - `{` inside JSX for expressions */
289
+ tc_expr: TokContext & { token: '{' };
290
+ }
291
+
292
+ /**
293
+ * Combined TypeScript extensions object
294
+ */
295
+ export interface AcornTypeScriptExtensions {
296
+ tokTypes: AcornTypeScriptTokTypes;
297
+ tokContexts: AcornTypeScriptTokContexts;
298
+ }
299
+
300
+ /**
301
+ * Extended Parser instance with internal properties
302
+ *
303
+ * These properties are used internally by Acorn but not exposed in official types.
304
+ * They are accessed by Ripple's custom parser plugin for whitespace handling,
305
+ * JSX parsing, and other advanced features.
306
+ */
307
+ export interface Parser {
308
+ // ============================================================
309
+ // Position and Location Tracking
310
+ // ============================================================
311
+ /** Start position of the current token (0-indexed) */
312
+ start: number;
313
+ /** End position of the current token (0-indexed) */
314
+ end: number;
315
+ /** Current parsing position in input string (0-indexed) */
316
+ pos: number;
317
+ /** Current line number (1-indexed) */
318
+ curLine: number;
319
+ /** Position where the current line starts (0-indexed) */
320
+ lineStart: number;
321
+
322
+ /** Start location of current token */
323
+ startLoc: AST.Position;
324
+ /** End location of current token */
325
+ endLoc: AST.Position;
326
+ /** End position of the last token */
327
+ lastTokEnd: number;
328
+ /** Start position of the last token */
329
+ lastTokStart: number;
330
+ /** End location of the last token */
331
+ lastTokEndLoc: AST.Position;
332
+ /** Start location of the last token */
333
+ lastTokStartLoc: AST.Position;
334
+
335
+ // ============================================================
336
+ // Current Token State
337
+ // ============================================================
338
+ /** Current token type */
339
+ type: TokenType;
340
+ /** Current token value (string for names, number for nums, etc.) */
341
+ value: string | number | RegExp | bigint | null;
342
+
343
+ // ============================================================
344
+ // Parser State
345
+ // ============================================================
346
+ /** The source code being parsed */
347
+ input: string;
348
+ /** Whether the current position expects an expression */
349
+ exprAllowed: boolean;
350
+ /** Whether the parser is in strict mode */
351
+ strict: boolean;
352
+ /** Whether we're inside a generator function */
353
+ inGenerator: boolean;
354
+ /** Whether we're inside an async function */
355
+ inAsync: boolean;
356
+ /** Whether we're inside a function */
357
+ inFunction: boolean;
358
+ /** Stack of label names for break/continue statements */
359
+ labels: Array<{ kind: string | null; name?: string; statementStart?: number }>;
360
+ /** Current scope flags stack */
361
+ scopeStack: Array<{ flags: number; var: string[]; lexical: string[]; functions: string[] }>;
362
+ /** Regular expression validation state */
363
+ regexpState?: any;
364
+ /** Whether we can use await keyword */
365
+ canAwait: boolean;
366
+ /** Position of await keyword (0 if not in async context) */
367
+ awaitPos: number;
368
+ /** Position of yield keyword (0 if not in generator context) */
369
+ yieldPos: number;
370
+ /** Position of await used as identifier (for error reporting) */
371
+ awaitIdentPos: number;
372
+ /** Whether current identifier contains escape sequences */
373
+ containsEsc: boolean;
374
+ /** Potential arrow function position */
375
+ potentialArrowAt: number;
376
+ /** Potential arrow in for-await position */
377
+ potentialArrowInForAwait: boolean;
378
+ /** Private name stack for class private fields validation */
379
+ privateNameStack: Array<{ declared: Record<string, any>; used: Array<AST.Node> }>;
380
+ /** Undefined exports for module validation */
381
+ undefinedExports: Record<string, AST.Node>;
382
+
383
+ // ============================================================
384
+ // Context Stack
385
+ // ============================================================
386
+ /** Token context stack for tokenizer state */
387
+ context: TokContext[];
388
+ /** Whether to preserve spaces in current context */
389
+ preserveSpace?: boolean;
390
+
391
+ // ============================================================
392
+ // Parser Configuration
393
+ // ============================================================
394
+ /** Parser options (from constructor) */
395
+ options: Options;
396
+ /** ECMAScript version being parsed */
397
+ ecmaVersion: number;
398
+ /** Keywords regex for current ecmaVersion */
399
+ keywords: RegExp;
400
+ /** Reserved words regex */
401
+ reservedWords: RegExp;
402
+ /** Whether we're parsing a module */
403
+ inModule: boolean;
404
+
405
+ // ============================================================
406
+ // Token Methods
407
+ // ============================================================
408
+ /**
409
+ * Finish current token with given type and optional value
410
+ * @see https://github.com/acornjs/acorn/blob/main/acorn/src/tokenize.js
411
+ */
412
+ finishToken(type: TokenType, val?: string | number | RegExp | bigint): void;
413
+
414
+ readAtIdentifier(): void;
415
+
416
+ /**
417
+ * Read a token based on character code
418
+ * Called by nextToken() for each character
419
+ */
420
+ readToken(code: number): void;
421
+
422
+ /**
423
+ * Read a word (identifier or keyword)
424
+ * @returns Token type (name or keyword)
425
+ */
426
+ readWord(): TokenType;
427
+
428
+ /**
429
+ * Read word starting from current position
430
+ * @returns The word string
431
+ */
432
+ readWord1(): string;
433
+
434
+ /** Read a number literal */
435
+ readNumber(startsWithDot: boolean): void;
436
+
437
+ /** Read a string literal */
438
+ readString(quote: number): void;
439
+
440
+ /** Read a template token */
441
+ readTmplToken(): void;
442
+
443
+ /** Read a regular expression literal */
444
+ readRegexp(): void;
445
+
446
+ /** Skip block comment, tracking line positions */
447
+ skipBlockComment(): void;
448
+
449
+ /** Skip line comment */
450
+ skipLineComment(startSkip: number): void;
451
+
452
+ /** Skip whitespace and comments */
453
+ skipSpace(): void;
454
+
455
+ /** Read and return the next token */
456
+ nextToken(): void;
457
+
458
+ /** Advance to next token (wrapper around nextToken) */
459
+ next(): void;
460
+
461
+ /**
462
+ * Get token from character code
463
+ * Main tokenizer dispatch based on first character
464
+ */
465
+ getTokenFromCode(code: number): void;
466
+
467
+ /**
468
+ * Get current position as Position object
469
+ * @returns { line: number, column: number, index: number }
470
+ */
471
+ curPosition(): AST.Position;
472
+
473
+ /**
474
+ * Finish building an operator token
475
+ * @param type Token type
476
+ * @param size Number of characters consumed
477
+ */
478
+ finishOp(type: TokenType, size: number): TokenType;
479
+
480
+ // ============================================================
481
+ // Node Creation Methods
482
+ // ============================================================
483
+ /**
484
+ * Finish a node, setting its end position and type
485
+ * @template T Node type extending AST.Node
486
+ * @param node The node to finish
487
+ * @param type The node type string (e.g., "Identifier", "BinaryExpression")
488
+ * @returns The finished node
489
+ */
490
+ finishNode<T extends AST.Node>(node: T, type: string): T;
491
+
492
+ /**
493
+ * Finish a node at a specific position
494
+ */
495
+ finishNodeAt<T extends AST.Node>(node: T, type: string, pos: number, loc: AST.Position): T;
496
+
497
+ /**
498
+ * Start a new node at current position
499
+ */
500
+ startNode(): AST.Node;
501
+
502
+ /**
503
+ * Start a new node at a specific position
504
+ * @param pos Start position
505
+ * @param loc Start location
506
+ * @returns A new node with specified start position
507
+ */
508
+ startNodeAt(pos: number, loc: AST.Position): AST.Node;
509
+
510
+ /**
511
+ * Start a node at the same position as another node
512
+ * @param node The node to copy position from
513
+ * @returns A new node with copied start position
514
+ */
515
+ startNodeAtNode(node: AST.Node): AST.Node;
516
+
517
+ /**
518
+ * Copy a node's position info
519
+ * @template T Node type
520
+ * @param node The node to copy
521
+ * @returns A shallow copy of the node
522
+ */
523
+ copyNode<T extends AST.Node>(node: T): T;
524
+
525
+ /**
526
+ * Reset end location from another node
527
+ * @param node Node to update
528
+ */
529
+ resetEndLocation(node: AST.Node): void;
530
+
531
+ /**
532
+ * Reset start location from another node
533
+ * @param node Node to update
534
+ * @param locationNode Node to copy from
535
+ */
536
+ resetStartLocationFromNode(node: AST.Node, locationNode: AST.Node): void;
537
+
538
+ // ============================================================
539
+ // Error Handling
540
+ // ============================================================
541
+ /**
542
+ * Raise a fatal error at given position
543
+ * @throws SyntaxError
544
+ */
545
+ raise(pos: number, message: string): never;
546
+
547
+ /**
548
+ * Raise a recoverable error (warning that doesn't stop parsing)
549
+ */
550
+ raiseRecoverable(pos: number, message: string): void;
551
+
552
+ /**
553
+ * Throw unexpected token error
554
+ * @param pos Optional position (defaults to current)
555
+ */
556
+ unexpected(pos?: number): never;
557
+
558
+ // ============================================================
559
+ // Token Consumption Methods
560
+ // ============================================================
561
+ /**
562
+ * Expect a specific token type, raise error if not found
563
+ * @param type Expected token type
564
+ */
565
+ expect(type: TokenType): void;
566
+
567
+ /**
568
+ * Consume token if it matches, return true if consumed
569
+ * @param type Token type to eat
570
+ * @returns true if token was consumed
571
+ */
572
+ eat(type: TokenType): boolean;
573
+
574
+ /**
575
+ * Check if current token matches type (alias for this.type === type)
576
+ * @param type Token type to match
577
+ */
578
+ match(type: TokenType): boolean;
579
+
580
+ /**
581
+ * Peek at character at position
582
+ * @deprecated Use charCodeAt instead
583
+ */
584
+ charAt(pos: number): string;
585
+
586
+ /**
587
+ * Get character code at position in input
588
+ */
589
+ charCodeAt(pos: number): number;
590
+
591
+ /**
592
+ * Check if current token is a contextual keyword
593
+ * @param name Keyword to check (e.g., "async", "of")
594
+ */
595
+ isContextual(name: string): boolean;
596
+
597
+ /**
598
+ * Consume if current token is a contextual keyword
599
+ * @param name Keyword to consume
600
+ * @returns true if consumed
601
+ */
602
+ eatContextual(name: string): boolean;
603
+
604
+ /**
605
+ * Expect a contextual keyword, raise error if not found
606
+ * @param name Expected keyword
607
+ */
608
+ expectContextual(name: string): void;
609
+
610
+ /**
611
+ * Check if semicolon can be inserted at current position (ASI)
612
+ */
613
+ canInsertSemicolon(): boolean;
614
+
615
+ /**
616
+ * Insert a semicolon if allowed by ASI rules
617
+ * returns true if semicolon was inserted
618
+ */
619
+ insertSemicolon(): boolean;
620
+
621
+ /**
622
+ * Consume semicolon or insert via ASI
623
+ */
624
+ semicolon(): void;
625
+
626
+ /**
627
+ * Handle trailing comma in lists
628
+ */
629
+ afterTrailingComma(type: TokenType, notNext?: boolean): boolean;
630
+
631
+ // ============================================================
632
+ // Scope Management
633
+ // ============================================================
634
+ /**
635
+ * Enter a new scope
636
+ * @param flags Scope flags (SCOPE_* constants)
637
+ */
638
+ enterScope(flags: number): void;
639
+
640
+ /** Exit current scope */
641
+ exitScope(): void;
642
+
643
+ /**
644
+ * Declare a name in current scope
645
+ */
646
+ declareName(name: string, bindingType: BindingType[keyof BindingType], pos: number): void;
647
+
648
+ /** Get current scope */
649
+ currentScope(): { flags: number; var: string[]; lexical: string[]; functions: string[] };
650
+
651
+ /** Get current variable scope (for var declarations) */
652
+ currentVarScope(): { flags: number; var: string[]; lexical: string[]; functions: string[] };
653
+
654
+ /** Get current "this" scope */
655
+ currentThisScope(): { flags: number; var: string[]; lexical: string[]; functions: string[] };
656
+
657
+ /** Check if treating functions as var in current scope */
658
+ treatFunctionsAsVarInScope(scope: any): boolean;
659
+
660
+ // ============================================================
661
+ // Context Management
662
+ // ============================================================
663
+ /**
664
+ * Get current token context
665
+ * @returns Current context from stack
666
+ */
667
+ curContext(): TokContext;
668
+
669
+ /**
670
+ * Update token context based on previous token
671
+ * @param prevType Previous token type
672
+ */
673
+ updateContext(prevType: TokenType): void;
674
+
675
+ /**
676
+ * Override the current context
677
+ * @param context New context to push
678
+ */
679
+ overrideContext(context: TokContext): void;
680
+
681
+ // ============================================================
682
+ // Lookahead
683
+ // ============================================================
684
+ /**
685
+ * Look ahead one token without consuming
686
+ * @returns Object with type and value of next token
687
+ */
688
+ lookahead(): { type: TokenType; value: any };
689
+
690
+ /**
691
+ * Get next token start position
692
+ */
693
+ nextTokenStart(): number;
694
+
695
+ /**
696
+ * Get next token start since given position
697
+ */
698
+ nextTokenStartSince(pos: number): number;
699
+
700
+ /**
701
+ * Look ahead at character code
702
+ */
703
+ lookaheadCharCode(): number;
704
+
705
+ // ============================================================
706
+ // Expression Parsing
707
+ // ============================================================
708
+ /**
709
+ * Parse an expression
710
+ */
711
+ parseExpression(
712
+ forInit?: ForInit,
713
+ refDestructuringErrors?: DestructuringErrors,
714
+ ): AST.Expression;
715
+
716
+ /**
717
+ * Parse maybe-assignment expression (handles = and op=)
718
+ */
719
+ parseMaybeAssign(
720
+ forInit?: ForInit,
721
+ refDestructuringErrors?: DestructuringErrors,
722
+ afterLeftParse?: (node: AST.Node, startPos: number, startLoc: AST.Position) => AST.Node,
723
+ ): AST.Expression;
724
+
725
+ /**
726
+ * Parse maybe-conditional expression (?:)
727
+ */
728
+ parseMaybeConditional(
729
+ forInit?: ForInit,
730
+ refDestructuringErrors?: DestructuringErrors,
731
+ ): AST.Expression;
732
+
733
+ /**
734
+ * Parse expression with operators (handles precedence)
735
+ */
736
+ parseExprOps(forInit?: ForInit, refDestructuringErrors?: DestructuringErrors): AST.Expression;
737
+
738
+ /**
739
+ * Parse expression with operator at given precedence
740
+ */
741
+ parseExprOp(
742
+ left: AST.Expression,
743
+ leftStartPos: number,
744
+ leftStartLoc: AST.Position,
745
+ minPrec: number,
746
+ forInit?: ForInit,
747
+ ): AST.Expression;
748
+
749
+ /**
750
+ * Parse maybe-unary expression (prefix operators)
751
+ */
752
+ parseMaybeUnary(
753
+ refDestructuringErrors?: DestructuringErrors | null,
754
+ sawUnary?: boolean,
755
+ incDec?: boolean,
756
+ forInit?: ForInit,
757
+ ): AST.Expression;
758
+
759
+ /**
760
+ * Parse expression subscripts (member access, calls)
761
+ */
762
+ parseExprSubscripts(
763
+ refDestructuringErrors?: DestructuringErrors,
764
+ forInit?: ForInit,
765
+ ): AST.Expression;
766
+
767
+ /**
768
+ * Parse subscripts (., [], (), ?.)
769
+ */
770
+ parseSubscripts(
771
+ base: AST.Expression,
772
+ startPos: number,
773
+ startLoc: AST.Position,
774
+ noCalls?: boolean,
775
+ maybeAsyncArrow?: boolean,
776
+ optionalChained?: boolean,
777
+ forInit?: ForInit,
778
+ ): AST.Expression;
779
+
780
+ parseSubscript(
781
+ base: AST.Expression,
782
+ startPos: number,
783
+ startLoc: AST.Position,
784
+ noCalls?: boolean,
785
+ maybeAsyncArrow?: boolean,
786
+ optionalChained?: boolean,
787
+ forInit?: ForInit,
788
+ ): AST.Expression;
789
+
790
+ /**
791
+ * Parse expression atom (literals, identifiers, etc.)
792
+ */
793
+ parseExprAtom(
794
+ refDestructuringErrors?: DestructuringErrors,
795
+ forInit?: ForInit,
796
+ forNew?: boolean,
797
+ ):
798
+ | AST.ServerIdentifier
799
+ | AST.TrackedExpression
800
+ | AST.TrackedMapExpression
801
+ | AST.TrackedSetExpression
802
+ | AST.TrackedArrayExpression
803
+ | AST.TrackedObjectExpression
804
+ | AST.Component;
805
+
806
+ /** Default handler for parseExprAtom when no other case matches */
807
+ parseExprAtomDefault(): AST.Expression;
808
+
809
+ /**
810
+ * Parse a literal value (string, number, boolean, null, regex)
811
+ * @param value The literal value
812
+ * @returns Literal node
813
+ */
814
+ parseLiteral(value: string | number | boolean | null | RegExp | bigint): AST.Literal;
815
+
816
+ /**
817
+ * Parse parenthesized expression, distinguishing arrow functions
818
+ */
819
+ parseParenAndDistinguishExpression(canBeArrow?: boolean, forInit?: ForInit): AST.Expression;
820
+
821
+ /** Parse parenthesized expression (just the expression) */
822
+ parseParenExpression(): AST.Expression;
823
+
824
+ parseTrackedCollectionExpression(
825
+ type: 'TrackedMapExpression' | 'TrackedSetExpression',
826
+ ): AST.TrackedMapExpression | AST.TrackedSetExpression;
827
+
828
+ parseTrackedArrayExpression(): AST.TrackedArrayExpression;
829
+
830
+ parseTrackedExpression(): AST.TrackedExpression;
831
+
832
+ parseTrackedObjectExpression(): AST.TrackedObjectExpression;
833
+
834
+ /**
835
+ * Parse item in parentheses (can be overridden for flow/ts)
836
+ */
837
+ parseParenItem(item: AST.Node): AST.Node;
838
+
839
+ /**
840
+ * Parse arrow expression
841
+
842
+ */
843
+ parseArrowExpression(
844
+ node: AST.Node,
845
+ params: AST.Node[],
846
+ isAsync?: boolean,
847
+ forInit?: ForInit,
848
+ ): AST.ArrowFunctionExpression;
849
+
850
+ /**
851
+ * Check if arrow should be parsed
852
+ */
853
+ shouldParseArrow(exprList: AST.Node[]): boolean;
854
+
855
+ /**
856
+ * Parse spread element (...expr)
857
+ */
858
+ parseSpread(refDestructuringErrors?: DestructuringErrors): AST.SpreadElement;
859
+
860
+ /**
861
+ * Parse rest binding pattern (...pattern)
862
+ * @returns RestElement node
863
+ */
864
+ parseRestBinding(): AST.RestElement;
865
+
866
+ /**
867
+ * Parse 'new' expression
868
+ * @returns NewExpression or MetaProperty (new.target)
869
+ */
870
+ parseNew(): AST.NewExpression | AST.MetaProperty;
871
+
872
+ /**
873
+ * Parse dynamic import expression
874
+ * @param forNew Whether in new expression context
875
+ */
876
+ parseExprImport(forNew?: boolean): AST.ImportExpression | AST.MetaProperty;
877
+
878
+ /**
879
+ * Parse dynamic import call
880
+ * @param node Import expression node
881
+ */
882
+ parseDynamicImport(node: AST.Node): AST.ImportExpression;
883
+
884
+ /**
885
+ * Parse import.meta
886
+ * @param node MetaProperty node
887
+ */
888
+ parseImportMeta(node: AST.Node): AST.MetaProperty;
889
+
890
+ /** Parse yield expression */
891
+ parseYield(forInit?: ForInit): AST.YieldExpression;
892
+
893
+ /** Parse await expression */
894
+ parseAwait(forInit?: ForInit): AST.AwaitExpression;
895
+
896
+ /**
897
+ * Parse template literal
898
+ * @param isTagged Whether this is a tagged template
899
+ */
900
+ parseTemplate(isTagged?: { start: number }): AST.TemplateLiteral;
901
+
902
+ /**
903
+ * Parse template element
904
+ * @param options { isTagged: boolean }
905
+ */
906
+ parseTemplateElement(options: { isTagged: boolean }): AST.TemplateElement;
907
+
908
+ // ============================================================
909
+ // Identifier Parsing
910
+ // ============================================================
911
+ /**
912
+ * Parse an identifier
913
+ */
914
+ parseIdent(liberal?: boolean): AST.Identifier;
915
+
916
+ /**
917
+ * Parse identifier node (internal, doesn't consume token)
918
+ * @returns Partial identifier node
919
+ */
920
+ parseIdentNode(): AST.Node;
921
+
922
+ /**
923
+ * Parse private identifier (#name)
924
+ * @returns PrivateIdentifier node
925
+ */
926
+ parsePrivateIdent(): AST.PrivateIdentifier;
927
+
928
+ /**
929
+ * Check if identifier is unreserved
930
+ * @param ref Node with name, start, end
931
+ */
932
+ checkUnreserved(ref: { name: string; start: number; end: number }): void;
933
+
934
+ // ============================================================
935
+ // Object/Array Parsing
936
+ // ============================================================
937
+ /**
938
+ * Parse object expression or pattern
939
+ * @param isPattern Whether parsing a pattern
940
+ * @param refDestructuringErrors Error collector
941
+ * @returns ObjectExpression or ObjectPattern
942
+ */
943
+ parseObj(
944
+ isPattern?: boolean,
945
+ refDestructuringErrors?: DestructuringErrors,
946
+ ): AST.ObjectExpression | AST.ObjectPattern;
947
+
948
+ /**
949
+ * Parse property in object literal
950
+ * @param isPattern Whether parsing a pattern
951
+ * @param refDestructuringErrors Error collector
952
+ * @returns Property node
953
+ */
954
+ parseProperty(
955
+ isPattern: boolean,
956
+ refDestructuringErrors?: DestructuringErrors,
957
+ ): AST.Property | AST.SpreadElement;
958
+
959
+ /**
960
+ * Parse property name (identifier, string, number, computed)
961
+ * @param prop Property node to update
962
+ * @returns The key expression
963
+ */
964
+ parsePropertyName(prop: AST.Node): AST.Expression | AST.PrivateIdentifier;
965
+
966
+ /**
967
+ * Parse property value
968
+ * @param prop Property node
969
+ * @param isPattern Whether parsing pattern
970
+ * @param isGenerator Whether generator method
971
+ * @param isAsync Whether async method
972
+ * @param startPos Start position
973
+ * @param startLoc Start location
974
+ * @param refDestructuringErrors Error collector
975
+ * @param containsEsc Whether key contains escapes
976
+ */
977
+ parsePropertyValue(
978
+ prop: AST.Node,
979
+ isPattern: boolean,
980
+ isGenerator: boolean,
981
+ isAsync: boolean,
982
+ startPos: number,
983
+ startLoc: AST.Position,
984
+ refDestructuringErrors?: DestructuringErrors,
985
+ containsEsc?: boolean,
986
+ ): void;
987
+
988
+ /**
989
+ * Get property kind from name
990
+ * @param prop Property node
991
+ * @returns "init", "get", or "set"
992
+ */
993
+ getPropertyKind(prop: AST.Node): 'init' | 'get' | 'set';
994
+
995
+ /**
996
+ * Parse expression list (array elements, call arguments)
997
+ * @param close Closing token type
998
+ * @param allowTrailingComma Whether trailing comma allowed
999
+ * @param allowEmpty Whether empty slots allowed
1000
+ * @param refDestructuringErrors Error collector
1001
+ * @returns Array of expressions
1002
+ */
1003
+ parseExprList(
1004
+ close: TokenType,
1005
+ allowTrailingComma?: boolean,
1006
+ allowEmpty?: boolean,
1007
+ refDestructuringErrors?: DestructuringErrors,
1008
+ ): (AST.Expression | null)[];
1009
+
1010
+ /**
1011
+ * Parse binding list (pattern elements)
1012
+ * @param close Closing token type
1013
+ * @param allowEmpty Whether empty slots allowed
1014
+ * @param allowTrailingComma Whether trailing comma allowed
1015
+ * @param allowModifiers Whether modifiers allowed (TS)
1016
+ */
1017
+ parseBindingList(
1018
+ close: TokenType,
1019
+ allowEmpty?: boolean,
1020
+ allowTrailingComma?: boolean,
1021
+ allowModifiers?: boolean,
1022
+ ): AST.Pattern[];
1023
+
1024
+ /**
1025
+ * Parse binding atom (identifier or pattern)
1026
+ * @returns Pattern node
1027
+ */
1028
+ parseBindingAtom(): AST.Pattern;
1029
+
1030
+ // ============================================================
1031
+ // Statement Parsing
1032
+ // ============================================================
1033
+ /**
1034
+ * Parse top level program
1035
+ * @param node Program node to populate
1036
+ * @returns Completed Program node
1037
+ */
1038
+ parseTopLevel(node: AST.Program): AST.Program;
1039
+
1040
+ parseServerBlock(): AST.ServerBlock;
1041
+
1042
+ parseElement(): AST.Element | AST.TsxCompat;
1043
+
1044
+ parseTemplateBody(
1045
+ body: (AST.Statement | AST.Node | ESTreeJSX.JSXText | ESTreeJSX.JSXElement['children'])[],
1046
+ ): void;
1047
+
1048
+ parseComponent(
1049
+ params?:
1050
+ | {
1051
+ requireName?: boolean;
1052
+ isDefault?: boolean;
1053
+ declareName?: boolean;
1054
+ }
1055
+ | undefined,
1056
+ ): AST.Component;
1057
+
1058
+ /**
1059
+ * Parse a statement
1060
+ * @param context Statement context ("for", "if", "label", etc.)
1061
+ * @param topLevel Whether at top level
1062
+ * @param exports Export set for module
1063
+ * @returns Statement node
1064
+ */
1065
+ parseStatement(
1066
+ context?: string | null,
1067
+ topLevel?: boolean,
1068
+ exports?: AST.ExportSpecifier,
1069
+ ):
1070
+ | AST.TextNode
1071
+ | ESTreeJSX.JSXEmptyExpression
1072
+ | ESTreeJSX.JSXExpressionContainer
1073
+ | AST.ServerBlock
1074
+ | AST.Component
1075
+ | AST.ExpressionStatement
1076
+ | ReturnType<Parser['parseElement']>
1077
+ | AST.Statement;
1078
+
1079
+ parseBlock(
1080
+ createNewLexicalScope?: boolean,
1081
+ node?: AST.BlockStatement,
1082
+ exitStrict?: boolean,
1083
+ ): AST.BlockStatement;
1084
+
1085
+ /** Parse empty statement (;) */
1086
+ parseEmptyStatement(node: AST.Node): AST.EmptyStatement;
1087
+
1088
+ /** Parse expression statement */
1089
+ parseExpressionStatement(node: AST.Node, expr: AST.Expression): AST.ExpressionStatement;
1090
+
1091
+ /** Parse labeled statement */
1092
+ parseLabeledStatement(
1093
+ node: AST.Node,
1094
+ maybeName: string,
1095
+ expr: AST.Expression,
1096
+ context?: string,
1097
+ ): AST.LabeledStatement;
1098
+
1099
+ /** Parse if statement */
1100
+ parseIfStatement(node: AST.Node): AST.IfStatement;
1101
+
1102
+ /** Parse switch statement */
1103
+ parseSwitchStatement(node: AST.Node): AST.SwitchStatement;
1104
+
1105
+ /** Parse while statement */
1106
+ parseWhileStatement(node: AST.Node): AST.WhileStatement;
1107
+
1108
+ /** Parse do-while statement */
1109
+ parseDoStatement(node: AST.Node): AST.DoWhileStatement;
1110
+
1111
+ /** Parse for statement (all variants) */
1112
+ parseForStatement(
1113
+ node: AST.ForStatement | AST.ForInStatement | AST.ForOfStatement,
1114
+ ): AST.ForStatement | AST.ForInStatement | AST.ForOfStatement;
1115
+
1116
+ parseForAfterInitWithIndex(
1117
+ node: AST.ForStatement | AST.ForInStatement | AST.ForOfStatement,
1118
+ init: AST.VariableDeclaration,
1119
+ awaitAt: number,
1120
+ ): AST.ForStatement | AST.ForInStatement | AST.ForOfStatement;
1121
+
1122
+ parseForInWithIndex(
1123
+ node: AST.ForInStatement | AST.ForOfStatement,
1124
+ init: AST.VariableDeclaration | AST.Pattern,
1125
+ ): AST.ForInStatement | AST.ForOfStatement;
1126
+
1127
+ /**
1128
+ * Parse regular for loop
1129
+ * @param node For statement node
1130
+ * @param init Initializer expression
1131
+ */
1132
+ parseFor(node: AST.Node, init: AST.Node | null): AST.ForStatement;
1133
+
1134
+ /**
1135
+ * Parse for-in loop
1136
+ * @param node For statement node
1137
+ * @param init Left-hand binding
1138
+ */
1139
+ parseForIn(node: AST.Node, init: AST.Node): AST.ForInStatement;
1140
+
1141
+ /** Parse break statement */
1142
+ parseBreakContinueStatement(
1143
+ node: AST.Node,
1144
+ keyword: string,
1145
+ ): AST.BreakStatement | AST.ContinueStatement;
1146
+
1147
+ /** Parse return statement */
1148
+ parseReturnStatement(node: AST.Node): AST.ReturnStatement;
1149
+
1150
+ /** Parse throw statement */
1151
+ parseThrowStatement(node: AST.Node): AST.ThrowStatement;
1152
+
1153
+ /** Parse try statement */
1154
+ parseTryStatement(node: AST.TryStatement): AST.TryStatement;
1155
+
1156
+ /**
1157
+ * Parse catch clause parameter
1158
+ * @returns Pattern node for catch param
1159
+ */
1160
+ parseCatchClauseParam(): AST.Pattern;
1161
+
1162
+ /** Parse with statement */
1163
+ parseWithStatement(node: AST.Node): AST.WithStatement;
1164
+
1165
+ /** Parse debugger statement */
1166
+ parseDebuggerStatement(node: AST.Node): AST.DebuggerStatement;
1167
+
1168
+ // ============================================================
1169
+ // Variable Declaration Parsing
1170
+ // ============================================================
1171
+ /** Parse variable statement (var, let, const) */
1172
+ parseVarStatement(node: AST.Node, kind: string): AST.VariableDeclaration;
1173
+
1174
+ /**
1175
+ * Parse variable declarations
1176
+ * @param node Declaration node
1177
+ * @param isFor Whether in for-loop initializer
1178
+ * @param kind "var", "let", "const", "using", or "await using"
1179
+ * @returns VariableDeclaration node
1180
+ */
1181
+ parseVar(node: AST.Node, isFor: boolean, kind: string): AST.VariableDeclaration;
1182
+
1183
+ /**
1184
+ * Parse variable ID (identifier or pattern)
1185
+ * @param decl Declarator node
1186
+ * @param kind Variable kind
1187
+ */
1188
+ parseVarId(decl: AST.Node, kind: string): void;
1189
+
1190
+ /** Check if current token starts 'let' declaration */
1191
+ isLet(context?: string): boolean;
1192
+
1193
+ /** Check if current token starts 'using' declaration */
1194
+ isUsing?(isFor?: boolean): boolean;
1195
+
1196
+ /** Check if current token starts 'await using' declaration */
1197
+ isAwaitUsing?(isFor?: boolean): boolean;
1198
+
1199
+ // ============================================================
1200
+ // Function Parsing
1201
+ // ============================================================
1202
+ /**
1203
+ * Parse function declaration or expression
1204
+ */
1205
+ parseFunction(
1206
+ node: AST.Node,
1207
+ statement: number,
1208
+ allowExpressionBody?: boolean,
1209
+ isAsync?: boolean,
1210
+ forInit?: ForInit,
1211
+ ): AST.FunctionDeclaration | AST.FunctionExpression;
1212
+
1213
+ /** Parse function statement */
1214
+ parseFunctionStatement(
1215
+ node: AST.Node,
1216
+ isAsync?: boolean,
1217
+ declarationPosition?: boolean,
1218
+ ): AST.FunctionDeclaration;
1219
+
1220
+ /**
1221
+ * Parse function parameters into node.params
1222
+ * @param node Function node to populate
1223
+ */
1224
+ parseFunctionParams(node: AST.Node): void;
1225
+
1226
+ /**
1227
+ * Parse function body
1228
+ */
1229
+ parseFunctionBody(
1230
+ node: AST.Node,
1231
+ isArrowFunction: boolean,
1232
+ isMethod: boolean,
1233
+ forInit?: ForInit,
1234
+ ): void;
1235
+
1236
+ /** Initialize function node properties */
1237
+ initFunction(node: AST.Node): void;
1238
+
1239
+ /** Check for yield/await in default parameters */
1240
+ checkYieldAwaitInDefaultParams(): void;
1241
+
1242
+ /** Check if async function */
1243
+ isAsyncFunction(): boolean;
1244
+
1245
+ // ============================================================
1246
+ // Class Parsing
1247
+ // ============================================================
1248
+ /**
1249
+ * Parse class declaration or expression
1250
+ * @param node Class node
1251
+ * @param isStatement true, "nullableID", or false
1252
+ */
1253
+ parseClass(
1254
+ node: AST.Node,
1255
+ isStatement: boolean | 'nullableID',
1256
+ ): AST.ClassDeclaration | AST.ClassExpression;
1257
+
1258
+ /** Parse class ID (name) */
1259
+ parseClassId(node: AST.Node, isStatement: boolean | 'nullableID'): void;
1260
+
1261
+ /** Parse class superclass */
1262
+ parseClassSuper(node: AST.Node): void;
1263
+
1264
+ /** Enter class body scope */
1265
+ enterClassBody(): Record<string, any>;
1266
+
1267
+ /** Exit class body scope */
1268
+ exitClassBody(): void;
1269
+
1270
+ /**
1271
+ * Parse class element (method, field, static block)
1272
+ * @param constructorAllowsSuper Whether constructor can call super
1273
+ */
1274
+ parseClassElement(
1275
+ constructorAllowsSuper: boolean,
1276
+ ): AST.MethodDefinition | AST.PropertyDefinition | AST.StaticBlock | null;
1277
+
1278
+ /** Parse class element name */
1279
+ parseClassElementName(element: AST.Node): void;
1280
+
1281
+ /** Parse class static block */
1282
+ parseClassStaticBlock(node: AST.Node): AST.StaticBlock;
1283
+
1284
+ /** Parse class method */
1285
+ parseClassMethod(
1286
+ method: AST.Node,
1287
+ isGenerator: boolean,
1288
+ isAsync: boolean,
1289
+ allowDirectSuper: boolean,
1290
+ ): AST.MethodDefinition;
1291
+
1292
+ /** Parse class field */
1293
+ parseClassField(field: AST.Node): AST.PropertyDefinition;
1294
+
1295
+ /** Check if class element name start */
1296
+ isClassElementNameStart(): boolean;
1297
+
1298
+ /**
1299
+ * Parse method definition
1300
+ * @param isGenerator Whether generator method
1301
+ * @param isAsync Whether async method
1302
+ * @param allowDirectSuper Whether super() allowed
1303
+ */
1304
+ parseMethod(
1305
+ isGenerator: boolean,
1306
+ isAsync?: boolean,
1307
+ allowDirectSuper?: boolean,
1308
+ ): AST.FunctionExpression;
1309
+
1310
+ // ============================================================
1311
+ // Module Parsing (Import/Export)
1312
+ // ============================================================
1313
+ /** Parse import declaration */
1314
+ parseImport(node: AST.Node): AST.ImportDeclaration;
1315
+
1316
+ /** Parse import specifiers */
1317
+ parseImportSpecifiers(): AST.ImportSpecifier[];
1318
+
1319
+ /** Parse single import specifier */
1320
+ parseImportSpecifier(): AST.ImportSpecifier;
1321
+
1322
+ /** Parse module export name (identifier or string) */
1323
+ parseModuleExportName(): AST.Identifier | AST.Literal;
1324
+
1325
+ /** Parse export declaration */
1326
+ parseExport(
1327
+ node: AST.Node,
1328
+ exports?: any,
1329
+ ): AST.ExportNamedDeclaration | AST.ExportDefaultDeclaration | AST.ExportAllDeclaration;
1330
+
1331
+ /** Parse export specifiers */
1332
+ parseExportSpecifiers(exports?: any): AST.ExportSpecifier[];
1333
+
1334
+ /** Parse export default declaration */
1335
+ parseExportDefaultDeclaration(): AST.Declaration | AST.Expression | AST.Component;
1336
+
1337
+ /** Check if export statement should be parsed */
1338
+ shouldParseExportStatement(): boolean;
1339
+
1340
+ /** Parse export declaration body */
1341
+ parseExportDeclaration(node: AST.Node): AST.Declaration;
1342
+
1343
+ // ============================================================
1344
+ // LValue and Pattern Checking
1345
+ // ============================================================
1346
+ /**
1347
+ * Convert expression to assignable pattern
1348
+ * @param node Expression to convert
1349
+ * @param isBinding Whether binding pattern
1350
+ * @param refDestructuringErrors Error collector
1351
+ */
1352
+ toAssignable(
1353
+ node: AST.Node,
1354
+ isBinding?: boolean,
1355
+ refDestructuringErrors?: DestructuringErrors,
1356
+ ): AST.Pattern;
1357
+
1358
+ /**
1359
+ * Convert expression list to assignable list
1360
+ * @param exprList Expression list
1361
+ * @param isBinding Whether binding patterns
1362
+ */
1363
+ toAssignableList(exprList: AST.Node[], isBinding: boolean): AST.Pattern[];
1364
+
1365
+ /**
1366
+ * Parse maybe-default pattern (pattern = defaultValue)
1367
+ * @param startPos Start position
1368
+ * @param startLoc Start location
1369
+ * @param left Left-hand pattern
1370
+ */
1371
+ parseMaybeDefault(startPos: number, startLoc: AST.Position, left?: AST.Node): AST.Pattern;
1372
+
1373
+ /**
1374
+ * Check left-value pattern (for destructuring)
1375
+ */
1376
+ checkLValPattern(
1377
+ node: AST.Node,
1378
+ bindingType?: BindingType[keyof BindingType],
1379
+ checkClashes?: Record<string, boolean>,
1380
+ ): void;
1381
+
1382
+ /**
1383
+ * Check left-value simple (identifier or member expression)
1384
+ */
1385
+ checkLValSimple(
1386
+ expr: AST.Node,
1387
+ bindingType?: BindingType[keyof BindingType],
1388
+ checkClashes?: Record<string, boolean>,
1389
+ ): void;
1390
+
1391
+ /**
1392
+ * Check left-value inner pattern
1393
+ * @param node Pattern node
1394
+ * @param bindingType Binding type constant
1395
+ * @param checkClashes Clash detection object
1396
+ */
1397
+ checkLValInnerPattern(
1398
+ node: AST.Node,
1399
+ bindingType?: BindingType[keyof BindingType],
1400
+ checkClashes?: Record<string, boolean>,
1401
+ ): void;
1402
+
1403
+ /**
1404
+ * Check expression errors
1405
+ * @param refDestructuringErrors Error collector
1406
+ * @param andThrow Whether to throw on error
1407
+ * @returns Whether there were errors
1408
+ */
1409
+ checkExpressionErrors(
1410
+ refDestructuringErrors: DestructuringErrors | null,
1411
+ andThrow?: boolean,
1412
+ ): boolean;
1413
+
1414
+ /**
1415
+ * Check if expression is simple assign target
1416
+ * @param expr Expression to check
1417
+ */
1418
+ isSimpleAssignTarget(expr: AST.Node): boolean;
1419
+
1420
+ // ============================================================
1421
+ // JSX Methods (from @sveltejs/acorn-typescript)
1422
+ // ============================================================
1423
+ /**
1424
+ * Read JSX contents token
1425
+ */
1426
+ jsx_readToken(): void;
1427
+
1428
+ /**
1429
+ * Read JSX word (element/attribute name)
1430
+ */
1431
+ jsx_readWord(): void;
1432
+
1433
+ /**
1434
+ * Read JSX string
1435
+ * @param quote Quote character code
1436
+ */
1437
+ jsx_readString(quote: number): void;
1438
+
1439
+ /**
1440
+ * Read JSX entity (e.g., &amp; &lt;)
1441
+ * @returns Decoded entity string
1442
+ */
1443
+ jsx_readEntity(): string;
1444
+
1445
+ /**
1446
+ * Read JSX new line (handles CRLF normalization)
1447
+ * @param normalizeCRLF Whether to normalize CRLF to LF
1448
+ * @returns Newline string
1449
+ */
1450
+ jsx_readNewLine(normalizeCRLF?: boolean): string;
1451
+
1452
+ /**
1453
+ * Parse JSX identifier
1454
+ * @returns JSXIdentifier node
1455
+ */
1456
+ jsx_parseIdentifier(): ESTreeJSX.JSXIdentifier;
1457
+
1458
+ /**
1459
+ * Parse JSX namespaced name (ns:name)
1460
+ */
1461
+ jsx_parseNamespacedName():
1462
+ | ESTreeJSX.JSXNamespacedName
1463
+ | ReturnType<Parser['jsx_parseIdentifier']>;
1464
+
1465
+ /**
1466
+ * Parse JSX element name (identifier, member, namespaced)
1467
+ */
1468
+ jsx_parseElementName():
1469
+ | ESTreeJSX.JSXMemberExpression
1470
+ | ReturnType<Parser['jsx_parseNamespacedName']>
1471
+ | '';
1472
+
1473
+ /**
1474
+ * Parse JSX attribute value
1475
+ * @returns Attribute value (expression, string, or element)
1476
+ */
1477
+ jsx_parseAttributeValue():
1478
+ | ESTreeJSX.JSXExpressionContainer
1479
+ | ReturnType<Parser['parseExprAtom']>;
1480
+
1481
+ /**
1482
+ * Parse JSX empty expression (for {})
1483
+ */
1484
+ jsx_parseEmptyExpression(): ESTreeJSX.JSXEmptyExpression;
1485
+
1486
+ jsx_parseTupleContainer(): ESTreeJSX.JSXExpressionContainer;
1487
+
1488
+ /**
1489
+ * Parse JSX expression container ({...})
1490
+ * @returns JSXExpressionContainer node
1491
+ */
1492
+ jsx_parseExpressionContainer(): AST.Node;
1493
+
1494
+ /**
1495
+ * Parse JSX attribute (name="value" or {spread})
1496
+ * @returns JSXAttribute or JSXSpreadAttribute
1497
+ */
1498
+ jsx_parseAttribute(): AST.RippleAttribute | ESTreeJSX.JSXAttribute;
1499
+
1500
+ /**
1501
+ * Parse JSX opening element at position
1502
+ * @param startPos Start position
1503
+ * @param startLoc Start location
1504
+ * @returns JSXOpeningElement or JSXOpeningFragment
1505
+ */
1506
+ jsx_parseOpeningElementAt(
1507
+ startPos?: number,
1508
+ startLoc?: AST.Position,
1509
+ ): ESTreeJSX.JSXOpeningElement;
1510
+ // it could also be ESTreeJSX.JSXOpeningFragment
1511
+ // but not in our case since we don't use fragments
1512
+
1513
+ /**
1514
+ * Parse JSX closing element at position
1515
+ * @param startPos Start position
1516
+ * @param startLoc Start location
1517
+ * @returns JSXClosingElement or JSXClosingFragment
1518
+ */
1519
+ jsx_parseClosingElementAt(startPos: number, startLoc: AST.Position): AST.Node;
1520
+
1521
+ /**
1522
+ * Parse JSX element at position
1523
+ * @param startPos Start position
1524
+ * @param startLoc Start location
1525
+ * @returns JSXElement or JSXFragment
1526
+ */
1527
+ jsx_parseElementAt(startPos: number, startLoc: AST.Position): AST.Node;
1528
+
1529
+ /**
1530
+ * Parse JSX text node
1531
+ * @returns JSXText node
1532
+ */
1533
+ jsx_parseText(): AST.Node;
1534
+
1535
+ /**
1536
+ * Parse complete JSX element
1537
+ * @returns JSXElement or JSXFragment
1538
+ */
1539
+ jsx_parseElement(): AST.Node;
1540
+
1541
+ // ============================================================
1542
+ // Try-Parse for Recovery
1543
+ // ============================================================
1544
+ /**
1545
+ * Try to parse, returning result with error info if failed
1546
+ * @param fn Parsing function to try
1547
+ * @returns Result with node, error, thrown, aborted, failState
1548
+ */
1549
+ tryParse<T>(fn: () => T): {
1550
+ node: T | null;
1551
+ error: Error | null;
1552
+ thrown: boolean;
1553
+ aborted: boolean;
1554
+ failState: any;
1555
+ };
1556
+ parse(input: string, options: Options): AST.Program;
1557
+
1558
+ getElementName(node?: AST.Node): string | null;
1559
+ }
1560
+
1561
+ /**
1562
+ * The constructor/class type for the extended Ripple parser.
1563
+ * This represents the static side of the parser class after extending with plugins.
1564
+ */
1565
+ export interface ParserConstructor {
1566
+ new (options: Options, input: string): Parser;
1567
+ /** Built-in token types */
1568
+ tokTypes: TokTypes;
1569
+ /** Built-in token contexts */
1570
+ tokContexts: TokContexts;
1571
+ /** TypeScript extensions when using acorn-typescript */
1572
+ acornTypeScript: AcornTypeScriptExtensions;
1573
+ /** Static parse method that returns Ripple's extended Program type */
1574
+ parse(input: string, options: Options): AST.Program;
1575
+ /** Static parseExpressionAt method */
1576
+ parseExpressionAt(input: string, pos: number, options: Options): AST.Expression;
1577
+ /** Extend with plugins */
1578
+ extend(...plugins: ((BaseParser: ParserConstructor) => ParserConstructor)[]): ParserConstructor;
1579
+ }
1580
+ }