ripple 0.2.45 → 0.2.47
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 +1 -1
- package/src/compiler/phases/1-parse/index.js +8 -1
- package/src/compiler/phases/2-analyze/index.js +640 -650
- package/src/compiler/phases/3-transform/index.js +1877 -1813
- package/src/compiler/phases/3-transform/segments.js +2 -2
- package/src/compiler/utils.js +600 -523
- package/src/jsx-runtime.js +12 -12
- package/src/runtime/array.js +611 -609
- package/src/runtime/index.js +29 -17
- package/src/runtime/internal/client/array.js +128 -128
- package/src/runtime/internal/client/blocks.js +206 -207
- package/src/runtime/internal/client/constants.js +2 -2
- package/src/runtime/internal/client/context.js +40 -40
- package/src/runtime/internal/client/events.js +191 -191
- package/src/runtime/internal/client/for.js +355 -355
- package/src/runtime/internal/client/if.js +25 -25
- package/src/runtime/internal/client/index.js +57 -52
- package/src/runtime/internal/client/operations.js +32 -32
- package/src/runtime/internal/client/portal.js +20 -20
- package/src/runtime/internal/client/render.js +132 -132
- package/src/runtime/internal/client/runtime.js +858 -824
- package/src/runtime/internal/client/template.js +36 -36
- package/src/runtime/internal/client/try.js +113 -113
- package/src/runtime/internal/client/types.d.ts +10 -10
- package/src/runtime/internal/client/utils.js +5 -5
- package/src/runtime/map.js +139 -139
- package/src/runtime/set.js +130 -130
- package/src/utils/ast.js +189 -189
- package/src/utils/builders.js +244 -244
- package/src/utils/sanitize_template_string.js +1 -1
- package/tests/__snapshots__/composite.test.ripple.snap +1 -1
- package/tests/accessors-props.test.ripple +9 -9
- package/tests/basic.test.ripple +4 -4
- package/tests/boundaries.test.ripple +17 -17
- package/tests/composite.test.ripple +43 -72
- package/types/index.d.ts +6 -2
package/src/utils/builders.js
CHANGED
|
@@ -7,7 +7,7 @@ import { sanitize_template_string } from './sanitize_template_string.js';
|
|
|
7
7
|
* @returns {ESTree.ArrayExpression}
|
|
8
8
|
*/
|
|
9
9
|
export function array(elements = []) {
|
|
10
|
-
|
|
10
|
+
return { type: 'ArrayExpression', elements };
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -15,7 +15,7 @@ export function array(elements = []) {
|
|
|
15
15
|
* @returns {ESTree.ArrayPattern}
|
|
16
16
|
*/
|
|
17
17
|
export function array_pattern(elements) {
|
|
18
|
-
|
|
18
|
+
return { type: 'ArrayPattern', elements };
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -24,7 +24,7 @@ export function array_pattern(elements) {
|
|
|
24
24
|
* @returns {ESTree.AssignmentPattern}
|
|
25
25
|
*/
|
|
26
26
|
export function assignment_pattern(left, right) {
|
|
27
|
-
|
|
27
|
+
return { type: 'AssignmentPattern', left, right };
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -33,24 +33,24 @@ export function assignment_pattern(left, right) {
|
|
|
33
33
|
* @returns {ESTree.ArrowFunctionExpression}
|
|
34
34
|
*/
|
|
35
35
|
export function arrow(params, body, async = false) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
return {
|
|
37
|
+
type: 'ArrowFunctionExpression',
|
|
38
|
+
params,
|
|
39
|
+
body,
|
|
40
|
+
expression: body.type !== 'BlockStatement',
|
|
41
|
+
generator: false,
|
|
42
|
+
async,
|
|
43
|
+
metadata: /** @type {any} */ (null), // should not be used by codegen
|
|
44
|
+
};
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export function component(id, params, body) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
return {
|
|
49
|
+
type: 'Component',
|
|
50
|
+
id,
|
|
51
|
+
params,
|
|
52
|
+
body,
|
|
53
|
+
};
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/**
|
|
@@ -60,7 +60,7 @@ export function component(id, params, body) {
|
|
|
60
60
|
* @returns {ESTree.AssignmentExpression}
|
|
61
61
|
*/
|
|
62
62
|
export function assignment(operator, left, right) {
|
|
63
|
-
|
|
63
|
+
return { type: 'AssignmentExpression', operator, left, right };
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/**
|
|
@@ -69,7 +69,7 @@ export function assignment(operator, left, right) {
|
|
|
69
69
|
* @returns {T & ESTree.BaseFunction}
|
|
70
70
|
*/
|
|
71
71
|
export function async(func) {
|
|
72
|
-
|
|
72
|
+
return { ...func, async: true };
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
@@ -77,7 +77,7 @@ export function async(func) {
|
|
|
77
77
|
* @returns {ESTree.AwaitExpression}
|
|
78
78
|
*/
|
|
79
79
|
function await_builder(argument) {
|
|
80
|
-
|
|
80
|
+
return { type: 'AwaitExpression', argument };
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
/**
|
|
@@ -87,7 +87,7 @@ function await_builder(argument) {
|
|
|
87
87
|
* @returns {ESTree.BinaryExpression}
|
|
88
88
|
*/
|
|
89
89
|
export function binary(operator, left, right) {
|
|
90
|
-
|
|
90
|
+
return { type: 'BinaryExpression', operator, left, right };
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
/**
|
|
@@ -95,7 +95,7 @@ export function binary(operator, left, right) {
|
|
|
95
95
|
* @returns {ESTree.BlockStatement}
|
|
96
96
|
*/
|
|
97
97
|
export function block(body) {
|
|
98
|
-
|
|
98
|
+
return { type: 'BlockStatement', body };
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/**
|
|
@@ -104,7 +104,7 @@ export function block(body) {
|
|
|
104
104
|
* @returns {ESTree.LabeledStatement}
|
|
105
105
|
*/
|
|
106
106
|
export function labeled(name, body) {
|
|
107
|
-
|
|
107
|
+
return { type: 'LabeledStatement', label: id(name), body };
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
@@ -113,30 +113,30 @@ export function labeled(name, body) {
|
|
|
113
113
|
* @returns {ESTree.CallExpression}
|
|
114
114
|
*/
|
|
115
115
|
export function call(callee, ...args) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
116
|
+
if (typeof callee === 'string') callee = id(callee);
|
|
117
|
+
args = args.slice();
|
|
118
|
+
|
|
119
|
+
// replacing missing arguments with `void(0)`, unless they're at the end in which case remove them
|
|
120
|
+
let i = args.length;
|
|
121
|
+
let popping = true;
|
|
122
|
+
while (i--) {
|
|
123
|
+
if (!args[i]) {
|
|
124
|
+
if (popping) {
|
|
125
|
+
args.pop();
|
|
126
|
+
} else {
|
|
127
|
+
args[i] = void0;
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
popping = false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
type: 'CallExpression',
|
|
136
|
+
callee,
|
|
137
|
+
arguments: /** @type {Array<ESTree.Expression | ESTree.SpreadElement>} */ (args),
|
|
138
|
+
optional: false,
|
|
139
|
+
};
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/**
|
|
@@ -145,13 +145,13 @@ export function call(callee, ...args) {
|
|
|
145
145
|
* @returns {ESTree.ChainExpression}
|
|
146
146
|
*/
|
|
147
147
|
export function maybe_call(callee, ...args) {
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
const expression = /** @type {ESTree.SimpleCallExpression} */ (call(callee, ...args));
|
|
149
|
+
expression.optional = true;
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
return {
|
|
152
|
+
type: 'ChainExpression',
|
|
153
|
+
expression,
|
|
154
|
+
};
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
/**
|
|
@@ -160,7 +160,7 @@ export function maybe_call(callee, ...args) {
|
|
|
160
160
|
* @returns {ESTree.UnaryExpression}
|
|
161
161
|
*/
|
|
162
162
|
export function unary(operator, argument) {
|
|
163
|
-
|
|
163
|
+
return { type: 'UnaryExpression', argument, operator, prefix: true };
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
/**
|
|
@@ -170,7 +170,7 @@ export function unary(operator, argument) {
|
|
|
170
170
|
* @returns {ESTree.ConditionalExpression}
|
|
171
171
|
*/
|
|
172
172
|
export function conditional(test, consequent, alternate) {
|
|
173
|
-
|
|
173
|
+
return { type: 'ConditionalExpression', test, consequent, alternate };
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
/**
|
|
@@ -180,7 +180,7 @@ export function conditional(test, consequent, alternate) {
|
|
|
180
180
|
* @returns {ESTree.LogicalExpression}
|
|
181
181
|
*/
|
|
182
182
|
export function logical(operator, left, right) {
|
|
183
|
-
|
|
183
|
+
return { type: 'LogicalExpression', operator, left, right };
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
/**
|
|
@@ -189,11 +189,11 @@ export function logical(operator, left, right) {
|
|
|
189
189
|
* @returns {ESTree.VariableDeclaration}
|
|
190
190
|
*/
|
|
191
191
|
export function declaration(kind, declarations) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
192
|
+
return {
|
|
193
|
+
type: 'VariableDeclaration',
|
|
194
|
+
kind,
|
|
195
|
+
declarations,
|
|
196
|
+
};
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
/**
|
|
@@ -202,13 +202,13 @@ export function declaration(kind, declarations) {
|
|
|
202
202
|
* @returns {ESTree.VariableDeclarator}
|
|
203
203
|
*/
|
|
204
204
|
export function declarator(pattern, init) {
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
if (typeof pattern === 'string') pattern = id(pattern);
|
|
206
|
+
return { type: 'VariableDeclarator', id: pattern, init };
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
/** @type {ESTree.EmptyStatement} */
|
|
210
210
|
export const empty = {
|
|
211
|
-
|
|
211
|
+
type: 'EmptyStatement',
|
|
212
212
|
};
|
|
213
213
|
|
|
214
214
|
/**
|
|
@@ -216,7 +216,7 @@ export const empty = {
|
|
|
216
216
|
* @returns {ESTree.ExportDefaultDeclaration}
|
|
217
217
|
*/
|
|
218
218
|
export function export_default(declaration) {
|
|
219
|
-
|
|
219
|
+
return { type: 'ExportDefaultDeclaration', declaration };
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
/**
|
|
@@ -226,15 +226,15 @@ export function export_default(declaration) {
|
|
|
226
226
|
* @returns {ESTree.FunctionDeclaration}
|
|
227
227
|
*/
|
|
228
228
|
export function function_declaration(id, params, body) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
229
|
+
return {
|
|
230
|
+
type: 'FunctionDeclaration',
|
|
231
|
+
id,
|
|
232
|
+
params,
|
|
233
|
+
body,
|
|
234
|
+
generator: false,
|
|
235
|
+
async: false,
|
|
236
|
+
metadata: /** @type {any} */ (null), // should not be used by codegen
|
|
237
|
+
};
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
/**
|
|
@@ -243,7 +243,7 @@ export function function_declaration(id, params, body) {
|
|
|
243
243
|
* @returns {ESTree.Property & { value: ESTree.FunctionExpression}}}
|
|
244
244
|
*/
|
|
245
245
|
export function get(name, body) {
|
|
246
|
-
|
|
246
|
+
return prop('get', key(name), function_builder(null, [], block(body)));
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
/**
|
|
@@ -251,7 +251,7 @@ export function get(name, body) {
|
|
|
251
251
|
* @returns {ESTree.Identifier}
|
|
252
252
|
*/
|
|
253
253
|
export function id(name) {
|
|
254
|
-
|
|
254
|
+
return { type: 'Identifier', name };
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
/**
|
|
@@ -259,7 +259,7 @@ export function id(name) {
|
|
|
259
259
|
* @returns {ESTree.PrivateIdentifier}
|
|
260
260
|
*/
|
|
261
261
|
export function private_id(name) {
|
|
262
|
-
|
|
262
|
+
return { type: 'PrivateIdentifier', name };
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
/**
|
|
@@ -267,10 +267,10 @@ export function private_id(name) {
|
|
|
267
267
|
* @returns {ESTree.ImportNamespaceSpecifier}
|
|
268
268
|
*/
|
|
269
269
|
function import_namespace(local) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
270
|
+
return {
|
|
271
|
+
type: 'ImportNamespaceSpecifier',
|
|
272
|
+
local: id(local),
|
|
273
|
+
};
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
/**
|
|
@@ -279,7 +279,7 @@ function import_namespace(local) {
|
|
|
279
279
|
* @returns {ESTree.Property}
|
|
280
280
|
*/
|
|
281
281
|
export function init(name, value) {
|
|
282
|
-
|
|
282
|
+
return prop('init', key(name), value);
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
/**
|
|
@@ -287,8 +287,8 @@ export function init(name, value) {
|
|
|
287
287
|
* @returns {ESTree.Literal}
|
|
288
288
|
*/
|
|
289
289
|
export function literal(value) {
|
|
290
|
-
|
|
291
|
-
|
|
290
|
+
// @ts-expect-error we don't want to muck around with bigint here
|
|
291
|
+
return { type: 'Literal', value };
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
/**
|
|
@@ -299,11 +299,11 @@ export function literal(value) {
|
|
|
299
299
|
* @returns {ESTree.MemberExpression}
|
|
300
300
|
*/
|
|
301
301
|
export function member(object, property, computed = false, optional = false) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
302
|
+
if (typeof property === 'string') {
|
|
303
|
+
property = id(property);
|
|
304
|
+
}
|
|
305
305
|
|
|
306
|
-
|
|
306
|
+
return { type: 'MemberExpression', object, property, computed, optional };
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
/**
|
|
@@ -311,15 +311,15 @@ export function member(object, property, computed = false, optional = false) {
|
|
|
311
311
|
* @returns {ESTree.Identifier | ESTree.MemberExpression}
|
|
312
312
|
*/
|
|
313
313
|
export function member_id(path) {
|
|
314
|
-
|
|
314
|
+
const parts = path.split('.');
|
|
315
315
|
|
|
316
|
-
|
|
317
|
-
|
|
316
|
+
/** @type {ESTree.Identifier | ESTree.MemberExpression} */
|
|
317
|
+
let expression = id(parts[0]);
|
|
318
318
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
319
|
+
for (let i = 1; i < parts.length; i += 1) {
|
|
320
|
+
expression = member(expression, id(parts[i]));
|
|
321
|
+
}
|
|
322
|
+
return expression;
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
/**
|
|
@@ -327,7 +327,7 @@ export function member_id(path) {
|
|
|
327
327
|
* @returns {ESTree.ObjectExpression}
|
|
328
328
|
*/
|
|
329
329
|
export function object(properties) {
|
|
330
|
-
|
|
330
|
+
return { type: 'ObjectExpression', properties };
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
/**
|
|
@@ -335,8 +335,8 @@ export function object(properties) {
|
|
|
335
335
|
* @returns {ESTree.ObjectPattern}
|
|
336
336
|
*/
|
|
337
337
|
export function object_pattern(properties) {
|
|
338
|
-
|
|
339
|
-
|
|
338
|
+
// @ts-expect-error the types appear to be wrong
|
|
339
|
+
return { type: 'ObjectPattern', properties };
|
|
340
340
|
}
|
|
341
341
|
|
|
342
342
|
/**
|
|
@@ -348,7 +348,7 @@ export function object_pattern(properties) {
|
|
|
348
348
|
* @returns {ESTree.Property & { value: Value }}
|
|
349
349
|
*/
|
|
350
350
|
export function prop(kind, key, value, computed = false) {
|
|
351
|
-
|
|
351
|
+
return { type: 'Property', kind, key, value, method: false, shorthand: false, computed };
|
|
352
352
|
}
|
|
353
353
|
|
|
354
354
|
/**
|
|
@@ -359,7 +359,7 @@ export function prop(kind, key, value, computed = false) {
|
|
|
359
359
|
* @returns {ESTree.PropertyDefinition}
|
|
360
360
|
*/
|
|
361
361
|
export function prop_def(key, value, computed = false, is_static = false) {
|
|
362
|
-
|
|
362
|
+
return { type: 'PropertyDefinition', key, value, computed, static: is_static };
|
|
363
363
|
}
|
|
364
364
|
|
|
365
365
|
/**
|
|
@@ -368,8 +368,8 @@ export function prop_def(key, value, computed = false, is_static = false) {
|
|
|
368
368
|
* @returns {ESTree.TemplateElement}
|
|
369
369
|
*/
|
|
370
370
|
export function quasi(cooked, tail = false) {
|
|
371
|
-
|
|
372
|
-
|
|
371
|
+
const raw = sanitize_template_string(cooked);
|
|
372
|
+
return { type: 'TemplateElement', value: { raw, cooked }, tail };
|
|
373
373
|
}
|
|
374
374
|
|
|
375
375
|
/**
|
|
@@ -377,7 +377,7 @@ export function quasi(cooked, tail = false) {
|
|
|
377
377
|
* @returns {ESTree.RestElement}
|
|
378
378
|
*/
|
|
379
379
|
export function rest(argument) {
|
|
380
|
-
|
|
380
|
+
return { type: 'RestElement', argument };
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
/**
|
|
@@ -385,7 +385,7 @@ export function rest(argument) {
|
|
|
385
385
|
* @returns {ESTree.SequenceExpression}
|
|
386
386
|
*/
|
|
387
387
|
export function sequence(expressions) {
|
|
388
|
-
|
|
388
|
+
return { type: 'SequenceExpression', expressions };
|
|
389
389
|
}
|
|
390
390
|
|
|
391
391
|
/**
|
|
@@ -394,7 +394,7 @@ export function sequence(expressions) {
|
|
|
394
394
|
* @returns {ESTree.Property & { value: ESTree.FunctionExpression}}
|
|
395
395
|
*/
|
|
396
396
|
export function set(name, body) {
|
|
397
|
-
|
|
397
|
+
return prop('set', key(name), function_builder(null, [id('$$value')], block(body)));
|
|
398
398
|
}
|
|
399
399
|
|
|
400
400
|
/**
|
|
@@ -402,7 +402,7 @@ export function set(name, body) {
|
|
|
402
402
|
* @returns {ESTree.SpreadElement}
|
|
403
403
|
*/
|
|
404
404
|
export function spread(argument) {
|
|
405
|
-
|
|
405
|
+
return { type: 'SpreadElement', argument };
|
|
406
406
|
}
|
|
407
407
|
|
|
408
408
|
/**
|
|
@@ -410,7 +410,7 @@ export function spread(argument) {
|
|
|
410
410
|
* @returns {ESTree.ExpressionStatement}
|
|
411
411
|
*/
|
|
412
412
|
export function stmt(expression) {
|
|
413
|
-
|
|
413
|
+
return { type: 'ExpressionStatement', expression };
|
|
414
414
|
}
|
|
415
415
|
|
|
416
416
|
/**
|
|
@@ -419,7 +419,7 @@ export function stmt(expression) {
|
|
|
419
419
|
* @returns {ESTree.TemplateLiteral}
|
|
420
420
|
*/
|
|
421
421
|
export function template(elements, expressions) {
|
|
422
|
-
|
|
422
|
+
return { type: 'TemplateLiteral', quasis: elements, expressions };
|
|
423
423
|
}
|
|
424
424
|
|
|
425
425
|
/**
|
|
@@ -428,9 +428,9 @@ export function template(elements, expressions) {
|
|
|
428
428
|
* @returns {ESTree.Expression}
|
|
429
429
|
*/
|
|
430
430
|
export function thunk(expression, async = false) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
431
|
+
const fn = arrow([], expression);
|
|
432
|
+
if (async) fn.async = true;
|
|
433
|
+
return unthunk(fn);
|
|
434
434
|
}
|
|
435
435
|
|
|
436
436
|
/**
|
|
@@ -439,20 +439,20 @@ export function thunk(expression, async = false) {
|
|
|
439
439
|
* @returns {ESTree.Expression}
|
|
440
440
|
*/
|
|
441
441
|
export function unthunk(expression) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
442
|
+
if (
|
|
443
|
+
expression.type === 'ArrowFunctionExpression' &&
|
|
444
|
+
expression.async === false &&
|
|
445
|
+
expression.body.type === 'CallExpression' &&
|
|
446
|
+
expression.body.callee.type === 'Identifier' &&
|
|
447
|
+
expression.params.length === expression.body.arguments.length &&
|
|
448
|
+
expression.params.every((param, index) => {
|
|
449
|
+
const arg = /** @type {ESTree.SimpleCallExpression} */ (expression.body).arguments[index];
|
|
450
|
+
return param.type === 'Identifier' && arg.type === 'Identifier' && param.name === arg.name;
|
|
451
|
+
})
|
|
452
|
+
) {
|
|
453
|
+
return expression.body.callee;
|
|
454
|
+
}
|
|
455
|
+
return expression;
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
/**
|
|
@@ -462,13 +462,13 @@ export function unthunk(expression) {
|
|
|
462
462
|
* @returns {ESTree.NewExpression}
|
|
463
463
|
*/
|
|
464
464
|
function new_builder(expression, ...args) {
|
|
465
|
-
|
|
465
|
+
if (typeof expression === 'string') expression = id(expression);
|
|
466
466
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
467
|
+
return {
|
|
468
|
+
callee: expression,
|
|
469
|
+
arguments: args,
|
|
470
|
+
type: 'NewExpression',
|
|
471
|
+
};
|
|
472
472
|
}
|
|
473
473
|
|
|
474
474
|
/**
|
|
@@ -478,7 +478,7 @@ function new_builder(expression, ...args) {
|
|
|
478
478
|
* @returns {ESTree.UpdateExpression}
|
|
479
479
|
*/
|
|
480
480
|
export function update(operator, argument, prefix = false) {
|
|
481
|
-
|
|
481
|
+
return { type: 'UpdateExpression', operator, argument, prefix };
|
|
482
482
|
}
|
|
483
483
|
|
|
484
484
|
/**
|
|
@@ -487,7 +487,7 @@ export function update(operator, argument, prefix = false) {
|
|
|
487
487
|
* @returns {ESTree.DoWhileStatement}
|
|
488
488
|
*/
|
|
489
489
|
export function do_while(test, body) {
|
|
490
|
-
|
|
490
|
+
return { type: 'DoWhileStatement', test, body };
|
|
491
491
|
}
|
|
492
492
|
|
|
493
493
|
const true_instance = literal(true);
|
|
@@ -496,12 +496,12 @@ const null_instane = literal(null);
|
|
|
496
496
|
|
|
497
497
|
/** @type {ESTree.DebuggerStatement} */
|
|
498
498
|
const debugger_builder = {
|
|
499
|
-
|
|
499
|
+
type: 'DebuggerStatement',
|
|
500
500
|
};
|
|
501
501
|
|
|
502
502
|
/** @type {ESTree.ThisExpression} */
|
|
503
503
|
const this_instance = {
|
|
504
|
-
|
|
504
|
+
type: 'ThisExpression',
|
|
505
505
|
};
|
|
506
506
|
|
|
507
507
|
/**
|
|
@@ -510,7 +510,7 @@ const this_instance = {
|
|
|
510
510
|
* @returns {ESTree.VariableDeclaration}
|
|
511
511
|
*/
|
|
512
512
|
function let_builder(pattern, init) {
|
|
513
|
-
|
|
513
|
+
return declaration('let', [declarator(pattern, init)]);
|
|
514
514
|
}
|
|
515
515
|
|
|
516
516
|
/**
|
|
@@ -519,7 +519,7 @@ function let_builder(pattern, init) {
|
|
|
519
519
|
* @returns {ESTree.VariableDeclaration}
|
|
520
520
|
*/
|
|
521
521
|
function const_builder(pattern, init) {
|
|
522
|
-
|
|
522
|
+
return declaration('const', [declarator(pattern, init)]);
|
|
523
523
|
}
|
|
524
524
|
|
|
525
525
|
/**
|
|
@@ -528,7 +528,7 @@ function const_builder(pattern, init) {
|
|
|
528
528
|
* @returns {ESTree.VariableDeclaration}
|
|
529
529
|
*/
|
|
530
530
|
function var_builder(pattern, init) {
|
|
531
|
-
|
|
531
|
+
return declaration('var', [declarator(pattern, init)]);
|
|
532
532
|
}
|
|
533
533
|
|
|
534
534
|
/**
|
|
@@ -540,7 +540,7 @@ function var_builder(pattern, init) {
|
|
|
540
540
|
* @returns {ESTree.ForStatement}
|
|
541
541
|
*/
|
|
542
542
|
function for_builder(init, test, update, body) {
|
|
543
|
-
|
|
543
|
+
return { type: 'ForStatement', init, test, update, body };
|
|
544
544
|
}
|
|
545
545
|
|
|
546
546
|
/**
|
|
@@ -551,7 +551,7 @@ function for_builder(init, test, update, body) {
|
|
|
551
551
|
* @returns {ESTree.ForOfStatement}
|
|
552
552
|
*/
|
|
553
553
|
export function for_of(left, right, body, await_flag = false) {
|
|
554
|
-
|
|
554
|
+
return { type: 'ForOfStatement', left, right, body, await: await_flag };
|
|
555
555
|
}
|
|
556
556
|
|
|
557
557
|
/**
|
|
@@ -565,14 +565,14 @@ export function for_of(left, right, body, await_flag = false) {
|
|
|
565
565
|
* @returns {ESTree.MethodDefinition}
|
|
566
566
|
*/
|
|
567
567
|
export function method(kind, key, params, body, computed = false, is_static = false) {
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
568
|
+
return {
|
|
569
|
+
type: 'MethodDefinition',
|
|
570
|
+
key,
|
|
571
|
+
kind,
|
|
572
|
+
value: function_builder(null, params, block(body)),
|
|
573
|
+
computed,
|
|
574
|
+
static: is_static,
|
|
575
|
+
};
|
|
576
576
|
}
|
|
577
577
|
|
|
578
578
|
/**
|
|
@@ -583,15 +583,15 @@ export function method(kind, key, params, body, computed = false, is_static = fa
|
|
|
583
583
|
* @returns {ESTree.FunctionExpression}
|
|
584
584
|
*/
|
|
585
585
|
function function_builder(id, params, body) {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
586
|
+
return {
|
|
587
|
+
type: 'FunctionExpression',
|
|
588
|
+
id,
|
|
589
|
+
params,
|
|
590
|
+
body,
|
|
591
|
+
generator: false,
|
|
592
|
+
async: false,
|
|
593
|
+
metadata: /** @type {any} */ (null), // should not be used by codegen
|
|
594
|
+
};
|
|
595
595
|
}
|
|
596
596
|
|
|
597
597
|
/**
|
|
@@ -601,7 +601,7 @@ function function_builder(id, params, body) {
|
|
|
601
601
|
* @returns {ESTree.IfStatement}
|
|
602
602
|
*/
|
|
603
603
|
function if_builder(test, consequent, alternate) {
|
|
604
|
-
|
|
604
|
+
return { type: 'IfStatement', test, consequent, alternate };
|
|
605
605
|
}
|
|
606
606
|
|
|
607
607
|
/**
|
|
@@ -610,11 +610,11 @@ function if_builder(test, consequent, alternate) {
|
|
|
610
610
|
* @returns {ESTree.ImportDeclaration}
|
|
611
611
|
*/
|
|
612
612
|
export function import_all(as, source) {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
613
|
+
return {
|
|
614
|
+
type: 'ImportDeclaration',
|
|
615
|
+
source: literal(source),
|
|
616
|
+
specifiers: [import_namespace(as)],
|
|
617
|
+
};
|
|
618
618
|
}
|
|
619
619
|
|
|
620
620
|
/**
|
|
@@ -623,15 +623,15 @@ export function import_all(as, source) {
|
|
|
623
623
|
* @returns {ESTree.ImportDeclaration}
|
|
624
624
|
*/
|
|
625
625
|
export function imports(parts, source) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
626
|
+
return {
|
|
627
|
+
type: 'ImportDeclaration',
|
|
628
|
+
source: literal(source),
|
|
629
|
+
specifiers: parts.map((p) => ({
|
|
630
|
+
type: 'ImportSpecifier',
|
|
631
|
+
imported: id(p[0]),
|
|
632
|
+
local: id(p[1]),
|
|
633
|
+
})),
|
|
634
|
+
};
|
|
635
635
|
}
|
|
636
636
|
|
|
637
637
|
/**
|
|
@@ -639,7 +639,7 @@ export function imports(parts, source) {
|
|
|
639
639
|
* @returns {ESTree.ReturnStatement}
|
|
640
640
|
*/
|
|
641
641
|
function return_builder(argument = null) {
|
|
642
|
-
|
|
642
|
+
return { type: 'ReturnStatement', argument };
|
|
643
643
|
}
|
|
644
644
|
|
|
645
645
|
/**
|
|
@@ -647,10 +647,10 @@ function return_builder(argument = null) {
|
|
|
647
647
|
* @returns {ESTree.ThrowStatement}
|
|
648
648
|
*/
|
|
649
649
|
export function throw_error(str) {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
650
|
+
return {
|
|
651
|
+
type: 'ThrowStatement',
|
|
652
|
+
argument: new_builder('Error', literal(str)),
|
|
653
|
+
};
|
|
654
654
|
}
|
|
655
655
|
|
|
656
656
|
/**
|
|
@@ -660,12 +660,12 @@ export function throw_error(str) {
|
|
|
660
660
|
* @returns {ESTree.TryStatement}
|
|
661
661
|
*/
|
|
662
662
|
export function try_builder(block, handler = null, finalizer = null) {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
663
|
+
return {
|
|
664
|
+
type: 'TryStatement',
|
|
665
|
+
block,
|
|
666
|
+
handler,
|
|
667
|
+
finalizer,
|
|
668
|
+
};
|
|
669
669
|
}
|
|
670
670
|
|
|
671
671
|
/**
|
|
@@ -674,11 +674,11 @@ export function try_builder(block, handler = null, finalizer = null) {
|
|
|
674
674
|
* @returns {ESTree.CatchClause}
|
|
675
675
|
*/
|
|
676
676
|
export function catch_clause_builder(param, body) {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
677
|
+
return {
|
|
678
|
+
type: 'CatchClause',
|
|
679
|
+
param,
|
|
680
|
+
body,
|
|
681
|
+
};
|
|
682
682
|
}
|
|
683
683
|
|
|
684
684
|
export { catch_clause_builder as catch_clause };
|
|
@@ -688,7 +688,7 @@ export { catch_clause_builder as catch_clause };
|
|
|
688
688
|
* @returns {ESTree.Expression}
|
|
689
689
|
*/
|
|
690
690
|
export function key(name) {
|
|
691
|
-
|
|
691
|
+
return regex_is_valid_identifier.test(name) ? id(name) : literal(name);
|
|
692
692
|
}
|
|
693
693
|
|
|
694
694
|
/**
|
|
@@ -697,11 +697,11 @@ export function key(name) {
|
|
|
697
697
|
* @returns {ESTree.JSXAttribute}
|
|
698
698
|
*/
|
|
699
699
|
export function jsx_attribute(name, value = null) {
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
700
|
+
return {
|
|
701
|
+
type: 'JSXAttribute',
|
|
702
|
+
name,
|
|
703
|
+
value,
|
|
704
|
+
};
|
|
705
705
|
}
|
|
706
706
|
|
|
707
707
|
/**
|
|
@@ -712,32 +712,32 @@ export function jsx_attribute(name, value = null) {
|
|
|
712
712
|
* @returns {{ element: ESTree.JSXElement, opening_element: ESTree.JSXOpeningElement }}
|
|
713
713
|
*/
|
|
714
714
|
export function jsx_element(
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
715
|
+
name,
|
|
716
|
+
attributes = [],
|
|
717
|
+
children = [],
|
|
718
|
+
self_closing = false,
|
|
719
|
+
closing_name = name,
|
|
720
720
|
) {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
721
|
+
const opening_element = {
|
|
722
|
+
type: 'JSXOpeningElement',
|
|
723
|
+
name,
|
|
724
|
+
attributes,
|
|
725
|
+
selfClosing: self_closing,
|
|
726
|
+
};
|
|
727
727
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
728
|
+
const element = {
|
|
729
|
+
type: 'JSXElement',
|
|
730
|
+
openingElement: opening_element,
|
|
731
|
+
closingElement: self_closing
|
|
732
|
+
? null
|
|
733
|
+
: {
|
|
734
|
+
type: 'JSXClosingElement',
|
|
735
|
+
name: closing_name,
|
|
736
|
+
},
|
|
737
|
+
children,
|
|
738
|
+
};
|
|
739
739
|
|
|
740
|
-
|
|
740
|
+
return element;
|
|
741
741
|
}
|
|
742
742
|
|
|
743
743
|
/**
|
|
@@ -745,10 +745,10 @@ export function jsx_element(
|
|
|
745
745
|
* @returns {ESTree.JSXExpressionContainer}
|
|
746
746
|
*/
|
|
747
747
|
export function jsx_expression_container(expression) {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
748
|
+
return {
|
|
749
|
+
type: 'JSXExpressionContainer',
|
|
750
|
+
expression,
|
|
751
|
+
};
|
|
752
752
|
}
|
|
753
753
|
|
|
754
754
|
/**
|
|
@@ -756,10 +756,10 @@ export function jsx_expression_container(expression) {
|
|
|
756
756
|
* @returns {ESTree.JSXIdentifier}
|
|
757
757
|
*/
|
|
758
758
|
export function jsx_id(name) {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
759
|
+
return {
|
|
760
|
+
type: 'JSXIdentifier',
|
|
761
|
+
name,
|
|
762
|
+
};
|
|
763
763
|
}
|
|
764
764
|
|
|
765
765
|
/**
|
|
@@ -767,27 +767,27 @@ export function jsx_id(name) {
|
|
|
767
767
|
* @returns {ESTree.JSXSpreadAttribute}
|
|
768
768
|
*/
|
|
769
769
|
export function jsx_spread_attribute(argument) {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
770
|
+
return {
|
|
771
|
+
type: 'JSXSpreadAttribute',
|
|
772
|
+
argument,
|
|
773
|
+
};
|
|
774
774
|
}
|
|
775
775
|
|
|
776
776
|
export const void0 = unary('void', literal(0));
|
|
777
777
|
|
|
778
778
|
export {
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
779
|
+
await_builder as await,
|
|
780
|
+
let_builder as let,
|
|
781
|
+
const_builder as const,
|
|
782
|
+
var_builder as var,
|
|
783
|
+
true_instance as true,
|
|
784
|
+
false_instance as false,
|
|
785
|
+
for_builder as for,
|
|
786
|
+
function_builder as function,
|
|
787
|
+
return_builder as return,
|
|
788
|
+
if_builder as if,
|
|
789
|
+
this_instance as this,
|
|
790
|
+
null_instane as null,
|
|
791
|
+
debugger_builder as debugger,
|
|
792
|
+
try_builder as try,
|
|
793
793
|
};
|