From f109f3cae1cd81db22ba490a4da17a7a4c495047 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 30 Aug 2018 16:10:26 -0700 Subject: Rename `wasm2asm` to `wasm2js`, emit ESM by default (#1642) * Rename the `wasm2asm` tool to `wasm2js` This commit performs a relatively simple rename of the `wasm2asm` tool to `wasm2js`. The functionality of the tool doesn't change just yet but it's intended that we'll start generating an ES module instead of just an `asm.js` function soon. * wasm2js: Support `*.wasm` input files Previously `wasm2js` only supported `*.wast` files but to make it a bit easier to use in tooling pipelines this commit adds support for reading in a `*.wasm` file directly. Determining which parser to use depends on the input filename, where the binary parser is used with `*.wasm` files and the wast parser is used for all other files. * wasm2js: Emit ESM imports/exports by default This commit alters the default behavior of `wasm2js` to emit an ESM by default, either importing items from the environment or exporting. Items like initialization of memory are also handled here. --- scripts/test/node-esm-loader.mjs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 scripts/test/node-esm-loader.mjs (limited to 'scripts/test/node-esm-loader.mjs') diff --git a/scripts/test/node-esm-loader.mjs b/scripts/test/node-esm-loader.mjs new file mode 100644 index 000000000..73ff47800 --- /dev/null +++ b/scripts/test/node-esm-loader.mjs @@ -0,0 +1,32 @@ +// originally lifted from https://nodejs.org/api/esm.html + +import path from 'path'; +import process from 'process'; +import Module from 'module'; + +const builtins = Module.builtinModules; + +const baseURL = new URL('file://'); +baseURL.pathname = `${process.cwd()}/`; + +export function resolve(specifier, parentModuleURL = baseURL, defaultResolve) { + if (builtins.includes(specifier)) { + return { + url: specifier, + format: 'builtin' + }; + } + // Resolve the 'spectest' module to our special module which has some builtins + if (specifier == 'spectest') { + const resolved = new URL('./scripts/test/spectest.js', parentModuleURL); + return { + url: resolved.href, + format: 'esm' + }; + } + const resolved = new URL(specifier, parentModuleURL); + return { + url: resolved.href, + format: 'esm' + }; +} -- cgit v1.2.3