Skip to content

Commit 25c615c

Browse files
module: throw ERR_NO_TYPESCRIPT when compiled without amaro
1 parent 54b5ec9 commit 25c615c

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

doc/api/errors.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,17 @@ Data passed to a Brotli stream was not successfully compressed.
717717

718718
An invalid parameter key was passed during construction of a Brotli stream.
719719

720+
<a id="ERR_NO_TYPESCRIPT"></a>
721+
722+
### `ERR_NO_TYPESCRIPT`
723+
724+
<!-- YAML
725+
added: REPLACEME
726+
-->
727+
728+
An attempt was made to use features that require [Native TypeScript support][], but Node.js was not
729+
compiled with TypeScript support.
730+
720731
<a id="ERR_BUFFER_CONTEXT_NOT_AVAILABLE"></a>
721732

722733
### `ERR_BUFFER_CONTEXT_NOT_AVAILABLE`
@@ -4111,6 +4122,7 @@ An error occurred trying to allocate memory. This should never happen.
41114122
[ICU]: intl.md#internationalization-support
41124123
[JSON Web Key Elliptic Curve Registry]: https://www.iana.org/assignments/jose/jose.xhtml#web-key-elliptic-curve
41134124
[JSON Web Key Types Registry]: https://www.iana.org/assignments/jose/jose.xhtml#web-key-types
4125+
[Native TypeScript support]: typescript.md#type-stripping
41144126
[Node.js error codes]: #nodejs-error-codes
41154127
[Permission Model]: permissions.md#permission-model
41164128
[RFC 7230 Section 3]: https://tools.ietf.org/html/rfc7230#section-3

lib/internal/errors.js

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

lib/internal/modules/helpers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const assert = require('internal/assert');
2727

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

3333
const lazyTmpdir = getLazy(() => require('os').tmpdir());
@@ -342,6 +342,7 @@ function loadTypeScriptParser(parser) {
342342
if (parser) {
343343
typeScriptParser = parser;
344344
} else {
345+
assertTypeScript();
345346
const amaro = require('internal/deps/amaro/dist/index');
346347
// Default option for Amaro is to perform Type Stripping only.
347348
typeScriptParsingMode = getOptionValue('--experimental-transform-types') ? 'transform' : 'strip-only';

lib/internal/util.js

Lines changed: 8 additions & 0 deletions
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)