Skip to content

Commit 90f56db

Browse files
module: throw ERR_NO_TYPESCRIPT when compiled without amaro
PR-URL: #55332 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent fdf838a commit 90f56db

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

doc/api/errors.md

+12
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,17 @@ OpenSSL crypto support.
23302330
An attempt was made to use features that require [ICU][], but Node.js was not
23312331
compiled with ICU support.
23322332

2333+
<a id="ERR_NO_TYPESCRIPT"></a>
2334+
2335+
### `ERR_NO_TYPESCRIPT`
2336+
2337+
<!-- YAML
2338+
added: REPLACEME
2339+
-->
2340+
2341+
An attempt was made to use features that require [Native TypeScript support][], but Node.js was not
2342+
compiled with TypeScript support.
2343+
23332344
<a id="ERR_OPERATION_FAILED"></a>
23342345

23352346
### `ERR_OPERATION_FAILED`
@@ -4128,6 +4139,7 @@ An error occurred trying to allocate memory. This should never happen.
41284139
[ICU]: intl.md#internationalization-support
41294140
[JSON Web Key Elliptic Curve Registry]: https://www.iana.org/assignments/jose/jose.xhtml#web-key-elliptic-curve
41304141
[JSON Web Key Types Registry]: https://www.iana.org/assignments/jose/jose.xhtml#web-key-types
4142+
[Native TypeScript support]: typescript.md#type-stripping
41314143
[Node.js error codes]: #nodejs-error-codes
41324144
[Permission Model]: permissions.md#permission-model
41334145
[RFC 7230 Section 3]: https://tools.ietf.org/html/rfc7230#section-3

lib/internal/errors.js

+2
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,8 @@ E('ERR_NO_CRYPTO',
16011601
'Node.js is not compiled with OpenSSL crypto support', Error);
16021602
E('ERR_NO_ICU',
16031603
'%s is not supported on Node.js compiled without ICU', TypeError);
1604+
E('ERR_NO_TYPESCRIPT',
1605+
'Node.js is not compiled with TypeScript support', Error);
16041606
E('ERR_OPERATION_FAILED', 'Operation failed: %s', Error, TypeError);
16051607
E('ERR_OUT_OF_RANGE',
16061608
(str, range, input, replaceDefaultBoolean = false) => {

lib/internal/modules/helpers.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const assert = require('internal/assert');
2828

2929
const { Buffer } = require('buffer');
3030
const { getOptionValue } = require('internal/options');
31-
const { setOwnProperty, getLazy } = require('internal/util');
31+
const { assertTypeScript, setOwnProperty, getLazy } = require('internal/util');
3232
const { inspect } = require('internal/util/inspect');
3333

3434
const lazyTmpdir = getLazy(() => require('os').tmpdir());
@@ -327,6 +327,7 @@ const getTypeScriptParsingMode = getLazy(() =>
327327
* @returns {Function} The TypeScript parser function.
328328
*/
329329
const loadTypeScriptParser = getLazy(() => {
330+
assertTypeScript();
330331
const amaro = require('internal/deps/amaro/dist/index');
331332
return amaro.transformSync;
332333
});

lib/internal/util.js

+8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const {
4545
const {
4646
codes: {
4747
ERR_NO_CRYPTO,
48+
ERR_NO_TYPESCRIPT,
4849
ERR_UNKNOWN_SIGNAL,
4950
},
5051
isErrorStackTraceLimitWritable,
@@ -65,6 +66,7 @@ const { getOptionValue } = require('internal/options');
6566
const { encodings } = internalBinding('string_decoder');
6667

6768
const noCrypto = !process.versions.openssl;
69+
const noTypeScript = !process.versions.amaro;
6870

6971
const isWindows = process.platform === 'win32';
7072
const isMacOS = process.platform === 'darwin';
@@ -194,6 +196,11 @@ function assertCrypto() {
194196
throw new ERR_NO_CRYPTO();
195197
}
196198

199+
function assertTypeScript() {
200+
if (noTypeScript)
201+
throw new ERR_NO_TYPESCRIPT();
202+
}
203+
197204
/**
198205
* Move the "slow cases" to a separate function to make sure this function gets
199206
* inlined properly. That prioritizes the common case.
@@ -861,6 +868,7 @@ for (let i = 0; i < encodings.length; ++i)
861868
module.exports = {
862869
getLazy,
863870
assertCrypto,
871+
assertTypeScript,
864872
cachedResult,
865873
convertToValidSignal,
866874
createClassWrapper,

0 commit comments

Comments
 (0)