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.
@@ -1,38 +1,38 @@
1
- /** @import * as ESTree from 'estree' */
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<ESTree.Expression | ESTree.SpreadElement | null>} elements
9
- * @returns {ESTree.ArrayExpression}
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<ESTree.Pattern | null>} elements
17
- * @returns {ESTree.ArrayPattern}
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 {ESTree.Pattern} left
25
- * @param {ESTree.Expression} right
26
- * @returns {ESTree.AssignmentPattern}
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<ESTree.Pattern>} params
34
- * @param {ESTree.BlockStatement | ESTree.Expression} body
35
- * @returns {ESTree.ArrowFunctionExpression}
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 {ESTree.Identifier} id
51
- * @param {ESTree.Pattern[]} params
52
- * @param {ESTree.BlockStatement} body
53
- * @returns {ESTree.Component}
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 {ESTree.AssignmentOperator} operator
66
- * @param {ESTree.Pattern} left
67
- * @param {ESTree.Expression} right
68
- * @returns {ESTree.AssignmentExpression}
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 & ESTree.BaseFunction} func
77
- * @returns {T & ESTree.BaseFunction}
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 {ESTree.Expression} argument
85
- * @returns {ESTree.AwaitExpression}
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 {ESTree.BinaryOperator} operator
93
- * @param {ESTree.Expression} left
94
- * @param {ESTree.Expression} right
95
- * @returns {ESTree.BinaryExpression}
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 {ESTree.Statement[]} body
103
- * @returns {ESTree.BlockStatement}
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 {ESTree.Statement[]} body
111
- * @param {ESTree.SourceLocation} loc
112
- * @returns {ESTree.BlockStatement}
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 {ESTree.Statement} body
121
- * @returns {ESTree.LabeledStatement}
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 | ESTree.Expression} callee
129
- * @param {...(ESTree.Expression | ESTree.SpreadElement | false | undefined)} args
130
- * @returns {ESTree.CallExpression}
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<ESTree.Expression | ESTree.SpreadElement>} */ (args),
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 | ESTree.Expression} callee
161
- * @param {...ESTree.Expression} args
162
- * @returns {ESTree.ChainExpression}
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 {ESTree.SimpleCallExpression} */ (call(callee, ...args));
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 {ESTree.UnaryOperator} operator
176
- * @param {ESTree.Expression} argument
177
- * @returns {ESTree.UnaryExpression}
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 {ESTree.Expression} test
185
- * @param {ESTree.Expression} consequent
186
- * @param {ESTree.Expression} alternate
187
- * @returns {ESTree.ConditionalExpression}
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 {ESTree.LogicalOperator} operator
195
- * @param {ESTree.Expression} left
196
- * @param {ESTree.Expression} right
197
- * @returns {ESTree.LogicalExpression}
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 {ESTree.VariableDeclarator[]} declarations
206
- * @returns {ESTree.VariableDeclaration}
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 {ESTree.Pattern | string} pattern
218
- * @param {ESTree.Expression} [init]
219
- * @returns {ESTree.VariableDeclarator}
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 {ESTree.EmptyStatement} */
232
+ /** @type {AST.EmptyStatement} */
227
233
  export const empty = {
228
234
  type: 'EmptyStatement',
235
+ metadata: { path: [] },
229
236
  };
230
237
 
231
238
  /**
232
- * @param {ESTree.Expression | ESTree.MaybeNamedClassDeclaration | ESTree.MaybeNamedFunctionDeclaration} declaration
233
- * @returns {ESTree.ExportDefaultDeclaration}
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 {ESTree.Declaration | null} declaration
241
- * @param {ESTree.ExportSpecifier[]} [specifiers]
242
- * @param {ESTree.ImportAttribute[]} [attributes]
243
- * @param {ESTree.Literal | null} [source]
244
- * @returns {ESTree.ExportNamedDeclaration}
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(declaration, specifiers = [], attributes = [], source = null) {
247
- return { type: 'ExportNamedDeclaration', declaration, specifiers, attributes, source };
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 {ESTree.Identifier} id
252
- * @param {ESTree.Pattern[]} params
253
- * @param {ESTree.BlockStatement} body
254
- * @returns {ESTree.FunctionDeclaration}
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: /** @type {any} */ (null), // should not be used by codegen
286
+ metadata: { path: [] },
265
287
  };
266
288
  }
267
289
 
268
290
  /**
269
291
  * @param {string} name
270
- * @param {ESTree.Statement[]} body
271
- * @returns {ESTree.Property & { value: ESTree.FunctionExpression}}}
292
+ * @param {AST.Statement[]} body
293
+ * @returns {AST.Property & { value: AST.FunctionExpression}}}
272
294
  */
