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 4b4a33e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/internal/repl/experimental/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ const matchers = [
],
},
{
// Keyword
// Keywords
color: inspect.colors[inspect.styles.special],
patterns: [
/=>|\b(this|set|get|as|async|await|break|case|catch|class|const|constructor|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|if|implements|import|in|instanceof|interface|let|var|of|new|package|private|protected|public|return|static|super|switch|throw|throws|try|typeof|void|while|with|yield)\b/g,
/=>|\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|from|function|if|import|in|instanceof|let|new|of|return|static|switch|throw|try|typeof|var|void|while|with|yield|this|super)\b/g,
],
},
{
Expand Down
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';
},
});
} 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 4b4a33e

Please sign in to comment.