fix corner case with spread syntax (#5572)
This commit is contained in:
12
lib/parse.js
12
lib/parse.js
@@ -552,16 +552,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
|
|
||||||
function handle_dot() {
|
function handle_dot() {
|
||||||
next();
|
next();
|
||||||
var ch = peek();
|
if (looking_at("..")) return token("operator", "." + next() + next());
|
||||||
if (ch == ".") {
|
return is_digit(peek().charCodeAt(0)) ? read_num(".") : token("punc", ".");
|
||||||
var op = ".";
|
|
||||||
do {
|
|
||||||
op += ".";
|
|
||||||
next();
|
|
||||||
} while (peek() == ".");
|
|
||||||
return token("operator", op);
|
|
||||||
}
|
|
||||||
return is_digit(ch.charCodeAt(0)) ? read_num(".") : token("punc", ".");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_word() {
|
function read_word() {
|
||||||
|
|||||||
@@ -1,3 +1,12 @@
|
|||||||
|
decimal: {
|
||||||
|
input: {
|
||||||
|
console.log({... 0.42});
|
||||||
|
}
|
||||||
|
expect_exact: "console.log({....42});"
|
||||||
|
expect_stdout: "{}"
|
||||||
|
node_version: ">=8.3.0"
|
||||||
|
}
|
||||||
|
|
||||||
collapse_vars_1: {
|
collapse_vars_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
|||||||
@@ -61,12 +61,12 @@ function test(input, to_moz, description, skip_on_error, beautified) {
|
|||||||
var ast = UglifyJS.AST_Node.from_mozilla_ast(to_moz(input));
|
var ast = UglifyJS.AST_Node.from_mozilla_ast(to_moz(input));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (skip_on_error) return true;
|
if (skip_on_error) return true;
|
||||||
console.log("//=============================================================");
|
console.error("//=============================================================");
|
||||||
console.log("//", description, "failed... round", round);
|
console.error("//", description, "failed... round", round);
|
||||||
console.log(e);
|
console.error(e);
|
||||||
console.log("// original code");
|
console.error("// original code");
|
||||||
if (beautified === true) console.log("// (beautified)");
|
if (beautified === true) console.error("// (beautified)");
|
||||||
console.log(input.code);
|
console.error(input.code);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var transformed = validate(ast);
|
var transformed = validate(ast);
|
||||||
@@ -78,34 +78,34 @@ function test(input, to_moz, description, skip_on_error, beautified) {
|
|||||||
if (!test(beautified, to_moz, description, skip_on_error, true)) return false;
|
if (!test(beautified, to_moz, description, skip_on_error, true)) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("//=============================================================");
|
console.error("//=============================================================");
|
||||||
console.log("// !!!!!! Failed... round", round);
|
console.error("// !!!!!! Failed... round", round);
|
||||||
console.log("// original code");
|
console.error("// original code");
|
||||||
if (beautified.error) {
|
if (beautified.error) {
|
||||||
console.log("// !!! beautify failed !!!");
|
console.error("// !!! beautify failed !!!");
|
||||||
console.log(beautified.error.stack);
|
console.error(beautified.error.stack);
|
||||||
} else if (beautified === true) {
|
} else if (beautified === true) {
|
||||||
console.log("// (beautified)");
|
console.error("// (beautified)");
|
||||||
}
|
}
|
||||||
console.log(input.raw);
|
console.error(input.raw);
|
||||||
console.log();
|
console.error();
|
||||||
console.log();
|
console.error();
|
||||||
console.log("//-------------------------------------------------------------");
|
console.error("//-------------------------------------------------------------");
|
||||||
console.log("//", description);
|
console.error("//", description);
|
||||||
if (transformed.error) {
|
if (transformed.error) {
|
||||||
console.log(transformed.error.stack);
|
console.error(transformed.error.stack);
|
||||||
} else {
|
} else {
|
||||||
beautified = beautify(transformed.ast);
|
beautified = beautify(transformed.ast);
|
||||||
if (beautified.error) {
|
if (beautified.error) {
|
||||||
console.log("// !!! beautify failed !!!");
|
console.error("// !!! beautify failed !!!");
|
||||||
console.log(beautified.error.stack);
|
console.error(beautified.error.stack);
|
||||||
console.log(transformed.code);
|
console.error(transformed.code);
|
||||||
} else {
|
} else {
|
||||||
console.log("// (beautified)");
|
console.error("// (beautified)");
|
||||||
console.log(beautified.code);
|
console.error(beautified.code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("!!!!!! Failed... round", round);
|
console.error("!!!!!! Failed... round", round);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -119,10 +119,26 @@ for (var round = 1; round <= num_iterations; round++) {
|
|||||||
var code = ufuzz.createTopLevelCode();
|
var code = ufuzz.createTopLevelCode();
|
||||||
minify_options.forEach(function(options) {
|
minify_options.forEach(function(options) {
|
||||||
var ok = true;
|
var ok = true;
|
||||||
var input = UglifyJS.minify(options ? function(options) {
|
var minified;
|
||||||
options.module = ufuzz.module;
|
if (options) {
|
||||||
return UglifyJS.minify(code, options).code;
|
var o = JSON.parse(options);
|
||||||
}(JSON.parse(options)) : code, {
|
o.module = ufuzz.module;
|
||||||
|
minified = UglifyJS.minify(code, o);
|
||||||
|
if (minified.error) {
|
||||||
|
console.log("//=============================================================");
|
||||||
|
console.log("// minify() failed... round", round);
|
||||||
|
console.log("// original code");
|
||||||
|
console.log(code);
|
||||||
|
console.log();
|
||||||
|
console.log();
|
||||||
|
console.log("//-------------------------------------------------------------");
|
||||||
|
console.log("minify(options):");
|
||||||
|
console.log(JSON.stringify(o, null, 2));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
minified = minified.code;
|
||||||
|
}
|
||||||
|
var input = UglifyJS.minify(minified || code, {
|
||||||
compress: false,
|
compress: false,
|
||||||
mangle: false,
|
mangle: false,
|
||||||
module: ufuzz.module,
|
module: ufuzz.module,
|
||||||
@@ -133,11 +149,27 @@ for (var round = 1; round <= num_iterations; round++) {
|
|||||||
input.raw = options ? input.code : code;
|
input.raw = options ? input.code : code;
|
||||||
if (input.error) {
|
if (input.error) {
|
||||||
ok = false;
|
ok = false;
|
||||||
console.log("//=============================================================");
|
console.error("//=============================================================");
|
||||||
console.log("// minify() failed... round", round);
|
console.error("// parse() failed... round", round);
|
||||||
console.log(input.error);
|
console.error("// original code");
|
||||||
console.log("// original code");
|
console.error(code);
|
||||||
console.log(code);
|
console.error();
|
||||||
|
console.error();
|
||||||
|
if (options) {
|
||||||
|
console.error("//-------------------------------------------------------------");
|
||||||
|
console.error("// minified code");
|
||||||
|
console.error(minified);
|
||||||
|
console.error();
|
||||||
|
console.error();
|
||||||
|
console.error("//-------------------------------------------------------------");
|
||||||
|
console.error("minify(options):");
|
||||||
|
console.error(JSON.stringify(o, null, 2));
|
||||||
|
console.error();
|
||||||
|
console.error();
|
||||||
|
}
|
||||||
|
console.error("//-------------------------------------------------------------");
|
||||||
|
console.error("// parse() error");
|
||||||
|
console.error(input.error);
|
||||||
}
|
}
|
||||||
if (ok) ok = test(input, function(input) {
|
if (ok) ok = test(input, function(input) {
|
||||||
return input.ast.to_mozilla_ast();
|
return input.ast.to_mozilla_ast();
|
||||||
@@ -149,7 +181,10 @@ for (var round = 1; round <= num_iterations; round++) {
|
|||||||
sourceType: "module",
|
sourceType: "module",
|
||||||
});
|
});
|
||||||
}, "acorn.parse()", !ufuzz.verbose);
|
}, "acorn.parse()", !ufuzz.verbose);
|
||||||
if (!ok) process.exit(1);
|
if (!ok && isFinite(num_iterations)) {
|
||||||
|
console.log();
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log();
|
console.log();
|
||||||
|
|||||||
Reference in New Issue
Block a user