terser 5.9.0 → 5.14.2
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/CHANGELOG.md +63 -0
- package/README.md +30 -8
- package/dist/bundle.min.js +5407 -3433
- package/lib/ast.js +1685 -348
- package/lib/cli.js +13 -9
- package/lib/compress/common.js +48 -0
- package/lib/compress/evaluate.js +18 -17
- package/lib/compress/index.js +57 -551
- package/lib/compress/inline.js +641 -0
- package/lib/compress/native-objects.js +1 -0
- package/lib/compress/tighten-body.js +1 -1
- package/lib/equivalent-to.js +81 -107
- package/lib/minify.js +96 -15
- package/lib/mozilla-ast.js +522 -87
- package/lib/output.js +94 -24
- package/lib/parse.js +91 -72
- package/lib/propmangle.js +1 -1
- package/lib/scope.js +27 -4
- package/lib/size.js +6 -8
- package/lib/sourcemap.js +60 -26
- package/lib/utils/index.js +9 -1
- package/package.json +9 -5
- package/tools/domprops.js +12 -0
- package/tools/terser.d.ts +6 -3
package/lib/mozilla-ast.js
CHANGED
@@ -41,7 +41,6 @@
|
|
41
41
|
|
42
42
|
***********************************************************************/
|
43
43
|
|
44
|
-
import * as ast from "./ast.js";
|
45
44
|
import { make_node } from "./utils/index.js";
|
46
45
|
import {
|
47
46
|
AST_Accessor,
|
@@ -158,6 +157,7 @@ import {
|
|
158
157
|
AST_With,
|
159
158
|
AST_Yield,
|
160
159
|
} from "./ast.js";
|
160
|
+
import { is_basic_identifier_string } from "./parse.js";
|
161
161
|
|
162
162
|
(function() {
|
163
163
|
|
@@ -179,6 +179,24 @@ import {
|
|
179
179
|
return body;
|
180
180
|
};
|
181
181
|
|
182
|
+
const assert_clause_from_moz = (assertions) => {
|
183
|
+
if (assertions && assertions.length > 0) {
|
184
|
+
return new AST_Object({
|
185
|
+
start: my_start_token(assertions),
|
186
|
+
end: my_end_token(assertions),
|
187
|
+
properties: assertions.map((assertion_kv) =>
|
188
|
+
new AST_ObjectKeyVal({
|
189
|
+
start: my_start_token(assertion_kv),
|
190
|
+
end: my_end_token(assertion_kv),
|
191
|
+
key: assertion_kv.key.name || assertion_kv.key.value,
|
192
|
+
value: from_moz(assertion_kv.value)
|
193
|
+
})
|
194
|
+
)
|
195
|
+
});
|
196
|
+
}
|
197
|
+
return null;
|
198
|
+
};
|
199
|
+
|
182
200
|
var MOZ_TO_ME = {
|
183
201
|
Program: function(M) {
|
184
202
|
return new AST_Toplevel({
|
@@ -187,6 +205,7 @@ import {
|
|
187
205
|
body: normalize_directives(M.body.map(from_moz))
|
188
206
|
});
|
189
207
|
},
|
208
|
+
|
190
209
|
ArrayPattern: function(M) {
|
191
210
|
return new AST_Destructuring({
|
192
211
|
start: my_start_token(M),
|
@@ -200,6 +219,7 @@ import {
|
|
200
219
|
is_array: true
|
201
220
|
});
|
202
221
|
},
|
222
|
+
|
203
223
|
ObjectPattern: function(M) {
|
204
224
|
return new AST_Destructuring({
|
205
225
|
start: my_start_token(M),
|
@@ -208,6 +228,7 @@ import {
|
|
208
228
|
is_array: false
|
209
229
|
});
|
210
230
|
},
|
231
|
+
|
211
232
|
AssignmentPattern: function(M) {
|
212
233
|
return new AST_DefaultAssign({
|
213
234
|
start: my_start_token(M),
|
@@ -217,6 +238,7 @@ import {
|
|
217
238
|
right: from_moz(M.right)
|
218
239
|
});
|
219
240
|
},
|
241
|
+
|
220
242
|
SpreadElement: function(M) {
|
221
243
|
return new AST_Expansion({
|
222
244
|
start: my_start_token(M),
|
@@ -224,6 +246,7 @@ import {
|
|
224
246
|
expression: from_moz(M.argument)
|
225
247
|
});
|
226
248
|
},
|
249
|
+
|
227
250
|
RestElement: function(M) {
|
228
251
|
return new AST_Expansion({
|
229
252
|
start: my_start_token(M),
|
@@ -231,6 +254,7 @@ import {
|
|
231
254
|
expression: from_moz(M.argument)
|
232
255
|
});
|
233
256
|
},
|
257
|
+
|
234
258
|
TemplateElement: function(M) {
|
235
259
|
return new AST_TemplateSegment({
|
236
260
|
start: my_start_token(M),
|
@@ -239,6 +263,7 @@ import {
|
|
239
263
|
raw: M.value.raw
|
240
264
|
});
|
241
265
|
},
|
266
|
+
|
242
267
|
TemplateLiteral: function(M) {
|
243
268
|
var segments = [];
|
244
269
|
for (var i = 0; i < M.quasis.length; i++) {
|
@@ -253,6 +278,7 @@ import {
|
|
253
278
|
segments: segments
|
254
279
|
});
|
255
280
|
},
|
281
|
+
|
256
282
|
TaggedTemplateExpression: function(M) {
|
257
283
|
return new AST_PrefixedTemplateString({
|
258
284
|
start: my_start_token(M),
|
@@ -261,6 +287,7 @@ import {
|
|
261
287
|
prefix: from_moz(M.tag)
|
262
288
|
});
|
263
289
|
},
|
290
|
+
|
264
291
|
FunctionDeclaration: function(M) {
|
265
292
|
return new AST_Defun({
|
266
293
|
start: my_start_token(M),
|
@@ -272,6 +299,7 @@ import {
|
|
272
299
|
body: normalize_directives(from_moz(M.body).body)
|
273
300
|
});
|
274
301
|
},
|
302
|
+
|
275
303
|
FunctionExpression: function(M) {
|
276
304
|
return new AST_Function({
|
277
305
|
start: my_start_token(M),
|
@@ -283,6 +311,7 @@ import {
|
|
283
311
|
body: normalize_directives(from_moz(M.body).body)
|
284
312
|
});
|
285
313
|
},
|
314
|
+
|
286
315
|
ArrowFunctionExpression: function(M) {
|
287
316
|
const body = M.body.type === "BlockStatement"
|
288
317
|
? from_moz(M.body).body
|
@@ -295,6 +324,7 @@ import {
|
|
295
324
|
async: M.async,
|
296
325
|
});
|
297
326
|
},
|
327
|
+
|
298
328
|
ExpressionStatement: function(M) {
|
299
329
|
return new AST_SimpleStatement({
|
300
330
|
start: my_start_token(M),
|
@@ -302,6 +332,7 @@ import {
|
|
302
332
|
body: from_moz(M.expression)
|
303
333
|
});
|
304
334
|
},
|
335
|
+
|
305
336
|
TryStatement: function(M) {
|
306
337
|
var handlers = M.handlers || [M.handler];
|
307
338
|
if (handlers.length > 1 || M.guardedHandlers && M.guardedHandlers.length) {
|
@@ -315,6 +346,7 @@ import {
|
|
315
346
|
bfinally : M.finalizer ? new AST_Finally(from_moz(M.finalizer)) : null
|
316
347
|
});
|
317
348
|
},
|
349
|
+
|
318
350
|
Property: function(M) {
|
319
351
|
var key = M.key;
|
320
352
|
var args = {
|
@@ -357,6 +389,7 @@ import {
|
|
357
389
|
return new AST_ConciseMethod(args);
|
358
390
|
}
|
359
391
|
},
|
392
|
+
|
360
393
|
MethodDefinition: function(M) {
|
361
394
|
var args = {
|
362
395
|
start : my_start_token(M),
|
@@ -375,6 +408,7 @@ import {
|
|
375
408
|
args.async = M.value.async;
|
376
409
|
return new AST_ConciseMethod(args);
|
377
410
|
},
|
411
|
+
|
378
412
|
FieldDefinition: function(M) {
|
379
413
|
let key;
|
380
414
|
if (M.computed) {
|
@@ -391,6 +425,7 @@ import {
|
|
391
425
|
static : M.static,
|
392
426
|
});
|
393
427
|
},
|
428
|
+
|
394
429
|
PropertyDefinition: function(M) {
|
395
430
|
let key;
|
396
431
|
if (M.computed) {
|
@@ -408,6 +443,7 @@ import {
|
|
408
443
|
static : M.static,
|
409
444
|
});
|
410
445
|
},
|
446
|
+
|
411
447
|
ArrayExpression: function(M) {
|
412
448
|
return new AST_Array({
|
413
449
|
start : my_start_token(M),
|
@@ -417,6 +453,7 @@ import {
|
|
417
453
|
})
|
418
454
|
});
|
419
455
|
},
|
456
|
+
|
420
457
|
ObjectExpression: function(M) {
|
421
458
|
return new AST_Object({
|
422
459
|
start : my_start_token(M),
|
@@ -430,6 +467,7 @@ import {
|
|
430
467
|
})
|
431
468
|
});
|
432
469
|
},
|
470
|
+
|
433
471
|
SequenceExpression: function(M) {
|
434
472
|
return new AST_Sequence({
|
435
473
|
start : my_start_token(M),
|
@@ -437,6 +475,7 @@ import {
|
|
437
475
|
expressions: M.expressions.map(from_moz)
|
438
476
|
});
|
439
477
|
},
|
478
|
+
|
440
479
|
MemberExpression: function(M) {
|
441
480
|
return new (M.computed ? AST_Sub : AST_Dot)({
|
442
481
|
start : my_start_token(M),
|
@@ -446,6 +485,7 @@ import {
|
|
446
485
|
optional : M.optional || false
|
447
486
|
});
|
448
487
|
},
|
488
|
+
|
449
489
|
ChainExpression: function(M) {
|
450
490
|
return new AST_Chain({
|
451
491
|
start : my_start_token(M),
|
@@ -453,6 +493,7 @@ import {
|
|
453
493
|
expression : from_moz(M.expression)
|
454
494
|
});
|
455
495
|
},
|
496
|
+
|
456
497
|
SwitchCase: function(M) {
|
457
498
|
return new (M.test ? AST_Case : AST_Default)({
|
458
499
|
start : my_start_token(M),
|
@@ -461,6 +502,7 @@ import {
|
|
461
502
|
body : M.consequent.map(from_moz)
|
462
503
|
});
|
463
504
|
},
|
505
|
+
|
464
506
|
VariableDeclaration: function(M) {
|
465
507
|
return new (M.kind === "const" ? AST_Const :
|
466
508
|
M.kind === "let" ? AST_Let : AST_Var)({
|
@@ -499,9 +541,11 @@ import {
|
|
499
541
|
end : my_end_token(M),
|
500
542
|
imported_name: imported_name,
|
501
543
|
imported_names : imported_names,
|
502
|
-
module_name : from_moz(M.source)
|
544
|
+
module_name : from_moz(M.source),
|
545
|
+
assert_clause: assert_clause_from_moz(M.assertions)
|
503
546
|
});
|
504
547
|
},
|
548
|
+
|
505
549
|
ExportAllDeclaration: function(M) {
|
506
550
|
return new AST_Export({
|
507
551
|
start: my_start_token(M),
|
@@ -512,9 +556,11 @@ import {
|
|
512
556
|
foreign_name: new AST_SymbolExportForeign({ name: "*" })
|
513
557
|
})
|
514
558
|
],
|
515
|
-
module_name: from_moz(M.source)
|
559
|
+
module_name: from_moz(M.source),
|
560
|
+
assert_clause: assert_clause_from_moz(M.assertions)
|
516
561
|
});
|
517
562
|
},
|
563
|
+
|
518
564
|
ExportNamedDeclaration: function(M) {
|
519
565
|
return new AST_Export({
|
520
566
|
start: my_start_token(M),
|
@@ -526,9 +572,11 @@ import {
|
|
526
572
|
name: from_moz(specifier.local)
|
527
573
|
});
|
528
574
|
}) : null,
|
529
|
-
module_name: from_moz(M.source)
|
575
|
+
module_name: from_moz(M.source),
|
576
|
+
assert_clause: assert_clause_from_moz(M.assertions)
|
530
577
|
});
|
531
578
|
},
|
579
|
+
|
532
580
|
ExportDefaultDeclaration: function(M) {
|
533
581
|
return new AST_Export({
|
534
582
|
start: my_start_token(M),
|
@@ -537,6 +585,7 @@ import {
|
|
537
585
|
is_default: true
|
538
586
|
});
|
539
587
|
},
|
588
|
+
|
540
589
|
Literal: function(M) {
|
541
590
|
var val = M.value, args = {
|
542
591
|
start : my_start_token(M),
|
@@ -572,6 +621,7 @@ import {
|
|
572
621
|
return new (val ? AST_True : AST_False)(args);
|
573
622
|
}
|
574
623
|
},
|
624
|
+
|
575
625
|
MetaProperty: function(M) {
|
576
626
|
if (M.meta.name === "new" && M.property.name === "target") {
|
577
627
|
return new AST_NewTarget({
|
@@ -585,6 +635,7 @@ import {
|
|
585
635
|
});
|
586
636
|
}
|
587
637
|
},
|
638
|
+
|
588
639
|
Identifier: function(M) {
|
589
640
|
var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
|
590
641
|
return new ( p.type == "LabeledStatement" ? AST_Label
|
@@ -607,12 +658,262 @@ import {
|
|
607
658
|
name : M.name
|
608
659
|
});
|
609
660
|
},
|
661
|
+
|
610
662
|
BigIntLiteral(M) {
|
611
663
|
return new AST_BigInt({
|
612
664
|
start : my_start_token(M),
|
613
665
|
end : my_end_token(M),
|
614
666
|
value : M.value
|
615
667
|
});
|
668
|
+
},
|
669
|
+
|
670
|
+
EmptyStatement: function(M) {
|
671
|
+
return new AST_EmptyStatement({
|
672
|
+
start: my_start_token(M),
|
673
|
+
end: my_end_token(M)
|
674
|
+
});
|
675
|
+
},
|
676
|
+
|
677
|
+
BlockStatement: function(M) {
|
678
|
+
return new AST_BlockStatement({
|
679
|
+
start: my_start_token(M),
|
680
|
+
end: my_end_token(M),
|
681
|
+
body: M.body.map(from_moz)
|
682
|
+
});
|
683
|
+
},
|
684
|
+
|
685
|
+
IfStatement: function(M) {
|
686
|
+
return new AST_If({
|
687
|
+
start: my_start_token(M),
|
688
|
+
end: my_end_token(M),
|
689
|
+
condition: from_moz(M.test),
|
690
|
+
body: from_moz(M.consequent),
|
691
|
+
alternative: from_moz(M.alternate)
|
692
|
+
});
|
693
|
+
},
|
694
|
+
|
695
|
+
LabeledStatement: function(M) {
|
696
|
+
return new AST_LabeledStatement({
|
697
|
+
start: my_start_token(M),
|
698
|
+
end: my_end_token(M),
|
699
|
+
label: from_moz(M.label),
|
700
|
+
body: from_moz(M.body)
|
701
|
+
});
|
702
|
+
},
|
703
|
+
|
704
|
+
BreakStatement: function(M) {
|
705
|
+
return new AST_Break({
|
706
|
+
start: my_start_token(M),
|
707
|
+
end: my_end_token(M),
|
708
|
+
label: from_moz(M.label)
|
709
|
+
});
|
710
|
+
},
|
711
|
+
|
712
|
+
ContinueStatement: function(M) {
|
713
|
+
return new AST_Continue({
|
714
|
+
start: my_start_token(M),
|
715
|
+
end: my_end_token(M),
|
716
|
+
label: from_moz(M.label)
|
717
|
+
});
|
718
|
+
},
|
719
|
+
|
720
|
+
WithStatement: function(M) {
|
721
|
+
return new AST_With({
|
722
|
+
start: my_start_token(M),
|
723
|
+
end: my_end_token(M),
|
724
|
+
expression: from_moz(M.object),
|
725
|
+
body: from_moz(M.body)
|
726
|
+
});
|
727
|
+
},
|
728
|
+
|
729
|
+
SwitchStatement: function(M) {
|
730
|
+
return new AST_Switch({
|
731
|
+
start: my_start_token(M),
|
732
|
+
end: my_end_token(M),
|
733
|
+
expression: from_moz(M.discriminant),
|
734
|
+
body: M.cases.map(from_moz)
|
735
|
+
});
|
736
|
+
},
|
737
|
+
|
738
|
+
ReturnStatement: function(M) {
|
739
|
+
return new AST_Return({
|
740
|
+
start: my_start_token(M),
|
741
|
+
end: my_end_token(M),
|
742
|
+
value: from_moz(M.argument)
|
743
|
+
});
|
744
|
+
},
|
745
|
+
|
746
|
+
ThrowStatement: function(M) {
|
747
|
+
return new AST_Throw({
|
748
|
+
start: my_start_token(M),
|
749
|
+
end: my_end_token(M),
|
750
|
+
value: from_moz(M.argument)
|
751
|
+
});
|
752
|
+
},
|
753
|
+
|
754
|
+
WhileStatement: function(M) {
|
755
|
+
return new AST_While({
|
756
|
+
start: my_start_token(M),
|
757
|
+
end: my_end_token(M),
|
758
|
+
condition: from_moz(M.test),
|
759
|
+
body: from_moz(M.body)
|
760
|
+
});
|
761
|
+
},
|
762
|
+
|
763
|
+
DoWhileStatement: function(M) {
|
764
|
+
return new AST_Do({
|
765
|
+
start: my_start_token(M),
|
766
|
+
end: my_end_token(M),
|
767
|
+
condition: from_moz(M.test),
|
768
|
+
body: from_moz(M.body)
|
769
|
+
});
|
770
|
+
},
|
771
|
+
|
772
|
+
ForStatement: function(M) {
|
773
|
+
return new AST_For({
|
774
|
+
start: my_start_token(M),
|
775
|
+
end: my_end_token(M),
|
776
|
+
init: from_moz(M.init),
|
777
|
+
condition: from_moz(M.test),
|
778
|
+
step: from_moz(M.update),
|
779
|
+
body: from_moz(M.body)
|
780
|
+
});
|
781
|
+
},
|
782
|
+
|
783
|
+
ForInStatement: function(M) {
|
784
|
+
return new AST_ForIn({
|
785
|
+
start: my_start_token(M),
|
786
|
+
end: my_end_token(M),
|
787
|
+
init: from_moz(M.left),
|
788
|
+
object: from_moz(M.right),
|
789
|
+
body: from_moz(M.body)
|
790
|
+
});
|
791
|
+
},
|
792
|
+
|
793
|
+
ForOfStatement: function(M) {
|
794
|
+
return new AST_ForOf({
|
795
|
+
start: my_start_token(M),
|
796
|
+
end: my_end_token(M),
|
797
|
+
init: from_moz(M.left),
|
798
|
+
object: from_moz(M.right),
|
799
|
+
body: from_moz(M.body),
|
800
|
+
await: M.await
|
801
|
+
});
|
802
|
+
},
|
803
|
+
|
804
|
+
AwaitExpression: function(M) {
|
805
|
+
return new AST_Await({
|
806
|
+
start: my_start_token(M),
|
807
|
+
end: my_end_token(M),
|
808
|
+
expression: from_moz(M.argument)
|
809
|
+
});
|
810
|
+
},
|
811
|
+
|
812
|
+
YieldExpression: function(M) {
|
813
|
+
return new AST_Yield({
|
814
|
+
start: my_start_token(M),
|
815
|
+
end: my_end_token(M),
|
816
|
+
expression: from_moz(M.argument),
|
817
|
+
is_star: M.delegate
|
818
|
+
});
|
819
|
+
},
|
820
|
+
|
821
|
+
DebuggerStatement: function(M) {
|
822
|
+
return new AST_Debugger({
|
823
|
+
start: my_start_token(M),
|
824
|
+
end: my_end_token(M)
|
825
|
+
});
|
826
|
+
},
|
827
|
+
|
828
|
+
VariableDeclarator: function(M) {
|
829
|
+
return new AST_VarDef({
|
830
|
+
start: my_start_token(M),
|
831
|
+
end: my_end_token(M),
|
832
|
+
name: from_moz(M.id),
|
833
|
+
value: from_moz(M.init)
|
834
|
+
});
|
835
|
+
},
|
836
|
+
|
837
|
+
CatchClause: function(M) {
|
838
|
+
return new AST_Catch({
|
839
|
+
start: my_start_token(M),
|
840
|
+
end: my_end_token(M),
|
841
|
+
argname: from_moz(M.param),
|
842
|
+
body: from_moz(M.body).body
|
843
|
+
});
|
844
|
+
},
|
845
|
+
|
846
|
+
ThisExpression: function(M) {
|
847
|
+
return new AST_This({
|
848
|
+
start: my_start_token(M),
|
849
|
+
end: my_end_token(M)
|
850
|
+
});
|
851
|
+
},
|
852
|
+
|
853
|
+
Super: function(M) {
|
854
|
+
return new AST_Super({
|
855
|
+
start: my_start_token(M),
|
856
|
+
end: my_end_token(M)
|
857
|
+
});
|
858
|
+
},
|
859
|
+
|
860
|
+
BinaryExpression: function(M) {
|
861
|
+
return new AST_Binary({
|
862
|
+
start: my_start_token(M),
|
863
|
+
end: my_end_token(M),
|
864
|
+
operator: M.operator,
|
865
|
+
left: from_moz(M.left),
|
866
|
+
right: from_moz(M.right)
|
867
|
+
});
|
868
|
+
},
|
869
|
+
|
870
|
+
LogicalExpression: function(M) {
|
871
|
+
return new AST_Binary({
|
872
|
+
start: my_start_token(M),
|
873
|
+
end: my_end_token(M),
|
874
|
+
operator: M.operator,
|
875
|
+
left: from_moz(M.left),
|
876
|
+
right: from_moz(M.right)
|
877
|
+
});
|
878
|
+
},
|
879
|
+
|
880
|
+
AssignmentExpression: function(M) {
|
881
|
+
return new AST_Assign({
|
882
|
+
start: my_start_token(M),
|
883
|
+
end: my_end_token(M),
|
884
|
+
operator: M.operator,
|
885
|
+
left: from_moz(M.left),
|
886
|
+
right: from_moz(M.right)
|
887
|
+
});
|
888
|
+
},
|
889
|
+
|
890
|
+
ConditionalExpression: function(M) {
|
891
|
+
return new AST_Conditional({
|
892
|
+
start: my_start_token(M),
|
893
|
+
end: my_end_token(M),
|
894
|
+
condition: from_moz(M.test),
|
895
|
+
consequent: from_moz(M.consequent),
|
896
|
+
alternative: from_moz(M.alternate)
|
897
|
+
});
|
898
|
+
},
|
899
|
+
|
900
|
+
NewExpression: function(M) {
|
901
|
+
return new AST_New({
|
902
|
+
start: my_start_token(M),
|
903
|
+
end: my_end_token(M),
|
904
|
+
expression: from_moz(M.callee),
|
905
|
+
args: M.arguments.map(from_moz)
|
906
|
+
});
|
907
|
+
},
|
908
|
+
|
909
|
+
CallExpression: function(M) {
|
910
|
+
return new AST_Call({
|
911
|
+
start: my_start_token(M),
|
912
|
+
end: my_end_token(M),
|
913
|
+
expression: from_moz(M.callee),
|
914
|
+
optional: M.optional,
|
915
|
+
args: M.arguments.map(from_moz)
|
916
|
+
});
|
616
917
|
}
|
617
918
|
};
|
618
919
|
|
@@ -639,35 +940,200 @@ import {
|
|
639
940
|
});
|
640
941
|
};
|
641
942
|
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
943
|
+
def_to_moz(AST_EmptyStatement, function To_Moz_EmptyStatement() {
|
944
|
+
return {
|
945
|
+
type: "EmptyStatement"
|
946
|
+
};
|
947
|
+
});
|
948
|
+
def_to_moz(AST_BlockStatement, function To_Moz_BlockStatement(M) {
|
949
|
+
return {
|
950
|
+
type: "BlockStatement",
|
951
|
+
body: M.body.map(to_moz)
|
952
|
+
};
|
953
|
+
});
|
954
|
+
def_to_moz(AST_If, function To_Moz_IfStatement(M) {
|
955
|
+
return {
|
956
|
+
type: "IfStatement",
|
957
|
+
test: to_moz(M.condition),
|
958
|
+
consequent: to_moz(M.body),
|
959
|
+
alternate: to_moz(M.alternative)
|
960
|
+
};
|
961
|
+
});
|
962
|
+
def_to_moz(AST_LabeledStatement, function To_Moz_LabeledStatement(M) {
|
963
|
+
return {
|
964
|
+
type: "LabeledStatement",
|
965
|
+
label: to_moz(M.label),
|
966
|
+
body: to_moz(M.body)
|
967
|
+
};
|
968
|
+
});
|
969
|
+
def_to_moz(AST_Break, function To_Moz_BreakStatement(M) {
|
970
|
+
return {
|
971
|
+
type: "BreakStatement",
|
972
|
+
label: to_moz(M.label)
|
973
|
+
};
|
974
|
+
});
|
975
|
+
def_to_moz(AST_Continue, function To_Moz_ContinueStatement(M) {
|
976
|
+
return {
|
977
|
+
type: "ContinueStatement",
|
978
|
+
label: to_moz(M.label)
|
979
|
+
};
|
980
|
+
});
|
981
|
+
def_to_moz(AST_With, function To_Moz_WithStatement(M) {
|
982
|
+
return {
|
983
|
+
type: "WithStatement",
|
984
|
+
object: to_moz(M.expression),
|
985
|
+
body: to_moz(M.body)
|
986
|
+
};
|
987
|
+
});
|
988
|
+
def_to_moz(AST_Switch, function To_Moz_SwitchStatement(M) {
|
989
|
+
return {
|
990
|
+
type: "SwitchStatement",
|
991
|
+
discriminant: to_moz(M.expression),
|
992
|
+
cases: M.body.map(to_moz)
|
993
|
+
};
|
994
|
+
});
|
995
|
+
def_to_moz(AST_Return, function To_Moz_ReturnStatement(M) {
|
996
|
+
return {
|
997
|
+
type: "ReturnStatement",
|
998
|
+
argument: to_moz(M.value)
|
999
|
+
};
|
1000
|
+
});
|
1001
|
+
def_to_moz(AST_Throw, function To_Moz_ThrowStatement(M) {
|
1002
|
+
return {
|
1003
|
+
type: "ThrowStatement",
|
1004
|
+
argument: to_moz(M.value)
|
1005
|
+
};
|
1006
|
+
});
|
1007
|
+
def_to_moz(AST_While, function To_Moz_WhileStatement(M) {
|
1008
|
+
return {
|
1009
|
+
type: "WhileStatement",
|
1010
|
+
test: to_moz(M.condition),
|
1011
|
+
body: to_moz(M.body)
|
1012
|
+
};
|
1013
|
+
});
|
1014
|
+
def_to_moz(AST_Do, function To_Moz_DoWhileStatement(M) {
|
1015
|
+
return {
|
1016
|
+
type: "DoWhileStatement",
|
1017
|
+
test: to_moz(M.condition),
|
1018
|
+
body: to_moz(M.body)
|
1019
|
+
};
|
1020
|
+
});
|
1021
|
+
def_to_moz(AST_For, function To_Moz_ForStatement(M) {
|
1022
|
+
return {
|
1023
|
+
type: "ForStatement",
|
1024
|
+
init: to_moz(M.init),
|
1025
|
+
test: to_moz(M.condition),
|
1026
|
+
update: to_moz(M.step),
|
1027
|
+
body: to_moz(M.body)
|
1028
|
+
};
|
1029
|
+
});
|
1030
|
+
def_to_moz(AST_ForIn, function To_Moz_ForInStatement(M) {
|
1031
|
+
return {
|
1032
|
+
type: "ForInStatement",
|
1033
|
+
left: to_moz(M.init),
|
1034
|
+
right: to_moz(M.object),
|
1035
|
+
body: to_moz(M.body)
|
1036
|
+
};
|
1037
|
+
});
|
1038
|
+
def_to_moz(AST_ForOf, function To_Moz_ForOfStatement(M) {
|
1039
|
+
return {
|
1040
|
+
type: "ForOfStatement",
|
1041
|
+
left: to_moz(M.init),
|
1042
|
+
right: to_moz(M.object),
|
1043
|
+
body: to_moz(M.body),
|
1044
|
+
await: M.await
|
1045
|
+
};
|
1046
|
+
});
|
1047
|
+
def_to_moz(AST_Await, function To_Moz_AwaitExpression(M) {
|
1048
|
+
return {
|
1049
|
+
type: "AwaitExpression",
|
1050
|
+
argument: to_moz(M.expression)
|
1051
|
+
};
|
1052
|
+
});
|
1053
|
+
def_to_moz(AST_Yield, function To_Moz_YieldExpression(M) {
|
1054
|
+
return {
|
1055
|
+
type: "YieldExpression",
|
1056
|
+
argument: to_moz(M.expression),
|
1057
|
+
delegate: M.is_star
|
1058
|
+
};
|
1059
|
+
});
|
1060
|
+
def_to_moz(AST_Debugger, function To_Moz_DebuggerStatement() {
|
1061
|
+
return {
|
1062
|
+
type: "DebuggerStatement"
|
1063
|
+
};
|
1064
|
+
});
|
1065
|
+
def_to_moz(AST_VarDef, function To_Moz_VariableDeclarator(M) {
|
1066
|
+
return {
|
1067
|
+
type: "VariableDeclarator",
|
1068
|
+
id: to_moz(M.name),
|
1069
|
+
init: to_moz(M.value)
|
1070
|
+
};
|
1071
|
+
});
|
1072
|
+
def_to_moz(AST_Catch, function To_Moz_CatchClause(M) {
|
1073
|
+
return {
|
1074
|
+
type: "CatchClause",
|
1075
|
+
param: to_moz(M.argname),
|
1076
|
+
body: to_moz_block(M)
|
1077
|
+
};
|
1078
|
+
});
|
1079
|
+
|
1080
|
+
def_to_moz(AST_This, function To_Moz_ThisExpression() {
|
1081
|
+
return {
|
1082
|
+
type: "ThisExpression"
|
1083
|
+
};
|
1084
|
+
});
|
1085
|
+
def_to_moz(AST_Super, function To_Moz_Super() {
|
1086
|
+
return {
|
1087
|
+
type: "Super"
|
1088
|
+
};
|
1089
|
+
});
|
1090
|
+
def_to_moz(AST_Binary, function To_Moz_BinaryExpression(M) {
|
1091
|
+
return {
|
1092
|
+
type: "BinaryExpression",
|
1093
|
+
operator: M.operator,
|
1094
|
+
left: to_moz(M.left),
|
1095
|
+
right: to_moz(M.right)
|
1096
|
+
};
|
1097
|
+
});
|
1098
|
+
def_to_moz(AST_Binary, function To_Moz_LogicalExpression(M) {
|
1099
|
+
return {
|
1100
|
+
type: "LogicalExpression",
|
1101
|
+
operator: M.operator,
|
1102
|
+
left: to_moz(M.left),
|
1103
|
+
right: to_moz(M.right)
|
1104
|
+
};
|
1105
|
+
});
|
1106
|
+
def_to_moz(AST_Assign, function To_Moz_AssignmentExpression(M) {
|
1107
|
+
return {
|
1108
|
+
type: "AssignmentExpression",
|
1109
|
+
operator: M.operator,
|
1110
|
+
left: to_moz(M.left),
|
1111
|
+
right: to_moz(M.right)
|
1112
|
+
};
|
1113
|
+
});
|
1114
|
+
def_to_moz(AST_Conditional, function To_Moz_ConditionalExpression(M) {
|
1115
|
+
return {
|
1116
|
+
type: "ConditionalExpression",
|
1117
|
+
test: to_moz(M.condition),
|
1118
|
+
consequent: to_moz(M.consequent),
|
1119
|
+
alternate: to_moz(M.alternative)
|
1120
|
+
};
|
1121
|
+
});
|
1122
|
+
def_to_moz(AST_New, function To_Moz_NewExpression(M) {
|
1123
|
+
return {
|
1124
|
+
type: "NewExpression",
|
1125
|
+
callee: to_moz(M.expression),
|
1126
|
+
arguments: M.args.map(to_moz)
|
1127
|
+
};
|
1128
|
+
});
|
1129
|
+
def_to_moz(AST_Call, function To_Moz_CallExpression(M) {
|
1130
|
+
return {
|
1131
|
+
type: "CallExpression",
|
1132
|
+
callee: to_moz(M.expression),
|
1133
|
+
optional: M.optional,
|
1134
|
+
arguments: M.args.map(to_moz)
|
1135
|
+
};
|
1136
|
+
});
|
671
1137
|
|
672
1138
|
def_to_moz(AST_Toplevel, function To_Moz_Program(M) {
|
673
1139
|
return to_moz_scope("Program", M);
|
@@ -818,12 +1284,30 @@ import {
|
|
818
1284
|
};
|
819
1285
|
});
|
820
1286
|
|
1287
|
+
const assert_clause_to_moz = assert_clause => {
|
1288
|
+
const assertions = [];
|
1289
|
+
if (assert_clause) {
|
1290
|
+
for (const { key, value } of assert_clause.properties) {
|
1291
|
+
const key_moz = is_basic_identifier_string(key)
|
1292
|
+
? { type: "Identifier", name: key }
|
1293
|
+
: { type: "Literal", value: key, raw: JSON.stringify(key) };
|
1294
|
+
assertions.push({
|
1295
|
+
type: "ImportAttribute",
|
1296
|
+
key: key_moz,
|
1297
|
+
value: to_moz(value)
|
1298
|
+
});
|
1299
|
+
}
|
1300
|
+
}
|
1301
|
+
return assertions;
|
1302
|
+
};
|
1303
|
+
|
821
1304
|
def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {
|
822
1305
|
if (M.exported_names) {
|
823
1306
|
if (M.exported_names[0].name.name === "*") {
|
824
1307
|
return {
|
825
1308
|
type: "ExportAllDeclaration",
|
826
|
-
source: to_moz(M.module_name)
|
1309
|
+
source: to_moz(M.module_name),
|
1310
|
+
assertions: assert_clause_to_moz(M.assert_clause)
|
827
1311
|
};
|
828
1312
|
}
|
829
1313
|
return {
|
@@ -836,7 +1320,8 @@ import {
|
|
836
1320
|
};
|
837
1321
|
}),
|
838
1322
|
declaration: to_moz(M.exported_definition),
|
839
|
-
source: to_moz(M.module_name)
|
1323
|
+
source: to_moz(M.module_name),
|
1324
|
+
assertions: assert_clause_to_moz(M.assert_clause)
|
840
1325
|
};
|
841
1326
|
}
|
842
1327
|
return {
|
@@ -870,7 +1355,8 @@ import {
|
|
870
1355
|
return {
|
871
1356
|
type: "ImportDeclaration",
|
872
1357
|
specifiers: specifiers,
|
873
|
-
source: to_moz(M.module_name)
|
1358
|
+
source: to_moz(M.module_name),
|
1359
|
+
assertions: assert_clause_to_moz(M.assert_clause)
|
874
1360
|
};
|
875
1361
|
});
|
876
1362
|
|
@@ -1198,57 +1684,6 @@ import {
|
|
1198
1684
|
);
|
1199
1685
|
}
|
1200
1686
|
|
1201
|
-
function map(moztype, mytype, propmap) {
|
1202
|
-
var moz_to_me = "function From_Moz_" + moztype + "(M){\n";
|
1203
|
-
moz_to_me += "return new U2." + mytype.name + "({\n" +
|
1204
|
-
"start: my_start_token(M),\n" +
|
1205
|
-
"end: my_end_token(M)";
|
1206
|
-
|
1207
|
-
var me_to_moz = "function To_Moz_" + moztype + "(M){\n";
|
1208
|
-
me_to_moz += "return {\n" +
|
1209
|
-
"type: " + JSON.stringify(moztype);
|
1210
|
-
|
1211
|
-
if (propmap) propmap.split(/\s*,\s*/).forEach(function(prop) {
|
1212
|
-
var m = /([a-z0-9$_]+)([=@>%])([a-z0-9$_]+)/i.exec(prop);
|
1213
|
-
if (!m) throw new Error("Can't understand property map: " + prop);
|
1214
|
-
var moz = m[1], how = m[2], my = m[3];
|
1215
|
-
moz_to_me += ",\n" + my + ": ";
|
1216
|
-
me_to_moz += ",\n" + moz + ": ";
|
1217
|
-
switch (how) {
|
1218
|
-
case "@":
|
1219
|
-
moz_to_me += "M." + moz + ".map(from_moz)";
|
1220
|
-
me_to_moz += "M." + my + ".map(to_moz)";
|
1221
|
-
break;
|
1222
|
-
case ">":
|
1223
|
-
moz_to_me += "from_moz(M." + moz + ")";
|
1224
|
-
me_to_moz += "to_moz(M." + my + ")";
|
1225
|
-
break;
|
1226
|
-
case "=":
|
1227
|
-
moz_to_me += "M." + moz;
|
1228
|
-
me_to_moz += "M." + my;
|
1229
|
-
break;
|
1230
|
-
case "%":
|
1231
|
-
moz_to_me += "from_moz(M." + moz + ").body";
|
1232
|
-
me_to_moz += "to_moz_block(M)";
|
1233
|
-
break;
|
1234
|
-
default:
|
1235
|
-
throw new Error("Can't understand operator in propmap: " + prop);
|
1236
|
-
}
|
1237
|
-
});
|
1238
|
-
|
1239
|
-
moz_to_me += "\n})\n}";
|
1240
|
-
me_to_moz += "\n}\n}";
|
1241
|
-
|
1242
|
-
moz_to_me = new Function("U2", "my_start_token", "my_end_token", "from_moz", "return(" + moz_to_me + ")")(
|
1243
|
-
ast, my_start_token, my_end_token, from_moz
|
1244
|
-
);
|
1245
|
-
me_to_moz = new Function("to_moz", "to_moz_block", "to_moz_scope", "return(" + me_to_moz + ")")(
|
1246
|
-
to_moz, to_moz_block, to_moz_scope
|
1247
|
-
);
|
1248
|
-
MOZ_TO_ME[moztype] = moz_to_me;
|
1249
|
-
def_to_moz(mytype, me_to_moz);
|
1250
|
-
}
|
1251
|
-
|
1252
1687
|
var FROM_MOZ_STACK = null;
|
1253
1688
|
|
1254
1689
|
function from_moz(node) {
|