Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,12 @@ writer.options = { ...inspect.defaultOptions, showProxy: true };
// Converts static import statement to dynamic import statement
const toDynamicImport = (codeLine) => {
let dynamicImportStatement = '';
const ast = acornParse(codeLine, { __proto__: null, sourceType: 'module', ecmaVersion: 'latest' });
let ast;
try {
ast = acornParse(codeLine, { __proto__: null, sourceType: 'module', ecmaVersion: 'latest' });
} catch {
return codeLine;
}
acornWalk.ancestor(ast, {
ImportDeclaration(node) {
const awaitDynamicImport = `await import(${JSONStringify(node.source.value)});`;
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-repl-import-incomplete-crash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
require('../common');
const repl = require('repl');

// Regression test for https://github.com/nodejs/node/issues/63551:
// Typing a bare `import` keyword in the REPL must not crash the process.
const replserver = new repl.REPLServer();

replserver.emit('line', 'import');
replserver.emit('line', '.exit');