Only last parameter between parentheses can have spread

This commit is contained in:
Anthony Van de Gejuchte
2016-06-12 22:40:07 +02:00
committed by Richard van Velzen
parent f9cab7ad61
commit 6b03b800b3
5 changed files with 170 additions and 0 deletions

30
test/mocha/function.js Normal file
View File

@@ -0,0 +1,30 @@
var assert = require("assert");
var uglify = require("../../");
describe("Function", function() {
it("Should not accept spread on non-last parameters", function() {
var tests = [
"var a = function(...a, b) { return a.join(b) }",
"var b = function(a, b, ...c, d) { return c.join(a + b) + d }",
"function foo(...a, b) { return a.join(b) }",
"function bar(a, b, ...c, d) { return c.join(a + b) + d }",
"var a = function*(...a, b) { return a.join(b) }",
"var b = function*(a, b, ...c, d) { return c.join(a + b) + d }",
"function* foo(...a, b) { return a.join(b) }",
"function* bar(a, b, ...c, d) { return c.join(a + b) + d }"
];
var test = function(code) {
return function() {
uglify.parse(code, {fromString: true});
}
}
var error = function(e) {
return e instanceof uglify.JS_Parse_Error &&
e.message === "Unexpected token: expand (...)";
}
for (var i = 0; i < tests.length; i++) {
assert.throws(test(tests[i]), error);
}
});
});