module: throw ERR_NO_TYPESCRIPT when compiled without amaro

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Marco Ippolito 2024-10-11 20:41:38 +05:00 committed by GitHub
parent fdf838aee6
commit 90f56dbad9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 1 deletions

View File

@ -2330,6 +2330,17 @@ OpenSSL crypto support.
An attempt was made to use features that require [ICU][], but Node.js was not
compiled with ICU support.
<a id="ERR_NO_TYPESCRIPT"></a>
### `ERR_NO_TYPESCRIPT`
<!-- YAML
added: REPLACEME
-->
An attempt was made to use features that require [Native TypeScript support][], but Node.js was not
compiled with TypeScript support.
<a id="ERR_OPERATION_FAILED"></a>
### `ERR_OPERATION_FAILED`
@ -4128,6 +4139,7 @@ An error occurred trying to allocate memory. This should never happen.
[ICU]: intl.md#internationalization-support
[JSON Web Key Elliptic Curve Registry]: https://www.iana.org/assignments/jose/jose.xhtml#web-key-elliptic-curve
[JSON Web Key Types Registry]: https://www.iana.org/assignments/jose/jose.xhtml#web-key-types
[Native TypeScript support]: typescript.md#type-stripping
[Node.js error codes]: #nodejs-error-codes
[Permission Model]: permissions.md#permission-model
[RFC 7230 Section 3]: https://tools.ietf.org/html/rfc7230#section-3

View File

@ -1601,6 +1601,8 @@ E('ERR_NO_CRYPTO',
'Node.js is not compiled with OpenSSL crypto support', Error);
E('ERR_NO_ICU',
'%s is not supported on Node.js compiled without ICU', TypeError);
E('ERR_NO_TYPESCRIPT',
'Node.js is not compiled with TypeScript support', Error);
E('ERR_OPERATION_FAILED', 'Operation failed: %s', Error, TypeError);
E('ERR_OUT_OF_RANGE',
(str, range, input, replaceDefaultBoolean = false) => {

View File

@ -28,7 +28,7 @@ const assert = require('internal/assert');
const { Buffer } = require('buffer');
const { getOptionValue } = require('internal/options');
const { setOwnProperty, getLazy } = require('internal/util');
const { assertTypeScript, setOwnProperty, getLazy } = require('internal/util');
const { inspect } = require('internal/util/inspect');
const lazyTmpdir = getLazy(() => require('os').tmpdir());
@ -327,6 +327,7 @@ const getTypeScriptParsingMode = getLazy(() =>
* @returns {Function} The TypeScript parser function.
*/
const loadTypeScriptParser = getLazy(() => {
assertTypeScript();
const amaro = require('internal/deps/amaro/dist/index');
return amaro.transformSync;
});

View File

@ -45,6 +45,7 @@ const {
const {
codes: {
ERR_NO_CRYPTO,
ERR_NO_TYPESCRIPT,
ERR_UNKNOWN_SIGNAL,
},
isErrorStackTraceLimitWritable,
@ -65,6 +66,7 @@ const { getOptionValue } = require('internal/options');
const { encodings } = internalBinding('string_decoder');
const noCrypto = !process.versions.openssl;
const noTypeScript = !process.versions.amaro;
const isWindows = process.platform === 'win32';
const isMacOS = process.platform === 'darwin';
@ -194,6 +196,11 @@ function assertCrypto() {
throw new ERR_NO_CRYPTO();
}
function assertTypeScript() {
if (noTypeScript)
throw new ERR_NO_TYPESCRIPT();
}
/**
* Move the "slow cases" to a separate function to make sure this function gets
* inlined properly. That prioritizes the common case.
@ -861,6 +868,7 @@ for (let i = 0; i < encodings.length; ++i)
module.exports = {
getLazy,
assertCrypto,
assertTypeScript,
cachedResult,
convertToValidSignal,
createClassWrapper,