Skip to content

Commit a3456a8

Browse files
authored
Fix minor ParenthesizedExpression-related issues (#1277)
And run test262 test suite with preserveParens enabled FIX: Fix a bug where some invalid `delete` expressions were let through when the operand was parenthesized and `preserveParens` was enabled.
1 parent 80b3562 commit a3456a8

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

acorn/src/expression.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ pp.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forInit)
242242
node.argument = this.parseMaybeUnary(null, true, update, forInit)
243243
this.checkExpressionErrors(refDestructuringErrors, true)
244244
if (update) this.checkLValSimple(node.argument)
245-
else if (this.strict && node.operator === "delete" &&
246-
node.argument.type === "Identifier")
245+
else if (this.strict && node.operator === "delete" && isLocalVariableAccess(node.argument))
247246
this.raiseRecoverable(node.start, "Deleting local variable in strict mode")
248247
else if (node.operator === "delete" && isPrivateFieldAccess(node.argument))
249248
this.raiseRecoverable(node.start, "Private fields can not be deleted")
@@ -278,10 +277,18 @@ pp.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forInit)
278277
}
279278
}
280279

280+
function isLocalVariableAccess(node) {
281+
return (
282+
node.type === "Identifier" ||
283+
node.type === "ParenthesizedExpression" && isLocalVariableAccess(node.expression)
284+
)
285+
}
286+
281287
function isPrivateFieldAccess(node) {
282288
return (
283289
node.type === "MemberExpression" && node.property.type === "PrivateIdentifier" ||
284-
node.type === "ChainExpression" && isPrivateFieldAccess(node.expression)
290+
node.type === "ChainExpression" && isPrivateFieldAccess(node.expression) ||
291+
node.type === "ParenthesizedExpression" && isPrivateFieldAccess(node.expression)
285292
)
286293
}
287294

bin/run_test262.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function loadList(filename) {
1010
}
1111

1212
run(
13-
(content, {sourceType}) => parse(content, {sourceType, ecmaVersion: "latest"}),
13+
(content, {sourceType}) => parse(content, {sourceType, ecmaVersion: "latest", preserveParens: true}),
1414
{
1515
testsDirectory: path.dirname(require.resolve("test262/package.json")),
1616
skip: test => test.attrs.features &&

0 commit comments

Comments
 (0)