Skip to content

Commit

Permalink
fixup: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeck committed Oct 27, 2021
1 parent 2ad8d50 commit f584efb
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions doc/api/esm.md
Expand Up @@ -815,11 +815,11 @@ normally.
```js
/**
* This example causes
* This example causes
* @param {object} utilities
* @param {MessagePort} utilities.port
*/
export function getGlobalPreloadCode({port}) {
export function getGlobalPreloadCode({ port }) {
port.onmessage = (evt) => {
// ...
};
Expand Down
9 changes: 7 additions & 2 deletions lib/internal/modules/esm/initialize_import_meta.js
@@ -1,11 +1,16 @@
'use strict';

const { getOptionValue } = require('internal/options');
const experimentalImportMetaResolve =
getOptionValue('--experimental-import-meta-resolve');
const { PromisePrototypeThen, PromiseReject } = primordials;
const asyncESM = require('internal/process/esm_loader');

function createImportMetaResolve(defaultParentUrl) {
return async function resolve(specifier, parentUrl = defaultParentUrl) {
return PromisePrototypeCatch(
asyncESM.ESMLoader.resolve(specifier, parentUrl),
return PromisePrototypeThen(
asyncESM.esmLoader.resolve(specifier, parentUrl),
({ url }) => url,
(error) => (
error.code === 'ERR_UNSUPPORTED_DIR_IMPORT' ?
error.url : PromiseReject(error))
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/modules/esm/loader.js
Expand Up @@ -18,6 +18,7 @@ const {
SafeWeakMap,
globalThis,
} = primordials;
const { MessageChannel } = require('internal/worker/io');

const {
ERR_INVALID_ARG_TYPE,
Expand Down Expand Up @@ -403,7 +404,7 @@ class ESMLoader {
throw new ERR_INVALID_ARG_VALUE('builtinName', builtinName);
}, insidePreload, (fn) => {
if (finished || typeof fn !== 'function') {
throw new ERR_INVALID_ARG_TYPE('fn', fn)
throw new ERR_INVALID_ARG_TYPE('fn', fn);
}
replacedImportMetaInitializer = true;
const parent = next;
Expand Down
1 change: 0 additions & 1 deletion lib/internal/modules/esm/translators.js
Expand Up @@ -50,7 +50,6 @@ const {
const { maybeCacheSourceMap } = require('internal/source_map/source_map_cache');
const moduleWrap = internalBinding('module_wrap');
const { ModuleWrap } = moduleWrap;
const { getOptionValue } = require('internal/options');
const asyncESM = require('internal/process/esm_loader');
const { emitWarningSync } = require('internal/process/warning');
const { TextDecoder } = require('internal/encoding');
Expand Down
5 changes: 2 additions & 3 deletions test/es-module/test-esm-loader-mock.mjs
@@ -1,5 +1,4 @@
// Flags: --experimental-loader
// ./test/fixtures/es-module-loaders/mock-loader.mjs
// Flags: --loader ./test/fixtures/es-module-loaders/mock-loader.mjs
import '../common/index.mjs';
import assert from 'assert/strict';
import mock from 'node:mock';
Expand All @@ -8,7 +7,7 @@ mock('node:events', {
EventEmitter: 'This is mocked!'
});

// this resolves to node:events
// This resolves to node:events
assert.deepStrictEqual(await import('events'), Object.defineProperty({
__proto__: null,
EventEmitter: 'This is mocked!'
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-bootstrap-modules.js
Expand Up @@ -76,6 +76,7 @@ const expectedModules = new Set([
'NativeModule internal/modules/esm/module_job',
'NativeModule internal/modules/esm/module_map',
'NativeModule internal/modules/esm/resolve',
'NativeModule internal/modules/esm/initialize_import_meta',
'NativeModule internal/modules/esm/translators',
'NativeModule internal/process/esm_loader',
'NativeModule internal/options',
Expand Down

0 comments on commit f584efb

Please sign in to comment.