ripple 0.2.180 → 0.2.183
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +80 -50
- 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 +6 -4
- package/src/compiler/phases/3-transform/server/index.js +278 -121
- package/src/compiler/scope.js +45 -93
- package/src/compiler/types/index.d.ts +619 -199
- package/src/compiler/types/parse.d.ts +1580 -0
- package/src/compiler/utils.js +62 -74
- package/src/runtime/internal/client/blocks.js +4 -1
- package/src/utils/ast.js +247 -192
- package/src/utils/builders.js +309 -247
- package/src/utils/sanitize_template_string.js +2 -2
package/src/utils/builders.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
/** @import * as
|
|
1
|
+
/** @import * as AST from 'estree' */
|
|
2
2
|
/** @import * as ESTreeJSX from 'estree-jsx' */
|
|
3
3
|
|
|
4
4
|
import { regex_is_valid_identifier } from './patterns.js';
|
|
5
5
|
import { sanitize_template_string } from './sanitize_template_string.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @param {Array<
|
|
9
|
-
* @returns {
|
|
8
|
+
* @param {Array<AST.Expression | AST.SpreadElement | null>} elements
|
|
9
|
+
* @returns {AST.ArrayExpression}
|
|
10
10
|
*/
|
|
11
11
|
export function array(elements = []) {
|
|
12
|
-
return { type: 'ArrayExpression', elements };
|
|
12
|
+
return { type: 'ArrayExpression', elements, metadata: { path: [] } };
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* @param {Array<
|
|
17
|
-
* @returns {
|
|
16
|
+
* @param {Array<AST.Pattern | null>} elements
|
|
17
|
+
* @returns {AST.ArrayPattern}
|
|
18
18
|
*/
|
|
19
19
|
export function array_pattern(elements) {
|
|
20
|
-
return { type: 'ArrayPattern', elements };
|
|
20
|
+
return { type: 'ArrayPattern', elements, metadata: { path: [] } };
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* @param {
|
|
25
|
-
* @param {
|
|
26
|
-
* @returns {
|
|
24
|
+
* @param {AST.Pattern} left
|
|
25
|
+
* @param {AST.Expression} right
|
|
26
|
+
* @returns {AST.AssignmentPattern}
|
|
27
27
|
*/
|
|
28
28
|
export function assignment_pattern(left, right) {
|
|
29
|
-
return { type: 'AssignmentPattern', left, right };
|
|
29
|
+
return { type: 'AssignmentPattern', left, right, metadata: { path: [] } };
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* @param {Array<
|
|
34
|
-
* @param {
|
|
35
|
-
* @returns {
|
|
33
|
+
* @param {Array<AST.Pattern>} params
|
|
34
|
+
* @param {AST.BlockStatement | AST.Expression} body
|
|
35
|
+
* @returns {AST.ArrowFunctionExpression}
|
|
36
36
|
*/
|
|
37
37
|
export function arrow(params, body, async = false) {
|
|
38
38
|
return {
|
|
@@ -47,10 +47,10 @@ export function arrow(params, body, async = false) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
* @param {
|
|
51
|
-
* @param {
|
|
52
|
-
* @param {
|
|
53
|
-
* @returns {
|
|
50
|
+
* @param {AST.Identifier} id
|
|
51
|
+
* @param {AST.Pattern[]} params
|
|
52
|
+
* @param {AST.Node[]} body
|
|
53
|
+
* @returns {AST.Component}
|
|
54
54
|
*/
|
|
55
55
|
export function component(id, params, body) {
|
|
56
56
|
return {
|
|
@@ -58,76 +58,79 @@ export function component(id, params, body) {
|
|
|
58
58
|
id,
|
|
59
59
|
params,
|
|
60
60
|
body,
|
|
61
|
+
css: null,
|
|
62
|
+
metadata: { path: [] },
|
|
63
|
+
default: false,
|
|
61
64
|
};
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
/**
|
|
65
|
-
* @param {
|
|
66
|
-
* @param {
|
|
67
|
-
* @param {
|
|
68
|
-
* @returns {
|
|
68
|
+
* @param {AST.AssignmentOperator} operator
|
|
69
|
+
* @param {AST.Pattern} left
|
|
70
|
+
* @param {AST.Expression} right
|
|
71
|
+
* @returns {AST.AssignmentExpression}
|
|
69
72
|
*/
|
|
70
73
|
export function assignment(operator, left, right) {
|
|
71
|
-
return { type: 'AssignmentExpression', operator, left, right };
|
|
74
|
+
return { type: 'AssignmentExpression', operator, left, right, metadata: { path: [] } };
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
/**
|
|
75
78
|
* @template T
|
|
76
|
-
* @param {T &
|
|
77
|
-
* @returns {T &
|
|
79
|
+
* @param {T & AST.BaseFunction} func
|
|
80
|
+
* @returns {T & AST.BaseFunction}
|
|
78
81
|
*/
|
|
79
82
|
export function async(func) {
|
|
80
83
|
return { ...func, async: true };
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
/**
|
|
84
|
-
* @param {
|
|
85
|
-
* @returns {
|
|
87
|
+
* @param {AST.Expression} argument
|
|
88
|
+
* @returns {AST.AwaitExpression}
|
|
86
89
|
*/
|
|
87
90
|
function await_builder(argument) {
|
|
88
|
-
return { type: 'AwaitExpression', argument };
|
|
91
|
+
return { type: 'AwaitExpression', argument, metadata: { path: [] } };
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
/**
|
|
92
|
-
* @param {
|
|
93
|
-
* @param {
|
|
94
|
-
* @param {
|
|
95
|
-
* @returns {
|
|
95
|
+
* @param {AST.BinaryOperator} operator
|
|
96
|
+
* @param {AST.Expression} left
|
|
97
|
+
* @param {AST.Expression} right
|
|
98
|
+
* @returns {AST.BinaryExpression}
|
|
96
99
|
*/
|
|
97
100
|
export function binary(operator, left, right) {
|
|
98
|
-
return { type: 'BinaryExpression', operator, left, right };
|
|
101
|
+
return { type: 'BinaryExpression', operator, left, right, metadata: { path: [] } };
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
/**
|
|
102
|
-
* @param {
|
|
103
|
-
* @returns {
|
|
105
|
+
* @param {AST.Statement[]} body
|
|
106
|
+
* @returns {AST.BlockStatement}
|
|
104
107
|
*/
|
|
105
108
|
export function block(body) {
|
|
106
|
-
return { type: 'BlockStatement', body };
|
|
109
|
+
return { type: 'BlockStatement', body, metadata: { path: [] } };
|
|
107
110
|
}
|
|
108
111
|
|
|
109
112
|
/**
|
|
110
|
-
* @param {
|
|
111
|
-
* @param {
|
|
112
|
-
* @returns {
|
|
113
|
+
* @param {AST.Statement[]} body
|
|
114
|
+
* @param {AST.SourceLocation | null} [loc]
|
|
115
|
+
* @returns {AST.BlockStatement}
|
|
113
116
|
*/
|
|
114
117
|
export function try_item_block(body, loc) {
|
|
115
|
-
return { type: 'BlockStatement', body, loc };
|
|
118
|
+
return { type: 'BlockStatement', body, loc, metadata: { path: [] } };
|
|
116
119
|
}
|
|
117
120
|
|
|
118
121
|
/**
|
|
119
122
|
* @param {string} name
|
|
120
|
-
* @param {
|
|
121
|
-
* @returns {
|
|
123
|
+
* @param {AST.Statement} body
|
|
124
|
+
* @returns {AST.LabeledStatement}
|
|
122
125
|
*/
|
|
123
126
|
export function labeled(name, body) {
|
|
124
|
-
return { type: 'LabeledStatement', label: id(name), body };
|
|
127
|
+
return { type: 'LabeledStatement', label: id(name), body, metadata: { path: [] } };
|
|
125
128
|
}
|
|
126
129
|
|
|
127
130
|
/**
|
|
128
|
-
* @param {string |
|
|
129
|
-
* @param {...(
|
|
130
|
-
* @returns {
|
|
131
|
+
* @param {string | AST.Expression} callee
|
|
132
|
+
* @param {...(AST.Expression | AST.SpreadElement | false | undefined)} args
|
|
133
|
+
* @returns {AST.CallExpression}
|
|
131
134
|
*/
|
|
132
135
|
export function call(callee, ...args) {
|
|
133
136
|
if (typeof callee === 'string') callee = id(callee);
|
|
@@ -151,107 +154,126 @@ export function call(callee, ...args) {
|
|
|
151
154
|
return {
|
|
152
155
|
type: 'CallExpression',
|
|
153
156
|
callee,
|
|
154
|
-
arguments: /** @type {Array<
|
|
157
|
+
arguments: /** @type {Array<AST.Expression | AST.SpreadElement>} */ (args),
|
|
155
158
|
optional: false,
|
|
159
|
+
metadata: { path: [] },
|
|
156
160
|
};
|
|
157
161
|
}
|
|
158
162
|
|
|
159
163
|
/**
|
|
160
|
-
* @param {string |
|
|
161
|
-
* @param {...
|
|
162
|
-
* @returns {
|
|
164
|
+
* @param {string | AST.Expression} callee
|
|
165
|
+
* @param {...AST.Expression} args
|
|
166
|
+
* @returns {AST.ChainExpression}
|
|
163
167
|
*/
|
|
164
168
|
export function maybe_call(callee, ...args) {
|
|
165
|
-
const expression = /** @type {
|
|
169
|
+
const expression = /** @type {AST.SimpleCallExpression} */ (call(callee, ...args));
|
|
166
170
|
expression.optional = true;
|
|
167
171
|
|
|
168
172
|
return {
|
|
169
173
|
type: 'ChainExpression',
|
|
170
174
|
expression,
|
|
175
|
+
metadata: { path: [] },
|
|
171
176
|
};
|
|
172
177
|
}
|
|
173
178
|
|
|
174
179
|
/**
|
|
175
|
-
* @param {
|
|
176
|
-
* @param {
|
|
177
|
-
* @returns {
|
|
180
|
+
* @param {AST.UnaryOperator} operator
|
|
181
|
+
* @param {AST.Expression} argument
|
|
182
|
+
* @returns {AST.UnaryExpression}
|
|
178
183
|
*/
|
|
179
184
|
export function unary(operator, argument) {
|
|
180
|
-
return { type: 'UnaryExpression', argument, operator, prefix: true };
|
|
185
|
+
return { type: 'UnaryExpression', argument, operator, prefix: true, metadata: { path: [] } };
|
|
181
186
|
}
|
|
182
187
|
|
|
183
188
|
/**
|
|
184
|
-
* @param {
|
|
185
|
-
* @param {
|
|
186
|
-
* @param {
|
|
187
|
-
* @returns {
|
|
189
|
+
* @param {AST.Expression} test
|
|
190
|
+
* @param {AST.Expression} consequent
|
|
191
|
+
* @param {AST.Expression} alternate
|
|
192
|
+
* @returns {AST.ConditionalExpression}
|
|
188
193
|
*/
|
|
189
194
|
export function conditional(test, consequent, alternate) {
|
|
190
|
-
return { type: 'ConditionalExpression', test, consequent, alternate };
|
|
195
|
+
return { type: 'ConditionalExpression', test, consequent, alternate, metadata: { path: [] } };
|
|
191
196
|
}
|
|
192
197
|
|
|
193
198
|
/**
|
|
194
|
-
* @param {
|
|
195
|
-
* @param {
|
|
196
|
-
* @param {
|
|
197
|
-
* @returns {
|
|
199
|
+
* @param {AST.LogicalOperator} operator
|
|
200
|
+
* @param {AST.Expression} left
|
|
201
|
+
* @param {AST.Expression} right
|
|
202
|
+
* @returns {AST.LogicalExpression}
|
|
198
203
|
*/
|
|
199
204
|
export function logical(operator, left, right) {
|
|
200
|
-
return { type: 'LogicalExpression', operator, left, right };
|
|
205
|
+
return { type: 'LogicalExpression', operator, left, right, metadata: { path: [] } };
|
|
201
206
|
}
|
|
202
207
|
|
|
203
208
|
/**
|
|
204
209
|
* @param {'const' | 'let' | 'var'} kind
|
|
205
|
-
* @param {
|
|
206
|
-
* @returns {
|
|
210
|
+
* @param {AST.VariableDeclarator[]} declarations
|
|
211
|
+
* @returns {AST.VariableDeclaration}
|
|
207
212
|
*/
|
|
208
213
|
export function declaration(kind, declarations) {
|
|
209
214
|
return {
|
|
210
215
|
type: 'VariableDeclaration',
|
|
211
216
|
kind,
|
|
212
217
|
declarations,
|
|
218
|
+
metadata: { path: [] },
|
|
213
219
|
};
|
|
214
220
|
}
|
|
215
221
|
|
|
216
222
|
/**
|
|
217
|
-
* @param {
|
|
218
|
-
* @param {
|
|
219
|
-
* @returns {
|
|
223
|
+
* @param {AST.Pattern | string} pattern
|
|
224
|
+
* @param {AST.Expression} [init]
|
|
225
|
+
* @returns {AST.VariableDeclarator}
|
|
220
226
|
*/
|
|
221
227
|
export function declarator(pattern, init) {
|
|
222
228
|
if (typeof pattern === 'string') pattern = id(pattern);
|
|
223
|
-
return { type: 'VariableDeclarator', id: pattern, init };
|
|
229
|
+
return { type: 'VariableDeclarator', id: pattern, init, metadata: { path: [] } };
|
|
224
230
|
}
|
|
225
231
|
|
|
226
|
-
/** @type {
|
|
232
|
+
/** @type {AST.EmptyStatement} */
|
|
227
233
|
export const empty = {
|
|
228
234
|
type: 'EmptyStatement',
|
|
235
|
+
metadata: { path: [] },
|
|
229
236
|
};
|
|
230
237
|
|
|
231
238
|
/**
|
|
232
|
-
* @param {
|
|
233
|
-
* @returns {
|
|
239
|
+
* @param {AST.Expression | AST.MaybeNamedClassDeclaration | AST.MaybeNamedFunctionDeclaration} declaration
|
|
240
|
+
* @returns {AST.ExportDefaultDeclaration}
|
|
234
241
|
*/
|
|
235
242
|
export function export_default(declaration) {
|
|
236
|
-
return { type: 'ExportDefaultDeclaration', declaration };
|
|
243
|
+
return { type: 'ExportDefaultDeclaration', declaration, metadata: { path: [] } };
|
|
237
244
|
}
|
|
238
245
|
|
|
239
246
|
/**
|
|
240
|
-
* @param {
|
|
241
|
-
* @param {
|
|
242
|
-
* @param {
|
|
243
|
-
* @param {
|
|
244
|
-
* @
|
|
247
|
+
* @param {AST.Declaration | null} declaration
|
|
248
|
+
* @param {AST.ExportSpecifier[]} [specifiers]
|
|
249
|
+
* @param {AST.ImportAttribute[]} [attributes]
|
|
250
|
+
* @param {AST.ExportNamedDeclaration['exportKind']} [exportKind]
|
|
251
|
+
* @param {AST.Literal | null} [source]
|
|
252
|
+
* @returns {AST.ExportNamedDeclaration}
|
|
245
253
|
*/
|
|
246
|
-
export function export_builder(
|
|
247
|
-
|
|
254
|
+
export function export_builder(
|
|
255
|
+
declaration,
|
|
256
|
+
specifiers = [],
|
|
257
|
+
attributes = [],
|
|
258
|
+
exportKind = 'value',
|
|
259
|
+
source = null,
|
|
260
|
+
) {
|
|
261
|
+
return {
|
|
262
|
+
type: 'ExportNamedDeclaration',
|
|
263
|
+
declaration,
|
|
264
|
+
specifiers,
|
|
265
|
+
attributes,
|
|
266
|
+
exportKind,
|
|
267
|
+
source,
|
|
268
|
+
metadata: { path: [] },
|
|
269
|
+
};
|
|
248
270
|
}
|
|
249
271
|
|
|
250
272
|
/**
|
|
251
|
-
* @param {
|
|
252
|
-
* @param {
|
|
253
|
-
* @param {
|
|
254
|
-
* @returns {
|
|
273
|
+
* @param {AST.Identifier} id
|
|
274
|
+
* @param {AST.Pattern[]} params
|
|
275
|
+
* @param {AST.BlockStatement} body
|
|
276
|
+
* @returns {AST.FunctionDeclaration}
|
|
255
277
|
*/
|
|
256
278
|
export function function_declaration(id, params, body, async = false) {
|
|
257
279
|
return {
|
|
@@ -261,87 +283,89 @@ export function function_declaration(id, params, body, async = false) {
|
|
|
261
283
|
body,
|
|
262
284
|
generator: false,
|
|
263
285
|
async,
|
|
264
|
-
metadata:
|
|
286
|
+
metadata: { path: [] },
|
|
265
287
|
};
|
|
266
288
|
}
|
|
267
289
|
|
|
268
290
|
/**
|
|
269
291
|
* @param {string} name
|
|
270
|
-
* @param {
|
|
271
|
-
* @returns {
|
|
292
|
+
* @param {AST.Statement[]} body
|
|
293
|
+
* @returns {AST.Property & { value: AST.FunctionExpression}}}
|
|
272
294
|
*/
|
|
273
295
|
export function get(name, body) {
|
|
274
|
-
return
|
|
296
|
+
return /** @type {AST.Property & { value: AST.FunctionExpression}} */ (
|
|
297
|
+
prop('get', key(name), function_builder(null, [], block(body)))
|
|
298
|
+
);
|
|
275
299
|
}
|
|
276
300
|
|
|
277
301
|
/**
|
|
278
302
|
* @param {string} name
|
|
279
|
-
* @returns {
|
|
303
|
+
* @returns {AST.Identifier}
|
|
280
304
|
*/
|
|
281
305
|
export function id(name) {
|
|
282
|
-
return { type: 'Identifier', name };
|
|
306
|
+
return { type: 'Identifier', name, metadata: { path: [] } };
|
|
283
307
|
}
|
|
284
308
|
|
|
285
309
|
/**
|
|
286
310
|
* @param {string} name
|
|
287
|
-
* @returns {
|
|
311
|
+
* @returns {AST.PrivateIdentifier}
|
|
288
312
|
*/
|
|
289
313
|
export function private_id(name) {
|
|
290
|
-
return { type: 'PrivateIdentifier', name };
|
|
314
|
+
return { type: 'PrivateIdentifier', name, metadata: { path: [] } };
|
|
291
315
|
}
|
|
292
316
|
|
|
293
317
|
/**
|
|
294
318
|
* @param {string} local
|
|
295
|
-
* @returns {
|
|
319
|
+
* @returns {AST.ImportNamespaceSpecifier}
|
|
296
320
|
*/
|
|
297
321
|
function import_namespace(local) {
|
|
298
322
|
return {
|
|
299
323
|
type: 'ImportNamespaceSpecifier',
|
|
300
324
|
local: id(local),
|
|
325
|
+
metadata: { path: [] },
|
|
301
326
|
};
|
|
302
327
|
}
|
|
303
328
|
|
|
304
329
|
/**
|
|
305
330
|
* @param {string} name
|
|
306
|
-
* @param {
|
|
307
|
-
* @returns {
|
|
331
|
+
* @param {AST.Expression} value
|
|
332
|
+
* @returns {AST.Property}
|
|
308
333
|
*/
|
|
309
334
|
export function init(name, value) {
|
|
310
335
|
return prop('init', key(name), value);
|
|
311
336
|
}
|
|
312
337
|
|
|
313
338
|
/**
|
|
314
|
-
* @param {string |
|
|
315
|
-
* @returns {
|
|
339
|
+
* @param {boolean | string | number | bigint | false | RegExp | null | undefined} value
|
|
340
|
+
* @returns {AST.Literal}
|
|
316
341
|
*/
|
|
317
342
|
export function literal(value) {
|
|
318
|
-
|
|
319
|
-
return { type: 'Literal', value };
|
|
343
|
+
return /** @type {AST.Literal} */ ({ type: 'Literal', value, metadata: { path: [] } });
|
|
320
344
|
}
|
|
321
345
|
|
|
322
346
|
/**
|
|
323
|
-
* @param {
|
|
324
|
-
* @param {string |
|
|
347
|
+
* @param {AST.Expression | AST.Super} object
|
|
348
|
+
* @param {string | AST.Expression | AST.PrivateIdentifier} property
|
|
325
349
|
* @param {boolean} computed
|
|
326
350
|
* @param {boolean} optional
|
|
327
|
-
* @returns {
|
|
351
|
+
* @returns {AST.MemberExpression}
|
|
328
352
|
*/
|
|
329
353
|
export function member(object, property, computed = false, optional = false) {
|
|
330
354
|
if (typeof property === 'string') {
|
|
331
355
|
property = id(property);
|
|
332
356
|
}
|
|
333
357
|
|
|
334
|
-
return { type: 'MemberExpression', object, property, computed, optional };
|
|
358
|
+
return { type: 'MemberExpression', object, property, computed, optional, metadata: { path: [] } };
|
|
335
359
|
}
|
|
336
360
|
|
|
337
361
|
/**
|
|
338
362
|
* @param {string} path
|
|
339
|
-
* @returns {
|
|
363
|
+
* @returns {AST.Identifier | AST.MemberExpression}
|
|
340
364
|
*/
|
|
341
365
|
export function member_id(path) {
|
|
342
366
|
const parts = path.split('.');
|
|
343
367
|
|
|
344
|
-
/** @type {
|
|
368
|
+
/** @type {AST.Identifier | AST.MemberExpression} */
|
|
345
369
|
let expression = id(parts[0]);
|
|
346
370
|
|
|
347
371
|
for (let i = 1; i < parts.length; i += 1) {
|
|
@@ -351,109 +375,126 @@ export function member_id(path) {
|
|
|
351
375
|
}
|
|
352
376
|
|
|
353
377
|
/**
|
|
354
|
-
* @param {Array<
|
|
355
|
-
* @returns {
|
|
378
|
+
* @param {Array<AST.Property | AST.SpreadElement>} properties
|
|
379
|
+
* @returns {AST.ObjectExpression}
|
|
356
380
|
*/
|
|
357
381
|
export function object(properties) {
|
|
358
|
-
return { type: 'ObjectExpression', properties };
|
|
382
|
+
return { type: 'ObjectExpression', properties, metadata: { path: [] } };
|
|
359
383
|
}
|
|
360
384
|
|
|
361
385
|
/**
|
|
362
|
-
* @param {Array<
|
|
363
|
-
* @returns {
|
|
386
|
+
* @param {Array<AST.RestElement | AST.AssignmentProperty>} properties
|
|
387
|
+
* @returns {AST.ObjectPattern}
|
|
364
388
|
*/
|
|
365
389
|
export function object_pattern(properties) {
|
|
366
|
-
|
|
367
|
-
return { type: 'ObjectPattern', properties };
|
|
390
|
+
return { type: 'ObjectPattern', properties, metadata: { path: [] } };
|
|
368
391
|
}
|
|
369
392
|
|
|
370
393
|
/**
|
|
371
|
-
* @template {
|
|
372
|
-
* @param {'
|
|
373
|
-
* @param {
|
|
394
|
+
* @template {AST.Expression} Value
|
|
395
|
+
* @param {AST.Property['kind']} kind
|
|
396
|
+
* @param {AST.Expression } key
|
|
374
397
|
* @param {Value} value
|
|
375
398
|
* @param {boolean} computed
|
|
376
|
-
* @returns {
|
|
399
|
+
* @returns {AST.Property}
|
|
377
400
|
*/
|
|
378
401
|
export function prop(kind, key, value, computed = false) {
|
|
379
|
-
return {
|
|
402
|
+
return {
|
|
403
|
+
type: 'Property',
|
|
404
|
+
kind,
|
|
405
|
+
key,
|
|
406
|
+
value,
|
|
407
|
+
method: false,
|
|
408
|
+
shorthand: false,
|
|
409
|
+
computed,
|
|
410
|
+
metadata: { path: [] },
|
|
411
|
+
};
|
|
380
412
|
}
|
|
381
413
|
|
|
382
414
|
/**
|
|
383
|
-
* @param {
|
|
384
|
-
* @param {
|
|
415
|
+
* @param {AST.Expression | AST.PrivateIdentifier} key
|
|
416
|
+
* @param {AST.Expression | null | undefined} value
|
|
385
417
|
* @param {boolean} computed
|
|
386
418
|
* @param {boolean} is_static
|
|
387
|
-
* @returns {
|
|
419
|
+
* @returns {AST.PropertyDefinition}
|
|
388
420
|
*/
|
|
389
421
|
export function prop_def(key, value, computed = false, is_static = false) {
|
|
390
|
-
return {
|
|
422
|
+
return {
|
|
423
|
+
type: 'PropertyDefinition',
|
|
424
|
+
key,
|
|
425
|
+
value,
|
|
426
|
+
computed,
|
|
427
|
+
static: is_static,
|
|
428
|
+
metadata: { path: [] },
|
|
429
|
+
};
|
|
391
430
|
}
|
|
392
431
|
|
|
393
432
|
/**
|
|
394
433
|
* @param {string} cooked
|
|
395
434
|
* @param {boolean} tail
|
|
396
|
-
* @returns {
|
|
435
|
+
* @returns {AST.TemplateElement}
|
|
397
436
|
*/
|
|
398
437
|
export function quasi(cooked, tail = false) {
|
|
399
438
|
const raw = sanitize_template_string(cooked);
|
|
400
|
-
return { type: 'TemplateElement', value: { raw, cooked }, tail };
|
|
439
|
+
return { type: 'TemplateElement', value: { raw, cooked }, tail, metadata: { path: [] } };
|
|
401
440
|
}
|
|
402
441
|
|
|
403
442
|
/**
|
|
404
|
-
* @param {
|
|
405
|
-
* @returns {
|
|
443
|
+
* @param {AST.Pattern} argument
|
|
444
|
+
* @returns {AST.RestElement}
|
|
406
445
|
*/
|
|
407
446
|
export function rest(argument) {
|
|
408
|
-
return { type: 'RestElement', argument };
|
|
447
|
+
return { type: 'RestElement', argument, metadata: { path: [] } };
|
|
409
448
|
}
|
|
410
449
|
|
|
411
450
|
/**
|
|
412
|
-
* @param {
|
|
413
|
-
* @returns {
|
|
451
|
+
* @param {AST.Expression[]} expressions
|
|
452
|
+
* @returns {AST.SequenceExpression}
|
|
414
453
|
*/
|
|
415
454
|
export function sequence(expressions) {
|
|
416
|
-
return { type: 'SequenceExpression', expressions };
|
|
455
|
+
return { type: 'SequenceExpression', expressions, metadata: { path: [] } };
|
|
417
456
|
}
|
|
418
457
|
|
|
419
458
|
/**
|
|
420
459
|
* @param {string} name
|
|
421
|
-
* @param {
|
|
422
|
-
* @returns {
|
|
460
|
+
* @param {AST.Statement[]} body
|
|
461
|
+
* @returns {AST.Property & { value: AST.FunctionExpression}}
|
|
423
462
|
*/
|
|
424
463
|
export function set(name, body) {
|
|
425
|
-
return
|
|
464
|
+
return /** @type {AST.Property & { value: AST.FunctionExpression}} */ (
|
|
465
|
+
prop('set', key(name), function_builder(null, [id('$$value')], block(body)))
|
|
466
|
+
);
|
|
426
467
|
}
|
|
427
468
|
|
|
428
469
|
/**
|
|
429
|
-
* @param {
|
|
430
|
-
* @returns {
|
|
470
|
+
* @param {AST.Expression} argument
|
|
471
|
+
* @returns {AST.SpreadElement}
|
|
431
472
|
*/
|
|
432
473
|
export function spread(argument) {
|
|
433
|
-
return { type: 'SpreadElement', argument };
|
|
474
|
+
return { type: 'SpreadElement', argument, metadata: { path: [] } };
|
|
434
475
|
}
|
|
435
476
|
|
|
436
477
|
/**
|
|
437
|
-
* @param {
|
|
438
|
-
* @returns {
|
|
478
|
+
* @param {AST.Expression} expression
|
|
479
|
+
* @returns {AST.ExpressionStatement}
|
|
439
480
|
*/
|
|
440
481
|
export function stmt(expression) {
|
|
441
|
-
return { type: 'ExpressionStatement', expression };
|
|
482
|
+
return { type: 'ExpressionStatement', expression, metadata: { path: [] } };
|
|
442
483
|
}
|
|
443
484
|
|
|
444
485
|
/**
|
|
445
|
-
* @param {
|
|
446
|
-
* @param {
|
|
447
|
-
* @returns {
|
|
486
|
+
* @param {AST.TemplateElement[]} elements
|
|
487
|
+
* @param {AST.Expression[]} expressions
|
|
488
|
+
* @returns {AST.TemplateLiteral}
|
|
448
489
|
*/
|
|
449
490
|
export function template(elements, expressions) {
|
|
450
|
-
return { type: 'TemplateLiteral', quasis: elements, expressions };
|
|
491
|
+
return { type: 'TemplateLiteral', quasis: elements, expressions, metadata: { path: [] } };
|
|
451
492
|
}
|
|
452
493
|
|
|
453
494
|
/**
|
|
454
|
-
* @param {
|
|
495
|
+
* @param {AST.Expression | AST.BlockStatement} expression
|
|
455
496
|
* @param {boolean} [async]
|
|
456
|
-
* @returns {
|
|
497
|
+
* @returns {ReturnType<typeof unthunk>}
|
|
457
498
|
*/
|
|
458
499
|
export function thunk(expression, async = false) {
|
|
459
500
|
const fn = arrow([], expression);
|
|
@@ -463,8 +504,8 @@ export function thunk(expression, async = false) {
|
|
|
463
504
|
|
|
464
505
|
/**
|
|
465
506
|
* Replace "(arg) => func(arg)" to "func"
|
|
466
|
-
* @param {
|
|
467
|
-
* @returns {
|
|
507
|
+
* @param {AST.Expression} expression
|
|
508
|
+
* @returns {AST.Expression}
|
|
468
509
|
*/
|
|
469
510
|
export function unthunk(expression) {
|
|
470
511
|
if (
|
|
@@ -474,7 +515,7 @@ export function unthunk(expression) {
|
|
|
474
515
|
expression.body.callee.type === 'Identifier' &&
|
|
475
516
|
expression.params.length === expression.body.arguments.length &&
|
|
476
517
|
expression.params.every((param, index) => {
|
|
477
|
-
const arg = /** @type {
|
|
518
|
+
const arg = /** @type {AST.SimpleCallExpression} */ (expression.body).arguments[index];
|
|
478
519
|
return param.type === 'Identifier' && arg.type === 'Identifier' && param.name === arg.name;
|
|
479
520
|
})
|
|
480
521
|
) {
|
|
@@ -485,9 +526,9 @@ export function unthunk(expression) {
|
|
|
485
526
|
|
|
486
527
|
/**
|
|
487
528
|
*
|
|
488
|
-
* @param {string |
|
|
489
|
-
* @param {...
|
|
490
|
-
* @returns {
|
|
529
|
+
* @param {string | AST.Expression} expression
|
|
530
|
+
* @param {...AST.Expression} args
|
|
531
|
+
* @returns {AST.NewExpression}
|
|
491
532
|
*/
|
|
492
533
|
function new_builder(expression, ...args) {
|
|
493
534
|
if (typeof expression === 'string') expression = id(expression);
|
|
@@ -496,64 +537,67 @@ function new_builder(expression, ...args) {
|
|
|
496
537
|
callee: expression,
|
|
497
538
|
arguments: args,
|
|
498
539
|
type: 'NewExpression',
|
|
540
|
+
metadata: { path: [] },
|
|
499
541
|
};
|
|
500
542
|
}
|
|
501
543
|
|
|
502
544
|
/**
|
|
503
|
-
* @param {
|
|
504
|
-
* @param {
|
|
545
|
+
* @param {AST.UpdateOperator} operator
|
|
546
|
+
* @param {AST.Expression} argument
|
|
505
547
|
* @param {boolean} prefix
|
|
506
|
-
* @returns {
|
|
548
|
+
* @returns {AST.UpdateExpression}
|
|
507
549
|
*/
|
|
508
550
|
export function update(operator, argument, prefix = false) {
|
|
509
|
-
return { type: 'UpdateExpression', operator, argument, prefix };
|
|
551
|
+
return { type: 'UpdateExpression', operator, argument, prefix, metadata: { path: [] } };
|
|
510
552
|
}
|
|
511
553
|
|
|
512
554
|
/**
|
|
513
|
-
* @param {
|
|
514
|
-
* @param {
|
|
515
|
-
* @returns {
|
|
555
|
+
* @param {AST.Expression} test
|
|
556
|
+
* @param {AST.Statement} body
|
|
557
|
+
* @returns {AST.DoWhileStatement}
|
|
516
558
|
*/
|
|
517
559
|
export function do_while(test, body) {
|
|
518
|
-
return { type: 'DoWhileStatement', test, body };
|
|
560
|
+
return { type: 'DoWhileStatement', test, body, metadata: { path: [] } };
|
|
519
561
|
}
|
|
520
562
|
|
|
521
563
|
const true_instance = literal(true);
|
|
522
564
|
const false_instance = literal(false);
|
|
523
|
-
const
|
|
565
|
+
const null_instance = literal(null);
|
|
524
566
|
|
|
525
|
-
/** @type {
|
|
567
|
+
/** @type {AST.DebuggerStatement} */
|
|
526
568
|
const debugger_builder = {
|
|
527
569
|
type: 'DebuggerStatement',
|
|
570
|
+
metadata: { path: [] },
|
|
528
571
|
};
|
|
529
572
|
|
|
530
|
-
/** @type {
|
|
573
|
+
/** @type {AST.ThisExpression} */
|
|
531
574
|
const this_instance = {
|
|
532
575
|
type: 'ThisExpression',
|
|
576
|
+
metadata: { path: [] },
|
|
533
577
|
};
|
|
534
578
|
|
|
535
579
|
/**
|
|
536
|
-
* @param {string |
|
|
537
|
-
* @param {
|
|
538
|
-
* @returns {
|
|
580
|
+
* @param {string | AST.Pattern} pattern
|
|
581
|
+
* @param { AST.Expression} [init]
|
|
582
|
+
* @returns {AST.VariableDeclaration}
|
|
539
583
|
*/
|
|
540
584
|
function let_builder(pattern, init) {
|
|
541
585
|
return declaration('let', [declarator(pattern, init)]);
|
|
542
586
|
}
|
|
543
587
|
|
|
544
588
|
/**
|
|
545
|
-
* @param {string |
|
|
546
|
-
* @param {
|
|
547
|
-
* @returns {
|
|
589
|
+
* @param {string | AST.Pattern} pattern
|
|
590
|
+
* @param { AST.Expression} init
|
|
591
|
+
* @returns {AST.VariableDeclaration}
|
|
548
592
|
*/
|
|
549
593
|
function const_builder(pattern, init) {
|
|
550
594
|
return declaration('const', [declarator(pattern, init)]);
|
|
551
595
|
}
|
|
552
596
|
|
|
553
597
|
/**
|
|
554
|
-
* @param {string |
|
|
555
|
-
* @param {
|
|
556
|
-
* @returns {
|
|
598
|
+
* @param {string | AST.Pattern} pattern
|
|
599
|
+
* @param { AST.Expression} [init]
|
|
600
|
+
* @returns {AST.VariableDeclaration}
|
|
557
601
|
*/
|
|
558
602
|
function var_builder(pattern, init) {
|
|
559
603
|
return declaration('var', [declarator(pattern, init)]);
|
|
@@ -561,36 +605,36 @@ function var_builder(pattern, init) {
|
|
|
561
605
|
|
|
562
606
|
/**
|
|
563
607
|
*
|
|
564
|
-
* @param {
|
|
565
|
-
* @param {
|
|
566
|
-
* @param {
|
|
567
|
-
* @param {
|
|
568
|
-
* @returns {
|
|
608
|
+
* @param {AST.VariableDeclaration | AST.Expression | null} init
|
|
609
|
+
* @param {AST.Expression} test
|
|
610
|
+
* @param {AST.Expression} update
|
|
611
|
+
* @param {AST.Statement} body
|
|
612
|
+
* @returns {AST.ForStatement}
|
|
569
613
|
*/
|
|
570
614
|
function for_builder(init, test, update, body) {
|
|
571
|
-
return { type: 'ForStatement', init, test, update, body };
|
|
615
|
+
return { type: 'ForStatement', init, test, update, body, metadata: { path: [] } };
|
|
572
616
|
}
|
|
573
617
|
|
|
574
618
|
/**
|
|
575
|
-
* @param {
|
|
576
|
-
* @param {
|
|
577
|
-
* @param {
|
|
619
|
+
* @param {AST.VariableDeclaration | AST.Pattern} left
|
|
620
|
+
* @param {AST.Expression} right
|
|
621
|
+
* @param {AST.Statement} body
|
|
578
622
|
* @param {boolean} [await_flag]
|
|
579
|
-
* @returns {
|
|
623
|
+
* @returns {AST.ForOfStatement}
|
|
580
624
|
*/
|
|
581
625
|
export function for_of(left, right, body, await_flag = false) {
|
|
582
|
-
return { type: 'ForOfStatement', left, right, body, await: await_flag };
|
|
626
|
+
return { type: 'ForOfStatement', left, right, body, await: await_flag, metadata: { path: [] } };
|
|
583
627
|
}
|
|
584
628
|
|
|
585
629
|
/**
|
|
586
630
|
*
|
|
587
631
|
* @param {'constructor' | 'method' | 'get' | 'set'} kind
|
|
588
|
-
* @param {
|
|
589
|
-
* @param {
|
|
590
|
-
* @param {
|
|
632
|
+
* @param {AST.Expression | AST.PrivateIdentifier} key
|
|
633
|
+
* @param {AST.Pattern[]} params
|
|
634
|
+
* @param {AST.Statement[]} body
|
|
591
635
|
* @param {boolean} computed
|
|
592
636
|
* @param {boolean} is_static
|
|
593
|
-
* @returns {
|
|
637
|
+
* @returns {AST.MethodDefinition}
|
|
594
638
|
*/
|
|
595
639
|
export function method(kind, key, params, body, computed = false, is_static = false) {
|
|
596
640
|
return {
|
|
@@ -600,16 +644,17 @@ export function method(kind, key, params, body, computed = false, is_static = fa
|
|
|
600
644
|
value: function_builder(null, params, block(body)),
|
|
601
645
|
computed,
|
|
602
646
|
static: is_static,
|
|
647
|
+
metadata: { path: [] },
|
|
603
648
|
};
|
|
604
649
|
}
|
|
605
650
|
|
|
606
651
|
/**
|
|
607
652
|
*
|
|
608
|
-
* @param {
|
|
609
|
-
* @param {
|
|
610
|
-
* @param {
|
|
653
|
+
* @param {AST.Identifier | null} id
|
|
654
|
+
* @param {AST.Pattern[]} params
|
|
655
|
+
* @param {AST.BlockStatement} body
|
|
611
656
|
* @param {boolean} async
|
|
612
|
-
* @returns {
|
|
657
|
+
* @returns {AST.FunctionExpression}
|
|
613
658
|
*/
|
|
614
659
|
function function_builder(id, params, body, async = false) {
|
|
615
660
|
return {
|
|
@@ -619,42 +664,46 @@ function function_builder(id, params, body, async = false) {
|
|
|
619
664
|
body,
|
|
620
665
|
generator: false,
|
|
621
666
|
async,
|
|
622
|
-
metadata:
|
|
667
|
+
metadata: { path: [] },
|
|
623
668
|
};
|
|
624
669
|
}
|
|
625
670
|
|
|
626
671
|
/**
|
|
627
|
-
* @param {
|
|
628
|
-
* @param {
|
|
629
|
-
* @param {
|
|
630
|
-
* @returns {
|
|
672
|
+
* @param {AST.Expression} test
|
|
673
|
+
* @param {AST.Statement} consequent
|
|
674
|
+
* @param {AST.Statement | null} [alternate]
|
|
675
|
+
* @returns {AST.IfStatement}
|
|
631
676
|
*/
|
|
632
677
|
function if_builder(test, consequent, alternate) {
|
|
633
|
-
return { type: 'IfStatement', test, consequent, alternate };
|
|
678
|
+
return { type: 'IfStatement', test, consequent, alternate, metadata: { path: [] } };
|
|
634
679
|
}
|
|
635
680
|
|
|
636
681
|
/**
|
|
637
682
|
* @param {string} as
|
|
638
683
|
* @param {string} source
|
|
639
|
-
* @param {Array<
|
|
640
|
-
* @
|
|
684
|
+
* @param {Array<AST.ImportAttribute>} attributes
|
|
685
|
+
* @param {AST.ImportDeclaration['importKind']} importKind
|
|
686
|
+
* @returns {AST.ImportDeclaration}
|
|
641
687
|
*/
|
|
642
|
-
export function import_all(as, source, attributes = []) {
|
|
688
|
+
export function import_all(as, source, attributes = [], importKind = 'value') {
|
|
643
689
|
return {
|
|
644
690
|
type: 'ImportDeclaration',
|
|
645
691
|
source: literal(source),
|
|
646
692
|
specifiers: [import_namespace(as)],
|
|
647
693
|
attributes,
|
|
694
|
+
importKind,
|
|
695
|
+
metadata: { path: [] },
|
|
648
696
|
};
|
|
649
697
|
}
|
|
650
698
|
|
|
651
699
|
/**
|
|
652
|
-
* @param {Array<[string, string]>} parts
|
|
700
|
+
* @param {Array<[string, string, AST.ImportDeclaration['importKind']]>} parts
|
|
653
701
|
* @param {string} source
|
|
654
|
-
* @param {Array<
|
|
655
|
-
* @
|
|
702
|
+
* @param {Array<AST.ImportAttribute>} attributes
|
|
703
|
+
* @param {AST.ImportDeclaration['importKind']} importKind
|
|
704
|
+
* @returns {AST.ImportDeclaration}
|
|
656
705
|
*/
|
|
657
|
-
export function imports(parts, source, attributes = []) {
|
|
706
|
+
export function imports(parts, source, attributes = [], importKind = 'value') {
|
|
658
707
|
return {
|
|
659
708
|
type: 'ImportDeclaration',
|
|
660
709
|
source: literal(source),
|
|
@@ -663,35 +712,40 @@ export function imports(parts, source, attributes = []) {
|
|
|
663
712
|
type: 'ImportSpecifier',
|
|
664
713
|
imported: id(p[0]),
|
|
665
714
|
local: id(p[1]),
|
|
715
|
+
importKind: p.length > 2 ? p[2] : 'value',
|
|
716
|
+
metadata: { path: [] },
|
|
666
717
|
})),
|
|
718
|
+
importKind,
|
|
719
|
+
metadata: { path: [] },
|
|
667
720
|
};
|
|
668
721
|
}
|
|
669
722
|
|
|
670
723
|
/**
|
|
671
|
-
* @param {
|
|
672
|
-
* @returns {
|
|
724
|
+
* @param {AST.Expression | null} argument
|
|
725
|
+
* @returns {AST.ReturnStatement}
|
|
673
726
|
*/
|
|
674
727
|
function return_builder(argument = null) {
|
|
675
|
-
return { type: 'ReturnStatement', argument };
|
|
728
|
+
return { type: 'ReturnStatement', argument, metadata: { path: [] } };
|
|
676
729
|
}
|
|
677
730
|
|
|
678
731
|
/**
|
|
679
732
|
* @param {string} str
|
|
680
|
-
* @returns {
|
|
733
|
+
* @returns {AST.ThrowStatement}
|
|
681
734
|
*/
|
|
682
735
|
export function throw_error(str) {
|
|
683
736
|
return {
|
|
684
737
|
type: 'ThrowStatement',
|
|
685
738
|
argument: new_builder('Error', literal(str)),
|
|
739
|
+
metadata: { path: [] },
|
|
686
740
|
};
|
|
687
741
|
}
|
|
688
742
|
|
|
689
743
|
/**
|
|
690
|
-
* @param {
|
|
691
|
-
* @param {
|
|
692
|
-
* @param {
|
|
693
|
-
* @param {
|
|
694
|
-
* @returns {
|
|
744
|
+
* @param {AST.BlockStatement} block
|
|
745
|
+
* @param {AST.CatchClause | null} handler
|
|
746
|
+
* @param {AST.BlockStatement | null} finalizer
|
|
747
|
+
* @param {AST.BlockStatement | null} pending
|
|
748
|
+
* @returns {AST.TryStatement}
|
|
695
749
|
*/
|
|
696
750
|
export function try_builder(block, handler = null, finalizer = null, pending = null) {
|
|
697
751
|
return {
|
|
@@ -700,19 +754,21 @@ export function try_builder(block, handler = null, finalizer = null, pending = n
|
|
|
700
754
|
handler,
|
|
701
755
|
finalizer,
|
|
702
756
|
pending,
|
|
757
|
+
metadata: { path: [] },
|
|
703
758
|
};
|
|
704
759
|
}
|
|
705
760
|
|
|
706
761
|
/**
|
|
707
|
-
* @param {
|
|
708
|
-
* @param {
|
|
709
|
-
* @return {
|
|
762
|
+
* @param {AST.Pattern | null} param
|
|
763
|
+
* @param {AST.BlockStatement} body
|
|
764
|
+
* @return {AST.CatchClause}
|
|
710
765
|
*/
|
|
711
766
|
export function catch_clause_builder(param, body) {
|
|
712
767
|
return {
|
|
713
768
|
type: 'CatchClause',
|
|
714
769
|
param,
|
|
715
770
|
body,
|
|
771
|
+
metadata: { path: [] },
|
|
716
772
|
};
|
|
717
773
|
}
|
|
718
774
|
|
|
@@ -720,7 +776,7 @@ export { catch_clause_builder as catch_clause };
|
|
|
720
776
|
|
|
721
777
|
/**
|
|
722
778
|
* @param {string} name
|
|
723
|
-
* @returns {
|
|
779
|
+
* @returns {AST.Expression}
|
|
724
780
|
*/
|
|
725
781
|
export function key(name) {
|
|
726
782
|
return regex_is_valid_identifier.test(name) ? id(name) : literal(name);
|
|
@@ -728,7 +784,7 @@ export function key(name) {
|
|
|
728
784
|
|
|
729
785
|
/**
|
|
730
786
|
* @param {ESTreeJSX.JSXIdentifier | ESTreeJSX.JSXNamespacedName} name
|
|
731
|
-
* @param {
|
|
787
|
+
* @param {AST.Literal | ESTreeJSX.JSXExpressionContainer | null} value
|
|
732
788
|
* @returns {ESTreeJSX.JSXAttribute}
|
|
733
789
|
*/
|
|
734
790
|
export function jsx_attribute(name, value = null) {
|
|
@@ -737,35 +793,27 @@ export function jsx_attribute(name, value = null) {
|
|
|
737
793
|
name,
|
|
738
794
|
value,
|
|
739
795
|
shorthand: false,
|
|
796
|
+
metadata: { path: [] },
|
|
740
797
|
};
|
|
741
798
|
}
|
|
742
799
|
|
|
743
800
|
/**
|
|
744
801
|
* @param {ESTreeJSX.JSXOpeningElement['name']} name
|
|
745
|
-
* @param {
|
|
802
|
+
* @param {AST.Element} node
|
|
746
803
|
* @param {ESTreeJSX.JSXOpeningElement['attributes']} attributes
|
|
747
804
|
* @param {ESTreeJSX.JSXElement['children']} children
|
|
748
|
-
* @param {
|
|
749
|
-
* @param {boolean} unclosed
|
|
750
|
-
* @param {ESTreeJSX.JSXClosingElement['name']} closing_name
|
|
805
|
+
* @param {ESTreeJSX.JSXClosingElement['name']} [closing_name]
|
|
751
806
|
* @returns {ESTreeJSX.JSXElement}
|
|
752
807
|
*/
|
|
753
|
-
export function jsx_element(
|
|
754
|
-
name,
|
|
755
|
-
loc,
|
|
756
|
-
attributes = [],
|
|
757
|
-
children = [],
|
|
758
|
-
self_closing = false,
|
|
759
|
-
unclosed = false,
|
|
760
|
-
closing_name = name,
|
|
761
|
-
) {
|
|
808
|
+
export function jsx_element(name, node, attributes = [], children = [], closing_name = name) {
|
|
762
809
|
/** @type {ESTreeJSX.JSXOpeningElement} */
|
|
763
810
|
const opening_element = {
|
|
764
811
|
type: 'JSXOpeningElement',
|
|
765
812
|
name,
|
|
766
813
|
attributes,
|
|
767
|
-
selfClosing:
|
|
768
|
-
loc: loc,
|
|
814
|
+
selfClosing: node.selfClosing ?? false,
|
|
815
|
+
loc: node.loc,
|
|
816
|
+
metadata: { path: [] },
|
|
769
817
|
};
|
|
770
818
|
|
|
771
819
|
/** @type {ESTreeJSX.JSXElement} */
|
|
@@ -774,43 +822,51 @@ export function jsx_element(
|
|
|
774
822
|
openingElement: opening_element,
|
|
775
823
|
children,
|
|
776
824
|
closingElement:
|
|
777
|
-
|
|
825
|
+
node.selfClosing || node.unclosed
|
|
778
826
|
? null
|
|
779
827
|
: {
|
|
780
828
|
type: 'JSXClosingElement',
|
|
781
829
|
name: closing_name,
|
|
782
|
-
loc,
|
|
830
|
+
loc: node.loc,
|
|
831
|
+
metadata: { path: [] },
|
|
783
832
|
},
|
|
833
|
+
metadata: { path: [] },
|
|
784
834
|
};
|
|
785
835
|
|
|
786
836
|
return element;
|
|
787
837
|
}
|
|
788
838
|
|
|
789
839
|
/**
|
|
790
|
-
* @param {
|
|
840
|
+
* @param {ESTreeJSX.JSXFragment['children']} children
|
|
841
|
+
* @param {ESTreeJSX.JSXOpeningFragment['attributes']} [attributes]
|
|
791
842
|
* @returns {ESTreeJSX.JSXFragment}
|
|
792
843
|
*/
|
|
793
|
-
export function jsx_fragment(children = []) {
|
|
844
|
+
export function jsx_fragment(children = [], attributes = []) {
|
|
794
845
|
return {
|
|
795
846
|
type: 'JSXFragment',
|
|
796
847
|
openingFragment: {
|
|
797
848
|
type: 'JSXOpeningFragment',
|
|
849
|
+
attributes,
|
|
850
|
+
metadata: { path: [] },
|
|
798
851
|
},
|
|
799
852
|
closingFragment: {
|
|
800
853
|
type: 'JSXClosingFragment',
|
|
854
|
+
metadata: { path: [] },
|
|
801
855
|
},
|
|
802
856
|
children,
|
|
857
|
+
metadata: { path: [] },
|
|
803
858
|
};
|
|
804
859
|
}
|
|
805
860
|
|
|
806
861
|
/**
|
|
807
|
-
* @param {
|
|
862
|
+
* @param {AST.Expression | ESTreeJSX.JSXEmptyExpression} expression
|
|
808
863
|
* @returns {ESTreeJSX.JSXExpressionContainer}
|
|
809
864
|
*/
|
|
810
865
|
export function jsx_expression_container(expression) {
|
|
811
866
|
return {
|
|
812
867
|
type: 'JSXExpressionContainer',
|
|
813
868
|
expression,
|
|
869
|
+
metadata: { path: [] },
|
|
814
870
|
};
|
|
815
871
|
}
|
|
816
872
|
|
|
@@ -822,6 +878,7 @@ export function jsx_id(name) {
|
|
|
822
878
|
return {
|
|
823
879
|
type: 'JSXIdentifier',
|
|
824
880
|
name,
|
|
881
|
+
metadata: { path: [] },
|
|
825
882
|
};
|
|
826
883
|
}
|
|
827
884
|
|
|
@@ -835,54 +892,59 @@ export function jsx_member(object, property) {
|
|
|
835
892
|
type: 'JSXMemberExpression',
|
|
836
893
|
object,
|
|
837
894
|
property,
|
|
895
|
+
metadata: { path: [] },
|
|
838
896
|
};
|
|
839
897
|
}
|
|
840
898
|
|
|
841
899
|
/**
|
|
842
|
-
* @param {
|
|
900
|
+
* @param {AST.Expression} argument
|
|
843
901
|
* @returns {ESTreeJSX.JSXSpreadAttribute}
|
|
844
902
|
*/
|
|
845
903
|
export function jsx_spread_attribute(argument) {
|
|
846
904
|
return {
|
|
847
905
|
type: 'JSXSpreadAttribute',
|
|
848
906
|
argument,
|
|
907
|
+
metadata: { path: [] },
|
|
849
908
|
};
|
|
850
909
|
}
|
|
851
910
|
|
|
852
911
|
/**
|
|
853
|
-
* @param {
|
|
854
|
-
* @param {
|
|
855
|
-
* @returns {
|
|
912
|
+
* @param {AST.Expression} discriminant
|
|
913
|
+
* @param {AST.SwitchCase[]} cases
|
|
914
|
+
* @returns {AST.SwitchStatement}
|
|
856
915
|
*/
|
|
857
916
|
export function switch_builder(discriminant, cases) {
|
|
858
917
|
return {
|
|
859
918
|
type: 'SwitchStatement',
|
|
860
919
|
discriminant,
|
|
861
920
|
cases,
|
|
921
|
+
metadata: { path: [] },
|
|
862
922
|
};
|
|
863
923
|
}
|
|
864
924
|
|
|
865
925
|
/**
|
|
866
|
-
* @param {
|
|
867
|
-
* @param {
|
|
868
|
-
* @returns {
|
|
926
|
+
* @param {AST.Expression | null} test
|
|
927
|
+
* @param {AST.Statement[]} consequent
|
|
928
|
+
* @returns {AST.SwitchCase}
|
|
869
929
|
*/
|
|
870
930
|
export function switch_case(test = null, consequent = []) {
|
|
871
931
|
return {
|
|
872
932
|
type: 'SwitchCase',
|
|
873
933
|
test,
|
|
874
934
|
consequent,
|
|
935
|
+
metadata: { path: [] },
|
|
875
936
|
};
|
|
876
937
|
}
|
|
877
938
|
|
|
878
939
|
export const void0 = unary('void', literal(0));
|
|
879
940
|
|
|
880
941
|
/**
|
|
881
|
-
* @
|
|
942
|
+
* @type {AST.BreakStatement}
|
|
882
943
|
*/
|
|
883
944
|
export const break_statement = {
|
|
884
945
|
type: 'BreakStatement',
|
|
885
946
|
label: null,
|
|
947
|
+
metadata: { path: [] },
|
|
886
948
|
};
|
|
887
949
|
|
|
888
950
|
export {
|
|
@@ -900,7 +962,7 @@ export {
|
|
|
900
962
|
return_builder as return,
|
|
901
963
|
if_builder as if,
|
|
902
964
|
this_instance as this,
|
|
903
|
-
|
|
965
|
+
null_instance as null,
|
|
904
966
|
debugger_builder as debugger,
|
|
905
967
|
try_builder as try,
|
|
906
968
|
new_builder as new,
|