ripple 0.3.13 → 0.3.15

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