273
295
  export function get(name, body) {
274
- return prop('get', key(name), function_builder(null, [], block(body)));
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 {ESTree.Identifier}
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 {ESTree.PrivateIdentifier}
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 {ESTree.ImportNamespaceSpecifier}
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 {ESTree.Expression} value
307
- * @returns {ESTree.Property}
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 | boolean | null | number | RegExp} value
315
- * @returns {ESTree.Literal}
339
+ * @param {boolean | string | number | bigint | false | RegExp | null | undefined} value
340
+ * @returns {AST.Literal}
316
341
  */
317
342
  export function literal(value) {
318
- // @ts-expect-error we don't want to muck around with bigint here
319
- return { type: 'Literal', value };
343
+ return /** @type {AST.Literal} */ ({ type: 'Literal', value, metadata: { path: [] } });
320
344
  }
321
345
 
322
346
  /**
323
- * @param {ESTree.Expression | ESTree.Super} object
324
- * @param {string | ESTree.Expression | ESTree.PrivateIdentifier} property
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 {ESTree.MemberExpression}
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 {ESTree.Identifier | ESTree.MemberExpression}
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 {ESTree.Identifier | ESTree.MemberExpression} */
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<ESTree.Property | ESTree.SpreadElement>} properties
355
- * @returns {ESTree.ObjectExpression}
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<ESTree.RestElement | ESTree.AssignmentProperty | ESTree.Property>} properties
363
- * @returns {ESTree.ObjectPattern}
386
+ * @param {Array<AST.RestElement | AST.AssignmentProperty>} properties
387
+ * @returns {AST.ObjectPattern}
364
388
  */
365
389
  export function object_pattern(properties) {
366
- // @ts-expect-error the types appear to be wrong
367
- return { type: 'ObjectPattern', properties };
390
+ return { type: 'ObjectPattern', properties, metadata: { path: [] } };
368
391
  }
369
392
 
370
393
  /**
371
- * @template {ESTree.Expression} Value
372
- * @param {'init' | 'get' | 'set'} kind
373
- * @param {ESTree.Expression} key
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 {ESTree.Property & { value: Value }}
399
+ * @returns {AST.Property}
377
400
  */
378
401
  export function prop(kind, key, value, computed = false) {
379
- return { type: 'Property', kind, key, value, method: false, shorthand: false, computed };
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 {ESTree.Expression | ESTree.PrivateIdentifier} key
384
- * @param {ESTree.Expression | null | undefined} value
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 {ESTree.PropertyDefinition}
419
+ * @returns {AST.PropertyDefinition}
388
420
  */
389
421
  export function prop_def(key, value, computed = false, is_static = false) {
390
- return { type: 'PropertyDefinition', key, value, computed, static: is_static };
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 {ESTree.TemplateElement}
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 {ESTree.Pattern} argument
405
- * @returns {ESTree.RestElement}
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 {ESTree.Expression[]} expressions
413
- * @returns {ESTree.SequenceExpression}
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 {ESTree.Statement[]} body
422
- * @returns {ESTree.Property & { value: ESTree.FunctionExpression}}
460
+ * @param {AST.Statement[]} body
461
+ * @returns {AST.Property & { value: AST.FunctionExpression}}
423
462
  */
424
463
  export function set(name, body) {
425
- return prop('set', key(name), function_builder(null, [id('$$value')], block(body)));
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 {ESTree.Expression} argument
430
- * @returns {ESTree.SpreadElement}
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 {ESTree.Expression} expression
438
- * @returns {ESTree.ExpressionStatement}
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 {ESTree.TemplateElement[]} elements
446
- * @param {ESTree.Expression[]} expressions
447
- * @returns {ESTree.TemplateLiteral}
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 {ESTree.Expression | ESTree.BlockStatement} expression
495
+ * @param {AST.Expression | AST.BlockStatement} expression
455
496
  * @param {boolean} [async]
456
- * @returns {ESTree.Expression}
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 {ESTree.Expression} expression
467
- * @returns {ESTree.Expression}
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 {ESTree.SimpleCallExpression} */ (expression.body).arguments[index];
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 | ESTree.Expression} expression
489
- * @param {...ESTree.Expression} args
490
- * @returns {ESTree.NewExpression}
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 {ESTree.UpdateOperator} operator
504
- * @param {ESTree.Expression} argument
545
+ * @param {AST.UpdateOperator} operator
546
+ * @param {AST.Expression} argument
505
547
  * @param {boolean} prefix
506
- * @returns {ESTree.UpdateExpression}
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 {ESTree.Expression} test
514
- * @param {ESTree.Statement} body
515
- * @returns {ESTree.DoWhileStatement}
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 null_instane = literal(null);
565
+ const null_instance = literal(null);
524
566
 
525
- /** @type {ESTree.DebuggerStatement} */
567
+ /** @type {AST.DebuggerStatement} */
526
568
  const debugger_builder = {
527
569
  type: 'DebuggerStatement',
570
+ metadata: { path: [] },
528
571
  };
529
572
 
530
- /** @type {ESTree.ThisExpression} */
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 | ESTree.Pattern} pattern
537
- * @param { ESTree.Expression} [init]
538
- * @returns {ESTree.VariableDeclaration}
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 | ESTree.Pattern} pattern
546
- * @param { ESTree.Expression} init
547
- * @returns {ESTree.VariableDeclaration}
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 | ESTree.Pattern} pattern
555
- * @param { ESTree.Expression} [init]
556
- * @returns {ESTree.VariableDeclaration}
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 {ESTree.VariableDeclaration | ESTree.Expression | null} init
565
- * @param {ESTree.Expression} test
566
- * @param {ESTree.Expression} update
567
- * @param {ESTree.Statement} body
568
- * @returns {ESTree.ForStatement}
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 {ESTree.VariableDeclaration | ESTree.Pattern} left
576
- * @param {ESTree.Expression} right
577
- * @param {ESTree.Statement} body
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 {ESTree.ForOfStatement}
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 {ESTree.Expression | ESTree.PrivateIdentifier} key
589
- * @param {ESTree.Pattern[]} params
590
- * @param {ESTree.Statement[]} body
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 {ESTree.MethodDefinition}
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 {ESTree.Identifier | null} id
609
- * @param {ESTree.Pattern[]} params
610
- * @param {ESTree.BlockStatement} body
653
+ * @param {AST.Identifier | null} id
654
+ * @param {AST.Pattern[]} params
655
+ * @param {AST.BlockStatement} body
611
656
  * @param {boolean} async
