ripple 0.2.182 → 0.2.184
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -2
- package/src/compiler/errors.js +3 -1
- package/src/compiler/index.d.ts +2 -1
- package/src/compiler/phases/1-parse/index.js +525 -311
- package/src/compiler/phases/1-parse/style.js +3 -1
- package/src/compiler/phases/2-analyze/css-analyze.js +116 -97
- package/src/compiler/phases/2-analyze/index.js +81 -51
- package/src/compiler/phases/2-analyze/prune.js +200 -58
- package/src/compiler/phases/2-analyze/validation.js +9 -7
- package/src/compiler/phases/3-transform/client/index.js +871 -394
- package/src/compiler/phases/3-transform/segments.js +99 -53
- package/src/compiler/phases/3-transform/server/index.js +278 -121
- package/src/compiler/scope.js +51 -104
- package/src/compiler/types/index.d.ts +834 -197
- package/src/compiler/types/parse.d.ts +1668 -0
- package/src/compiler/utils.js +62 -74
- package/src/utils/ast.js +247 -192
- package/src/utils/builders.js +309 -247
- package/src/utils/sanitize_template_string.js +2 -2
|
@@ -1,30 +1,319 @@
|
|
|
1
|
-
import type * as
|
|
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
|
+
|
|
7
|
+
export type RpcModules = Map<string, [string, string]>;
|
|
8
|
+
|
|
9
|
+
declare global {
|
|
10
|
+
var rpc_modules: RpcModules | undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type NameSpace = keyof typeof NAMESPACE_URI;
|
|
14
|
+
interface BaseNodeMetaData {
|
|
15
|
+
scoped?: boolean;
|
|
16
|
+
path: AST.Node[];
|
|
17
|
+
has_template?: boolean;
|
|
18
|
+
original_name?: string;
|
|
19
|
+
is_capitalized?: boolean;
|
|
20
|
+
has_await?: boolean;
|
|
21
|
+
commentContainerId?: number;
|
|
22
|
+
openingTagEnd?: number;
|
|
23
|
+
openingTagEndLoc?: AST.Position;
|
|
24
|
+
parenthesized?: boolean;
|
|
25
|
+
elementLeadingComments?: AST.Comment[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface FunctionMetaData extends BaseNodeMetaData {
|
|
29
|
+
was_component?: boolean;
|
|
30
|
+
tracked?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Strip parent, loc, and range from TSESTree nodes to match @sveltejs/acorn-typescript output
|
|
34
|
+
// acorn-typescript uses start/end instead of range, and loc is optional
|
|
35
|
+
type AcornTSNode<T> = Omit<T, 'parent' | 'loc' | 'range' | 'expression'> & {
|
|
36
|
+
start: number;
|
|
37
|
+
end: number;
|
|
38
|
+
loc?: AST.SourceLocation;
|
|
39
|
+
range?: AST.BaseNode['range'];
|
|
40
|
+
metadata: BaseNodeMetaData;
|
|
41
|
+
|
|
42
|
+
leadingComments?: AST.Comment[] | undefined;
|
|
43
|
+
trailingComments?: AST.Comment[] | undefined;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
interface FunctionLikeTS {
|
|
47
|
+
returnType?: AST.TSTypeAnnotation;
|
|
48
|
+
typeParameters?: AST.TSTypeParameterDeclaration;
|
|
49
|
+
typeAnnotation?: AST.TSTypeAnnotation;
|
|
50
|
+
}
|
|
2
51
|
|
|
3
52
|
// Ripple augmentation for ESTree function nodes
|
|
4
53
|
declare module 'estree' {
|
|
5
|
-
interface FunctionDeclaration {
|
|
6
|
-
metadata
|
|
54
|
+
interface FunctionDeclaration extends FunctionLikeTS {
|
|
55
|
+
metadata: FunctionMetaData;
|
|
7
56
|
}
|
|
8
|
-
interface FunctionExpression {
|
|
9
|
-
metadata
|
|
57
|
+
interface FunctionExpression extends FunctionLikeTS {
|
|
58
|
+
metadata: FunctionMetaData;
|
|
10
59
|
}
|
|
11
|
-
interface ArrowFunctionExpression {
|
|
12
|
-
metadata
|
|
60
|
+
interface ArrowFunctionExpression extends FunctionLikeTS {
|
|
61
|
+
metadata: FunctionMetaData;
|
|
13
62
|
}
|
|
14
|
-
|
|
63
|
+
|
|
64
|
+
interface Identifier extends TrackedNode {
|
|
65
|
+
metadata: BaseNode['metadata'] & {
|
|
66
|
+
tracked_shorthand?: '#Map' | '#Set';
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface MemberExpression extends TrackedNode {}
|
|
71
|
+
|
|
72
|
+
interface TrackedNode {
|
|
15
73
|
tracked?: boolean;
|
|
16
74
|
}
|
|
17
|
-
|
|
75
|
+
|
|
76
|
+
// Include TypeScript node types and Ripple-specific nodes in NodeMap
|
|
77
|
+
interface NodeMap {
|
|
78
|
+
Component: Component;
|
|
79
|
+
TsxCompat: TsxCompat;
|
|
80
|
+
Html: Html;
|
|
81
|
+
Element: Element;
|
|
82
|
+
Text: TextNode;
|
|
83
|
+
ServerBlock: ServerBlock;
|
|
84
|
+
ServerIdentifier: ServerIdentifier;
|
|
85
|
+
TrackedExpression: TrackedExpression;
|
|
86
|
+
Attribute: Attribute;
|
|
87
|
+
RefAttribute: RefAttribute;
|
|
88
|
+
SpreadAttribute: SpreadAttribute;
|
|
89
|
+
ParenthesizedExpression: ParenthesizedExpression;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface ExpressionMap {
|
|
93
|
+
TrackedArrayExpression: TrackedArrayExpression;
|
|
94
|
+
TrackedObjectExpression: TrackedObjectExpression;
|
|
95
|
+
TrackedMapExpression: TrackedMapExpression;
|
|
96
|
+
TrackedSetExpression: TrackedSetExpression;
|
|
97
|
+
TrackedExpression: TrackedExpression;
|
|
98
|
+
Text: TextNode;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Missing estree type
|
|
102
|
+
interface ParenthesizedExpression extends BaseNode {
|
|
103
|
+
type: 'ParenthesizedExpression';
|
|
104
|
+
expression: Expression;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface Comment {
|
|
108
|
+
context?: Parse.CommentMetaData | null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Custom Comment interface with location information
|
|
113
|
+
*/
|
|
114
|
+
type CommentWithLocation = Comment & NodeWithLocation;
|
|
115
|
+
|
|
116
|
+
interface TryStatement {
|
|
117
|
+
pending?: BlockStatement | null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface ForOfStatement {
|
|
121
|
+
index?: Identifier | null;
|
|
122
|
+
key?: Expression | null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface ServerIdentifier extends BaseNode {
|
|
126
|
+
type: 'ServerIdentifier';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface ImportDeclaration {
|
|
130
|
+
importKind: TSESTree.ImportDeclaration['importKind'];
|
|
131
|
+
}
|
|
132
|
+
interface ImportSpecifier {
|
|
133
|
+
importKind: TSESTree.ImportSpecifier['importKind'];
|
|
134
|
+
}
|
|
135
|
+
interface ExportNamedDeclaration {
|
|
136
|
+
exportKind: TSESTree.ExportNamedDeclaration['exportKind'];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface BaseNodeWithoutComments {
|
|
140
|
+
// Adding start, end for now as always there
|
|
141
|
+
// later might change to optional
|
|
142
|
+
// And only define on certain nodes
|
|
143
|
+
// BaseNode inherits from this interface
|
|
144
|
+
start?: number;
|
|
145
|
+
end?: number;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
interface BaseNode {
|
|
149
|
+
is_controlled?: boolean;
|
|
150
|
+
// This is for Pattern but it's a type alias
|
|
151
|
+
// So it's just easy to extend BaseNode even though
|
|
152
|
+
// typeAnnotation, typeArguments do not apply to all nodes
|
|
153
|
+
typeAnnotation?: TSTypeAnnotation;
|
|
154
|
+
typeArguments?: TSTypeParameterInstantiation;
|
|
155
|
+
|
|
156
|
+
// even though technically metadata starts out as undefined
|
|
157
|
+
// metadata is always populated by the `_` visitor
|
|
158
|
+
// which runs for every node before other visitors
|
|
159
|
+
// so taking a practical approach and making it required
|
|
160
|
+
// to avoid lots of typecasting or checking for undefined
|
|
161
|
+
metadata: BaseNodeMetaData;
|
|
162
|
+
|
|
163
|
+
comments?: AST.Comment[];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface NodeWithLocation {
|
|
167
|
+
start: number;
|
|
168
|
+
end: number;
|
|
169
|
+
loc: SourceLocation;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Ripple custom interfaces and types section
|
|
174
|
+
*/
|
|
175
|
+
interface Component extends BaseNode {
|
|
18
176
|
type: 'Component';
|
|
19
|
-
|
|
177
|
+
// null is for anonymous components {component: () => {}}
|
|
178
|
+
id: Identifier | null;
|
|
20
179
|
params: Pattern[];
|
|
180
|
+
body: Node[];
|
|
181
|
+
css: CSS.StyleSheet | null;
|
|
182
|
+
metadata: BaseNodeMetaData & {
|
|
183
|
+
inherited_css?: boolean;
|
|
184
|
+
};
|
|
185
|
+
default: boolean;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
interface TsxCompat extends BaseNode {
|
|
189
|
+
type: 'TsxCompat';
|
|
190
|
+
kind: string;
|
|
191
|
+
attributes: Array<any>;
|
|
192
|
+
children: ESTreeJSX.JSXElement['children'];
|
|
193
|
+
selfClosing?: boolean;
|
|
194
|
+
unclosed?: boolean;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
interface Html extends BaseNode {
|
|
198
|
+
type: 'Html';
|
|
199
|
+
expression: Expression;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
interface Element extends BaseNode {
|
|
203
|
+
type: 'Element';
|
|
204
|
+
id: Identifier;
|
|
205
|
+
attributes: RippleAttribute[];
|
|
206
|
+
children: Node[];
|
|
207
|
+
selfClosing?: boolean;
|
|
208
|
+
unclosed?: boolean;
|
|
209
|
+
loc: AST.SourceLocation;
|
|
210
|
+
metadata: BaseNodeMetaData & {
|
|
211
|
+
ts_name?: string;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// currently only for <style> and <script> tags
|
|
215
|
+
openingElement?: ESTreeJSX.JSXOpeningElement;
|
|
216
|
+
closingElement?: ESTreeJSX.JSXClosingElement;
|
|
217
|
+
|
|
218
|
+
// for <style> tags
|
|
219
|
+
css?: string;
|
|
220
|
+
|
|
221
|
+
// for <script> tags
|
|
222
|
+
content?: string;
|
|
223
|
+
|
|
224
|
+
innerComments?: Comment[];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface TextNode extends AST.BaseNode {
|
|
228
|
+
type: 'Text';
|
|
229
|
+
expression: Expression;
|
|
230
|
+
loc?: SourceLocation;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
interface ServerBlock extends BaseNode {
|
|
234
|
+
type: 'ServerBlock';
|
|
21
235
|
body: BlockStatement;
|
|
236
|
+
metadata: BaseNodeMetaData & {
|
|
237
|
+
exports: string[];
|
|
238
|
+
};
|
|
22
239
|
}
|
|
23
240
|
|
|
24
|
-
|
|
25
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Tracked Expressions
|
|
243
|
+
*/
|
|
244
|
+
interface TrackedArrayExpression extends Omit<ArrayExpression, 'type'> {
|
|
245
|
+
type: 'TrackedArrayExpression';
|
|
246
|
+
elements: (Expression | SpreadElement | null)[];
|
|
26
247
|
}
|
|
27
248
|
|
|
249
|
+
interface TrackedExpression extends BaseNode {
|
|
250
|
+
argument: Expression;
|
|
251
|
+
type: 'TrackedExpression';
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
interface TrackedObjectExpression extends Omit<ObjectExpression, 'type'> {
|
|
255
|
+
type: 'TrackedObjectExpression';
|
|
256
|
+
properties: (Property | SpreadElement)[];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
interface TrackedMapExpression extends BaseNode {
|
|
260
|
+
type: 'TrackedMapExpression';
|
|
261
|
+
arguments: (Expression | SpreadElement)[];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
interface TrackedSetExpression extends BaseNode {
|
|
265
|
+
type: 'TrackedSetExpression';
|
|
266
|
+
arguments: (Expression | SpreadElement)[];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Ripple attribute nodes
|
|
271
|
+
*/
|
|
272
|
+
interface Attribute extends BaseNode {
|
|
273
|
+
type: 'Attribute';
|
|
274
|
+
name: Identifier;
|
|
275
|
+
value: Expression | null;
|
|
276
|
+
loc?: SourceLocation;
|
|
277
|
+
shorthand?: boolean;
|
|
278
|
+
metadata: BaseNodeMetaData & {
|
|
279
|
+
delegated?: boolean;
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
interface RefAttribute extends BaseNode {
|
|
284
|
+
type: 'RefAttribute';
|
|
285
|
+
argument: Expression;
|
|
286
|
+
loc?: SourceLocation;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
interface SpreadAttribute extends BaseNode {
|
|
290
|
+
type: 'SpreadAttribute';
|
|
291
|
+
argument: Expression;
|
|
292
|
+
loc?: SourceLocation;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Ripple's extended Declaration type that includes Component
|
|
297
|
+
* Use this instead of AST.Declaration when you need Component support
|
|
298
|
+
*/
|
|
299
|
+
export type RippleDeclaration = AST.Declaration | AST.Component | AST.TSDeclareFunction;
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Ripple's extended ExportNamedDeclaration with Component support
|
|
303
|
+
*/
|
|
304
|
+
interface RippleExportNamedDeclaration extends Omit<AST.ExportNamedDeclaration, 'declaration'> {
|
|
305
|
+
declaration?: RippleDeclaration | null | undefined;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Ripple's extended Program with Component support
|
|
310
|
+
*/
|
|
311
|
+
interface RippleProgram extends Omit<AST.Program, 'body'> {
|
|
312
|
+
body: (AST.Program['body'][number] | Component)[];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export type RippleAttribute = Attribute | SpreadAttribute | RefAttribute;
|
|
316
|
+
|
|
28
317
|
export namespace CSS {
|
|
29
318
|
export interface BaseNode {
|
|
30
319
|
start: number;
|
|
@@ -79,6 +368,7 @@ declare module 'estree' {
|
|
|
79
368
|
metadata: {
|
|
80
369
|
rule: Rule | null;
|
|
81
370
|
used: boolean;
|
|
371
|
+
is_global?: boolean;
|
|
82
372
|
};
|
|
83
373
|
}
|
|
84
374
|
|
|
@@ -199,154 +489,432 @@ declare module 'estree-jsx' {
|
|
|
199
489
|
shorthand: boolean;
|
|
200
490
|
}
|
|
201
491
|
|
|
202
|
-
interface
|
|
203
|
-
loc:
|
|
492
|
+
interface JSXEmptyExpression {
|
|
493
|
+
loc: AST.SourceLocation;
|
|
494
|
+
innerComments?: Comment[];
|
|
204
495
|
}
|
|
205
496
|
|
|
206
|
-
interface
|
|
207
|
-
|
|
497
|
+
interface JSXOpeningFragment {
|
|
498
|
+
attributes: Array<JSXAttribute | JSXSpreadAttribute>;
|
|
208
499
|
}
|
|
209
|
-
}
|
|
210
500
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
VariableDeclarator,
|
|
217
|
-
FunctionDeclaration,
|
|
218
|
-
FunctionExpression,
|
|
219
|
-
ArrowFunctionExpression,
|
|
220
|
-
ClassDeclaration,
|
|
221
|
-
ImportDeclaration,
|
|
222
|
-
ArrayExpression,
|
|
223
|
-
ObjectExpression,
|
|
224
|
-
Expression,
|
|
225
|
-
Property,
|
|
226
|
-
SpreadElement,
|
|
227
|
-
Pattern,
|
|
228
|
-
} from 'estree';
|
|
501
|
+
interface JSXElement {
|
|
502
|
+
metadata: BaseNodeMetaData & {
|
|
503
|
+
ts_name?: string;
|
|
504
|
+
};
|
|
505
|
+
}
|
|
229
506
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
export interface ParseError {
|
|
234
|
-
message: string;
|
|
235
|
-
pos: number;
|
|
236
|
-
loc: Position;
|
|
237
|
-
}
|
|
507
|
+
interface JSXExpressionContainer {
|
|
508
|
+
html?: boolean;
|
|
509
|
+
}
|
|
238
510
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
export interface ParseResult {
|
|
243
|
-
ast: Program;
|
|
244
|
-
errors: ParseError[];
|
|
245
|
-
}
|
|
511
|
+
interface JSXMemberExpression {
|
|
512
|
+
computed?: boolean;
|
|
513
|
+
}
|
|
246
514
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
export interface CommentWithLocation extends Comment {
|
|
251
|
-
start: number;
|
|
252
|
-
end: number;
|
|
515
|
+
interface ExpressionMap {
|
|
516
|
+
JSXIdentifier: JSXIdentifier;
|
|
517
|
+
}
|
|
253
518
|
}
|
|
254
519
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
520
|
+
declare module 'estree' {
|
|
521
|
+
// Helper map for creating our own TypeNode
|
|
522
|
+
// and to be used to extend estree's NodeMap
|
|
523
|
+
interface TSNodeMap {
|
|
524
|
+
// TypeScript nodes
|
|
525
|
+
TSAnyKeyword: TSAnyKeyword;
|
|
526
|
+
TSArrayType: TSArrayType;
|
|
527
|
+
TSAsExpression: TSAsExpression;
|
|
528
|
+
TSBigIntKeyword: TSBigIntKeyword;
|
|
529
|
+
TSBooleanKeyword: TSBooleanKeyword;
|
|
530
|
+
TSCallSignatureDeclaration: TSCallSignatureDeclaration;
|
|
531
|
+
TSConditionalType: TSConditionalType;
|
|
532
|
+
TSConstructorType: TSConstructorType;
|
|
533
|
+
TSConstructSignatureDeclaration: TSConstructSignatureDeclaration;
|
|
534
|
+
TSDeclareFunction: TSDeclareFunction;
|
|
535
|
+
TSEnumDeclaration: TSEnumDeclaration;
|
|
536
|
+
TSEnumMember: TSEnumMember;
|
|
537
|
+
TSExportAssignment: TSExportAssignment;
|
|
538
|
+
TSExternalModuleReference: TSExternalModuleReference;
|
|
539
|
+
TSFunctionType: TSFunctionType;
|
|
540
|
+
TSImportEqualsDeclaration: TSImportEqualsDeclaration;
|
|
541
|
+
TSImportType: TSImportType;
|
|
542
|
+
TSIndexedAccessType: TSIndexedAccessType;
|
|
543
|
+
TSIndexSignature: TSIndexSignature;
|
|
544
|
+
TSInferType: TSInferType;
|
|
545
|
+
TSInstantiationExpression: TSInstantiationExpression;
|
|
546
|
+
TSInterfaceBody: TSInterfaceBody;
|
|
547
|
+
TSInterfaceDeclaration: TSInterfaceDeclaration;
|
|
548
|
+
TSIntersectionType: TSIntersectionType;
|
|
549
|
+
TSIntrinsicKeyword: TSIntrinsicKeyword;
|
|
550
|
+
TSLiteralType: TSLiteralType;
|
|
551
|
+
TSMappedType: TSMappedType;
|
|
552
|
+
TSMethodSignature: TSMethodSignature;
|
|
553
|
+
TSModuleBlock: TSModuleBlock;
|
|
554
|
+
TSModuleDeclaration: TSModuleDeclaration;
|
|
555
|
+
TSNamedTupleMember: TSNamedTupleMember;
|
|
556
|
+
TSNamespaceExportDeclaration: TSNamespaceExportDeclaration;
|
|
557
|
+
TSNeverKeyword: TSNeverKeyword;
|
|
558
|
+
TSNonNullExpression: TSNonNullExpression;
|
|
559
|
+
TSNullKeyword: TSNullKeyword;
|
|
560
|
+
TSNumberKeyword: TSNumberKeyword;
|
|
561
|
+
TSObjectKeyword: TSObjectKeyword;
|
|
562
|
+
TSOptionalType: TSOptionalType;
|
|
563
|
+
TSParameterProperty: TSParameterProperty;
|
|
564
|
+
TSPropertySignature: TSPropertySignature;
|
|
565
|
+
TSQualifiedName: TSQualifiedName;
|
|
566
|
+
TSRestType: TSRestType;
|
|
567
|
+
TSSatisfiesExpression: TSSatisfiesExpression;
|
|
568
|
+
TSStringKeyword: TSStringKeyword;
|
|
569
|
+
TSSymbolKeyword: TSSymbolKeyword;
|
|
570
|
+
TSThisType: TSThisType;
|
|
571
|
+
TSTupleType: TSTupleType;
|
|
572
|
+
TSTypeAliasDeclaration: TSTypeAliasDeclaration;
|
|
573
|
+
TSTypeAnnotation: TSTypeAnnotation;
|
|
574
|
+
TSTypeAssertion: TSTypeAssertion;
|
|
575
|
+
TSTypeLiteral: TSTypeLiteral;
|
|
576
|
+
TSTypeOperator: TSTypeOperator;
|
|
577
|
+
TSTypeParameter: TSTypeParameter;
|
|
578
|
+
TSTypeParameterDeclaration: TSTypeParameterDeclaration;
|
|
579
|
+
TSTypeParameterInstantiation: TSTypeParameterInstantiation;
|
|
580
|
+
TSTypePredicate: TSTypePredicate;
|
|
581
|
+
TSTypeQuery: TSTypeQuery;
|
|
582
|
+
TSTypeReference: TSTypeReference;
|
|
583
|
+
TSUndefinedKeyword: TSUndefinedKeyword;
|
|
584
|
+
TSUnionType: TSUnionType;
|
|
585
|
+
TSUnknownKeyword: TSUnknownKeyword;
|
|
586
|
+
TSVoidKeyword: TSVoidKeyword;
|
|
587
|
+
TSParenthesizedType: TSParenthesizedType;
|
|
588
|
+
TSExpressionWithTypeArguments: TSExpressionWithTypeArguments;
|
|
589
|
+
}
|
|
262
590
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
type: 'TrackedExpression';
|
|
266
|
-
}
|
|
591
|
+
// Extend NodeMap to include TypeScript nodes
|
|
592
|
+
interface NodeMap extends TSNodeMap {}
|
|
267
593
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
594
|
+
// Create our version of TypeNode with modified types to be used in replacements
|
|
595
|
+
type TypeNode = TSNodeMap[keyof TSNodeMap];
|
|
596
|
+
type EntityName = AST.Identifier | AST.ThisExpression | TSQualifiedName;
|
|
597
|
+
type Parameter =
|
|
598
|
+
| ArrayPattern
|
|
599
|
+
| AssignmentPattern
|
|
600
|
+
| Identifier
|
|
601
|
+
| ObjectPattern
|
|
602
|
+
| RestElement
|
|
603
|
+
| TSParameterProperty;
|
|
604
|
+
type TypeElement =
|
|
605
|
+
| TSCallSignatureDeclaration
|
|
606
|
+
| TSConstructSignatureDeclaration
|
|
607
|
+
| TSIndexSignature
|
|
608
|
+
| TSMethodSignature
|
|
609
|
+
| TSPropertySignature;
|
|
610
|
+
type TSPropertySignature = TSPropertySignatureComputedName | TSPropertySignatureNonComputedName;
|
|
611
|
+
type PropertyNameComputed = Expression;
|
|
612
|
+
type PropertyNameNonComputed = Identifier | NumberLiteral | StringLiteral;
|
|
275
613
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
614
|
+
// TypeScript AST node interfaces from @sveltejs/acorn-typescript
|
|
615
|
+
// Based on TSESTree types but adapted for acorn's output format
|
|
616
|
+
interface TSAnyKeyword extends AcornTSNode<TSESTree.TSAnyKeyword> {}
|
|
617
|
+
interface TSArrayType extends Omit<AcornTSNode<TSESTree.TSArrayType>, 'elementType'> {
|
|
618
|
+
elementType: TypeNode;
|
|
619
|
+
}
|
|
620
|
+
interface TSAsExpression extends AcornTSNode<TSESTree.TSAsExpression> {
|
|
621
|
+
// Have to override it to use our Expression for required properties like metadata
|
|
622
|
+
expression: AST.Expression;
|
|
623
|
+
}
|
|
624
|
+
interface TSBigIntKeyword extends AcornTSNode<TSESTree.TSBigIntKeyword> {}
|
|
625
|
+
interface TSBooleanKeyword extends AcornTSNode<TSESTree.TSBooleanKeyword> {}
|
|
626
|
+
interface TSCallSignatureDeclaration
|
|
627
|
+
extends Omit<
|
|
628
|
+
AcornTSNode<TSESTree.TSCallSignatureDeclaration>,
|
|
629
|
+
'typeParameters' | 'typeAnnotation'
|
|
630
|
+
> {
|
|
631
|
+
parameters: Parameter[];
|
|
632
|
+
typeParameters: TSTypeParameterDeclaration | undefined;
|
|
633
|
+
typeAnnotation: TSTypeAnnotation | undefined;
|
|
634
|
+
}
|
|
635
|
+
interface TSConditionalType
|
|
636
|
+
extends Omit<
|
|
637
|
+
AcornTSNode<TSESTree.TSConditionalType>,
|
|
638
|
+
'checkType' | 'extendsType' | 'falseType' | 'trueType'
|
|
639
|
+
> {
|
|
640
|
+
checkType: TypeNode;
|
|
641
|
+
extendsType: TypeNode;
|
|
642
|
+
falseType: TypeNode;
|
|
643
|
+
trueType: TypeNode;
|
|
644
|
+
}
|
|
645
|
+
interface TSConstructorType
|
|
646
|
+
extends Omit<AcornTSNode<TSESTree.TSConstructorType>, 'typeParameters' | 'params'> {
|
|
647
|
+
typeAnnotation: TSTypeAnnotation | undefined;
|
|
648
|
+
typeParameters: TSTypeParameterDeclaration | undefined;
|
|
649
|
+
parameters: Parameter[];
|
|
650
|
+
}
|
|
651
|
+
interface TSConstructSignatureDeclaration
|
|
652
|
+
extends Omit<
|
|
653
|
+
AcornTSNode<TSESTree.TSConstructSignatureDeclaration>,
|
|
654
|
+
'typeParameters' | 'typeAnnotation'
|
|
655
|
+
> {
|
|
656
|
+
parameters: Parameter[];
|
|
657
|
+
typeParameters: TSTypeParameterDeclaration | undefined;
|
|
658
|
+
typeAnnotation: TSTypeAnnotation | undefined;
|
|
659
|
+
}
|
|
660
|
+
interface TSDeclareFunction
|
|
661
|
+
extends Omit<
|
|
662
|
+
AcornTSNode<TSESTree.TSDeclareFunction>,
|
|
663
|
+
'id' | 'params' | 'typeParameters' | 'returnType'
|
|
664
|
+
> {
|
|
665
|
+
id: AST.Identifier;
|
|
666
|
+
params: Parameter[];
|
|
667
|
+
typeParameters: TSTypeParameterDeclaration | undefined;
|
|
668
|
+
returnType: TSTypeAnnotation | undefined;
|
|
669
|
+
}
|
|
670
|
+
interface TSEnumDeclaration
|
|
671
|
+
extends Omit<AcornTSNode<TSESTree.TSEnumDeclaration>, 'id' | 'members'> {
|
|
672
|
+
id: AST.Identifier;
|
|
673
|
+
members: TSEnumMember[];
|
|
674
|
+
}
|
|
675
|
+
interface TSEnumMember extends Omit<AcornTSNode<TSESTree.TSEnumMember>, 'id' | 'initializer'> {
|
|
676
|
+
id: AST.Identifier | StringLiteral;
|
|
677
|
+
initializer: AST.Expression | undefined;
|
|
678
|
+
}
|
|
679
|
+
interface TSExportAssignment
|
|
680
|
+
extends Omit<AcornTSNode<TSESTree.TSExportAssignment>, 'expression'> {
|
|
681
|
+
expression: AST.Expression;
|
|
682
|
+
}
|
|
683
|
+
interface TSExternalModuleReference
|
|
684
|
+
extends Omit<AcornTSNode<TSESTree.TSExternalModuleReference>, 'expression'> {
|
|
685
|
+
expression: StringLiteral;
|
|
686
|
+
}
|
|
687
|
+
interface TSFunctionType
|
|
688
|
+
extends Omit<AcornTSNode<TSESTree.TSFunctionType>, 'typeParameters' | 'params'> {
|
|
689
|
+
typeAnnotation: TSTypeAnnotation | undefined;
|
|
690
|
+
typeParameters: TSTypeParameterDeclaration | undefined;
|
|
691
|
+
parameters: Parameter[];
|
|
692
|
+
}
|
|
693
|
+
interface TSImportEqualsDeclaration extends AcornTSNode<TSESTree.TSImportEqualsDeclaration> {}
|
|
694
|
+
interface TSImportType
|
|
695
|
+
extends Omit<AcornTSNode<TSESTree.TSImportType>, 'argument' | 'qualifier' | 'typeParameters'> {
|
|
696
|
+
argument: TypeNode;
|
|
697
|
+
qualifier: EntityName | null;
|
|
698
|
+
// looks like acorn-typescript has typeParameters
|
|
699
|
+
typeParameters: TSTypeParameterDeclaration | undefined | undefined;
|
|
700
|
+
}
|
|
701
|
+
interface TSIndexedAccessType
|
|
702
|
+
extends Omit<AcornTSNode<TSESTree.TSIndexedAccessType>, 'indexType' | 'objectType'> {
|
|
703
|
+
indexType: TypeNode;
|
|
704
|
+
objectType: TypeNode;
|
|
705
|
+
}
|
|
706
|
+
interface TSIndexSignature
|
|
707
|
+
extends Omit<AcornTSNode<TSESTree.TSIndexSignature>, 'parameters' | 'typeAnnotation'> {
|
|
708
|
+
parameters: Parameter[];
|
|
709
|
+
typeAnnotation: TSTypeAnnotation | undefined;
|
|
710
|
+
}
|
|
711
|
+
interface TSInferType extends Omit<AcornTSNode<TSESTree.TSInferType>, 'typeParameter'> {
|
|
712
|
+
typeParameter: TSTypeParameter;
|
|
713
|
+
}
|
|
714
|
+
interface TSInstantiationExpression extends AcornTSNode<TSESTree.TSInstantiationExpression> {
|
|
715
|
+
expression: AST.Expression;
|
|
716
|
+
}
|
|
717
|
+
interface TSInterfaceBody extends Omit<AcornTSNode<TSESTree.TSInterfaceBody>, 'body'> {
|
|
718
|
+
body: TypeElement[];
|
|
719
|
+
}
|
|
720
|
+
interface TSInterfaceDeclaration
|
|
721
|
+
extends Omit<
|
|
722
|
+
AcornTSNode<TSESTree.TSInterfaceDeclaration>,
|
|
723
|
+
'id' | 'typeParameters' | 'body' | 'extends'
|
|
724
|
+
> {
|
|
725
|
+
id: AST.Identifier;
|
|
726
|
+
typeParameters: TSTypeParameterDeclaration | undefined;
|
|
727
|
+
body: TSInterfaceBody;
|
|
728
|
+
extends: TSExpressionWithTypeArguments[];
|
|
729
|
+
}
|
|
730
|
+
interface TSIntersectionType extends Omit<AcornTSNode<TSESTree.TSIntersectionType>, 'types'> {
|
|
731
|
+
types: TypeNode[];
|
|
732
|
+
}
|
|
733
|
+
interface TSIntrinsicKeyword extends AcornTSNode<TSESTree.TSIntrinsicKeyword> {}
|
|
734
|
+
interface TSLiteralType extends Omit<AcornTSNode<TSESTree.TSLiteralType>, 'literal'> {
|
|
735
|
+
literal: AST.Literal | AST.TemplateLiteral;
|
|
736
|
+
}
|
|
737
|
+
interface TSMappedType
|
|
738
|
+
extends Omit<AcornTSNode<TSESTree.TSMappedType>, 'typeParameter' | 'typeAnnotation'> {
|
|
739
|
+
typeAnnotation: TypeNode | undefined;
|
|
740
|
+
typeParameter: TSTypeParameter;
|
|
741
|
+
}
|
|
742
|
+
interface TSMethodSignature
|
|
743
|
+
extends Omit<
|
|
744
|
+
AcornTSNode<TSESTree.TSMethodSignature>,
|
|
745
|
+
'key' | 'typeParameters' | 'params' | 'typeAnnotation'
|
|
746
|
+
> {
|
|
747
|
+
key: PropertyNameComputed | PropertyNameNonComputed;
|
|
748
|
+
typeParameters: TSTypeParameterDeclaration | undefined;
|
|
749
|
+
parameters: Parameter[];
|
|
750
|
+
// doesn't actually exist in the spec but acorn-typescript adds it
|
|
751
|
+
typeAnnotation: TSTypeAnnotation | undefined;
|
|
752
|
+
}
|
|
753
|
+
interface TSModuleBlock extends Omit<AcornTSNode<TSESTree.TSModuleBlock>, 'body'> {
|
|
754
|
+
body: AST.Statement[];
|
|
755
|
+
}
|
|
756
|
+
interface TSModuleDeclaration
|
|
757
|
+
extends Omit<AcornTSNode<TSESTree.TSModuleDeclaration>, 'body' | 'id'> {
|
|
758
|
+
body: TSModuleBlock;
|
|
759
|
+
id: AST.Identifier;
|
|
760
|
+
}
|
|
761
|
+
interface TSNamedTupleMember
|
|
762
|
+
extends Omit<AcornTSNode<TSESTree.TSNamedTupleMember>, 'elementType' | 'label'> {
|
|
763
|
+
elementType: TypeNode;
|
|
764
|
+
label: AST.Identifier;
|
|
765
|
+
}
|
|
766
|
+
interface TSNamespaceExportDeclaration
|
|
767
|
+
extends Omit<AcornTSNode<TSESTree.TSNamespaceExportDeclaration>, 'id'> {
|
|
768
|
+
id: AST.Identifier;
|
|
769
|
+
}
|
|
770
|
+
interface TSNeverKeyword extends AcornTSNode<TSESTree.TSNeverKeyword> {}
|
|
771
|
+
interface TSNonNullExpression extends AcornTSNode<TSESTree.TSNonNullExpression> {
|
|
772
|
+
expression: AST.Expression;
|
|
773
|
+
}
|
|
774
|
+
interface TSNullKeyword extends AcornTSNode<TSESTree.TSNullKeyword> {}
|
|
775
|
+
interface TSNumberKeyword extends AcornTSNode<TSESTree.TSNumberKeyword> {}
|
|
776
|
+
interface TSObjectKeyword extends AcornTSNode<TSESTree.TSObjectKeyword> {}
|
|
777
|
+
interface TSOptionalType extends Omit<AcornTSNode<TSESTree.TSOptionalType>, 'typeAnnotation'> {
|
|
778
|
+
typeAnnotation: TypeNode;
|
|
779
|
+
}
|
|
780
|
+
interface TSParameterProperty extends AcornTSNode<TSESTree.TSParameterProperty> {}
|
|
781
|
+
interface TSPropertySignatureComputedName
|
|
782
|
+
extends Omit<AcornTSNode<TSESTree.TSPropertySignatureComputedName>, 'key' | 'typeAnnotation'> {
|
|
783
|
+
key: PropertyNameComputed;
|
|
784
|
+
typeAnnotation: TSTypeAnnotation | undefined;
|
|
785
|
+
}
|
|
786
|
+
interface TSPropertySignatureNonComputedName
|
|
787
|
+
extends Omit<
|
|
788
|
+
AcornTSNode<TSESTree.TSPropertySignatureNonComputedName>,
|
|
789
|
+
'key' | 'typeAnnotation'
|
|
790
|
+
> {
|
|
791
|
+
key: PropertyNameNonComputed;
|
|
792
|
+
typeAnnotation: TSTypeAnnotation | undefined;
|
|
793
|
+
}
|
|
794
|
+
interface TSQualifiedName extends Omit<AcornTSNode<TSESTree.TSQualifiedName>, 'left' | 'right'> {
|
|
795
|
+
left: EntityName;
|
|
796
|
+
right: AST.Identifier;
|
|
797
|
+
}
|
|
798
|
+
interface TSRestType extends Omit<AcornTSNode<TSESTree.TSRestType>, 'typeAnnotation'> {
|
|
799
|
+
typeAnnotation: TypeNode;
|
|
800
|
+
}
|
|
801
|
+
interface TSSatisfiesExpression extends AcornTSNode<TSESTree.TSSatisfiesExpression> {
|
|
802
|
+
expression: AST.Expression;
|
|
803
|
+
}
|
|
804
|
+
interface TSStringKeyword extends AcornTSNode<TSESTree.TSStringKeyword> {}
|
|
805
|
+
interface TSSymbolKeyword extends AcornTSNode<TSESTree.TSSymbolKeyword> {}
|
|
806
|
+
interface TSThisType extends AcornTSNode<TSESTree.TSThisType> {}
|
|
807
|
+
interface TSTupleType extends Omit<AcornTSNode<TSESTree.TSTupleType>, 'elementTypes'> {
|
|
808
|
+
elementTypes: TypeNode[];
|
|
809
|
+
}
|
|
810
|
+
interface TSTypeAliasDeclaration
|
|
811
|
+
extends Omit<
|
|
812
|
+
AcornTSNode<TSESTree.TSTypeAliasDeclaration>,
|
|
813
|
+
'id' | 'typeParameters' | 'typeAnnotation'
|
|
814
|
+
> {
|
|
815
|
+
id: AST.Identifier;
|
|
816
|
+
typeAnnotation: TypeNode;
|
|
817
|
+
typeParameters: TSTypeParameterDeclaration | undefined;
|
|
818
|
+
}
|
|
819
|
+
interface TSTypeAnnotation
|
|
820
|
+
extends Omit<AcornTSNode<TSESTree.TSTypeAnnotation>, 'typeAnnotation'> {
|
|
821
|
+
typeAnnotation: TypeNode;
|
|
822
|
+
}
|
|
823
|
+
interface TSTypeAssertion extends AcornTSNode<TSESTree.TSTypeAssertion> {
|
|
824
|
+
expression: AST.Expression;
|
|
825
|
+
}
|
|
826
|
+
interface TSTypeLiteral extends Omit<AcornTSNode<TSESTree.TSTypeLiteral>, 'members'> {
|
|
827
|
+
members: TypeElement[];
|
|
828
|
+
}
|
|
829
|
+
interface TSTypeOperator extends Omit<AcornTSNode<TSESTree.TSTypeOperator>, 'typeAnnotation'> {
|
|
830
|
+
typeAnnotation: TypeNode | undefined;
|
|
831
|
+
}
|
|
832
|
+
interface TSTypeParameter
|
|
833
|
+
extends Omit<AcornTSNode<TSESTree.TSTypeParameter>, 'name' | 'constraint' | 'default'> {
|
|
834
|
+
constraint: TypeNode | undefined;
|
|
835
|
+
default: TypeNode | undefined;
|
|
836
|
+
name: AST.Identifier;
|
|
837
|
+
}
|
|
838
|
+
interface TSTypeParameterDeclaration
|
|
839
|
+
extends Omit<AcornTSNode<TSESTree.TSTypeParameterDeclaration>, 'params'> {
|
|
840
|
+
params: TypeNode[];
|
|
841
|
+
}
|
|
842
|
+
interface TSTypeParameterInstantiation
|
|
843
|
+
extends Omit<AcornTSNode<TSESTree.TSTypeParameterInstantiation>, 'params'> {
|
|
844
|
+
params: TypeNode[];
|
|
845
|
+
}
|
|
846
|
+
interface TSTypePredicate extends AcornTSNode<TSESTree.TSTypePredicate> {}
|
|
847
|
+
interface TSTypeQuery
|
|
848
|
+
extends Omit<AcornTSNode<TSESTree.TSTypeQuery>, 'exprName' | 'typeArguments'> {
|
|
849
|
+
exprName: EntityName | TSImportType;
|
|
850
|
+
typeArguments: TSTypeParameterInstantiation | undefined;
|
|
851
|
+
}
|
|
852
|
+
interface TSTypeReference
|
|
853
|
+
extends Omit<AcornTSNode<TSESTree.TSTypeReference>, 'typeName' | 'typeArguments'> {
|
|
854
|
+
typeArguments: TSTypeParameterInstantiation | undefined;
|
|
855
|
+
typeName: EntityName;
|
|
856
|
+
}
|
|
857
|
+
interface TSUndefinedKeyword extends AcornTSNode<TSESTree.TSUndefinedKeyword> {}
|
|
858
|
+
interface TSUnionType extends Omit<AcornTSNode<TSESTree.TSUnionType>, 'types'> {
|
|
859
|
+
types: TypeNode[];
|
|
860
|
+
}
|
|
861
|
+
// TSInterfaceHeritage doesn't exist in acorn-typescript which uses TSExpressionWithTypeArguments
|
|
862
|
+
interface TSInterfaceHeritage
|
|
863
|
+
extends Omit<AcornTSNode<TSESTree.TSInterfaceHeritage>, 'expression' | 'typeParameters'> {
|
|
864
|
+
expression: AST.Expression;
|
|
865
|
+
// acorn-typescript uses typeParameters instead of typeArguments
|
|
866
|
+
typeParameters: TSTypeParameterInstantiation | undefined;
|
|
867
|
+
}
|
|
868
|
+
// Extends TSInterfaceHeritage as it's the semantically the same as used by acorn-typescript
|
|
869
|
+
interface TSExpressionWithTypeArguments extends Omit<TSInterfaceHeritage, 'type'> {
|
|
870
|
+
type: 'TSExpressionWithTypeArguments';
|
|
871
|
+
}
|
|
283
872
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
type: 'TrackedSetExpression';
|
|
289
|
-
arguments: (Expression | SpreadElement)[];
|
|
290
|
-
}
|
|
873
|
+
interface TSUnknownKeyword extends AcornTSNode<TSESTree.TSUnknownKeyword> {}
|
|
874
|
+
interface TSVoidKeyword extends AcornTSNode<TSESTree.TSVoidKeyword> {}
|
|
875
|
+
interface NumberLiteral extends AcornTSNode<TSESTree.NumberLiteral> {}
|
|
876
|
+
interface StringLiteral extends AcornTSNode<TSESTree.StringLiteral> {}
|
|
291
877
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
type: 'Component';
|
|
297
|
-
id: Identifier;
|
|
298
|
-
params: Pattern[];
|
|
299
|
-
body: Node[];
|
|
300
|
-
css: any;
|
|
301
|
-
start?: number;
|
|
302
|
-
end?: number;
|
|
303
|
-
loc?: any;
|
|
304
|
-
}
|
|
878
|
+
// acorn-typescript specific nodes (not in @typescript-eslint/types)
|
|
879
|
+
interface TSParenthesizedType extends AST.BaseNode {
|
|
880
|
+
type: 'TSParenthesizedType';
|
|
881
|
+
}
|
|
305
882
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
metadata: any;
|
|
883
|
+
// Extend ExpressionMap for TypeScript expressions
|
|
884
|
+
interface ExpressionMap {
|
|
885
|
+
TSAsExpression: TSAsExpression;
|
|
886
|
+
TSInstantiationExpression: TSInstantiationExpression;
|
|
887
|
+
TSNonNullExpression: TSNonNullExpression;
|
|
888
|
+
TSSatisfiesExpression: TSSatisfiesExpression;
|
|
889
|
+
TSTypeAssertion: TSTypeAssertion;
|
|
890
|
+
}
|
|
315
891
|
}
|
|
316
892
|
|
|
893
|
+
import type { Comment, Position } from 'acorn';
|
|
894
|
+
import type { A, M } from 'vitest/dist/chunks/environment.d.cL3nLXbE.js';
|
|
895
|
+
|
|
317
896
|
/**
|
|
318
|
-
*
|
|
319
|
-
* Note: TsxCompat elements cannot be self-closing and must have a closing tag
|
|
897
|
+
* Parse error information
|
|
320
898
|
*/
|
|
321
|
-
export interface
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
children: Node[];
|
|
326
|
-
metadata: any;
|
|
899
|
+
export interface ParseError {
|
|
900
|
+
message: string;
|
|
901
|
+
pos: number;
|
|
902
|
+
loc: Position;
|
|
327
903
|
}
|
|
328
904
|
|
|
329
905
|
/**
|
|
330
|
-
*
|
|
906
|
+
* Result of parsing operation
|
|
331
907
|
*/
|
|
332
|
-
export interface
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
value: Expression | null;
|
|
336
|
-
start?: number;
|
|
337
|
-
end?: number;
|
|
338
|
-
loc?: any;
|
|
908
|
+
export interface ParseResult {
|
|
909
|
+
ast: AST.Program;
|
|
910
|
+
errors: ParseError[];
|
|
339
911
|
}
|
|
340
912
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
argument: Expression;
|
|
347
|
-
start?: number;
|
|
348
|
-
end?: number;
|
|
349
|
-
loc?: any;
|
|
913
|
+
export interface AnalysisResult {
|
|
914
|
+
ast: AST.Program;
|
|
915
|
+
scopes: Map<AST.Node, ScopeInterface>;
|
|
916
|
+
scope: ScopeInterface;
|
|
917
|
+
component_metadata: Array<{ id: string; async: boolean }>;
|
|
350
918
|
}
|
|
351
919
|
|
|
352
920
|
/**
|
|
@@ -374,18 +942,29 @@ export type DeclarationKind =
|
|
|
374
942
|
/**
|
|
375
943
|
* Binding kinds
|
|
376
944
|
*/
|
|
377
|
-
export type BindingKind =
|
|
945
|
+
export type BindingKind =
|
|
946
|
+
| 'normal'
|
|
947
|
+
| 'for_pattern'
|
|
948
|
+
| 'rest_prop'
|
|
949
|
+
| 'prop'
|
|
950
|
+
| 'prop_fallback'
|
|
951
|
+
| 'index';
|
|
378
952
|
|
|
379
953
|
/**
|
|
380
954
|
* A variable binding in a scope
|
|
381
955
|
*/
|
|
382
956
|
export interface Binding {
|
|
383
957
|
/** The identifier node that declares this binding */
|
|
384
|
-
node: Identifier;
|
|
958
|
+
node: AST.Identifier;
|
|
385
959
|
/** References to this binding */
|
|
386
|
-
references: Array<{ node: Identifier; path: Node[] }>;
|
|
960
|
+
references: Array<{ node: AST.Identifier; path: AST.Node[] }>;
|
|
387
961
|
/** Initial value/declaration */
|
|
388
|
-
initial:
|
|
962
|
+
initial:
|
|
963
|
+
| null
|
|
964
|
+
| AST.Expression
|
|
965
|
+
| AST.FunctionDeclaration
|
|
966
|
+
| AST.ClassDeclaration
|
|
967
|
+
| AST.ImportDeclaration;
|
|
389
968
|
/** Whether this binding has been reassigned */
|
|
390
969
|
reassigned: boolean;
|
|
391
970
|
/** Whether this binding has been mutated (property access) */
|
|
@@ -395,13 +974,23 @@ export interface Binding {
|
|
|
395
974
|
/** Whether this binding represents a called function */
|
|
396
975
|
is_called: boolean;
|
|
397
976
|
/** Additional metadata for this binding */
|
|
398
|
-
metadata
|
|
977
|
+
metadata: {
|
|
978
|
+
is_dynamic_component?: boolean;
|
|
979
|
+
pattern?: AST.Identifier;
|
|
980
|
+
is_tracked_object?: boolean;
|
|
981
|
+
} | null;
|
|
399
982
|
/** Kind of binding */
|
|
400
983
|
kind: BindingKind;
|
|
401
984
|
/** Declaration kind */
|
|
402
985
|
declaration_kind?: DeclarationKind;
|
|
403
986
|
/** The scope that contains this binding */
|
|
404
|
-
scope
|
|
987
|
+
scope: ScopeInterface;
|
|
988
|
+
/** Transform functions for reading, assigning, and updating this binding */
|
|
989
|
+
transform?: {
|
|
990
|
+
read: (node?: AST.Identifier) => AST.Expression;
|
|
991
|
+
assign?: (node: AST.Pattern, value: AST.Expression) => AST.AssignmentExpression;
|
|
992
|
+
update?: (node: AST.UpdateExpression) => AST.UpdateExpression;
|
|
993
|
+
};
|
|
405
994
|
}
|
|
406
995
|
|
|
407
996
|
/**
|
|
@@ -411,7 +1000,7 @@ export interface ScopeRoot {
|
|
|
411
1000
|
/** Set of conflicting/reserved names */
|
|
412
1001
|
conflicts: Set<string>;
|
|
413
1002
|
/** Generate unique identifier name */
|
|
414
|
-
unique(preferred_name: string): Identifier;
|
|
1003
|
+
unique(preferred_name: string): AST.Identifier;
|
|
415
1004
|
}
|
|
416
1005
|
|
|
417
1006
|
/**
|
|
@@ -425,98 +1014,146 @@ export interface ScopeInterface {
|
|
|
425
1014
|
/** Map of declared bindings */
|
|
426
1015
|
declarations: Map<string, Binding>;
|
|
427
1016
|
/** Map of declarators to their bindings */
|
|
428
|
-
declarators: Map<VariableDeclarator, Binding[]>;
|
|
1017
|
+
declarators: Map<AST.VariableDeclarator, Binding[]>;
|
|
429
1018
|
/** Map of references in this scope */
|
|
430
|
-
references: Map<string, Array<{ node: Identifier; path: Node[] }>>;
|
|
1019
|
+
references: Map<string, Array<{ node: AST.Identifier; path: AST.Node[] }>>;
|
|
431
1020
|
/** Function nesting depth */
|
|
432
1021
|
function_depth: number;
|
|
433
1022
|
/** Whether reactive tracing is enabled */
|
|
434
|
-
tracing: null | Expression;
|
|
1023
|
+
tracing: null | AST.Expression;
|
|
1024
|
+
server_block?: boolean;
|
|
435
1025
|
|
|
436
1026
|
/** Create child scope */
|
|
437
1027
|
child(porous?: boolean): ScopeInterface;
|
|
438
1028
|
/** Declare a binding */
|
|
439
1029
|
declare(
|
|
440
|
-
node: Identifier,
|
|
1030
|
+
node: AST.Identifier,
|
|
441
1031
|
kind: BindingKind,
|
|
442
1032
|
declaration_kind: DeclarationKind,
|
|
443
|
-
initial?:
|
|
1033
|
+
initial?:
|
|
1034
|
+
| null
|
|
1035
|
+
| AST.Expression
|
|
1036
|
+
| AST.FunctionDeclaration
|
|
1037
|
+
| AST.ClassDeclaration
|
|
1038
|
+
| AST.ImportDeclaration,
|
|
444
1039
|
): Binding;
|
|
445
1040
|
/** Get binding by name */
|
|
446
1041
|
get(name: string): Binding | null;
|
|
447
1042
|
/** Get bindings for a declarator */
|
|
448
|
-
get_bindings(node: VariableDeclarator): Binding[];
|
|
1043
|
+
get_bindings(node: AST.VariableDeclarator): Binding[];
|
|
449
1044
|
/** Find the scope that owns a name */
|
|
450
1045
|
owner(name: string): ScopeInterface | null;
|
|
451
1046
|
/** Add a reference */
|
|
452
|
-
reference(node: Identifier, path: Node[]): void;
|
|
1047
|
+
reference(node: AST.Identifier, path: AST.Node[]): void;
|
|
453
1048
|
/** Generate unique identifier name */
|
|
454
1049
|
generate(preferred_name: string): string;
|
|
455
1050
|
}
|
|
456
1051
|
|
|
457
1052
|
/**
|
|
458
|
-
*
|
|
1053
|
+
* Compiler state object
|
|
459
1054
|
*/
|
|
460
|
-
export interface TextNode {
|
|
461
|
-
type: 'Text';
|
|
462
|
-
expression: Expression;
|
|
463
|
-
start?: number;
|
|
464
|
-
end?: number;
|
|
465
|
-
loc?: any;
|
|
466
|
-
}
|
|
467
1055
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
1056
|
+
interface BaseStateMetaData {
|
|
1057
|
+
tracking?: boolean | null;
|
|
1058
|
+
await?: boolean;
|
|
1059
|
+
}
|
|
472
1060
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
*/
|
|
476
|
-
export interface CompilerState {
|
|
477
|
-
/** Current scope */
|
|
1061
|
+
export interface BaseState {
|
|
1062
|
+
/** For utils */
|
|
478
1063
|
scope: ScopeInterface;
|
|
479
|
-
|
|
480
|
-
analysis?: {
|
|
481
|
-
/** Module analysis */
|
|
482
|
-
module?: {
|
|
483
|
-
/** Module scope */
|
|
484
|
-
scope?: {
|
|
485
|
-
/** Module references */
|
|
486
|
-
references?: Set<string>;
|
|
487
|
-
};
|
|
488
|
-
};
|
|
489
|
-
/** Exported identifiers */
|
|
490
|
-
exports?: Array<{ name: string }>;
|
|
491
|
-
};
|
|
492
|
-
/** Scopes map */
|
|
493
|
-
scopes?: Map<RippleNode, ScopeInterface>;
|
|
494
|
-
/** Whether inside head element */
|
|
1064
|
+
scopes: Map<AST.Node | AST.Node[], ScopeInterface>;
|
|
495
1065
|
inside_head?: boolean;
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
1066
|
+
|
|
1067
|
+
/** Common For All */
|
|
1068
|
+
to_ts: boolean;
|
|
1069
|
+
component?: AST.Component;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
export interface AnalysisState extends BaseState {
|
|
1073
|
+
analysis: AnalysisResult & {
|
|
1074
|
+
module: {
|
|
1075
|
+
ast: AnalysisResult['ast'];
|
|
1076
|
+
scope: AnalysisResult['scope'];
|
|
1077
|
+
scopes: AnalysisResult['scopes'];
|
|
1078
|
+
filename: string;
|
|
1079
|
+
};
|
|
500
1080
|
};
|
|
1081
|
+
elements?: AST.Element[];
|
|
1082
|
+
function_depth?: number;
|
|
1083
|
+
inside_server_block?: boolean;
|
|
1084
|
+
loose?: boolean;
|
|
1085
|
+
metadata: BaseStateMetaData;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
export interface TransformServerState extends BaseState {
|
|
1089
|
+
imports: Set<string>;
|
|
1090
|
+
init: Array<AST.Statement> | null;
|
|
1091
|
+
stylesheets: AST.CSS.StyleSheet[];
|
|
1092
|
+
component_metadata: AnalysisResult['component_metadata'];
|
|
1093
|
+
inside_server_block: boolean;
|
|
1094
|
+
filename: string;
|
|
1095
|
+
metadata: BaseStateMetaData;
|
|
1096
|
+
namespace: NameSpace;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
type UpdateList = Array<{
|
|
1100
|
+
identity?: AST.Identifier | AST.Expression;
|
|
1101
|
+
initial?: AST.Expression;
|
|
1102
|
+
operation: (expr?: AST.Expression, prev?: AST.Expression) => AST.ExpressionStatement;
|
|
1103
|
+
expression?: AST.Expression;
|
|
1104
|
+
needsPrevTracking?: boolean;
|
|
1105
|
+
}> & { async?: boolean };
|
|
1106
|
+
|
|
1107
|
+
export interface TransformClientState extends BaseState {
|
|
1108
|
+
events: Set<string>;
|
|
1109
|
+
filename: string;
|
|
1110
|
+
final: Array<AST.Statement> | null;
|
|
1111
|
+
flush_node: ((is_controlled?: boolean) => AST.Identifier) | null;
|
|
1112
|
+
hoisted: Array<AST.Statement>;
|
|
1113
|
+
imports: Set<string>;
|
|
1114
|
+
init: Array<AST.Statement> | null;
|
|
1115
|
+
metadata: BaseStateMetaData;
|
|
1116
|
+
namespace: NameSpace;
|
|
1117
|
+
ripple_user_imports: Map<string, string>;
|
|
1118
|
+
setup: Array<AST.Statement> | null;
|
|
1119
|
+
stylesheets: Array<AST.CSS.StyleSheet>;
|
|
1120
|
+
template: Array<string | AST.Expression> | null;
|
|
1121
|
+
update: UpdateList | null;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
/** Override zimmerframe types and provide our own */
|
|
1125
|
+
type NodeOf<T extends string, X> = X extends { type: T } ? X : never;
|
|
1126
|
+
|
|
1127
|
+
type SpecializedVisitors<T extends AST.Node | AST.CSS.Node, U> = {
|
|
1128
|
+
[K in T['type']]?: Visitor<NodeOf<K, T>, U, T>;
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1131
|
+
export type Visitor<T, U, V> = (node: T, context: Context<V, U>) => V | void;
|
|
1132
|
+
|
|
1133
|
+
export type Visitors<T extends AST.Node | AST.CSS.Node, U> = T['type'] extends '_'
|
|
1134
|
+
? never
|
|
1135
|
+
: SpecializedVisitors<T, U> & { _?: Visitor<T, U, T> };
|
|
1136
|
+
|
|
1137
|
+
export interface Context<T, U> {
|
|
1138
|
+
next: (state?: U) => T | void;
|
|
1139
|
+
path: T[];
|
|
1140
|
+
state: U;
|
|
1141
|
+
stop: () => void;
|
|
1142
|
+
visit: (node: T, state?: U) => T;
|
|
501
1143
|
}
|
|
502
1144
|
|
|
503
1145
|
/**
|
|
504
1146
|
* Transform context object
|
|
505
1147
|
*/
|
|
506
|
-
export
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
/** Visit function */
|
|
512
|
-
visit: (node: any, state?: any) => any;
|
|
513
|
-
/** Transform metadata */
|
|
514
|
-
metadata?: any;
|
|
515
|
-
}
|
|
1148
|
+
export type TransformClientContext = Context<AST.Node, TransformClientState>;
|
|
1149
|
+
export type TransformServerContext = Context<AST.Node, TransformServerState>;
|
|
1150
|
+
export type AnalysisContext = Context<AST.Node, AnalysisState>;
|
|
1151
|
+
export type CommonContext = TransformClientContext | TransformServerContext | AnalysisContext;
|
|
1152
|
+
export type VisitorClientContext = TransformClientContext & { root?: boolean };
|
|
516
1153
|
|
|
517
1154
|
/**
|
|
518
1155
|
* Delegated event result
|
|
519
1156
|
*/
|
|
520
1157
|
export interface DelegatedEventResult {
|
|
521
|
-
function?: FunctionExpression | FunctionDeclaration | ArrowFunctionExpression;
|
|
1158
|
+
function?: AST.FunctionExpression | AST.FunctionDeclaration | AST.ArrowFunctionExpression;
|
|
522
1159
|
}
|