Skip to content

Commit

Permalink
resolve 'delete' edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
avivkeller committed May 13, 2024
1 parent e186d94 commit 0c46beb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/internal/repl/experimental/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const {
isStaticIdentifier,
isScopeOpen,
stripVTControlCharacters: stripAnsi,
acornParseOptions,
} = require('internal/repl/experimental/util');
const getHistory = require('internal/repl/experimental/history');
const {
Expand Down Expand Up @@ -192,7 +193,7 @@ class ExperimentalREPLServer extends EventEmitter {
}

let { node: expression } = walk.findNodeAround(
acornParse(line, { ecmaVersion: 2021 }),
acornParse(line, acornParseOptions),
line.length,
(type) => type === 'MemberExpression' || type === 'Identifier',
);
Expand Down Expand Up @@ -278,7 +279,7 @@ class ExperimentalREPLServer extends EventEmitter {
preview(line) {
try {
const { node: expression } = walk.findNodeAround(
acornParse(line, { ecmaVersion: 2021 }),
acornParse(line, acornParseOptions),
line.length,
(type) => type === 'MemberExpression' || type === 'Identifier',
);
Expand Down
21 changes: 17 additions & 4 deletions lib/internal/repl/experimental/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,23 @@ const {
} = require('internal/deps/acorn/acorn/dist/acorn');
const walk = require('internal/deps/acorn/acorn-walk/dist/walk');

const acornParseOptions = {
__proto__: null,
ecmaVersion: 2021,
allowReserved: true,
allowReturnOutsideFunction: true,
allowImportExportEverywhere: true,
allowAwaitOutsideFunction: true,
allowSuperOutsideMethod: true,
allowHashBang: true,
checkPrivateFields: false,
};

function isStaticIdentifier(exp) {
let isStatic = true;

try {
walk.simple(acornParse(exp, {
ecmaVersion: 2021,
allowImportExportEverywhere: true,
}), {
walk.simple(acornParse(exp, acornParseOptions), {
VariableDeclaration() {
isStatic = false;
},
Expand Down Expand Up @@ -71,6 +80,9 @@ function isStaticIdentifier(exp) {
ExportAllDeclaration() {
isStatic = false;
},
UnaryExpression(node) {
isStatic = node.operator !== 'delete';
}

Check failure on line 85 in lib/internal/repl/experimental/util.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
});
} catch {
// We ignore the error because we don't care about invalid syntax.
Expand Down Expand Up @@ -299,4 +311,5 @@ module.exports = {
stripVTControlCharacters,
isStaticIdentifier,
isScopeOpen,
acornParseOptions,
};

0 comments on commit 0c46beb

Please sign in to comment.