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