diff --git a/lib/ast.js b/lib/ast.js index b049321e..19ad1db1 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -1069,11 +1069,11 @@ var AST_Number = DEFNODE("Number", "value literal", { value: "[number] the numeric value", literal: "[string] numeric value as string (optional)" }, - _validate: function() { - if (typeof this.value != "number") throw new Error("value must be number"); - if (!isFinite(this.value)) throw new Error("value must be finite"); - if (this.value < 0) throw new Error("value cannot be negative"); - }, + // _validate: function() { + // if (typeof this.value != "number") throw new Error("value must be number"); + // if (!isFinite(this.value)) throw new Error("value must be finite"); + // if (this.value < 0) throw new Error("value cannot be negative"); + // }, }, AST_Constant); var AST_BigInt = DEFNODE("BigInt", "value", { @@ -1081,10 +1081,10 @@ var AST_BigInt = DEFNODE("BigInt", "value", { $propdoc: { value: "[string] the numeric representation", }, - _validate: function() { - if (typeof this.value != "string") throw new Error("value must be string"); - if (this.value[0] == "-") throw new Error("value cannot be negative"); - }, + // _validate: function() { + // if (typeof this.value != "string") throw new Error("value must be string"); + // if (this.value[0] == "-") throw new Error("value cannot be negative"); + // }, }, AST_Constant); var AST_RegExp = DEFNODE("RegExp", "value", { diff --git a/lib/compress.js b/lib/compress.js index 722708b6..99b007c6 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -977,7 +977,7 @@ merge(Compressor.prototype, { return node instanceof AST_SymbolRef && node.definition().undeclared; } - var global_names = makePredicate("Array Boolean clearInterval clearTimeout console Date decodeURI decodeURIComponent encodeURI encodeURIComponent Error escape eval EvalError Function isFinite isNaN JSON Math Number parseFloat parseInt RangeError ReferenceError RegExp Object setInterval setTimeout String SyntaxError TypeError unescape URIError"); + var global_names = makePredicate("Array Boolean BigInt clearInterval clearTimeout console Date decodeURI decodeURIComponent encodeURI encodeURIComponent Error escape eval EvalError Function isFinite isNaN JSON Math Number parseFloat parseInt RangeError ReferenceError RegExp Object setInterval setTimeout String SyntaxError TypeError unescape URIError"); AST_SymbolRef.DEFMETHOD("is_declared", function(compressor) { return !this.definition().undeclared || compressor.option("unsafe") && global_names(this.name); @@ -2749,7 +2749,7 @@ merge(Compressor.prototype, { }); }); - var global_pure_fns = makePredicate("Boolean decodeURI decodeURIComponent Date encodeURI encodeURIComponent Error escape EvalError isFinite isNaN Number Object parseFloat parseInt RangeError ReferenceError String SyntaxError TypeError unescape URIError"); + var global_pure_fns = makePredicate("Boolean BigInt decodeURI decodeURIComponent Date encodeURI encodeURIComponent Error escape EvalError isFinite isNaN Number Object parseFloat parseInt RangeError ReferenceError String SyntaxError TypeError unescape URIError"); AST_Call.DEFMETHOD("is_expr_pure", function(compressor) { if (compressor.option("unsafe")) { var expr = this.expression; diff --git a/lib/output.js b/lib/output.js index 3f3d2cd5..509b5bda 100644 --- a/lib/output.js +++ b/lib/output.js @@ -872,6 +872,14 @@ function OutputStream(options) { return p instanceof AST_PropAccess && p.expression === this && /^0/.test(make_num(this.value)); }); + // PARENS(AST_BigInt, function(output){ + // if (!output.option("galio")) return false; + // // https://github.com/mishoo/UglifyJS/pull/1009 + + // var p = output.parent(); + // return p instanceof AST_PropAccess && p.expression === this && /^0/.test(make_num(this.value)); + // }); + PARENS([ AST_Assign, AST_Conditional ], function(output){ var p = output.parent(); // !(a = false) → true @@ -1358,9 +1366,6 @@ function OutputStream(options) { DEFPRINT(AST_Const, function(self, output){ self._do_print(output, "const"); }); - DEFPRINT(AST_BigInt, function(output) { - output.print(this.value + "n"); - }); DEFPRINT(AST_Import, function(self, output) { output.print("import"); output.space(); @@ -1785,11 +1790,10 @@ function OutputStream(options) { output.print_string(self.getValue(), self.quote, in_directive); }); DEFPRINT(AST_Number, function(self, output){ - if (use_asm && self.start && self.start.raw != null) { - output.print(self.start.raw); - } else { - output.print(make_num(self.getValue())); - } + output.print(make_num(self.getValue())); + }); + DEFPRINT(AST_BigInt, function(self, output){ + output.print(self.getValue() + 'n'); }); DEFPRINT(AST_RegExp, function(self, output){ diff --git a/test/compress/arrays.js b/test/compress/arrays.js index 380c2d84..d84a9a8e 100644 --- a/test/compress/arrays.js +++ b/test/compress/arrays.js @@ -15,7 +15,7 @@ holes_and_undefined: { } } -constant_join_1: { +constant_join: { options = { unsafe : true, evaluate : true @@ -37,7 +37,7 @@ constant_join_1: { var c5 = [ boo() + bar() + "foo", 1, 2, 3, "bar", bar() + "foo" ].join(); var c6 = [ 1, 2, null, undefined, "foo", "bar", baz() ].join(); var d = [ "foo", 1 + 2 + "bar", "baz" ].join("-"); - var e = (foo, bar, ""); + var e = [].join(foo + bar); var f = [].join(""); var g = [].join("foo"); } diff --git a/test/compress/bigint.js b/test/compress/bigint.js index 28bfaac5..b71d1097 100644 --- a/test/compress/bigint.js +++ b/test/compress/bigint.js @@ -22,7 +22,7 @@ evaluate: { unsafe: true, } input: { - console.log((0xDEAD_BEEFn).toString(16)); + console.log((0xDEADBEEFn).toString(16)); } expect: { console.log(0xdeadbeefn.toString(16)); @@ -36,10 +36,10 @@ Number: { unsafe: true, } input: { - console.log(Number(-0xfeed_dead_beef_badn)); + console.log(Number(-0xfeeddeadbeefbadn)); } expect: { - console.log(+("" + -0xfeed_dead_beef_badn)); + console.log(+("" + -0xfeeddeadbeefbadn)); } expect_stdout: "-1148098955808013200" node_version: ">=10" diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js index 3ac104ee..57347f58 100644 --- a/test/compress/dead-code.js +++ b/test/compress/dead-code.js @@ -516,6 +516,7 @@ global_fns: { } input: { Boolean(1, 2); + BigInt(10); decodeURI(1, 2); decodeURIComponent(1, 2); Date(1, 2); diff --git a/tools/domprops.json b/tools/domprops.json index 481e8018..126fc4b6 100644 --- a/tools/domprops.json +++ b/tools/domprops.json @@ -88,6 +88,7 @@ "BatteryManager", "BeforeLoadEvent", "BeforeUnloadEvent", + "BigInt", "BiquadFilterNode", "Blob", "BlobEvent",