fix delete syntax checking under "use strict"

This commit is contained in:
alexlamsl 2017-04-23 04:18:03 +08:00
parent 379365d391
commit a60171c00b
3 changed files with 8 additions and 2 deletions

View File

@ -1470,7 +1470,7 @@ function parse($TEXT, options) {
croak("Invalid use of " + op + " operator", token.line, token.col, token.pos);
break;
case "delete":
if (!(expr instanceof AST_PropAccess) && S.input.has_directive("use strict"))
if (expr instanceof AST_SymbolRef && S.input.has_directive("use strict"))
croak("Calling delete on expression not allowed in strict mode", expr.start.line, expr.start.col, expr.start.pos);
break;
}

View File

@ -1,8 +1,14 @@
function f(x) {
delete 42;
delete (0, x);
delete null;
delete x;
}
function g(x) {
"use strict";
delete 42;
delete (0, x);
delete null;
delete x;
}

View File

@ -401,7 +401,7 @@ describe("bin/uglifyjs", function () {
assert.ok(err);
assert.strictEqual(stdout, "");
assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [
"Parse error at test/input/invalid/delete.js:7,11",
"Parse error at test/input/invalid/delete.js:13,11",
" delete x;",
" ^",
"ERROR: Calling delete on expression not allowed in strict mode"