612
- * @returns {ESTree.FunctionExpression}
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: /** @type {any} */ (null), // should not be used by codegen
667
+ metadata: { path: [] },
623
668
  };
624
669
  }
625
670
 
626
671
  /**
627
- * @param {ESTree.Expression} test
628
- * @param {ESTree.Statement} consequent
629
- * @param {ESTree.Statement} [alternate]
630
- * @returns {ESTree.IfStatement}
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<ESTree.ImportAttribute>} attributes
640
- * @returns {ESTree.ImportDeclaration}
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<ESTree.ImportAttribute>} attributes
655
- * @returns {ESTree.ImportDeclaration}
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 {ESTree.Expression | null} argument
672
- * @returns {ESTree.ReturnStatement}
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 {ESTree.ThrowStatement}
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 {ESTree.BlockStatement} block
691
- * @param {ESTree.CatchClause | null} handler
692
- * @param {ESTree.BlockStatement | null} finalizer
693
- * @param {ESTree.BlockStatement | null} pending
694
- * @returns {ESTree.TryStatement}
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 {ESTree.Pattern | null} param
708
- * @param {ESTree.BlockStatement} body
709
- * @return {ESTree.CatchClause}
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 {ESTree.Expression}
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 {ESTree.Literal | ESTreeJSX.JSXExpressionContainer | null} value
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 {ESTree.SourceLocation} loc
802
+ * @param {AST.Element} node
746
803
  * @param {ESTreeJSX.JSXOpeningElement['attributes']} attributes
747
804
  * @param {ESTreeJSX.JSXElement['children']} children
748
- * @param {boolean} self_closing
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: self_closing,
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
- self_closing || unclosed
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 {Array<ESTreeJSX.JSXText | ESTreeJSX.JSXExpressionContainer | ESTreeJSX.JSXSpreadChild | ESTreeJSX.JSXElement | ESTreeJSX.JSXFragment>} children
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 {ESTree.Expression | ESTreeJSX.JSXEmptyExpression} expression
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 {ESTree.Expression} argument
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 {ESTree.Expression} discriminant
854
- * @param {ESTree.SwitchCase[]} cases
855
- * @returns {ESTree.SwitchStatement}
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 {ESTree.Expression | null} test
867
- * @param {ESTree.Statement[]} consequent
868
- * @returns {ESTree.SwitchCase}
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
- * @returns {ESTree.BreakStatement}
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
- null_instane as null,
965
+ null_instance as null,
904
966
  debugger_builder as debugger,
905
967
  try_builder as try,
906
968
  new_builder as new,