esm: use wasm version of cjs-module-lexer

The synchronous version has been available since 1.4.0.

PR-URL: https://github.com/nodejs/node/pull/60663
Refs: https://github.com/nodejs/node/issues/59913
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Joyee Cheung authored and Node.js GitHub Bot committed 2025-11-12 18:34:59 +00:00
1 parent 275215f7bc
commit 04a086a1f4
2 files changed
+14 -3

No files matched your search

+8 -3
View File
@@ -74,12 +74,17 @@ function getSource(url) {
let cjsParse;
/**
* Initializes the CommonJS module lexer parser using the JavaScript version.
* TODO(joyeecheung): Use `require('internal/deps/cjs-module-lexer/dist/lexer').initSync()`
* when cjs-module-lexer 1.4.0 is rolled in.
*/
function initCJSParseSync() {
if (cjsParse === undefined) {
cjsParse = require('internal/deps/cjs-module-lexer/lexer').parse;
if (typeof WebAssembly !== 'undefined') {
const { parse, initSync } = require('internal/deps/cjs-module-lexer/dist/lexer');
initSync();
cjsParse = parse;
} else {
const { parse } = require('internal/deps/cjs-module-lexer/lexer');
cjsParse = parse;
}
}
}
@@ -0,0 +1,6 @@
// Flags: --jitless
// Tests that importing a CJS module works in JIT-less mode (i.e. falling back to the
// JS parser if WASM is not available).
import '../common/index.mjs';
import '../fixtures/empty.cjs';