diff --git a/doc/api/esm.md b/doc/api/esm.md index 93152f569d3e26..707eb9d41d172c 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -717,13 +717,18 @@ into a new instance of `library.wasm`: ```js import source libraryModule from './library.wasm'; -const instance1 = await WebAssembly.instantiate(libraryModule, { - custom: import1, -}); +const instance1 = await WebAssembly.instantiate(libraryModule, importObject1); -const instance2 = await WebAssembly.instantiate(libraryModule, { - custom: import2, -}); +const instance2 = await WebAssembly.instantiate(libraryModule, importObject2); +``` + +In addition to the static source phase, there is also a dynamic variant of the +source phase via the `import.source` dynamic phase import syntax: + +```js +const dynamicLibrary = await import.source('./library.wasm'); + +const instance = await WebAssembly.instantiate(dynamicLibrary, importObject); ``` diff --git a/eslint.config.mjs b/eslint.config.mjs index 75241d0eed65c4..5f2e5b3b857cea 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -104,6 +104,7 @@ export default [ parser: babelEslintParser, parserOptions: { babelOptions: { + parserOpts: { createImportExpressions: true }, plugins: [ babelPluginProposalExplicitResourceManagement, babelPluginSyntaxImportAttributes, diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 1c7e9ff5a55474..2290a9072bfcfb 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -1065,10 +1065,8 @@ void ModuleWrap::SetImportModuleDynamicallyCallback( realm->set_host_import_module_dynamically_callback(import_callback); isolate->SetHostImportModuleDynamicallyCallback(ImportModuleDynamically); - // TODO(guybedford): Enable this once - // https://github.com/nodejs/node/pull/56842 lands. - // isolate->SetHostImportModuleWithPhaseDynamicallyCallback( - // ImportModuleDynamicallyWithPhase); + isolate->SetHostImportModuleWithPhaseDynamicallyCallback( + ImportModuleDynamicallyWithPhase); } void ModuleWrap::HostInitializeImportMetaObjectCallback( diff --git a/test/es-module/test-esm-wasm.mjs b/test/es-module/test-esm-wasm.mjs index b7a9230dd184b2..41e56b988a9f8f 100644 --- a/test/es-module/test-esm-wasm.mjs +++ b/test/es-module/test-esm-wasm.mjs @@ -124,8 +124,7 @@ describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () => strictEqual(code, 0); }); - // TODO: Enable this once https://github.com/nodejs/node/pull/56842 lands. - it.skip('should support dynamic source phase imports', async () => { + it('should support dynamic source phase imports', async () => { const { code, stderr, stdout } = await spawnPromisified(execPath, [ '--no-warnings', '--experimental-wasm-modules', @@ -166,8 +165,7 @@ describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () => strictEqual(code, 0); }); - // TODO: Enable this once https://github.com/nodejs/node/pull/56842 lands. - it.skip('should not execute dynamic source phase imports', async () => { + it('should not execute dynamic source phase imports', async () => { const { code, stderr, stdout } = await spawnPromisified(execPath, [ '--no-warnings', '--experimental-wasm-modules', @@ -181,8 +179,7 @@ describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () => strictEqual(code, 0); }); - // TODO: Enable this once https://github.com/nodejs/node/pull/56842 lands. - it.skip('should throw for dynamic source phase imports not defined', async () => { + it('should throw for dynamic source phase imports not defined', async () => { const fileUrl = fixtures.fileURL('es-modules/wasm-source-phase.js'); const { code, stderr, stdout } = await spawnPromisified(execPath, [ '--no-warnings', @@ -195,6 +192,7 @@ describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () => ' strictEqual(e instanceof SyntaxError, true);', ' strictEqual(e.message.includes("Source phase import object is not defined for module"), true);', ` strictEqual(e.message.includes(${JSON.stringify(fileUrl)}), true);`, + ` return true`, '});', ].join('\n'), ]); @@ -238,8 +236,7 @@ describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () => notStrictEqual(code, 0); }); - // TODO: Enable this once https://github.com/nodejs/node/pull/56842 lands. - it.skip('should throw for vm source phase dynamic import', async () => { + it('should throw for vm source phase dynamic import', async () => { const { code, stderr, stdout } = await spawnPromisified(execPath, [ '--no-warnings', '--experimental-wasm-modules',