Skip to content

Commit bf1ec67

Browse files
committed
lib: fix TypeScript support check in jitless mode
Moved the check to assertTypeScript and improved the error message.
1 parent e6cb215 commit bf1ec67

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

doc/api/errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3356,7 +3356,7 @@ The WASI instance has not been started.
33563356

33573357
A feature requiring WebAssembly was used, but WebAssembly is not supported or
33583358
has been disabled in the current environment (for example, when running with
3359-
`--jitless`).
3359+
`--jitless`). The error message specifies which feature requires WebAssembly.
33603360

33613361
<a id="ERR_WEBASSEMBLY_RESPONSE"></a>
33623362

lib/internal/errors.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,9 @@ E('ERR_VM_MODULE_NOT_MODULE',
19051905
'Provided module is not an instance of Module', Error);
19061906
E('ERR_VM_MODULE_STATUS', 'Module status %s', Error);
19071907
E('ERR_WASI_ALREADY_STARTED', 'WASI instance has already started', Error);
1908-
E('ERR_WEBASSEMBLY_NOT_SUPPORTED', 'WebAssembly is not supported', Error);
1908+
E('ERR_WEBASSEMBLY_NOT_SUPPORTED',
1909+
'WebAssembly is not supported in this environment, but is required for %s',
1910+
Error);
19091911
E('ERR_WEBASSEMBLY_RESPONSE', 'WebAssembly response %s', TypeError);
19101912
E('ERR_WORKER_INIT_FAILED', 'Worker initialization failure: %s', Error);
19111913
E('ERR_WORKER_INVALID_EXEC_ARGV', (errors, msg = 'invalid execArgv flags') =>

lib/internal/modules/typescript.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const {
44
ObjectPrototypeHasOwnProperty,
5-
globalThis: { WebAssembly },
65
} = primordials;
76
const {
87
validateBoolean,
@@ -19,7 +18,6 @@ const {
1918
ERR_INVALID_TYPESCRIPT_SYNTAX,
2019
ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING,
2120
ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX,
22-
ERR_WEBASSEMBLY_NOT_SUPPORTED,
2321
} = require('internal/errors').codes;
2422
const { getOptionValue } = require('internal/options');
2523
const assert = require('internal/assert');
@@ -46,9 +44,6 @@ const getTypeScriptParsingMode = getLazy(() =>
4644
*/
4745
const loadTypeScriptParser = getLazy(() => {
4846
assertTypeScript();
49-
if (WebAssembly === undefined) {
50-
throw new ERR_WEBASSEMBLY_NOT_SUPPORTED();
51-
}
5247
const amaro = require('internal/deps/amaro/dist/index');
5348
return amaro.transformSync;
5449
});

lib/internal/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ const {
4646
SymbolPrototypeGetDescription,
4747
SymbolReplace,
4848
SymbolSplit,
49+
globalThis,
4950
} = primordials;
5051

5152
const {
5253
codes: {
5354
ERR_NO_CRYPTO,
5455
ERR_NO_TYPESCRIPT,
56+
ERR_WEBASSEMBLY_NOT_SUPPORTED,
5557
ERR_UNKNOWN_SIGNAL,
5658
},
5759
isErrorStackTraceLimitWritable,
@@ -244,6 +246,8 @@ function assertCrypto() {
244246
function assertTypeScript() {
245247
if (noTypeScript)
246248
throw new ERR_NO_TYPESCRIPT();
249+
if (globalThis.WebAssembly === undefined)
250+
throw new ERR_WEBASSEMBLY_NOT_SUPPORTED('TypeScript');
247251
}
248252

249253
/**

test/es-module/test-typescript.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,6 @@ test('expect error when executing a TypeScript file with --jitless', async () =>
350350
]);
351351

352352
assert.match(result.stderr, /ERR_WEBASSEMBLY_NOT_SUPPORTED/);
353-
assert.match(result.stderr, /WebAssembly is not supported/);
353+
assert.match(result.stderr, /WebAssembly is not supported in this environment, but is required for TypeScript/);
354354
assert.strictEqual(result.code, 1);
355355
});

0 commit comments

Comments
 (0)