Do not allow arrow functions in the middle of an expression

This commit is contained in:
Anthony Van de Gejuchte
2016-10-28 20:42:28 +02:00
committed by Richard van Velzen
parent c2112d5886
commit 0aa526e72c
2 changed files with 29 additions and 8 deletions

View File

@@ -57,6 +57,25 @@ describe("Arrow functions", function() {
e.message === "SyntaxError: Unexpected newline before arrow (=>)";
}
for (var i = 0; i < tests.length; i++) {
assert.throws(test(tests[i]), error);
}
});
it("Should not accept arrow functions in the middle or end of an expression", function() {
var tests = [
"typeof x => 0",
"0 + x => 0"
];
var test = function(code) {
return function() {
uglify.parse(code, {fromString: true});
}
}
var error = function(e) {
return e instanceof uglify.JS_Parse_Error &&
e.message === "SyntaxError: Unexpected token: arrow (=>)";
}
for (var i = 0; i < tests.length; i++) {
assert.throws(test(tests[i]), error);
}