Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
repl: enable dynamic import
  • Loading branch information
devsnek committed Apr 23, 2018
commit eee5c1f6bd8c7ba8ce468b5022401b9051f9aa85
13 changes: 12 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const {
} = require('internal/modules/cjs/helpers');
const internalUtil = require('internal/util');
const { isTypedArray } = require('internal/util/types');
const { getURLFromFilePath } = require('internal/url');
const util = require('util');
const utilBinding = process.binding('util');
const { inherits } = util;
Expand Down Expand Up @@ -256,7 +257,17 @@ function REPLServer(prompt,
}
script = vm.createScript(code, {
filename: file,
displayErrors: true
displayErrors: true,
async resolveDynamicImport(specifier, scriptOrModule) {
const loader = await require('internal/process/esm_loader')
.loaderPromise;

const filename = scriptOrModule.filename;
const referrer = scriptOrModule.url ||
getURLFromFilePath(filename === 'repl' ?
path.join(process.cwd(), filename) : filename).href;
return loader.import(specifier, referrer);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this can work without any isNamespace checks then?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't work, it's wrong and needs a test :D

},
});
} catch (e) {
debug('parse error %j', code, e);
Expand Down