Skip to content

Commit

Permalink
repl: enable dynamic import
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Apr 23, 2018
1 parent 3de362e commit eee5c1f
Showing 1 changed file with 12 additions and 1 deletion.
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);
},
});
} catch (e) {
debug('parse error %j', code, e);
Expand Down

0 comments on commit eee5c1f

Please sign in to comment.