terser 3.7.6 → 3.8.1
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.
Potentially problematic release.
This version of terser might be problematic. Click here for more details.
- package/README.md +55 -15
- package/bin/uglifyjs +19 -7
- package/dist/.gitkeep +0 -0
- package/dist/browser.bundle.js +11960 -0
- package/dist/browser.bundle.js.map +1 -0
- package/lib/ast.js +46 -47
- package/lib/compress.js +309 -254
- package/lib/minify.js +1 -1
- package/lib/mozilla-ast.js +31 -31
- package/lib/output.js +217 -213
- package/lib/parse.js +128 -108
- package/lib/propmangle.js +4 -4
- package/lib/scope.js +19 -19
- package/lib/sourcemap.js +3 -3
- package/lib/transform.js +37 -37
- package/lib/utils.js +29 -29
- package/package.json +35 -6
- package/tools/colorless-console.js +3 -2
- package/tools/exports.js +3 -3
package/lib/output.js
CHANGED
@@ -66,7 +66,6 @@ function OutputStream(options) {
|
|
66
66
|
keep_quoted_props: false,
|
67
67
|
max_line_len : false,
|
68
68
|
preamble : null,
|
69
|
-
preserve_line : false,
|
70
69
|
quote_keys : false,
|
71
70
|
quote_style : 0,
|
72
71
|
safari10 : false,
|
@@ -149,7 +148,7 @@ function OutputStream(options) {
|
|
149
148
|
function make_string(str, quote) {
|
150
149
|
var dq = 0, sq = 0;
|
151
150
|
str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g,
|
152
|
-
function(s, i){
|
151
|
+
function(s, i) {
|
153
152
|
switch (s) {
|
154
153
|
case '"': ++dq; return '"';
|
155
154
|
case "'": ++sq; return "'";
|
@@ -175,7 +174,7 @@ function OutputStream(options) {
|
|
175
174
|
return '"' + str.replace(/\x22/g, '\\"') + '"';
|
176
175
|
}
|
177
176
|
function quote_template() {
|
178
|
-
return
|
177
|
+
return "`" + str.replace(/`/g, "\\`") + "`";
|
179
178
|
}
|
180
179
|
str = to_utf8(str);
|
181
180
|
if (quote === "`") return quote_template();
|
@@ -189,7 +188,7 @@ function OutputStream(options) {
|
|
189
188
|
default:
|
190
189
|
return dq > sq ? quote_single() : quote_double();
|
191
190
|
}
|
192
|
-
}
|
191
|
+
}
|
193
192
|
|
194
193
|
function encode_string(str, quote) {
|
195
194
|
var ret = make_string(str, quote);
|
@@ -199,20 +198,21 @@ function OutputStream(options) {
|
|
199
198
|
ret = ret.replace(/--\x3e/g, "--\\x3e");
|
200
199
|
}
|
201
200
|
return ret;
|
202
|
-
}
|
201
|
+
}
|
203
202
|
|
204
203
|
function make_name(name) {
|
205
204
|
name = name.toString();
|
206
205
|
name = to_utf8(name, true);
|
207
206
|
return name;
|
208
|
-
}
|
207
|
+
}
|
209
208
|
|
210
209
|
function make_indent(back) {
|
211
210
|
return repeat_string(" ", options.indent_start + indentation - back * options.indent_level);
|
212
|
-
}
|
211
|
+
}
|
213
212
|
|
214
213
|
/* -----[ beautification/minification ]----- */
|
215
214
|
|
215
|
+
var has_parens = false;
|
216
216
|
var might_need_space = false;
|
217
217
|
var might_need_semicolon = false;
|
218
218
|
var might_add_newline = 0;
|
@@ -232,14 +232,14 @@ function OutputStream(options) {
|
|
232
232
|
!mapping.name && mapping.token.type == "name" ? mapping.token.value : mapping.name
|
233
233
|
);
|
234
234
|
} catch(ex) {
|
235
|
-
AST_Node.warn("Couldn't figure out mapping for {file}:{line},{col} → {cline},{ccol} [{name}]", {
|
235
|
+
mapping.token.file != null && AST_Node.warn("Couldn't figure out mapping for {file}:{line},{col} → {cline},{ccol} [{name}]", {
|
236
236
|
file: mapping.token.file,
|
237
237
|
line: mapping.token.line,
|
238
238
|
col: mapping.token.col,
|
239
239
|
cline: mapping.line,
|
240
240
|
ccol: mapping.col,
|
241
241
|
name: mapping.name || ""
|
242
|
-
})
|
242
|
+
});
|
243
243
|
}
|
244
244
|
});
|
245
245
|
mappings = [];
|
@@ -320,18 +320,6 @@ function OutputStream(options) {
|
|
320
320
|
}
|
321
321
|
}
|
322
322
|
|
323
|
-
if (!options.beautify && options.preserve_line && stack[stack.length - 1]) {
|
324
|
-
var target_line = stack[stack.length - 1].start.line;
|
325
|
-
while (current_line < target_line) {
|
326
|
-
ensure_line_len();
|
327
|
-
OUTPUT += "\n";
|
328
|
-
current_pos++;
|
329
|
-
current_line++;
|
330
|
-
current_col = 0;
|
331
|
-
might_need_space = false;
|
332
|
-
}
|
333
|
-
}
|
334
|
-
|
335
323
|
if (might_need_space) {
|
336
324
|
if ((is_identifier_char(prev)
|
337
325
|
&& (is_identifier_char(ch) || ch == "\\"))
|
@@ -357,6 +345,7 @@ function OutputStream(options) {
|
|
357
345
|
}
|
358
346
|
|
359
347
|
OUTPUT += str;
|
348
|
+
has_parens = str[str.length - 1] == "(";
|
360
349
|
current_pos += str.length;
|
361
350
|
var a = str.split(/\r?\n/), n = a.length - 1;
|
362
351
|
current_line += n;
|
@@ -366,11 +355,11 @@ function OutputStream(options) {
|
|
366
355
|
current_col = a[n].length;
|
367
356
|
}
|
368
357
|
last = str;
|
369
|
-
}
|
358
|
+
}
|
370
359
|
|
371
|
-
var star = function(){
|
360
|
+
var star = function() {
|
372
361
|
print("*");
|
373
|
-
}
|
362
|
+
};
|
374
363
|
|
375
364
|
var space = options.beautify ? function() {
|
376
365
|
print(" ");
|
@@ -391,7 +380,7 @@ function OutputStream(options) {
|
|
391
380
|
var ret = cont();
|
392
381
|
indentation = save_indentation;
|
393
382
|
return ret;
|
394
|
-
} : function(col, cont) { return cont() };
|
383
|
+
} : function(col, cont) { return cont(); };
|
395
384
|
|
396
385
|
var newline = options.beautify ? function() {
|
397
386
|
if (newline_insert < 0) return print("\n");
|
@@ -415,23 +404,23 @@ function OutputStream(options) {
|
|
415
404
|
function force_semicolon() {
|
416
405
|
might_need_semicolon = false;
|
417
406
|
print(";");
|
418
|
-
}
|
407
|
+
}
|
419
408
|
|
420
409
|
function next_indent() {
|
421
410
|
return indentation + options.indent_level;
|
422
|
-
}
|
411
|
+
}
|
423
412
|
|
424
413
|
function with_block(cont) {
|
425
414
|
var ret;
|
426
415
|
print("{");
|
427
416
|
newline();
|
428
|
-
with_indent(next_indent(), function(){
|
417
|
+
with_indent(next_indent(), function() {
|
429
418
|
ret = cont();
|
430
419
|
});
|
431
420
|
indent();
|
432
421
|
print("}");
|
433
422
|
return ret;
|
434
|
-
}
|
423
|
+
}
|
435
424
|
|
436
425
|
function with_parens(cont) {
|
437
426
|
print("(");
|
@@ -440,7 +429,7 @@ function OutputStream(options) {
|
|
440
429
|
var ret = cont();
|
441
430
|
print(")");
|
442
431
|
return ret;
|
443
|
-
}
|
432
|
+
}
|
444
433
|
|
445
434
|
function with_square(cont) {
|
446
435
|
print("[");
|
@@ -448,17 +437,17 @@ function OutputStream(options) {
|
|
448
437
|
var ret = cont();
|
449
438
|
print("]");
|
450
439
|
return ret;
|
451
|
-
}
|
440
|
+
}
|
452
441
|
|
453
442
|
function comma() {
|
454
443
|
print(",");
|
455
444
|
space();
|
456
|
-
}
|
445
|
+
}
|
457
446
|
|
458
447
|
function colon() {
|
459
448
|
print(":");
|
460
449
|
space();
|
461
|
-
}
|
450
|
+
}
|
462
451
|
|
463
452
|
var add_mapping = mappings ? function(token, name) {
|
464
453
|
mapping_token = token;
|
@@ -470,7 +459,7 @@ function OutputStream(options) {
|
|
470
459
|
ensure_line_len();
|
471
460
|
}
|
472
461
|
return OUTPUT;
|
473
|
-
}
|
462
|
+
}
|
474
463
|
|
475
464
|
function has_nlb() {
|
476
465
|
var index = OUTPUT.lastIndexOf("\n");
|
@@ -538,11 +527,11 @@ function OutputStream(options) {
|
|
538
527
|
}
|
539
528
|
}
|
540
529
|
if (/comment[134]/.test(c.type)) {
|
541
|
-
print("//" + c.value.replace(/[@#]__PURE__/g,
|
530
|
+
print("//" + c.value.replace(/[@#]__PURE__/g, " ") + "\n");
|
542
531
|
indent();
|
543
532
|
last_nlb = true;
|
544
533
|
} else if (c.type == "comment2") {
|
545
|
-
print("/*" + c.value.replace(/[@#]__PURE__/g,
|
534
|
+
print("/*" + c.value.replace(/[@#]__PURE__/g, " ") + "*/");
|
546
535
|
last_nlb = false;
|
547
536
|
}
|
548
537
|
});
|
@@ -580,10 +569,10 @@ function OutputStream(options) {
|
|
580
569
|
space();
|
581
570
|
}
|
582
571
|
if (/comment[134]/.test(c.type)) {
|
583
|
-
print("//" + c.value.replace(/[@#]__PURE__/g,
|
572
|
+
print("//" + c.value.replace(/[@#]__PURE__/g, " "));
|
584
573
|
need_newline_indented = true;
|
585
574
|
} else if (c.type == "comment2") {
|
586
|
-
print("/*" + c.value.replace(/[@#]__PURE__/g,
|
575
|
+
print("/*" + c.value.replace(/[@#]__PURE__/g, " ") + "*/");
|
587
576
|
need_space = true;
|
588
577
|
}
|
589
578
|
});
|
@@ -595,20 +584,21 @@ function OutputStream(options) {
|
|
595
584
|
get : get,
|
596
585
|
toString : get,
|
597
586
|
indent : indent,
|
598
|
-
indentation : function() { return indentation },
|
599
|
-
current_width : function() { return current_col - indentation },
|
600
|
-
should_break : function() { return options.width && this.current_width() >= options.width },
|
587
|
+
indentation : function() { return indentation; },
|
588
|
+
current_width : function() { return current_col - indentation; },
|
589
|
+
should_break : function() { return options.width && this.current_width() >= options.width; },
|
590
|
+
has_parens : function() { return has_parens; },
|
601
591
|
newline : newline,
|
602
592
|
print : print,
|
603
593
|
star : star,
|
604
594
|
space : space,
|
605
595
|
comma : comma,
|
606
596
|
colon : colon,
|
607
|
-
last : function() { return last },
|
597
|
+
last : function() { return last; },
|
608
598
|
semicolon : semicolon,
|
609
599
|
force_semicolon : force_semicolon,
|
610
600
|
to_utf8 : to_utf8,
|
611
|
-
print_name : function(name) { print(make_name(name)) },
|
601
|
+
print_name : function(name) { print(make_name(name)); },
|
612
602
|
print_string : function(str, quote, escape_directive) {
|
613
603
|
var encoded = encode_string(str, quote);
|
614
604
|
if (escape_directive === true && encoded.indexOf("\\") === -1) {
|
@@ -621,7 +611,7 @@ function OutputStream(options) {
|
|
621
611
|
print(encoded);
|
622
612
|
},
|
623
613
|
print_template_string_chars: function(str) {
|
624
|
-
var encoded = encode_string(str,
|
614
|
+
var encoded = encode_string(str, "`").replace(/\${/g, "\\${");
|
625
615
|
return print(encoded.substr(1, encoded.length - 2));
|
626
616
|
},
|
627
617
|
encode_string : encode_string,
|
@@ -631,36 +621,36 @@ function OutputStream(options) {
|
|
631
621
|
with_parens : with_parens,
|
632
622
|
with_square : with_square,
|
633
623
|
add_mapping : add_mapping,
|
634
|
-
option : function(opt) { return options[opt] },
|
624
|
+
option : function(opt) { return options[opt]; },
|
635
625
|
prepend_comments: readonly ? noop : prepend_comments,
|
636
626
|
append_comments : readonly || comment_filter === return_false ? noop : append_comments,
|
637
|
-
line : function() { return current_line },
|
638
|
-
col : function() { return current_col },
|
639
|
-
pos : function() { return current_pos },
|
640
|
-
push_node : function(node) { stack.push(node) },
|
641
|
-
pop_node : function() { return stack.pop() },
|
627
|
+
line : function() { return current_line; },
|
628
|
+
col : function() { return current_col; },
|
629
|
+
pos : function() { return current_pos; },
|
630
|
+
push_node : function(node) { stack.push(node); },
|
631
|
+
pop_node : function() { return stack.pop(); },
|
642
632
|
parent : function(n) {
|
643
633
|
return stack[stack.length - 2 - (n || 0)];
|
644
634
|
}
|
645
635
|
};
|
646
636
|
|
647
|
-
}
|
637
|
+
}
|
648
638
|
|
649
639
|
/* -----[ code generators ]----- */
|
650
640
|
|
651
|
-
(function(){
|
641
|
+
(function() {
|
652
642
|
|
653
643
|
/* -----[ utils ]----- */
|
654
644
|
|
655
645
|
function DEFPRINT(nodetype, generator) {
|
656
646
|
nodetype.DEFMETHOD("_codegen", generator);
|
657
|
-
}
|
647
|
+
}
|
658
648
|
|
659
649
|
var in_directive = false;
|
660
650
|
var active_scope = null;
|
661
651
|
var use_asm = null;
|
662
652
|
|
663
|
-
AST_Node.DEFMETHOD("print", function(stream, force_parens){
|
653
|
+
AST_Node.DEFMETHOD("print", function(stream, force_parens) {
|
664
654
|
var self = this, generator = self._codegen;
|
665
655
|
if (self instanceof AST_Scope) {
|
666
656
|
active_scope = self;
|
@@ -687,7 +677,7 @@ function OutputStream(options) {
|
|
687
677
|
});
|
688
678
|
AST_Node.DEFMETHOD("_print", AST_Node.prototype.print);
|
689
679
|
|
690
|
-
AST_Node.DEFMETHOD("print_to_string", function(options){
|
680
|
+
AST_Node.DEFMETHOD("print_to_string", function(options) {
|
691
681
|
var s = OutputStream(options);
|
692
682
|
this.print(s);
|
693
683
|
return s.get();
|
@@ -697,31 +687,31 @@ function OutputStream(options) {
|
|
697
687
|
|
698
688
|
function PARENS(nodetype, func) {
|
699
689
|
if (Array.isArray(nodetype)) {
|
700
|
-
nodetype.forEach(function(nodetype){
|
690
|
+
nodetype.forEach(function(nodetype) {
|
701
691
|
PARENS(nodetype, func);
|
702
692
|
});
|
703
693
|
} else {
|
704
694
|
nodetype.DEFMETHOD("needs_parens", func);
|
705
695
|
}
|
706
|
-
}
|
696
|
+
}
|
707
697
|
|
708
698
|
PARENS(AST_Node, return_false);
|
709
699
|
|
710
700
|
// a function expression needs parens around it when it's provably
|
711
701
|
// the first token to appear in a statement.
|
712
|
-
PARENS(AST_Function, function(output){
|
713
|
-
if (first_in_statement(output)) {
|
702
|
+
PARENS(AST_Function, function(output) {
|
703
|
+
if (!output.has_parens() && first_in_statement(output)) {
|
714
704
|
return true;
|
715
705
|
}
|
716
706
|
|
717
|
-
if (output.option(
|
707
|
+
if (output.option("webkit")) {
|
718
708
|
var p = output.parent();
|
719
709
|
if (p instanceof AST_PropAccess && p.expression === this) {
|
720
710
|
return true;
|
721
711
|
}
|
722
712
|
}
|
723
713
|
|
724
|
-
if (output.option(
|
714
|
+
if (output.option("wrap_iife")) {
|
725
715
|
var p = output.parent();
|
726
716
|
return p instanceof AST_Call && p.expression === this;
|
727
717
|
}
|
@@ -729,16 +719,20 @@ function OutputStream(options) {
|
|
729
719
|
return false;
|
730
720
|
});
|
731
721
|
|
732
|
-
PARENS(AST_Arrow, function(output){
|
722
|
+
PARENS(AST_Arrow, function(output) {
|
733
723
|
var p = output.parent();
|
734
724
|
return p instanceof AST_PropAccess && p.expression === this;
|
735
725
|
});
|
736
726
|
|
737
727
|
// same goes for an object literal, because otherwise it would be
|
738
728
|
// interpreted as a block of code.
|
739
|
-
PARENS(
|
729
|
+
PARENS(AST_Object, function(output) {
|
730
|
+
return !output.has_parens() && first_in_statement(output);
|
731
|
+
});
|
732
|
+
|
733
|
+
PARENS(AST_ClassExpression, first_in_statement);
|
740
734
|
|
741
|
-
PARENS(AST_Unary, function(output){
|
735
|
+
PARENS(AST_Unary, function(output) {
|
742
736
|
var p = output.parent();
|
743
737
|
return p instanceof AST_PropAccess && p.expression === this
|
744
738
|
|| p instanceof AST_Call && p.expression === this
|
@@ -750,14 +744,14 @@ function OutputStream(options) {
|
|
750
744
|
&& this.operator !== "--";
|
751
745
|
});
|
752
746
|
|
753
|
-
PARENS(AST_Await, function(output){
|
747
|
+
PARENS(AST_Await, function(output) {
|
754
748
|
var p = output.parent();
|
755
749
|
return p instanceof AST_PropAccess && p.expression === this
|
756
750
|
|| p instanceof AST_Call && p.expression === this
|
757
751
|
|| output.option("safari10") && p instanceof AST_UnaryPrefix;
|
758
752
|
});
|
759
753
|
|
760
|
-
PARENS(AST_Sequence, function(output){
|
754
|
+
PARENS(AST_Sequence, function(output) {
|
761
755
|
var p = output.parent();
|
762
756
|
return p instanceof AST_Call // (foo, bar)() or foo(1, (2, 3), 4)
|
763
757
|
|| p instanceof AST_Unary // !(foo, bar, baz)
|
@@ -777,7 +771,7 @@ function OutputStream(options) {
|
|
777
771
|
;
|
778
772
|
});
|
779
773
|
|
780
|
-
PARENS(AST_Binary, function(output){
|
774
|
+
PARENS(AST_Binary, function(output) {
|
781
775
|
var p = output.parent();
|
782
776
|
// (foo && bar)()
|
783
777
|
if (p instanceof AST_Call && p.expression === this)
|
@@ -800,7 +794,7 @@ function OutputStream(options) {
|
|
800
794
|
}
|
801
795
|
});
|
802
796
|
|
803
|
-
PARENS(AST_Yield, function(output){
|
797
|
+
PARENS(AST_Yield, function(output) {
|
804
798
|
var p = output.parent();
|
805
799
|
// (yield 1) + (yield 2)
|
806
800
|
// a = yield 3
|
@@ -822,7 +816,7 @@ function OutputStream(options) {
|
|
822
816
|
return true;
|
823
817
|
});
|
824
818
|
|
825
|
-
PARENS(AST_PropAccess, function(output){
|
819
|
+
PARENS(AST_PropAccess, function(output) {
|
826
820
|
var p = output.parent();
|
827
821
|
if (p instanceof AST_New && p.expression === this) {
|
828
822
|
// i.e. new (foo.bar().baz)
|
@@ -843,7 +837,7 @@ function OutputStream(options) {
|
|
843
837
|
}
|
844
838
|
});
|
845
839
|
|
846
|
-
PARENS(AST_Call, function(output){
|
840
|
+
PARENS(AST_Call, function(output) {
|
847
841
|
var p = output.parent(), p1;
|
848
842
|
if (p instanceof AST_New && p.expression === this
|
849
843
|
|| p instanceof AST_Export && p.is_default && this.expression instanceof AST_Function)
|
@@ -858,7 +852,7 @@ function OutputStream(options) {
|
|
858
852
|
&& p1.left === p;
|
859
853
|
});
|
860
854
|
|
861
|
-
PARENS(AST_New, function(output){
|
855
|
+
PARENS(AST_New, function(output) {
|
862
856
|
var p = output.parent();
|
863
857
|
if (!need_constructor_parens(this, output)
|
864
858
|
&& (p instanceof AST_PropAccess // (new Date).getTime(), (new Date)["getTime"]()
|
@@ -866,7 +860,7 @@ function OutputStream(options) {
|
|
866
860
|
return true;
|
867
861
|
});
|
868
862
|
|
869
|
-
PARENS(AST_Number, function(output){
|
863
|
+
PARENS(AST_Number, function(output) {
|
870
864
|
var p = output.parent();
|
871
865
|
if (p instanceof AST_PropAccess && p.expression === this) {
|
872
866
|
var value = this.getValue();
|
@@ -876,7 +870,7 @@ function OutputStream(options) {
|
|
876
870
|
}
|
877
871
|
});
|
878
872
|
|
879
|
-
PARENS([ AST_Assign, AST_Conditional ], function(output){
|
873
|
+
PARENS([ AST_Assign, AST_Conditional ], function(output) {
|
880
874
|
var p = output.parent();
|
881
875
|
// !(a = false) → true
|
882
876
|
if (p instanceof AST_Unary)
|
@@ -900,13 +894,13 @@ function OutputStream(options) {
|
|
900
894
|
|
901
895
|
/* -----[ PRINTERS ]----- */
|
902
896
|
|
903
|
-
DEFPRINT(AST_Directive, function(self, output){
|
897
|
+
DEFPRINT(AST_Directive, function(self, output) {
|
904
898
|
output.print_string(self.value, self.quote);
|
905
899
|
output.semicolon();
|
906
900
|
});
|
907
901
|
|
908
902
|
DEFPRINT(AST_Expansion, function (self, output) {
|
909
|
-
output.print(
|
903
|
+
output.print("...");
|
910
904
|
self.expression.print(output);
|
911
905
|
});
|
912
906
|
|
@@ -924,7 +918,7 @@ function OutputStream(options) {
|
|
924
918
|
output.print(self.is_array ? "]" : "}");
|
925
919
|
});
|
926
920
|
|
927
|
-
DEFPRINT(AST_Debugger, function(self, output){
|
921
|
+
DEFPRINT(AST_Debugger, function(self, output) {
|
928
922
|
output.print("debugger");
|
929
923
|
output.semicolon();
|
930
924
|
});
|
@@ -934,7 +928,7 @@ function OutputStream(options) {
|
|
934
928
|
function display_body(body, is_toplevel, output, allow_directives) {
|
935
929
|
var last = body.length - 1;
|
936
930
|
in_directive = allow_directives;
|
937
|
-
body.forEach(function(stmt, i){
|
931
|
+
body.forEach(function(stmt, i) {
|
938
932
|
if (in_directive === true && !(stmt instanceof AST_Directive ||
|
939
933
|
stmt instanceof AST_EmptyStatement ||
|
940
934
|
(stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String)
|
@@ -957,26 +951,26 @@ function OutputStream(options) {
|
|
957
951
|
}
|
958
952
|
});
|
959
953
|
in_directive = false;
|
960
|
-
}
|
954
|
+
}
|
961
955
|
|
962
|
-
AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output){
|
956
|
+
AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output) {
|
963
957
|
force_statement(this.body, output);
|
964
958
|
});
|
965
959
|
|
966
|
-
DEFPRINT(AST_Statement, function(self, output){
|
960
|
+
DEFPRINT(AST_Statement, function(self, output) {
|
967
961
|
self.body.print(output);
|
968
962
|
output.semicolon();
|
969
963
|
});
|
970
|
-
DEFPRINT(AST_Toplevel, function(self, output){
|
964
|
+
DEFPRINT(AST_Toplevel, function(self, output) {
|
971
965
|
display_body(self.body, true, output, true);
|
972
966
|
output.print("");
|
973
967
|
});
|
974
|
-
DEFPRINT(AST_LabeledStatement, function(self, output){
|
968
|
+
DEFPRINT(AST_LabeledStatement, function(self, output) {
|
975
969
|
self.label.print(output);
|
976
970
|
output.colon();
|
977
971
|
self.body.print(output);
|
978
972
|
});
|
979
|
-
DEFPRINT(AST_SimpleStatement, function(self, output){
|
973
|
+
DEFPRINT(AST_SimpleStatement, function(self, output) {
|
980
974
|
self.body.print(output);
|
981
975
|
output.semicolon();
|
982
976
|
});
|
@@ -993,38 +987,38 @@ function OutputStream(options) {
|
|
993
987
|
display_body(self.body, false, output, allow_directives);
|
994
988
|
});
|
995
989
|
} else print_braced_empty(self, output);
|
996
|
-
}
|
997
|
-
DEFPRINT(AST_BlockStatement, function(self, output){
|
990
|
+
}
|
991
|
+
DEFPRINT(AST_BlockStatement, function(self, output) {
|
998
992
|
print_braced(self, output);
|
999
993
|
});
|
1000
|
-
DEFPRINT(AST_EmptyStatement, function(self, output){
|
994
|
+
DEFPRINT(AST_EmptyStatement, function(self, output) {
|
1001
995
|
output.semicolon();
|
1002
996
|
});
|
1003
|
-
DEFPRINT(AST_Do, function(self, output){
|
997
|
+
DEFPRINT(AST_Do, function(self, output) {
|
1004
998
|
output.print("do");
|
1005
999
|
output.space();
|
1006
1000
|
make_block(self.body, output);
|
1007
1001
|
output.space();
|
1008
1002
|
output.print("while");
|
1009
1003
|
output.space();
|
1010
|
-
output.with_parens(function(){
|
1004
|
+
output.with_parens(function() {
|
1011
1005
|
self.condition.print(output);
|
1012
1006
|
});
|
1013
1007
|
output.semicolon();
|
1014
1008
|
});
|
1015
|
-
DEFPRINT(AST_While, function(self, output){
|
1009
|
+
DEFPRINT(AST_While, function(self, output) {
|
1016
1010
|
output.print("while");
|
1017
1011
|
output.space();
|
1018
|
-
output.with_parens(function(){
|
1012
|
+
output.with_parens(function() {
|
1019
1013
|
self.condition.print(output);
|
1020
1014
|
});
|
1021
1015
|
output.space();
|
1022
1016
|
self._do_print_body(output);
|
1023
1017
|
});
|
1024
|
-
DEFPRINT(AST_For, function(self, output){
|
1018
|
+
DEFPRINT(AST_For, function(self, output) {
|
1025
1019
|
output.print("for");
|
1026
1020
|
output.space();
|
1027
|
-
output.with_parens(function(){
|
1021
|
+
output.with_parens(function() {
|
1028
1022
|
if (self.init) {
|
1029
1023
|
if (self.init instanceof AST_Definitions) {
|
1030
1024
|
self.init.print(output);
|
@@ -1050,10 +1044,14 @@ function OutputStream(options) {
|
|
1050
1044
|
output.space();
|
1051
1045
|
self._do_print_body(output);
|
1052
1046
|
});
|
1053
|
-
DEFPRINT(AST_ForIn, function(self, output){
|
1047
|
+
DEFPRINT(AST_ForIn, function(self, output) {
|
1054
1048
|
output.print("for");
|
1049
|
+
if (self.await) {
|
1050
|
+
output.space();
|
1051
|
+
output.print("await");
|
1052
|
+
}
|
1055
1053
|
output.space();
|
1056
|
-
output.with_parens(function(){
|
1054
|
+
output.with_parens(function() {
|
1057
1055
|
self.init.print(output);
|
1058
1056
|
output.space();
|
1059
1057
|
output.print(self instanceof AST_ForOf ? "of" : "in");
|
@@ -1063,10 +1061,10 @@ function OutputStream(options) {
|
|
1063
1061
|
output.space();
|
1064
1062
|
self._do_print_body(output);
|
1065
1063
|
});
|
1066
|
-
DEFPRINT(AST_With, function(self, output){
|
1064
|
+
DEFPRINT(AST_With, function(self, output) {
|
1067
1065
|
output.print("with");
|
1068
1066
|
output.space();
|
1069
|
-
output.with_parens(function(){
|
1067
|
+
output.with_parens(function() {
|
1070
1068
|
self.expression.print(output);
|
1071
1069
|
});
|
1072
1070
|
output.space();
|
@@ -1074,7 +1072,7 @@ function OutputStream(options) {
|
|
1074
1072
|
});
|
1075
1073
|
|
1076
1074
|
/* -----[ functions ]----- */
|
1077
|
-
AST_Lambda.DEFMETHOD("_do_print", function(output, nokeyword){
|
1075
|
+
AST_Lambda.DEFMETHOD("_do_print", function(output, nokeyword) {
|
1078
1076
|
var self = this;
|
1079
1077
|
if (!nokeyword) {
|
1080
1078
|
if (self.async) {
|
@@ -1096,8 +1094,8 @@ function OutputStream(options) {
|
|
1096
1094
|
self.name.print(output); // Computed method name
|
1097
1095
|
});
|
1098
1096
|
}
|
1099
|
-
output.with_parens(function(){
|
1100
|
-
self.argnames.forEach(function(arg, i){
|
1097
|
+
output.with_parens(function() {
|
1098
|
+
self.argnames.forEach(function(arg, i) {
|
1101
1099
|
if (i) output.comma();
|
1102
1100
|
arg.print(output);
|
1103
1101
|
});
|
@@ -1105,7 +1103,7 @@ function OutputStream(options) {
|
|
1105
1103
|
output.space();
|
1106
1104
|
print_braced(self, output, true);
|
1107
1105
|
});
|
1108
|
-
DEFPRINT(AST_Lambda, function(self, output){
|
1106
|
+
DEFPRINT(AST_Lambda, function(self, output) {
|
1109
1107
|
self._do_print(output);
|
1110
1108
|
});
|
1111
1109
|
|
@@ -1131,13 +1129,13 @@ function OutputStream(options) {
|
|
1131
1129
|
output.print("`");
|
1132
1130
|
});
|
1133
1131
|
|
1134
|
-
AST_Arrow.DEFMETHOD("_do_print", function(output){
|
1132
|
+
AST_Arrow.DEFMETHOD("_do_print", function(output) {
|
1135
1133
|
var self = this;
|
1136
1134
|
var parent = output.parent();
|
1137
1135
|
var needs_parens = parent instanceof AST_Binary ||
|
1138
1136
|
parent instanceof AST_Unary ||
|
1139
1137
|
(parent instanceof AST_Call && self === parent.expression);
|
1140
|
-
if (needs_parens) { output.print("(") }
|
1138
|
+
if (needs_parens) { output.print("("); }
|
1141
1139
|
if (self.async) {
|
1142
1140
|
output.print("async");
|
1143
1141
|
output.space();
|
@@ -1145,26 +1143,26 @@ function OutputStream(options) {
|
|
1145
1143
|
if (self.argnames.length === 1 && self.argnames[0] instanceof AST_Symbol) {
|
1146
1144
|
self.argnames[0].print(output);
|
1147
1145
|
} else {
|
1148
|
-
output.with_parens(function(){
|
1149
|
-
self.argnames.forEach(function(arg, i){
|
1146
|
+
output.with_parens(function() {
|
1147
|
+
self.argnames.forEach(function(arg, i) {
|
1150
1148
|
if (i) output.comma();
|
1151
1149
|
arg.print(output);
|
1152
1150
|
});
|
1153
1151
|
});
|
1154
1152
|
}
|
1155
1153
|
output.space();
|
1156
|
-
output.print(
|
1154
|
+
output.print("=>");
|
1157
1155
|
output.space();
|
1158
1156
|
if (self.body instanceof AST_Node) {
|
1159
1157
|
self.body.print(output);
|
1160
1158
|
} else {
|
1161
1159
|
print_braced(self, output);
|
1162
1160
|
}
|
1163
|
-
if (needs_parens) { output.print(")") }
|
1161
|
+
if (needs_parens) { output.print(")"); }
|
1164
1162
|
});
|
1165
1163
|
|
1166
1164
|
/* -----[ exits ]----- */
|
1167
|
-
AST_Exit.DEFMETHOD("_do_print", function(output, kind){
|
1165
|
+
AST_Exit.DEFMETHOD("_do_print", function(output, kind) {
|
1168
1166
|
output.print(kind);
|
1169
1167
|
if (this.value) {
|
1170
1168
|
output.space();
|
@@ -1172,16 +1170,16 @@ function OutputStream(options) {
|
|
1172
1170
|
}
|
1173
1171
|
output.semicolon();
|
1174
1172
|
});
|
1175
|
-
DEFPRINT(AST_Return, function(self, output){
|
1173
|
+
DEFPRINT(AST_Return, function(self, output) {
|
1176
1174
|
self._do_print(output, "return");
|
1177
1175
|
});
|
1178
|
-
DEFPRINT(AST_Throw, function(self, output){
|
1176
|
+
DEFPRINT(AST_Throw, function(self, output) {
|
1179
1177
|
self._do_print(output, "throw");
|
1180
1178
|
});
|
1181
1179
|
|
1182
1180
|
/* -----[ yield ]----- */
|
1183
1181
|
|
1184
|
-
DEFPRINT(AST_Yield, function(self, output){
|
1182
|
+
DEFPRINT(AST_Yield, function(self, output) {
|
1185
1183
|
var star = self.is_star ? "*" : "";
|
1186
1184
|
output.print("yield" + star);
|
1187
1185
|
if (self.expression) {
|
@@ -1190,7 +1188,7 @@ function OutputStream(options) {
|
|
1190
1188
|
}
|
1191
1189
|
});
|
1192
1190
|
|
1193
|
-
DEFPRINT(AST_Await, function(self, output){
|
1191
|
+
DEFPRINT(AST_Await, function(self, output) {
|
1194
1192
|
output.print("await");
|
1195
1193
|
output.space();
|
1196
1194
|
var e = self.expression;
|
@@ -1207,7 +1205,7 @@ function OutputStream(options) {
|
|
1207
1205
|
});
|
1208
1206
|
|
1209
1207
|
/* -----[ loop control ]----- */
|
1210
|
-
AST_LoopControl.DEFMETHOD("_do_print", function(output, kind){
|
1208
|
+
AST_LoopControl.DEFMETHOD("_do_print", function(output, kind) {
|
1211
1209
|
output.print(kind);
|
1212
1210
|
if (this.label) {
|
1213
1211
|
output.space();
|
@@ -1215,10 +1213,10 @@ function OutputStream(options) {
|
|
1215
1213
|
}
|
1216
1214
|
output.semicolon();
|
1217
1215
|
});
|
1218
|
-
DEFPRINT(AST_Break, function(self, output){
|
1216
|
+
DEFPRINT(AST_Break, function(self, output) {
|
1219
1217
|
self._do_print(output, "break");
|
1220
1218
|
});
|
1221
|
-
DEFPRINT(AST_Continue, function(self, output){
|
1219
|
+
DEFPRINT(AST_Continue, function(self, output) {
|
1222
1220
|
self._do_print(output, "continue");
|
1223
1221
|
});
|
1224
1222
|
|
@@ -1250,11 +1248,11 @@ function OutputStream(options) {
|
|
1250
1248
|
else break;
|
1251
1249
|
}
|
1252
1250
|
force_statement(self.body, output);
|
1253
|
-
}
|
1254
|
-
DEFPRINT(AST_If, function(self, output){
|
1251
|
+
}
|
1252
|
+
DEFPRINT(AST_If, function(self, output) {
|
1255
1253
|
output.print("if");
|
1256
1254
|
output.space();
|
1257
|
-
output.with_parens(function(){
|
1255
|
+
output.with_parens(function() {
|
1258
1256
|
self.condition.print(output);
|
1259
1257
|
});
|
1260
1258
|
output.space();
|
@@ -1273,17 +1271,17 @@ function OutputStream(options) {
|
|
1273
1271
|
});
|
1274
1272
|
|
1275
1273
|
/* -----[ switch ]----- */
|
1276
|
-
DEFPRINT(AST_Switch, function(self, output){
|
1274
|
+
DEFPRINT(AST_Switch, function(self, output) {
|
1277
1275
|
output.print("switch");
|
1278
1276
|
output.space();
|
1279
|
-
output.with_parens(function(){
|
1277
|
+
output.with_parens(function() {
|
1280
1278
|
self.expression.print(output);
|
1281
1279
|
});
|
1282
1280
|
output.space();
|
1283
1281
|
var last = self.body.length - 1;
|
1284
1282
|
if (last < 0) print_braced_empty(self, output);
|
1285
|
-
else output.with_block(function(){
|
1286
|
-
self.body.forEach(function(branch, i){
|
1283
|
+
else output.with_block(function() {
|
1284
|
+
self.body.forEach(function(branch, i) {
|
1287
1285
|
output.indent(true);
|
1288
1286
|
branch.print(output);
|
1289
1287
|
if (i < last && branch.body.length > 0)
|
@@ -1291,19 +1289,19 @@ function OutputStream(options) {
|
|
1291
1289
|
});
|
1292
1290
|
});
|
1293
1291
|
});
|
1294
|
-
AST_SwitchBranch.DEFMETHOD("_do_print_body", function(output){
|
1292
|
+
AST_SwitchBranch.DEFMETHOD("_do_print_body", function(output) {
|
1295
1293
|
output.newline();
|
1296
|
-
this.body.forEach(function(stmt){
|
1294
|
+
this.body.forEach(function(stmt) {
|
1297
1295
|
output.indent();
|
1298
1296
|
stmt.print(output);
|
1299
1297
|
output.newline();
|
1300
1298
|
});
|
1301
1299
|
});
|
1302
|
-
DEFPRINT(AST_Default, function(self, output){
|
1300
|
+
DEFPRINT(AST_Default, function(self, output) {
|
1303
1301
|
output.print("default:");
|
1304
1302
|
self._do_print_body(output);
|
1305
1303
|
});
|
1306
|
-
DEFPRINT(AST_Case, function(self, output){
|
1304
|
+
DEFPRINT(AST_Case, function(self, output) {
|
1307
1305
|
output.print("case");
|
1308
1306
|
output.space();
|
1309
1307
|
self.expression.print(output);
|
@@ -1312,7 +1310,7 @@ function OutputStream(options) {
|
|
1312
1310
|
});
|
1313
1311
|
|
1314
1312
|
/* -----[ exceptions ]----- */
|
1315
|
-
DEFPRINT(AST_Try, function(self, output){
|
1313
|
+
DEFPRINT(AST_Try, function(self, output) {
|
1316
1314
|
output.print("try");
|
1317
1315
|
output.space();
|
1318
1316
|
print_braced(self, output);
|
@@ -1325,26 +1323,26 @@ function OutputStream(options) {
|
|
1325
1323
|
self.bfinally.print(output);
|
1326
1324
|
}
|
1327
1325
|
});
|
1328
|
-
DEFPRINT(AST_Catch, function(self, output){
|
1326
|
+
DEFPRINT(AST_Catch, function(self, output) {
|
1329
1327
|
output.print("catch");
|
1330
1328
|
output.space();
|
1331
|
-
output.with_parens(function(){
|
1329
|
+
output.with_parens(function() {
|
1332
1330
|
self.argname.print(output);
|
1333
1331
|
});
|
1334
1332
|
output.space();
|
1335
1333
|
print_braced(self, output);
|
1336
1334
|
});
|
1337
|
-
DEFPRINT(AST_Finally, function(self, output){
|
1335
|
+
DEFPRINT(AST_Finally, function(self, output) {
|
1338
1336
|
output.print("finally");
|
1339
1337
|
output.space();
|
1340
1338
|
print_braced(self, output);
|
1341
1339
|
});
|
1342
1340
|
|
1343
1341
|
/* -----[ var/const ]----- */
|
1344
|
-
AST_Definitions.DEFMETHOD("_do_print", function(output, kind){
|
1342
|
+
AST_Definitions.DEFMETHOD("_do_print", function(output, kind) {
|
1345
1343
|
output.print(kind);
|
1346
1344
|
output.space();
|
1347
|
-
this.definitions.forEach(function(def, i){
|
1345
|
+
this.definitions.forEach(function(def, i) {
|
1348
1346
|
if (i) output.comma();
|
1349
1347
|
def.print(output);
|
1350
1348
|
});
|
@@ -1354,13 +1352,13 @@ function OutputStream(options) {
|
|
1354
1352
|
if (!avoid_semicolon)
|
1355
1353
|
output.semicolon();
|
1356
1354
|
});
|
1357
|
-
DEFPRINT(AST_Let, function(self, output){
|
1355
|
+
DEFPRINT(AST_Let, function(self, output) {
|
1358
1356
|
self._do_print(output, "let");
|
1359
1357
|
});
|
1360
|
-
DEFPRINT(AST_Var, function(self, output){
|
1358
|
+
DEFPRINT(AST_Var, function(self, output) {
|
1361
1359
|
self._do_print(output, "var");
|
1362
1360
|
});
|
1363
|
-
DEFPRINT(AST_Const, function(self, output){
|
1361
|
+
DEFPRINT(AST_Const, function(self, output) {
|
1364
1362
|
self._do_print(output, "const");
|
1365
1363
|
});
|
1366
1364
|
DEFPRINT(AST_Import, function(self, output) {
|
@@ -1391,7 +1389,7 @@ function OutputStream(options) {
|
|
1391
1389
|
}
|
1392
1390
|
if (self.imported_name || self.imported_names) {
|
1393
1391
|
output.space();
|
1394
|
-
output.print("from")
|
1392
|
+
output.print("from");
|
1395
1393
|
output.space();
|
1396
1394
|
}
|
1397
1395
|
self.module_name.print(output);
|
@@ -1481,9 +1479,9 @@ function OutputStream(options) {
|
|
1481
1479
|
}
|
1482
1480
|
}));
|
1483
1481
|
node.print(output, parens);
|
1484
|
-
}
|
1482
|
+
}
|
1485
1483
|
|
1486
|
-
DEFPRINT(AST_VarDef, function(self, output){
|
1484
|
+
DEFPRINT(AST_VarDef, function(self, output) {
|
1487
1485
|
self.name.print(output);
|
1488
1486
|
if (self.value) {
|
1489
1487
|
output.space();
|
@@ -1496,27 +1494,27 @@ function OutputStream(options) {
|
|
1496
1494
|
});
|
1497
1495
|
|
1498
1496
|
/* -----[ other expressions ]----- */
|
1499
|
-
DEFPRINT(AST_Call, function(self, output){
|
1497
|
+
DEFPRINT(AST_Call, function(self, output) {
|
1500
1498
|
self.expression.print(output);
|
1501
1499
|
if (self instanceof AST_New && !need_constructor_parens(self, output))
|
1502
1500
|
return;
|
1503
1501
|
if (self.expression instanceof AST_Call || self.expression instanceof AST_Lambda) {
|
1504
1502
|
output.add_mapping(self.start);
|
1505
1503
|
}
|
1506
|
-
output.with_parens(function(){
|
1507
|
-
self.args.forEach(function(expr, i){
|
1504
|
+
output.with_parens(function() {
|
1505
|
+
self.args.forEach(function(expr, i) {
|
1508
1506
|
if (i) output.comma();
|
1509
1507
|
expr.print(output);
|
1510
1508
|
});
|
1511
1509
|
});
|
1512
1510
|
});
|
1513
|
-
DEFPRINT(AST_New, function(self, output){
|
1511
|
+
DEFPRINT(AST_New, function(self, output) {
|
1514
1512
|
output.print("new");
|
1515
1513
|
output.space();
|
1516
1514
|
AST_Call.prototype._codegen(self, output);
|
1517
1515
|
});
|
1518
1516
|
|
1519
|
-
AST_Sequence.DEFMETHOD("_do_print", function(output){
|
1517
|
+
AST_Sequence.DEFMETHOD("_do_print", function(output) {
|
1520
1518
|
this.expressions.forEach(function(node, index) {
|
1521
1519
|
if (index > 0) {
|
1522
1520
|
output.comma();
|
@@ -1528,7 +1526,7 @@ function OutputStream(options) {
|
|
1528
1526
|
node.print(output);
|
1529
1527
|
});
|
1530
1528
|
});
|
1531
|
-
DEFPRINT(AST_Sequence, function(self, output){
|
1529
|
+
DEFPRINT(AST_Sequence, function(self, output) {
|
1532
1530
|
self._do_print(output);
|
1533
1531
|
// var p = output.parent();
|
1534
1532
|
// if (p instanceof AST_Statement) {
|
@@ -1539,7 +1537,7 @@ function OutputStream(options) {
|
|
1539
1537
|
// self._do_print(output);
|
1540
1538
|
// }
|
1541
1539
|
});
|
1542
|
-
DEFPRINT(AST_Dot, function(self, output){
|
1540
|
+
DEFPRINT(AST_Dot, function(self, output) {
|
1543
1541
|
var expr = self.expression;
|
1544
1542
|
expr.print(output);
|
1545
1543
|
var prop = self.property;
|
@@ -1560,13 +1558,13 @@ function OutputStream(options) {
|
|
1560
1558
|
output.print_name(prop);
|
1561
1559
|
}
|
1562
1560
|
});
|
1563
|
-
DEFPRINT(AST_Sub, function(self, output){
|
1561
|
+
DEFPRINT(AST_Sub, function(self, output) {
|
1564
1562
|
self.expression.print(output);
|
1565
1563
|
output.print("[");
|
1566
1564
|
self.property.print(output);
|
1567
1565
|
output.print("]");
|
1568
1566
|
});
|
1569
|
-
DEFPRINT(AST_UnaryPrefix, function(self, output){
|
1567
|
+
DEFPRINT(AST_UnaryPrefix, function(self, output) {
|
1570
1568
|
var op = self.operator;
|
1571
1569
|
output.print(op);
|
1572
1570
|
if (/^[a-z]/i.test(op)
|
@@ -1577,11 +1575,11 @@ function OutputStream(options) {
|
|
1577
1575
|
}
|
1578
1576
|
self.expression.print(output);
|
1579
1577
|
});
|
1580
|
-
DEFPRINT(AST_UnaryPostfix, function(self, output){
|
1578
|
+
DEFPRINT(AST_UnaryPostfix, function(self, output) {
|
1581
1579
|
self.expression.print(output);
|
1582
1580
|
output.print(self.operator);
|
1583
1581
|
});
|
1584
|
-
DEFPRINT(AST_Binary, function(self, output){
|
1582
|
+
DEFPRINT(AST_Binary, function(self, output) {
|
1585
1583
|
var op = self.operator;
|
1586
1584
|
self.left.print(output);
|
1587
1585
|
if (op[0] == ">" /* ">>" ">>>" ">" ">=" */
|
@@ -1607,7 +1605,7 @@ function OutputStream(options) {
|
|
1607
1605
|
}
|
1608
1606
|
self.right.print(output);
|
1609
1607
|
});
|
1610
|
-
DEFPRINT(AST_Conditional, function(self, output){
|
1608
|
+
DEFPRINT(AST_Conditional, function(self, output) {
|
1611
1609
|
self.condition.print(output);
|
1612
1610
|
output.space();
|
1613
1611
|
output.print("?");
|
@@ -1619,11 +1617,11 @@ function OutputStream(options) {
|
|
1619
1617
|
});
|
1620
1618
|
|
1621
1619
|
/* -----[ literals ]----- */
|
1622
|
-
DEFPRINT(AST_Array, function(self, output){
|
1623
|
-
output.with_square(function(){
|
1620
|
+
DEFPRINT(AST_Array, function(self, output) {
|
1621
|
+
output.with_square(function() {
|
1624
1622
|
var a = self.elements, len = a.length;
|
1625
1623
|
if (len > 0) output.space();
|
1626
|
-
a.forEach(function(exp, i){
|
1624
|
+
a.forEach(function(exp, i) {
|
1627
1625
|
if (i) output.comma();
|
1628
1626
|
exp.print(output);
|
1629
1627
|
// If the final element is a hole, we need to make sure it
|
@@ -1635,9 +1633,9 @@ function OutputStream(options) {
|
|
1635
1633
|
if (len > 0) output.space();
|
1636
1634
|
});
|
1637
1635
|
});
|
1638
|
-
DEFPRINT(AST_Object, function(self, output){
|
1639
|
-
if (self.properties.length > 0) output.with_block(function(){
|
1640
|
-
self.properties.forEach(function(prop, i){
|
1636
|
+
DEFPRINT(AST_Object, function(self, output) {
|
1637
|
+
if (self.properties.length > 0) output.with_block(function() {
|
1638
|
+
self.properties.forEach(function(prop, i) {
|
1641
1639
|
if (i) {
|
1642
1640
|
output.print(",");
|
1643
1641
|
output.newline();
|
@@ -1649,7 +1647,7 @@ function OutputStream(options) {
|
|
1649
1647
|
});
|
1650
1648
|
else print_braced_empty(self, output);
|
1651
1649
|
});
|
1652
|
-
DEFPRINT(AST_Class, function(self, output){
|
1650
|
+
DEFPRINT(AST_Class, function(self, output) {
|
1653
1651
|
output.print("class");
|
1654
1652
|
output.space();
|
1655
1653
|
if (self.name) {
|
@@ -1676,8 +1674,8 @@ function OutputStream(options) {
|
|
1676
1674
|
output.space();
|
1677
1675
|
}
|
1678
1676
|
}
|
1679
|
-
if (self.properties.length > 0) output.with_block(function(){
|
1680
|
-
self.properties.forEach(function(prop, i){
|
1677
|
+
if (self.properties.length > 0) output.with_block(function() {
|
1678
|
+
self.properties.forEach(function(prop, i) {
|
1681
1679
|
if (i) {
|
1682
1680
|
output.newline();
|
1683
1681
|
}
|
@@ -1708,7 +1706,7 @@ function OutputStream(options) {
|
|
1708
1706
|
}
|
1709
1707
|
}
|
1710
1708
|
|
1711
|
-
DEFPRINT(AST_ObjectKeyVal, function(self, output){
|
1709
|
+
DEFPRINT(AST_ObjectKeyVal, function(self, output) {
|
1712
1710
|
function get_name(self) {
|
1713
1711
|
var def = self.definition();
|
1714
1712
|
return def ? def.mangled_name || def.name : self.name;
|
@@ -1765,16 +1763,16 @@ function OutputStream(options) {
|
|
1765
1763
|
}
|
1766
1764
|
self.value._do_print(output, true);
|
1767
1765
|
});
|
1768
|
-
DEFPRINT(AST_ObjectSetter, function(self, output){
|
1766
|
+
DEFPRINT(AST_ObjectSetter, function(self, output) {
|
1769
1767
|
self._print_getter_setter("set", output);
|
1770
1768
|
});
|
1771
|
-
DEFPRINT(AST_ObjectGetter, function(self, output){
|
1769
|
+
DEFPRINT(AST_ObjectGetter, function(self, output) {
|
1772
1770
|
self._print_getter_setter("get", output);
|
1773
1771
|
});
|
1774
|
-
DEFPRINT(AST_ConciseMethod, function(self, output){
|
1772
|
+
DEFPRINT(AST_ConciseMethod, function(self, output) {
|
1775
1773
|
self._print_getter_setter(self.is_generator && "*" || self.async && "async", output);
|
1776
1774
|
});
|
1777
|
-
AST_Symbol.DEFMETHOD("_do_print", function(output){
|
1775
|
+
AST_Symbol.DEFMETHOD("_do_print", function(output) {
|
1778
1776
|
var def = this.definition();
|
1779
1777
|
output.print_name(def ? def.mangled_name || def.name : this.name);
|
1780
1778
|
});
|
@@ -1782,19 +1780,19 @@ function OutputStream(options) {
|
|
1782
1780
|
self._do_print(output);
|
1783
1781
|
});
|
1784
1782
|
DEFPRINT(AST_Hole, noop);
|
1785
|
-
DEFPRINT(AST_This, function(self, output){
|
1783
|
+
DEFPRINT(AST_This, function(self, output) {
|
1786
1784
|
output.print("this");
|
1787
1785
|
});
|
1788
|
-
DEFPRINT(AST_Super, function(self, output){
|
1786
|
+
DEFPRINT(AST_Super, function(self, output) {
|
1789
1787
|
output.print("super");
|
1790
1788
|
});
|
1791
|
-
DEFPRINT(AST_Constant, function(self, output){
|
1789
|
+
DEFPRINT(AST_Constant, function(self, output) {
|
1792
1790
|
output.print(self.getValue());
|
1793
1791
|
});
|
1794
|
-
DEFPRINT(AST_String, function(self, output){
|
1792
|
+
DEFPRINT(AST_String, function(self, output) {
|
1795
1793
|
output.print_string(self.getValue(), self.quote, in_directive);
|
1796
1794
|
});
|
1797
|
-
DEFPRINT(AST_Number, function(self, output){
|
1795
|
+
DEFPRINT(AST_Number, function(self, output) {
|
1798
1796
|
if (use_asm && self.start && self.start.raw != null) {
|
1799
1797
|
output.print(self.start.raw);
|
1800
1798
|
} else {
|
@@ -1802,7 +1800,7 @@ function OutputStream(options) {
|
|
1802
1800
|
}
|
1803
1801
|
});
|
1804
1802
|
|
1805
|
-
DEFPRINT(AST_RegExp, function(self, output){
|
1803
|
+
DEFPRINT(AST_RegExp, function(self, output) {
|
1806
1804
|
var regexp = self.getValue();
|
1807
1805
|
var str = regexp.toString();
|
1808
1806
|
str = output.to_utf8(str);
|
@@ -1821,7 +1819,7 @@ function OutputStream(options) {
|
|
1821
1819
|
else
|
1822
1820
|
stat.print(output);
|
1823
1821
|
}
|
1824
|
-
}
|
1822
|
+
}
|
1825
1823
|
|
1826
1824
|
// self should be AST_New. decide if we want to show parens or not.
|
1827
1825
|
function need_constructor_parens(self, output) {
|
@@ -1829,7 +1827,7 @@ function OutputStream(options) {
|
|
1829
1827
|
if (self.args.length > 0) return true;
|
1830
1828
|
|
1831
1829
|
return output.option("beautify");
|
1832
|
-
}
|
1830
|
+
}
|
1833
1831
|
|
1834
1832
|
function best_of(a) {
|
1835
1833
|
var best = a[0], len = best.length;
|
@@ -1840,10 +1838,10 @@ function OutputStream(options) {
|
|
1840
1838
|
}
|
1841
1839
|
}
|
1842
1840
|
return best;
|
1843
|
-
}
|
1841
|
+
}
|
1844
1842
|
|
1845
1843
|
function make_num(num) {
|
1846
|
-
var str = num.toString(10), a = [ str.replace(/^0\./, ".").replace(
|
1844
|
+
var str = num.toString(10), a = [ str.replace(/^0\./, ".").replace("e+", "e") ], m;
|
1847
1845
|
if (Math.floor(num) === num) {
|
1848
1846
|
if (num >= 0) {
|
1849
1847
|
a.push("0x" + num.toString(16).toLowerCase(), // probably pointless
|
@@ -1860,64 +1858,70 @@ function OutputStream(options) {
|
|
1860
1858
|
str.substr(str.indexOf(".")));
|
1861
1859
|
}
|
1862
1860
|
return best_of(a);
|
1863
|
-
}
|
1861
|
+
}
|
1864
1862
|
|
1865
1863
|
function make_block(stmt, output) {
|
1866
1864
|
if (!stmt || stmt instanceof AST_EmptyStatement)
|
1867
1865
|
output.print("{}");
|
1868
1866
|
else if (stmt instanceof AST_BlockStatement)
|
1869
1867
|
stmt.print(output);
|
1870
|
-
else output.with_block(function(){
|
1868
|
+
else output.with_block(function() {
|
1871
1869
|
output.indent();
|
1872
1870
|
stmt.print(output);
|
1873
1871
|
output.newline();
|
1874
1872
|
});
|
1875
|
-
}
|
1873
|
+
}
|
1876
1874
|
|
1877
1875
|
/* -----[ source map generators ]----- */
|
1878
1876
|
|
1879
1877
|
function DEFMAP(nodetype, generator) {
|
1880
|
-
nodetype.
|
1881
|
-
|
1878
|
+
nodetype.forEach(function(nodetype) {
|
1879
|
+
nodetype.DEFMETHOD("add_source_map", generator);
|
1882
1880
|
});
|
1883
|
-
}
|
1884
|
-
|
1885
|
-
// We could easily add info for ALL nodes, but it seems to me that
|
1886
|
-
// would be quite wasteful, hence this noop in the base class.
|
1887
|
-
DEFMAP(AST_Node, noop);
|
1881
|
+
}
|
1888
1882
|
|
1889
|
-
|
1890
|
-
|
1891
|
-
|
1883
|
+
DEFMAP([
|
1884
|
+
// We could easily add info for ALL nodes, but it seems to me that
|
1885
|
+
// would be quite wasteful, hence this noop in the base class.
|
1886
|
+
AST_Node,
|
1887
|
+
// since the label symbol will mark it
|
1888
|
+
AST_LabeledStatement,
|
1889
|
+
AST_Toplevel,
|
1890
|
+
], noop);
|
1892
1891
|
|
1893
1892
|
// XXX: I'm not exactly sure if we need it for all of these nodes,
|
1894
1893
|
// or if we should add even more.
|
1895
|
-
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1899
|
-
|
1900
|
-
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1894
|
+
DEFMAP([
|
1895
|
+
AST_Array,
|
1896
|
+
AST_BlockStatement,
|
1897
|
+
AST_Catch,
|
1898
|
+
AST_Class,
|
1899
|
+
AST_Constant,
|
1900
|
+
AST_Debugger,
|
1901
|
+
AST_Definitions,
|
1902
|
+
AST_Directive,
|
1903
|
+
AST_Finally,
|
1904
|
+
AST_Jump,
|
1905
|
+
AST_Lambda,
|
1906
|
+
AST_New,
|
1907
|
+
AST_Object,
|
1908
|
+
AST_StatementWithBody,
|
1909
|
+
AST_Symbol,
|
1910
|
+
AST_Switch,
|
1911
|
+
AST_SwitchBranch,
|
1912
|
+
AST_Try,
|
1913
|
+
], function(output) {
|
1914
|
+
output.add_mapping(this.start);
|
1915
|
+
});
|
1916
|
+
|
1917
|
+
DEFMAP([
|
1918
|
+
AST_ObjectGetter,
|
1919
|
+
AST_ObjectSetter,
|
1920
|
+
], function(output) {
|
1921
|
+
output.add_mapping(this.start, this.key.name);
|
1922
|
+
});
|
1923
|
+
|
1924
|
+
DEFMAP([ AST_ObjectProperty ], function(output) {
|
1925
|
+
output.add_mapping(this.start, this.key);
|
1921
1926
|
});
|
1922
|
-
|
1923
1927
|
})();
|