This commit is contained in:
Mark Vayngrib 2023-10-31 17:13:19 +08:00
parent 607cf64c22
commit 98f94d15e8
No known key found for this signature in database
GPG Key ID: AA48332BE2806A28
7 changed files with 30 additions and 24 deletions

View File

@ -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", {

View File

@ -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;

View File

@ -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()));
}
});
DEFPRINT(AST_BigInt, function(self, output){
output.print(self.getValue() + 'n');
});
DEFPRINT(AST_RegExp, function(self, output){

View File

@ -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");
}

View File

@ -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"

View File

@ -516,6 +516,7 @@ global_fns: {
}
input: {
Boolean(1, 2);
BigInt(10);
decodeURI(1, 2);
decodeURIComponent(1, 2);
Date(1, 2);

View File

@ -88,6 +88,7 @@
"BatteryManager",
"BeforeLoadEvent",
"BeforeUnloadEvent",
"BigInt",
"BiquadFilterNode",
"Blob",
"BlobEvent",