From a3456a8c6a5a3bc3d2b233f4eb7c922a5da63c3a Mon Sep 17 00:00:00 2001 From: adams85 <31276480+adams85@users.noreply.github.com> Date: Thu, 22 Feb 2024 08:08:16 +0100 Subject: [PATCH] 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. --- acorn/src/expression.js | 13 ++++++++++--- bin/run_test262.js | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/acorn/src/expression.js b/acorn/src/expression.js index 8aa29130d..06dcc6f92 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -242,8 +242,7 @@ pp.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forInit) node.argument = this.parseMaybeUnary(null, true, update, forInit) this.checkExpressionErrors(refDestructuringErrors, true) if (update) this.checkLValSimple(node.argument) - else if (this.strict && node.operator === "delete" && - node.argument.type === "Identifier") + else if (this.strict && node.operator === "delete" && isLocalVariableAccess(node.argument)) this.raiseRecoverable(node.start, "Deleting local variable in strict mode") else if (node.operator === "delete" && isPrivateFieldAccess(node.argument)) this.raiseRecoverable(node.start, "Private fields can not be deleted") @@ -278,10 +277,18 @@ pp.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forInit) } } +function isLocalVariableAccess(node) { + return ( + node.type === "Identifier" || + node.type === "ParenthesizedExpression" && isLocalVariableAccess(node.expression) + ) +} + function isPrivateFieldAccess(node) { return ( node.type === "MemberExpression" && node.property.type === "PrivateIdentifier" || - node.type === "ChainExpression" && isPrivateFieldAccess(node.expression) + node.type === "ChainExpression" && isPrivateFieldAccess(node.expression) || + node.type === "ParenthesizedExpression" && isPrivateFieldAccess(node.expression) ) } diff --git a/bin/run_test262.js b/bin/run_test262.js index 078b22601..129aebec5 100644 --- a/bin/run_test262.js +++ b/bin/run_test262.js @@ -10,7 +10,7 @@ function loadList(filename) { } run( - (content, {sourceType}) => parse(content, {sourceType, ecmaVersion: "latest"}), + (content, {sourceType}) => parse(content, {sourceType, ecmaVersion: "latest", preserveParens: true}), { testsDirectory: path.dirname(require.resolve("test262/package.json")), skip: test => test.attrs.features &&