mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 13:40:37 +00:00
esm: support top-level Wasm without package type
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
PR-URL: https://github.com/nodejs/node/pull/57610 Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
parent
78e2f99651
commit
870dec25f7
@ -33,7 +33,8 @@ If a file is found, its path will be passed to the
|
||||
|
||||
* The program was started with a command-line flag that forces the entry
|
||||
point to be loaded with ECMAScript module loader, such as `--import`.
|
||||
* The file has an `.mjs` extension.
|
||||
* The file has an `.mjs` or `.wasm` (with `--experimental-wasm-modules`)
|
||||
extension.
|
||||
* The file does not have a `.cjs` extension, and the nearest parent
|
||||
`package.json` file contains a top-level [`"type"`][] field with a value of
|
||||
`"module"`.
|
||||
|
@ -62,6 +62,7 @@ function shouldUseESMLoader(mainPath) {
|
||||
|
||||
// Determine the module format of the entry point.
|
||||
if (mainPath && StringPrototypeEndsWith(mainPath, '.mjs')) { return true; }
|
||||
if (mainPath && StringPrototypeEndsWith(mainPath, '.wasm')) { return true; }
|
||||
if (!mainPath || StringPrototypeEndsWith(mainPath, '.cjs')) { return false; }
|
||||
|
||||
if (getOptionValue('--experimental-strip-types')) {
|
||||
|
@ -91,6 +91,18 @@ describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () =>
|
||||
match(stderr, /WebAssembly/);
|
||||
});
|
||||
|
||||
it('should support top-level execution', async () => {
|
||||
const { code, stderr, stdout } = await spawnPromisified(execPath, [
|
||||
'--no-warnings',
|
||||
'--experimental-wasm-modules',
|
||||
fixtures.path('es-modules/top-level-wasm.wasm'),
|
||||
]);
|
||||
|
||||
strictEqual(stderr, '');
|
||||
strictEqual(stdout, '[Object: null prototype] { prop: \'hello world\' }\n');
|
||||
strictEqual(code, 0);
|
||||
});
|
||||
|
||||
it('should support static source phase imports', async () => {
|
||||
const { code, stderr, stdout } = await spawnPromisified(execPath, [
|
||||
'--no-warnings',
|
||||
|
BIN
test/fixtures/es-modules/top-level-wasm.wasm
vendored
Normal file
BIN
test/fixtures/es-modules/top-level-wasm.wasm
vendored
Normal file
Binary file not shown.
11
test/fixtures/es-modules/wasm-function.js
vendored
Normal file
11
test/fixtures/es-modules/wasm-function.js
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
export function call1 (func, thisObj, arg0) {
|
||||
return func.call(thisObj, arg0);
|
||||
}
|
||||
|
||||
export function call2 (func, thisObj, arg0, arg1) {
|
||||
return func.call(thisObj, arg0, arg1);
|
||||
}
|
||||
|
||||
export function call3 (func, thisObj, arg0, arg1, arg2) {
|
||||
return func.call(thisObj, arg0, arg1, arg2);
|
||||
}
|
3
test/fixtures/es-modules/wasm-object.js
vendored
Normal file
3
test/fixtures/es-modules/wasm-object.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export const { get: getProperty, set: setProperty } = Reflect;
|
||||
export const { create } = Object;
|
||||
export const global = globalThis;
|
6
test/fixtures/es-modules/wasm-string-constants.js
vendored
Normal file
6
test/fixtures/es-modules/wasm-string-constants.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
const console = 'console';
|
||||
const hello_world = 'hello world';
|
||||
const log = 'log';
|
||||
const prop = 'prop';
|
||||
|
||||
export { console, hello_world as 'hello world', log, prop }
|
Loading…
Reference in New Issue
Block a user