mirror of
https://github.com/nodejs/node.git
synced 2025-05-15 19:07:23 +00:00

This follows the EPS an allows the node CLI to have ESM as an entry point. `node ./example.mjs`. A newer V8 is needed for `import()` so that is not included. `import.meta` is still in specification stage so that also is not included. PR-URL: https://github.com/nodejs/node/pull/14369 Author: Bradley Farias <bradley.meck@gmail.com> Author: Guy Bedford <guybedford@gmail.com> Author: Jan Krems <jan.krems@groupon.com> Author: Timothy Gu <timothygu99@gmail.com> Author: Michaël Zasso <targos@protonmail.com> Author: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
34 lines
994 B
JavaScript
34 lines
994 B
JavaScript
'use strict';
|
|
|
|
const ModuleJob = require('internal/loader/ModuleJob');
|
|
const { SafeMap } = require('internal/safe_globals');
|
|
const debug = require('util').debuglog('esm');
|
|
const errors = require('internal/errors');
|
|
|
|
// Tracks the state of the loader-level module cache
|
|
class ModuleMap extends SafeMap {
|
|
get(url) {
|
|
if (typeof url !== 'string') {
|
|
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'url', 'string');
|
|
}
|
|
return super.get(url);
|
|
}
|
|
set(url, job) {
|
|
if (typeof url !== 'string') {
|
|
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'url', 'string');
|
|
}
|
|
if (job instanceof ModuleJob !== true) {
|
|
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'job', 'ModuleJob');
|
|
}
|
|
debug(`Storing ${url} in ModuleMap`);
|
|
return super.set(url, job);
|
|
}
|
|
has(url) {
|
|
if (typeof url !== 'string') {
|
|
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'url', 'string');
|
|
}
|
|
return super.has(url);
|
|
}
|
|
}
|
|
module.exports = ModuleMap;
|