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,1411 +0,0 @@
1
- import type * as AST from 'estree';
2
- import type * as ESTreeJSX from 'estree-jsx';
3
- import type { TSESTree } from '@typescript-eslint/types';
4
- import type { NAMESPACE_URI } from '../../runtime/internal/client/constants.js';
5
- import type { Parse } from '#parser';
6
- import type * as ESRap from 'esrap';
7
- import type { RippleCompileError, CompileOptions } from 'ripple/compiler';
8
- import type { Position } from 'acorn';
9
- import type { RequireAllOrNone } from '#helpers';
10
-
11
- export type NameSpace = keyof typeof NAMESPACE_URI;
12
- interface BaseNodeMetaData {
13
- scoped?: boolean;
14
- path: AST.Node[];
15
- has_template?: boolean;
16
- source_name?: string | '#server' | '#style';
17
- is_capitalized?: boolean;
18
- commentContainerId?: number;
19
- parenthesized?: boolean;
20
- elementLeadingComments?: AST.Comment[];
21
- returns?: AST.ReturnStatement[];
22
- has_return?: boolean;
23
- has_throw?: boolean;
24
- is_reactive?: boolean;
25
- lone_return?: boolean;
26
- forceMapping?: boolean;
27
- lazy_id?: string;
28
- }
29
-
30
- interface FunctionMetaData extends BaseNodeMetaData {
31
- // needed for volar tokens to recognize component functions
32
- is_component?: boolean;
33
- is_method?: boolean;
34
- tracked?: boolean;
35
- }
36
-
37
- // Strip parent, loc, and range from TSESTree nodes to match @sveltejs/acorn-typescript output
38
- // acorn-typescript uses start/end instead of range, and loc is optional
39
- type AcornTSNode<T> = Omit<T, 'parent' | 'loc' | 'range' | 'expression'> & {
40
- start?: number;
41
- end?: number;
42
- loc?: AST.SourceLocation;
43
- range?: AST.BaseNode['range'];
44
- metadata: BaseNodeMetaData;
45
-
46
- leadingComments?: AST.Comment[] | undefined;
47
- trailingComments?: AST.Comment[] | undefined;
48
- };
49
-
50
- interface FunctionLikeTS {
51
- returnType?: AST.TSTypeAnnotation;
52
- typeParameters?: AST.TSTypeParameterDeclaration;
53
- typeAnnotation?: AST.TSTypeAnnotation;
54
- }
55
-
56
- // Ripple augmentation for ESTree function nodes
57
- declare module 'estree' {
58
- interface Program {
59
- innerComments?: Comment[] | undefined;
60
- }
61
-
62
- interface FunctionDeclaration extends FunctionLikeTS {
63
- metadata: FunctionMetaData;
64
- }
65
- interface FunctionExpression extends FunctionLikeTS {
66
- metadata: FunctionMetaData;
67
- }
68
- interface ArrowFunctionExpression extends FunctionLikeTS {
69
- metadata: FunctionMetaData;
70
- }
71
-
72
- interface NewExpression {
73
- metadata: BaseNodeMetaData & {
74
- skipNewMapping?: boolean;
75
- };
76
- }
77
-
78
- type Accessibility = 'public' | 'protected' | 'private'; // missing in acorn-typescript types
79
- interface MethodDefinition {
80
- typeParameters?: TSTypeParameterDeclaration;
81
- accessibility?: Accessibility;
82
- }
83
-
84
- interface PropertyDefinition {
85
- accessibility?: Accessibility;
86
- readonly?: boolean;
87
- optional?: boolean;
88
- }
89
-
90
- interface ClassDeclaration {
91
- typeParameters?: AST.TSTypeParameterDeclaration;
92
- superTypeParameters?: AST.TSTypeParameterInstantiation;
93
- implements?: AST.TSClassImplements[];
94
- }
95
-
96
- interface ClassExpression {
97
- typeParameters?: AST.TSTypeParameterDeclaration;
98
- superTypeParameters?: AST.TSTypeParameterInstantiation;
99
- implements?: AST.TSClassImplements[];
100
- }
101
-
102
- interface Identifier extends AST.TrackedNode {
103
- metadata: BaseNodeMetaData & {
104
- // needed for volar tokens to recognize component functions
105
- is_component?: boolean;
106
- };
107
- typeAnnotation?: TSTypeAnnotation | undefined;
108
- decorators: TSESTree.Decorator[];
109
- optional: boolean;
110
- }
111
-
112
- // Lazy destructuring patterns (&{...} and &[...])
113
- interface ObjectPattern {
114
- lazy?: boolean;
115
- }
116
- interface ArrayPattern {
117
- lazy?: boolean;
118
- }
119
-
120
- // We mark the whole node as marked when member is @[expression]
121
- // Otherwise, we only mark Identifier nodes
122
- interface MemberExpression {
123
- tracked?: boolean;
124
- }
125
-
126
- interface SimpleLiteral extends AST.LiteralNode {}
127
- interface RegExpLiteral extends AST.LiteralNode {}
128
- interface BigIntLiteral extends AST.LiteralNode {}
129
-
130
- interface TrackedNode {
131
- tracked?: boolean;
132
- }
133
-
134
- interface LiteralNode {
135
- was_expression?: boolean;
136
- }
137
-
138
- // Include TypeScript node types and Ripple-specific nodes in NodeMap
139
- interface NodeMap {
140
- Component: Component;
141
- Tsx: Tsx;
142
- TsxCompat: TsxCompat;
143
- RippleExpression: RippleExpression;
144
- Html: Html;
145
- Element: Element;
146
- Text: TextNode;
147
- ServerBlock: ServerBlock;
148
- ServerBlockStatement: ServerBlockStatement;
149
- ServerIdentifier: ServerIdentifier;
150
- StyleIdentifier: StyleIdentifier;
151
- Attribute: Attribute;
152
- RefAttribute: RefAttribute;
153
- SpreadAttribute: SpreadAttribute;
154
- ParenthesizedExpression: ParenthesizedExpression;
155
- ScriptContent: ScriptContent;
156
- }
157
-
158
- interface ExpressionMap {
159
- StyleIdentifier: StyleIdentifier;
160
- ServerIdentifier: ServerIdentifier;
161
- Text: TextNode;
162
- JSXEmptyExpression: ESTreeJSX.JSXEmptyExpression;
163
- ParenthesizedExpression: ParenthesizedExpression;
164
- TSAsExpression: TSAsExpression;
165
- }
166
-
167
- // Missing estree type
168
- interface ParenthesizedExpression extends AST.BaseNode {
169
- type: 'ParenthesizedExpression';
170
- expression: AST.Expression;
171
- metadata: BaseNodeMetaData & {
172
- skipParenthesisMapping?: boolean;
173
- };
174
- }
175
-
176
- interface Comment {
177
- context?: Parse.CommentMetaData | null;
178
- }
179
-
180
- // For now only ObjectExpression needs printInline
181
- // Needed to avoid ts pragma comments being on the wrong line that
182
- // does not affect the next line as in the source code
183
- interface ObjectExpression {
184
- metadata: BaseNodeMetaData & {
185
- printInline?: boolean;
186
- };
187
- }
188
-
189
- /**
190
- * Custom Comment interface with location information
191
- */
192
- type CommentWithLocation = AST.Comment & NodeWithLocation;
193
-
194
- interface TryStatement {
195
- pending?: AST.BlockStatement | null;
196
- }
197
-
198
- interface CatchClause {
199
- resetParam?: AST.Pattern | null;
200
- }
201
-
202
- interface ForOfStatement {
203
- index?: AST.Identifier | null;
204
- key?: AST.Expression | null;
205
- }
206
-
207
- interface ServerIdentifier extends AST.BaseExpression {
208
- type: 'ServerIdentifier';
209
- }
210
-
211
- interface StyleIdentifier extends AST.BaseExpression {
212
- type: 'StyleIdentifier';
213
- }
214
-
215
- interface ImportDeclaration {
216
- importKind: TSESTree.ImportDeclaration['importKind'];
217
- }
218
- interface ImportSpecifier {
219
- importKind: TSESTree.ImportSpecifier['importKind'];
220
- }
221
- interface ExportNamedDeclaration {
222
- exportKind: TSESTree.ExportNamedDeclaration['exportKind'];
223
- }
224
-
225
- interface BaseNodeWithoutComments {
226
- // Adding start, end for now as always there
227
- // later might change to optional
228
- // And only define on certain nodes
229
- // BaseNode inherits from this interface
230
- start?: number;
231
- end?: number;
232
- }
233
-
234
- interface BaseNode {
235
- is_controlled?: boolean;
236
- // This is for Pattern but it's a type alias
237
- // So it's just easy to extend BaseNode even though
238
- // typeAnnotation, typeArguments do not apply to all nodes
239
- typeAnnotation?: TSTypeAnnotation;
240
- typeArguments?: TSTypeParameterInstantiation;
241
-
242
- // even though technically metadata starts out as undefined
243
- // metadata is always populated by the `_` visitor
244
- // which runs for every node before other visitors
245
- // so taking a practical approach and making it required
246
- // to avoid lots of typecasting or checking for undefined
247
- metadata: BaseNodeMetaData;
248
-
249
- comments?: Comment[];
250
- }
251
-
252
- interface NodeWithLocation {
253
- start: number;
254
- end: number;
255
- loc: AST.SourceLocation;
256
- }
257
-
258
- interface NodeWithMaybeComments {
259
- innerComments?: AST.Comment[] | undefined;
260
- leadingComments?: AST.Comment[] | undefined;
261
- trailingComments?: AST.Comment[] | undefined;
262
- }
263
-
264
- /**
265
- * Ripple custom interfaces and types section
266
- */
267
- interface Component extends AST.BaseNode {
268
- type: 'Component';
269
- // null is for anonymous components {component: () => {}}
270
- id: AST.Identifier | null;
271
- params: AST.Pattern[];
272
- body: AST.Node[];
273
- css: CSS.StyleSheet | null;
274
- metadata: BaseNodeMetaData & {
275
- topScopedClasses?: TopScopedClasses;
276
- styleClasses?: StyleClasses;
277
- styleIdentifierPresent?: boolean;
278
- };
279
- default: boolean;
280
- typeParameters?: AST.TSTypeParameterDeclaration;
281
- }
282
-
283
- interface Tsx extends AST.BaseNode {
284
- type: 'Tsx';
285
- attributes: Array<any>;
286
- children: ESTreeJSX.JSXElement['children'];
287
- selfClosing?: boolean;
288
- unclosed?: boolean;
289
- openingElement: ESTreeJSX.JSXOpeningElement;
290
- closingElement: ESTreeJSX.JSXClosingElement;
291
- }
292
-
293
- interface TsxCompat extends AST.BaseNode {
294
- type: 'TsxCompat';
295
- kind: string;
296
- attributes: Array<any>;
297
- children: ESTreeJSX.JSXElement['children'];
298
- selfClosing?: boolean;
299
- unclosed?: boolean;
300
- openingElement: ESTreeJSX.JSXOpeningElement;
301
- closingElement: ESTreeJSX.JSXClosingElement;
302
- }
303
-
304
- interface Html extends AST.BaseNode {
305
- type: 'Html';
306
- expression: AST.Expression;
307
- }
308
-
309
- export interface RippleExpression extends AST.BaseExpression {
310
- type: 'RippleExpression';
311
- expression: AST.Expression;
312
- loc?: AST.SourceLocation;
313
- }
314
-
315
- interface Element extends AST.BaseNode {
316
- type: 'Element';
317
- // MemberExpression for namespaced or dynamic elements
318
- id: AST.Identifier | AST.MemberExpression;
319
- attributes: RippleAttribute[];
320
- children: AST.Node[];
321
- selfClosing?: boolean;
322
- unclosed?: boolean;
323
- loc: SourceLocation;
324
- metadata: BaseNodeMetaData & {
325
- ts_name?: string;
326
- // for <style> tag
327
- styleScopeHash?: string;
328
- // for elements with scoped style classes
329
- css?: {
330
- scopedClasses: Map<
331
- string,
332
- {
333
- start: number;
334
- end: number;
335
- selector: CSS.ClassSelector;
336
- }
337
- >;
338
- hash: string;
339
- };
340
- };
341
- openingElement: ESTreeJSX.JSXOpeningElement;
342
- closingElement: ESTreeJSX.JSXClosingElement;
343
- // for <style> tags
344
- css?: string;
345
- innerComments?: Comment[];
346
- }
347
-
348
- export interface TextNode extends AST.BaseExpression {
349
- type: 'Text';
350
- expression: AST.Expression;
351
- loc?: AST.SourceLocation;
352
- }
353
-
354
- interface ServerBlockStatement extends Omit<BlockStatement, 'body'> {
355
- body: (AST.Statement | AST.ExportNamedDeclaration)[];
356
- }
357
-
358
- interface ServerBlock extends AST.BaseNode {
359
- type: 'ServerBlock';
360
- body: ServerBlockStatement;
361
- metadata: BaseNodeMetaData & {
362
- exports: Set<string>;
363
- };
364
- }
365
-
366
- interface ScriptContent extends Omit<AST.Element, 'type'> {
367
- type: 'ScriptContent';
368
- content: string;
369
- }
370
-
371
- /**
372
- * Ripple attribute nodes
373
- */
374
- interface Attribute extends AST.BaseNode {
375
- type: 'Attribute';
376
- name: AST.Identifier;
377
- value: AST.Expression | null;
378
- loc?: AST.SourceLocation;
379
- shorthand?: boolean;
380
- metadata: BaseNodeMetaData & {
381
- delegated?: boolean;
382
- };
383
- }
384
-
385
- interface RefAttribute extends AST.BaseNode {
386
- type: 'RefAttribute';
387
- argument: AST.Expression;
388
- loc?: AST.SourceLocation;
389
- }
390
-
391
- interface SpreadAttribute extends AST.BaseNode {
392
- type: 'SpreadAttribute';
393
- argument: AST.Expression;
394
- loc?: AST.SourceLocation;
395
- }
396
-
397
- /**
398
- * Ripple's extended Declaration type that includes Component
399
- * Use this instead of Declaration when you need Component support
400
- */
401
- export type RippleDeclaration = AST.Declaration | Component | AST.TSDeclareFunction;
402
-
403
- /**
404
- * Ripple's extended ExportNamedDeclaration with Component support
405
- */
406
- interface RippleExportNamedDeclaration extends Omit<AST.ExportNamedDeclaration, 'declaration'> {
407
- declaration?: RippleDeclaration | null | undefined;
408
- }
409
-
410
- /**
411
- * Ripple's extended Program with Component support
412
- */
413
- interface RippleProgram extends Omit<Program, 'body'> {
414
- body: (Program['body'][number] | Component | FunctionExpression)[];
415
- }
416
-
417
- interface RippleMethodDefinition extends Omit<AST.MethodDefinition, 'value'> {
418
- value: AST.MethodDefinition['value'] | Component;
419
- }
420
-
421
- interface RippleProperty extends Omit<AST.Property, 'value'> {
422
- value: AST.Property['value'] | Component;
423
- }
424
-
425
- export type RippleAttribute = AST.Attribute | AST.SpreadAttribute | AST.RefAttribute;
426
-
427
- export type RippleStatement = AST.Statement | TSESTree.Statement;
428
-
429
- export type NodeWithChildren = AST.Element | AST.Tsx | AST.TsxCompat;
430
-
431
- export namespace CSS {
432
- export interface BaseNode extends AST.NodeWithMaybeComments {
433
- start: number;
434
- end: number;
435
- loc?: AST.SourceLocation;
436
- }
437
-
438
- export interface StyleSheet extends BaseNode {
439
- type: 'StyleSheet';
440
- children: Array<Atrule | Rule>;
441
- source: string;
442
- hash: string;
443
- }
444
-
445
- export interface Atrule extends BaseNode {
446
- type: 'Atrule';
447
- name: string;
448
- prelude: string;
449
- block: Block | null;
450
- }
451
-
452
- export interface Rule extends BaseNode {
453
- type: 'Rule';
454
- prelude: SelectorList;
455
- block: Block;
456
- metadata: {
457
- parent_rule: Rule | null;
458
- has_local_selectors: boolean;
459
- is_global_block: boolean;
460
- };
461
- }
462
-
463
- /**
464
- * A list of selectors, e.g. `a, b, c {}`
465
- */
466
- export interface SelectorList extends BaseNode {
467
- type: 'SelectorList';
468
- /**
469
- * The `a`, `b` and `c` in `a, b, c {}`
470
- */
471
- children: ComplexSelector[];
472
- }
473
-
474
- /**
475
- * A complex selector, e.g. `a b c {}`
476
- */
477
- export interface ComplexSelector extends BaseNode {
478
- type: 'ComplexSelector';
479
- /**
480
- * The `a`, `b` and `c` in `a b c {}`
481
- */
482
- children: RelativeSelector[];
483
- metadata: {
484
- rule: Rule | null;
485
- used: boolean;
486
- is_global?: boolean;
487
- };
488
- }
489
-
490
- /**
491
- * A relative selector, e.g the `a` and `> b` in `a > b {}`
492
- */
493
- export interface RelativeSelector extends BaseNode {
494
- type: 'RelativeSelector';
495
- /**
496
- * In `a > b`, `> b` forms one relative selector, and `>` is the combinator. `null` for the first selector.
497
- */
498
- combinator: null | Combinator;
499
- /**
500
- * The `b:is(...)` in `> b:is(...)`
501
- */
502
- selectors: SimpleSelector[];
503
-
504
- metadata: {
505
- is_global: boolean;
506
- is_global_like: boolean;
507
- scoped: boolean;
508
- };
509
- }
510
-
511
- export interface TypeSelector extends BaseNode {
512
- type: 'TypeSelector';
513
- name: string;
514
- }
515
-
516
- export interface IdSelector extends BaseNode {
517
- type: 'IdSelector';
518
- name: string;
519
- }
520
-
521
- export interface ClassSelector extends BaseNode {
522
- type: 'ClassSelector';
523
- name: string;
524
- }
525
-
526
- export interface AttributeSelector extends BaseNode {
527
- type: 'AttributeSelector';
528
- name: string;
529
- matcher: string | null;
530
- value: string | null;
531
- flags: string | null;
532
- }
533
-
534
- export interface PseudoElementSelector extends BaseNode {
535
- type: 'PseudoElementSelector';
536
- name: string;
537
- }
538
-
539
- export interface PseudoClassSelector extends BaseNode {
540
- type: 'PseudoClassSelector';
541
- name: string;
542
- args: SelectorList | null;
543
- }
544
-
545
- export interface Percentage extends BaseNode {
546
- type: 'Percentage';
547
- value: string;
548
- }
549
-
550
- export interface NestingSelector extends BaseNode {
551
- type: 'NestingSelector';
552
- name: '&';
553
- }
554
-
555
- export interface Nth extends BaseNode {
556
- type: 'Nth';
557
- value: string;
558
- }
559
-
560
- export type SimpleSelector =
561
- | TypeSelector
562
- | IdSelector
563
- | ClassSelector
564
- | AttributeSelector
565
- | PseudoElementSelector
566
- | PseudoClassSelector
567
- | Percentage
568
- | Nth
569
- | NestingSelector;
570
-
571
- export interface Combinator extends BaseNode {
572
- type: 'Combinator';
573
- name: string;
574
- }
575
-
576
- export interface Block extends BaseNode {
577
- type: 'Block';
578
- children: Array<Declaration | Rule | Atrule>;
579
- }
580
-
581
- export interface Declaration extends BaseNode {
582
- type: 'Declaration';
583
- property: string;
584
- value: string;
585
- }
586
-
587
- // for zimmerframe
588
- export type Node =
589
- | StyleSheet
590
- | Rule
591
- | Atrule
592
- | SelectorList
593
- | Block
594
- | ComplexSelector
595
- | RelativeSelector
596
- | Combinator
597
- | SimpleSelector
598
- | Declaration;
599
- }
600
- }
601
-
602
- declare module 'estree-jsx' {
603
- interface JSXAttribute {
604
- shorthand: boolean;
605
- }
606
-
607
- interface JSXIdentifier {
608
- tracked?: boolean;
609
- metadata: BaseNodeMetaData & {
610
- is_component?: boolean;
611
- };
612
- }
613
-
614
- interface JSXEmptyExpression {
615
- loc: AST.SourceLocation;
616
- innerComments?: AST.Comment[];
617
- }
618
-
619
- interface JSXOpeningFragment {
620
- attributes: Array<JSXAttribute | JSXSpreadAttribute>;
621
- }
622
-
623
- interface JSXElement {
624
- metadata: BaseNodeMetaData & {
625
- ts_name?: string;
626
- };
627
- }
628
-
629
- interface JSXExpressionContainer {
630
- html?: boolean;
631
- text?: boolean;
632
- }
633
-
634
- interface JSXMemberExpression {
635
- computed?: boolean;
636
- }
637
-
638
- interface RippleJSXOpeningElement extends Omit<JSXOpeningElement, 'name'> {
639
- name: AST.MemberExpression | JSXIdentifier | JSXNamespacedName;
640
- }
641
-
642
- interface RippleJSXClosingElement extends Omit<JSXClosingElement, 'name'> {
643
- name: AST.MemberExpression | JSXIdentifier | JSXNamespacedName;
644
- }
645
-
646
- interface ExpressionMap {
647
- JSXIdentifier: JSXIdentifier;
648
- }
649
- }
650
-
651
- declare module 'estree' {
652
- // Helper map for creating our own TypeNode
653
- // and to be used to extend estree's NodeMap
654
- interface TSNodeMap {
655
- // TypeScript nodes
656
- TSAnyKeyword: TSAnyKeyword;
657
- TSArrayType: TSArrayType;
658
- TSAsExpression: TSAsExpression;
659
- TSBigIntKeyword: TSBigIntKeyword;
660
- TSBooleanKeyword: TSBooleanKeyword;
661
- TSCallSignatureDeclaration: TSCallSignatureDeclaration;
662
- TSConditionalType: TSConditionalType;
663
- TSConstructorType: TSConstructorType;
664
- TSConstructSignatureDeclaration: TSConstructSignatureDeclaration;
665
- TSDeclareFunction: TSDeclareFunction;
666
- TSEnumDeclaration: TSEnumDeclaration;
667
- TSEnumMember: TSEnumMember;
668
- TSExportAssignment: TSExportAssignment;
669
- TSExternalModuleReference: TSExternalModuleReference;
670
- TSFunctionType: TSFunctionType;
671
- TSImportEqualsDeclaration: TSImportEqualsDeclaration;
672
- TSImportType: TSImportType;
673
- TSIndexedAccessType: TSIndexedAccessType;
674
- TSIndexSignature: TSIndexSignature;
675
- TSInferType: TSInferType;
676
- TSInstantiationExpression: TSInstantiationExpression;
677
- TSInterfaceBody: TSInterfaceBody;
678
- TSInterfaceDeclaration: TSInterfaceDeclaration;
679
- TSIntersectionType: TSIntersectionType;
680
- TSIntrinsicKeyword: TSIntrinsicKeyword;
681
- TSLiteralType: TSLiteralType;
682
- TSMappedType: TSMappedType;
683
- TSMethodSignature: TSMethodSignature;
684
- TSModuleBlock: TSModuleBlock;
685
- TSModuleDeclaration: TSModuleDeclaration;
686
- TSNamedTupleMember: TSNamedTupleMember;
687
- TSNamespaceExportDeclaration: TSNamespaceExportDeclaration;
688
- TSNeverKeyword: TSNeverKeyword;
689
- TSNonNullExpression: TSNonNullExpression;
690
- TSNullKeyword: TSNullKeyword;
691
- TSNumberKeyword: TSNumberKeyword;
692
- TSObjectKeyword: TSObjectKeyword;
693
- TSOptionalType: TSOptionalType;
694
- TSParameterProperty: TSParameterProperty;
695
- TSPropertySignature: TSPropertySignature;
696
- TSQualifiedName: TSQualifiedName;
697
- TSRestType: TSRestType;
698
- TSSatisfiesExpression: TSSatisfiesExpression;
699
- TSStringKeyword: TSStringKeyword;
700
- TSSymbolKeyword: TSSymbolKeyword;
701
- TSThisType: TSThisType;
702
- TSTupleType: TSTupleType;
703
- TSTypeAliasDeclaration: TSTypeAliasDeclaration;
704
- TSTypeAnnotation: TSTypeAnnotation;
705
- TSTypeAssertion: TSTypeAssertion;
706
- TSTypeLiteral: TSTypeLiteral;
707
- TSTypeOperator: TSTypeOperator;
708
- TSTypeParameter: TSTypeParameter;
709
- TSTypeParameterDeclaration: TSTypeParameterDeclaration;
710
- TSTypeParameterInstantiation: TSTypeParameterInstantiation;
711
- TSTypePredicate: TSTypePredicate;
712
- TSTypeQuery: TSTypeQuery;
713
- TSTypeReference: TSTypeReference;
714
- TSUndefinedKeyword: TSUndefinedKeyword;
715
- TSUnionType: TSUnionType;
716
- TSUnknownKeyword: TSUnknownKeyword;
717
- TSVoidKeyword: TSVoidKeyword;
718
- TSParenthesizedType: TSParenthesizedType;
719
- TSExpressionWithTypeArguments: TSExpressionWithTypeArguments;
720
- TSClassImplements: TSClassImplements;
721
- }
722
-
723
- // Create our version of TypeNode with modified types to be used in replacements
724
- type TypeNode = TSNodeMap[keyof TSNodeMap];
725
-
726
- // Extend NodeMap to include TypeScript nodes
727
- interface NodeMap extends TSNodeMap {
728
- TypeNode: TypeNode;
729
- }
730
-
731
- type EntityName = AST.Identifier | AST.ThisExpression | TSQualifiedName;
732
- type Parameter =
733
- | AST.ArrayPattern
734
- | AST.AssignmentPattern
735
- | AST.Identifier
736
- | AST.ObjectPattern
737
- | AST.RestElement
738
- | TSParameterProperty;
739
- type TypeElement =
740
- | TSCallSignatureDeclaration
741
- | TSConstructSignatureDeclaration
742
- | TSIndexSignature
743
- | TSMethodSignature
744
- | TSPropertySignature;
745
- type TSPropertySignature = TSPropertySignatureComputedName | TSPropertySignatureNonComputedName;
746
- type PropertyNameComputed = AST.Expression;
747
- type PropertyNameNonComputed = AST.Identifier | NumberLiteral | StringLiteral;
748
-
749
- // TypeScript AST node interfaces from @sveltejs/acorn-typescript
750
- // Based on TSESTree types but adapted for acorn's output format
751
- interface TSAnyKeyword extends AcornTSNode<TSESTree.TSAnyKeyword> {}
752
- interface TSArrayType extends Omit<AcornTSNode<TSESTree.TSArrayType>, 'elementType'> {
753
- elementType: TypeNode;
754
- }
755
- interface TSAsExpression extends Omit<AcornTSNode<TSESTree.TSAsExpression>, 'typeAnnotation'> {
756
- // Have to override it to use our Expression for required properties like metadata
757
- expression: AST.Expression;
758
- typeAnnotation: TypeNode;
759
- }
760
- interface TSBigIntKeyword extends AcornTSNode<TSESTree.TSBigIntKeyword> {}
761
- interface TSBooleanKeyword extends AcornTSNode<TSESTree.TSBooleanKeyword> {}
762
- interface TSCallSignatureDeclaration extends Omit<
763
- AcornTSNode<TSESTree.TSCallSignatureDeclaration>,
764
- 'typeParameters' | 'typeAnnotation'
765
- > {
766
- parameters: Parameter[];
767
- typeParameters: TSTypeParameterDeclaration | undefined;
768
- typeAnnotation: TSTypeAnnotation | undefined;
769
- }
770
- interface TSConditionalType extends Omit<
771
- AcornTSNode<TSESTree.TSConditionalType>,
772
- 'checkType' | 'extendsType' | 'falseType' | 'trueType'
773
- > {
774
- checkType: TypeNode;
775
- extendsType: TypeNode;
776
- falseType: TypeNode;
777
- trueType: TypeNode;
778
- }
779
- interface TSConstructorType extends Omit<
780
- AcornTSNode<TSESTree.TSConstructorType>,
781
- 'typeParameters' | 'params'
782
- > {
783
- typeAnnotation: TSTypeAnnotation | undefined;
784
- typeParameters: TSTypeParameterDeclaration | undefined;
785
- parameters: AST.Parameter[];
786
- }
787
- interface TSConstructSignatureDeclaration extends Omit<
788
- AcornTSNode<TSESTree.TSConstructSignatureDeclaration>,
789
- 'typeParameters' | 'typeAnnotation'
790
- > {
791
- parameters: Parameter[];
792
- typeParameters: TSTypeParameterDeclaration | undefined;
793
- typeAnnotation: TSTypeAnnotation | undefined;
794
- }
795
- interface TSDeclareFunction extends Omit<
796
- AcornTSNode<TSESTree.TSDeclareFunction>,
797
- 'id' | 'params' | 'typeParameters' | 'returnType'
798
- > {
799
- id: AST.Identifier;
800
- params: Parameter[];
801
- typeParameters: TSTypeParameterDeclaration | undefined;
802
- returnType: TSTypeAnnotation | undefined;
803
- }
804
- interface TSEnumDeclaration extends Omit<
805
- AcornTSNode<TSESTree.TSEnumDeclaration>,
806
- 'id' | 'members'
807
- > {
808
- id: AST.Identifier;
809
- members: TSEnumMember[];
810
- }
811
- interface TSEnumMember extends Omit<AcornTSNode<TSESTree.TSEnumMember>, 'id' | 'initializer'> {
812
- id: AST.Identifier | StringLiteral;
813
- initializer: AST.Expression | undefined;
814
- }
815
- interface TSExportAssignment extends Omit<
816
- AcornTSNode<TSESTree.TSExportAssignment>,
817
- 'expression'
818
- > {
819
- expression: AST.Expression;
820
- }
821
- interface TSExternalModuleReference extends Omit<
822
- AcornTSNode<TSESTree.TSExternalModuleReference>,
823
- 'expression'
824
- > {
825
- expression: StringLiteral;
826
- }
827
- interface TSFunctionType extends Omit<
828
- AcornTSNode<TSESTree.TSFunctionType>,
829
- 'typeParameters' | 'params'
830
- > {
831
- typeAnnotation: TSTypeAnnotation | undefined;
832
- typeParameters: TSTypeParameterDeclaration | undefined;
833
- parameters: Parameter[];
834
- }
835
- interface TSImportEqualsDeclaration extends AcornTSNode<TSESTree.TSImportEqualsDeclaration> {}
836
- interface TSImportType extends Omit<
837
- AcornTSNode<TSESTree.TSImportType>,
838
- 'argument' | 'qualifier' | 'typeParameters'
839
- > {
840
- argument: TypeNode;
841
- qualifier: EntityName | null;
842
- // looks like acorn-typescript has typeParameters
843
- typeParameters: TSTypeParameterDeclaration | undefined | undefined;
844
- }
845
- interface TSIndexedAccessType extends Omit<
846
- AcornTSNode<TSESTree.TSIndexedAccessType>,
847
- 'indexType' | 'objectType'
848
- > {
849
- indexType: TypeNode;
850
- objectType: TypeNode;
851
- }
852
- interface TSIndexSignature extends Omit<
853
- AcornTSNode<TSESTree.TSIndexSignature>,
854
- 'parameters' | 'typeAnnotation'
855
- > {
856
- parameters: AST.Parameter[];
857
- typeAnnotation: TSTypeAnnotation | undefined;
858
- }
859
- interface TSInferType extends Omit<AcornTSNode<TSESTree.TSInferType>, 'typeParameter'> {
860
- typeParameter: TSTypeParameter;
861
- }
862
- interface TSInstantiationExpression extends Omit<
863
- AcornTSNode<TSESTree.TSInstantiationExpression>,
864
- 'typeArguments' | 'expression'
865
- > {
866
- expression: AST.Expression;
867
- typeArguments: TSTypeParameterInstantiation;
868
- }
869
- interface TSInterfaceBody extends Omit<AcornTSNode<TSESTree.TSInterfaceBody>, 'body'> {
870
- body: TypeElement[];
871
- }
872
- interface TSInterfaceDeclaration extends Omit<
873
- AcornTSNode<TSESTree.TSInterfaceDeclaration>,
874
- 'id' | 'typeParameters' | 'body' | 'extends'
875
- > {
876
- id: AST.Identifier;
877
- typeParameters: TSTypeParameterDeclaration | undefined;
878
- body: TSInterfaceBody;
879
- extends: TSExpressionWithTypeArguments[];
880
- }
881
- interface TSIntersectionType extends Omit<AcornTSNode<TSESTree.TSIntersectionType>, 'types'> {
882
- types: TypeNode[];
883
- }
884
- interface TSIntrinsicKeyword extends AcornTSNode<TSESTree.TSIntrinsicKeyword> {}
885
- interface TSLiteralType extends Omit<AcornTSNode<TSESTree.TSLiteralType>, 'literal'> {
886
- literal: AST.Literal | AST.TemplateLiteral;
887
- }
888
- interface TSMappedType extends Omit<
889
- AcornTSNode<TSESTree.TSMappedType>,
890
- 'typeParameter' | 'typeAnnotation' | 'nameType'
891
- > {
892
- typeAnnotation: TypeNode | undefined;
893
- typeParameter: TSTypeParameter;
894
- nameType: TypeNode | null;
895
- }
896
- interface TSMethodSignature extends Omit<
897
- AcornTSNode<TSESTree.TSMethodSignature>,
898
- 'key' | 'typeParameters' | 'params' | 'typeAnnotation'
899
- > {
900
- key: PropertyNameComputed | PropertyNameNonComputed;
901
- typeParameters: TSTypeParameterDeclaration | undefined;
902
- parameters: Parameter[];
903
- // doesn't actually exist in the spec but acorn-typescript adds it
904
- typeAnnotation: TSTypeAnnotation | undefined;
905
- }
906
- interface TSModuleBlock extends Omit<AcornTSNode<TSESTree.TSModuleBlock>, 'body'> {
907
- body: AST.Statement[];
908
- }
909
- interface TSModuleDeclaration extends Omit<
910
- AcornTSNode<TSESTree.TSModuleDeclaration>,
911
- 'body' | 'id'
912
- > {
913
- body: TSModuleBlock;
914
- id: AST.Identifier;
915
- }
916
- interface TSNamedTupleMember extends Omit<
917
- AcornTSNode<TSESTree.TSNamedTupleMember>,
918
- 'elementType' | 'label'
919
- > {
920
- elementType: TypeNode;
921
- label: AST.Identifier;
922
- }
923
- interface TSNamespaceExportDeclaration extends Omit<
924
- AcornTSNode<TSESTree.TSNamespaceExportDeclaration>,
925
- 'id'
926
- > {
927
- id: AST.Identifier;
928
- }
929
- interface TSNeverKeyword extends AcornTSNode<TSESTree.TSNeverKeyword> {}
930
- interface TSNonNullExpression extends AcornTSNode<TSESTree.TSNonNullExpression> {
931
- expression: AST.Expression;
932
- }
933
- interface TSNullKeyword extends AcornTSNode<TSESTree.TSNullKeyword> {}
934
- interface TSNumberKeyword extends AcornTSNode<TSESTree.TSNumberKeyword> {}
935
- interface TSObjectKeyword extends AcornTSNode<TSESTree.TSObjectKeyword> {}
936
- interface TSOptionalType extends Omit<AcornTSNode<TSESTree.TSOptionalType>, 'typeAnnotation'> {
937
- typeAnnotation: TypeNode;
938
- }
939
- interface TSParameterProperty extends AcornTSNode<TSESTree.TSParameterProperty> {}
940
- interface TSPropertySignatureComputedName extends Omit<
941
- AcornTSNode<TSESTree.TSPropertySignatureComputedName>,
942
- 'key' | 'typeAnnotation'
943
- > {
944
- key: PropertyNameComputed;
945
- typeAnnotation: TSTypeAnnotation | undefined;
946
- }
947
- interface TSPropertySignatureNonComputedName extends Omit<
948
- AcornTSNode<TSESTree.TSPropertySignatureNonComputedName>,
949
- 'key' | 'typeAnnotation'
950
- > {
951
- key: PropertyNameNonComputed;
952
- typeAnnotation: TSTypeAnnotation | undefined;
953
- }
954
- interface TSQualifiedName extends Omit<AcornTSNode<TSESTree.TSQualifiedName>, 'left' | 'right'> {
955
- left: EntityName;
956
- right: AST.Identifier;
957
- }
958
- interface TSRestType extends Omit<AcornTSNode<TSESTree.TSRestType>, 'typeAnnotation'> {
959
- typeAnnotation: TypeNode;
960
- }
961
- interface TSSatisfiesExpression extends Omit<
962
- AcornTSNode<TSESTree.TSSatisfiesExpression>,
963
- 'typeAnnotation'
964
- > {
965
- expression: AST.Expression;
966
- typeAnnotation: TypeNode;
967
- }
968
- interface TSStringKeyword extends AcornTSNode<TSESTree.TSStringKeyword> {}
969
- interface TSSymbolKeyword extends AcornTSNode<TSESTree.TSSymbolKeyword> {}
970
- interface TSThisType extends AcornTSNode<TSESTree.TSThisType> {}
971
- interface TSTupleType extends Omit<AcornTSNode<TSESTree.TSTupleType>, 'elementTypes'> {
972
- elementTypes: TypeNode[];
973
- }
974
- interface TSTypeAliasDeclaration extends Omit<
975
- AcornTSNode<TSESTree.TSTypeAliasDeclaration>,
976
- 'id' | 'typeParameters' | 'typeAnnotation'
977
- > {
978
- id: AST.Identifier;
979
- typeAnnotation: TypeNode;
980
- typeParameters: TSTypeParameterDeclaration | undefined;
981
- }
982
- interface TSTypeAnnotation extends Omit<
983
- AcornTSNode<TSESTree.TSTypeAnnotation>,
984
- 'typeAnnotation'
985
- > {
986
- typeAnnotation: TypeNode;
987
- }
988
- interface TSTypeAssertion extends AcornTSNode<TSESTree.TSTypeAssertion> {
989
- expression: AST.Expression;
990
- }
991
- interface TSTypeLiteral extends Omit<AcornTSNode<TSESTree.TSTypeLiteral>, 'members'> {
992
- members: TypeElement[];
993
- }
994
- interface TSTypeOperator extends Omit<AcornTSNode<TSESTree.TSTypeOperator>, 'typeAnnotation'> {
995
- typeAnnotation: TypeNode | undefined;
996
- }
997
- interface TSTypeParameter extends Omit<
998
- AcornTSNode<TSESTree.TSTypeParameter>,
999
- 'name' | 'constraint' | 'default'
1000
- > {
1001
- constraint: TypeNode | undefined;
1002
- default: TypeNode | undefined;
1003
- name: string; // for some reason acorn-typescript uses string instead of Identifier
1004
- }
1005
- interface TSTypeParameterDeclaration extends Omit<
1006
- AcornTSNode<TSESTree.TSTypeParameterDeclaration>,
1007
- 'params'
1008
- > {
1009
- params: TSTypeParameter[];
1010
- extra?: {
1011
- trailingComma: number;
1012
- };
1013
- }
1014
- interface TSTypeParameterInstantiation extends Omit<
1015
- AcornTSNode<TSESTree.TSTypeParameterInstantiation>,
1016
- 'params'
1017
- > {
1018
- params: TypeNode[];
1019
- }
1020
- interface TSTypePredicate extends AcornTSNode<TSESTree.TSTypePredicate> {}
1021
- interface TSTypeQuery extends Omit<
1022
- AcornTSNode<TSESTree.TSTypeQuery>,
1023
- 'exprName' | 'typeArguments'
1024
- > {
1025
- exprName: EntityName | TSImportType;
1026
- typeArguments: TSTypeParameterInstantiation | undefined;
1027
- }
1028
- interface TSTypeReference extends Omit<
1029
- AcornTSNode<TSESTree.TSTypeReference>,
1030
- 'typeName' | 'typeArguments'
1031
- > {
1032
- typeArguments: TSTypeParameterInstantiation | undefined;
1033
- typeName: EntityName;
1034
- }
1035
- interface TSUndefinedKeyword extends AcornTSNode<TSESTree.TSUndefinedKeyword> {}
1036
- interface TSUnionType extends Omit<AcornTSNode<TSESTree.TSUnionType>, 'types'> {
1037
- types: TypeNode[];
1038
- }
1039
- // TSInterfaceHeritage doesn't exist in acorn-typescript which uses TSExpressionWithTypeArguments
1040
- interface TSInterfaceHeritage extends Omit<
1041
- AcornTSNode<TSESTree.TSInterfaceHeritage>,
1042
- 'expression' | 'typeParameters'
1043
- > {
1044
- expression: AST.Expression;
1045
- // acorn-typescript uses typeParameters instead of typeArguments
1046
- typeParameters: TSTypeParameterInstantiation | undefined;
1047
- }
1048
- // Extends TSInterfaceHeritage as it's the semantically the same as used by acorn-typescript
1049
- interface TSExpressionWithTypeArguments extends Omit<TSInterfaceHeritage, 'type'> {
1050
- type: 'TSExpressionWithTypeArguments';
1051
- }
1052
-
1053
- interface TSClassImplements extends AcornTSNode<TSESTree.TSClassImplements> {}
1054
- interface TSUnknownKeyword extends AcornTSNode<TSESTree.TSUnknownKeyword> {}
1055
- interface TSVoidKeyword extends AcornTSNode<TSESTree.TSVoidKeyword> {}
1056
- interface NumberLiteral extends AcornTSNode<TSESTree.NumberLiteral> {}
1057
- interface StringLiteral extends AcornTSNode<TSESTree.StringLiteral> {}
1058
-
1059
- // acorn-typescript specific nodes (not in @typescript-eslint/types)
1060
- interface TSParenthesizedType extends AST.BaseNode {
1061
- type: 'TSParenthesizedType';
1062
- }
1063
-
1064
- // Extend ExpressionMap for TypeScript expressions
1065
- interface ExpressionMap {
1066
- TSAsExpression: TSAsExpression;
1067
- TSInstantiationExpression: TSInstantiationExpression;
1068
- TSNonNullExpression: TSNonNullExpression;
1069
- TSSatisfiesExpression: TSSatisfiesExpression;
1070
- TSTypeAssertion: TSTypeAssertion;
1071
- }
1072
- }
1073
-
1074
- /**
1075
- * Parse error information
1076
- */
1077
- export interface ParseError {
1078
- message: string;
1079
- pos: number;
1080
- loc: Position;
1081
- }
1082
-
1083
- /**
1084
- * Result of parsing operation
1085
- */
1086
- export interface ParseResult {
1087
- ast: AST.Program;
1088
- errors: ParseError[];
1089
- }
1090
-
1091
- export interface AnalysisResult {
1092
- ast: AST.Program;
1093
- scopes: Map<AST.Node, ScopeInterface>;
1094
- scope: ScopeInterface;
1095
- component_metadata: Array<{ id: string }>;
1096
- metadata: {
1097
- serverIdentifierPresent: boolean;
1098
- };
1099
- errors: RippleCompileError[];
1100
- comments: AST.CommentWithLocation[];
1101
- }
1102
-
1103
- /**
1104
- * Configuration for Ripple parser plugin
1105
- */
1106
- export interface RipplePluginConfig {
1107
- allowSatisfies?: boolean;
1108
- }
1109
-
1110
- /**
1111
- * Types of declarations in scope
1112
- */
1113
- export type DeclarationKind =
1114
- | 'var'
1115
- | 'let'
1116
- | 'const'
1117
- | 'function'
1118
- | 'param'
1119
- | 'rest_param'
1120
- | 'component'
1121
- | 'import'
1122
- | 'using'
1123
- | 'await using';
1124
-
1125
- /**
1126
- * Binding kinds
1127
- */
1128
- export type BindingKind =
1129
- | 'normal'
1130
- | 'for_pattern'
1131
- | 'rest_prop'
1132
- | 'prop'
1133
- | 'prop_fallback'
1134
- | 'lazy'
1135
- | 'lazy_fallback'
1136
- | 'index';
1137
-
1138
- /**
1139
- * A variable binding in a scope
1140
- */
1141
- export interface Binding {
1142
- /** The identifier node that declares this binding */
1143
- node: AST.Identifier;
1144
- /** References to this binding */
1145
- references: Array<{ node: AST.Identifier; path: AST.Node[] }>;
1146
- /** Initial value/declaration */
1147
- initial:
1148
- | null
1149
- | AST.Expression
1150
- | AST.FunctionDeclaration
1151
- | AST.ClassDeclaration
1152
- | AST.ImportDeclaration;
1153
- /** Whether this binding has been reassigned */
1154
- reassigned: boolean;
1155
- /** Whether this binding has been mutated (property access) */
1156
- mutated: boolean;
1157
- /** Whether this binding has been updated (reassigned or mutated) */
1158
- updated: boolean;
1159
- /** Whether this binding represents a called function */
1160
- is_called: boolean;
1161
- /** Additional metadata for this binding */
1162
- metadata: {
1163
- is_dynamic_component?: boolean;
1164
- pattern?: AST.Identifier;
1165
- is_ripple_object?: boolean;
1166
- } | null;
1167
- /** Kind of binding */
1168
- kind: BindingKind;
1169
- /** Declaration kind */
1170
- declaration_kind?: DeclarationKind;
1171
- /** The scope that contains this binding */
1172
- scope: ScopeInterface;
1173
- /** Transform functions for reading, assigning, and updating this binding */
1174
- transform?: {
1175
- read: (node?: AST.Identifier) => AST.Expression;
1176
- assign?: (node: AST.Identifier, value: AST.Expression) => AST.Expression;
1177
- update?: (node: AST.UpdateExpression) => AST.Expression;
1178
- };
1179
- /** Whether the read transform already produces an unwrapped value (calls get() internally) */
1180
- read_unwraps?: boolean;
1181
- }
1182
-
1183
- /**
1184
- * Root scope manager
1185
- */
1186
- export interface ScopeRoot {
1187
- /** Set of conflicting/reserved names */
1188
- conflicts: Set<string>;
1189
- /** Generate unique identifier name */
1190
- unique(preferred_name: string): AST.Identifier;
1191
- }
1192
-
1193
- export interface ScopeConstructorInterface {
1194
- root: ScopeRoot;
1195
- parent: ScopeInterface | null;
1196
- porous: boolean;
1197
- error_options: {
1198
- loose: boolean;
1199
- errors: RippleCompileError[];
1200
- filename: string;
1201
- comments?: AST.CommentWithLocation[];
1202
- };
1203
- }
1204
-
1205
- export type ScopeConstructorParameters = [
1206
- root: ScopeConstructorInterface['root'],
1207
- parent: ScopeConstructorInterface['parent'],
1208
- porous: ScopeConstructorInterface['porous'],
1209
- error_options: ScopeConstructorInterface['error_options'],
1210
- ];
1211
-
1212
- /**
1213
- * Lexical scope for variable bindings
1214
- */
1215
- export interface ScopeInterface {
1216
- /** Root scope manager */
1217
- root: ScopeRoot;
1218
- /** Parent scope */
1219
- parent: ScopeInterface | null;
1220
- /** Map of declared bindings */
1221
- declarations: Map<string, Binding>;
1222
- /** Map of declarators to their bindings */
1223
- declarators: Map<AST.VariableDeclarator, Binding[]>;
1224
- /** Map of references in this scope */
1225
- references: Map<string, Array<{ node: AST.Identifier; path: AST.Node[] }>>;
1226
- /** Function nesting depth */
1227
- function_depth: number;
1228
- /** Whether reactive tracing is enabled */
1229
- tracing: null | AST.Expression;
1230
- server_block?: boolean;
1231
-
1232
- /** Create child scope */
1233
- child(porous?: boolean): ScopeInterface;
1234
- /** Declare a binding */
1235
- declare(
1236
- node: AST.Identifier,
1237
- kind: BindingKind,
1238
- declaration_kind: DeclarationKind,
1239
- initial?:
1240
- | null
1241
- | AST.Expression
1242
- | AST.FunctionDeclaration
1243
- | AST.ClassDeclaration
1244
- | AST.ImportDeclaration,
1245
- ): Binding;
1246
- /** Get binding by name */
1247
- get(name: string): Binding | null;
1248
- /** Get bindings for a declarator */
1249
- get_bindings(node: AST.VariableDeclarator): Binding[];
1250
- /** Find the scope that owns a name */
1251
- owner(name: string): ScopeInterface | null;
1252
- /** Add a reference */
1253
- reference(node: AST.Identifier, path: AST.Node[]): void;
1254
- /** Generate unique identifier name */
1255
- generate(preferred_name: string): string;
1256
- }
1257
-
1258
- /**
1259
- * Compiler state object
1260
- */
1261
-
1262
- interface BaseStateMetaData {
1263
- tracking?: boolean | null;
1264
- }
1265
-
1266
- export interface BaseState {
1267
- /** For utils */
1268
- scope: ScopeInterface;
1269
- scopes: Map<AST.Node | AST.Node[], ScopeInterface>;
1270
- serverIdentifierPresent: boolean;
1271
- ancestor_server_block: AST.ServerBlock | undefined;
1272
- inside_head?: boolean;
1273
- keep_component_style?: boolean;
1274
-
1275
- /** Common For All */
1276
- to_ts: boolean;
1277
- component?: AST.Component;
1278
- }
1279
-
1280
- export interface AnalysisState extends BaseState {
1281
- analysis: AnalysisResult & {
1282
- module: {
1283
- ast: AnalysisResult['ast'];
1284
- scope: AnalysisResult['scope'];
1285
- scopes: AnalysisResult['scopes'];
1286
- filename: string;
1287
- };
1288
- };
1289
- elements?: AST.Element[];
1290
- function_depth?: number;
1291
- loose?: boolean;
1292
- configured_compat_kinds?: Set<string>;
1293
- metadata: BaseStateMetaData & {
1294
- styleClasses?: StyleClasses;
1295
- };
1296
- mode: CompileOptions['mode'];
1297
- }
1298
-
1299
- export interface TransformServerState extends BaseState {
1300
- imports: Set<string | AST.ImportDeclaration>;
1301
- init: Array<AST.Statement> | null;
1302
- stylesheets: AST.CSS.StyleSheet[];
1303
- component_metadata: AnalysisResult['component_metadata'];
1304
- filename: string;
1305
- metadata: BaseStateMetaData;
1306
- namespace: NameSpace;
1307
- server_block_locals: AST.VariableDeclaration[];
1308
- server_exported_names: string[];
1309
- dynamicElementName?: AST.TemplateLiteral;
1310
- applyParentCssScope?: AST.CSS.StyleSheet['hash'];
1311
- dev?: boolean;
1312
- return_flags?: Map<AST.ReturnStatement, { name: string; tracked: boolean }>;
1313
- template_child?: boolean;
1314
- skip_regular_blocks?: boolean;
1315
- in_regular_block?: boolean;
1316
- }
1317
-
1318
- type UpdateList = Array<
1319
- RequireAllOrNone<
1320
- {
1321
- identity?: AST.Identifier | AST.Expression;
1322
- initial?: AST.Expression;
1323
- operation: (expr?: AST.Expression, prev?: AST.Expression) => AST.ExpressionStatement;
1324
- expression?: AST.Expression;
1325
- needsPrevTracking?: boolean;
1326
- },
1327
- 'initial' | 'identity' | 'expression'
1328
- >
1329
- >;
1330
-
1331
- export interface TransformClientState extends BaseState {
1332
- events: Set<string>;
1333
- filename: string;
1334
- final: Array<AST.Statement> | null;
1335
- flush_node: ((is_text?: boolean, is_controlled?: boolean) => AST.Identifier) | null;
1336
- hoisted: Array<AST.Statement>;
1337
- imports: Set<string | AST.ImportDeclaration>;
1338
- server_block_locals: AST.VariableDeclaration[];
1339
- init: Array<AST.Statement> | null;
1340
- metadata: BaseStateMetaData;
1341
- namespace: NameSpace;
1342
- stylesheets: Array<AST.CSS.StyleSheet>;
1343
- template: Array<string | AST.Expression> | null;
1344
- update: UpdateList | null;
1345
- errors: RippleCompileError[];
1346
- applyParentCssScope?: AST.CSS.StyleSheet['hash'];
1347
- skip_children_traversal: boolean;
1348
- return_flags?: Map<AST.ReturnStatement, { name: string; tracked: boolean }>;
1349
- is_ripple_element?: boolean;
1350
- }
1351
-
1352
- /** Override zimmerframe types and provide our own */
1353
- type NodeOf<T extends string, X> = X extends { type: T } ? X : never;
1354
-
1355
- type SpecializedVisitors<T extends AST.Node | AST.CSS.Node, U> = {
1356
- [K in T['type']]?: Visitor<NodeOf<K, T>, U, T>;
1357
- };
1358
-
1359
- type VisitFn<V> = (node: V) => void;
1360
-
1361
- export type CatchAllVisitor<T, U, V> = (
1362
- node: T,
1363
- context: Context<V, U>,
1364
- visit: VisitFn<V>,
1365
- ) => V | void;
1366
-
1367
- export type Visitor<T, U, V> = (node: T, context: Context<V, U>) => V | void;
1368
-
1369
- export type Visitors<T extends AST.Node | AST.CSS.Node, U> = T['type'] extends '_'
1370
- ? never
1371
- : SpecializedVisitors<T, U> & {
1372
- _?: CatchAllVisitor<T, U, T>;
1373
- };
1374
-
1375
- export interface Context<T, U> extends Omit<
1376
- ESRap.Context,
1377
- 'path' | 'state' | 'visit' | 'next' | 'stop'
1378
- > {
1379
- next: (state?: U) => T | void;
1380
- path: T[];
1381
- state: U;
1382
- stop: () => void;
1383
- visit: (node: T, state?: U) => T;
1384
- }
1385
-
1386
- /**
1387
- * Transform context object
1388
- */
1389
- export type TransformClientContext = Context<AST.Node, TransformClientState>;
1390
- export type TransformServerContext = Context<AST.Node, TransformServerState>;
1391
- export type AnalysisContext = Context<AST.Node, AnalysisState>;
1392
- export type CommonContext = TransformClientContext | TransformServerContext | AnalysisContext;
1393
- export type VisitorClientContext = TransformClientContext & { root?: boolean };
1394
-
1395
- /**
1396
- * Delegated event result
1397
- */
1398
- export interface DelegatedEventResult {
1399
- function?: AST.FunctionExpression | AST.FunctionDeclaration | AST.ArrowFunctionExpression;
1400
- }
1401
-
1402
- export type TopScopedClasses = Map<
1403
- string,
1404
- {
1405
- start: number;
1406
- end: number;
1407
- selector: AST.CSS.ClassSelector;
1408
- }
1409
- >;
1410
-
1411
- export type StyleClasses = Map<string, AST.MemberExpression['property']>;