module: remove experimental warning from type stripping

PR-URL: https://github.com/nodejs/node/pull/58643
Refs: https://github.com/nodejs/typescript/issues/24
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
Marco Ippolito 2025-06-11 12:12:04 +02:00 committed by GitHub
parent 8c17ceb38f
commit 6584d5f811
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 26 additions and 20 deletions

View File

@ -2,6 +2,9 @@
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/58643
description: Type stripping no longer emits an experimental warning.
- version: v23.6.0
pr-url: https://github.com/nodejs/node/pull/56350
description: Type stripping is enabled by default.

View File

@ -33,7 +33,8 @@ const {
* @type {string}
*/
const getTypeScriptParsingMode = getLazy(() =>
(getOptionValue('--experimental-transform-types') ? 'transform' : 'strip-only'),
(getOptionValue('--experimental-transform-types') ?
(emitExperimentalWarning('Transform Types'), 'transform') : 'strip-only'),
);
/**
@ -174,13 +175,9 @@ function getCachedCodeType(mode, sourceMap) {
* It is used by internal loaders.
* @param {string} source TypeScript code to parse.
* @param {string} filename The filename of the source code.
* @param {boolean} emitWarning Whether to emit a warning.
* @returns {TransformOutput} The stripped TypeScript code.
*/
function stripTypeScriptModuleTypes(source, filename, emitWarning = true) {
if (emitWarning) {
emitExperimentalWarning('Type Stripping');
}
function stripTypeScriptModuleTypes(source, filename) {
assert(typeof source === 'string');
if (isUnderNodeModules(filename)) {
throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename);

View File

@ -39,7 +39,6 @@ const { getOptionValue } = require('internal/options');
const {
makeContextifyScript, runScriptInThisContext,
} = require('internal/vm');
const { emitExperimentalWarning } = require('internal/util');
// shouldAbortOnUncaughtToggle is a typed array for faster
// communication with JS.
const { shouldAbortOnUncaughtToggle } = internalBinding('util');
@ -261,7 +260,7 @@ function evalTypeScript(name, source, breakFirstLine, print, shouldLoadESM = fal
compiledScript = compileScript(name, source, baseUrl);
} catch (originalError) {
try {
sourceToRun = stripTypeScriptModuleTypes(source, kEvalTag, false);
sourceToRun = stripTypeScriptModuleTypes(source, kEvalTag);
// Retry the CJS/ESM syntax detection after stripping the types.
if (shouldUseModuleEntryPoint(name, sourceToRun)) {
return evalTypeScriptModuleEntryPoint(source, print);
@ -269,8 +268,6 @@ function evalTypeScript(name, source, breakFirstLine, print, shouldLoadESM = fal
// If the ContextifiedScript was successfully created, execute it.
// outside the try-catch block to avoid catching runtime errors.
compiledScript = compileScript(name, sourceToRun, baseUrl);
// Emit the experimental warning after the code was successfully evaluated.
emitExperimentalWarning('Type Stripping');
} catch (tsError) {
// If it's invalid or unsupported TypeScript syntax, rethrow the original error
// with the TypeScript error message added to the stack.
@ -324,12 +321,10 @@ function evalTypeScriptModuleEntryPoint(source, print) {
moduleWrap = loader.createModuleWrap(source, url);
} catch (originalError) {
try {
const strippedSource = stripTypeScriptModuleTypes(source, kEvalTag, false);
const strippedSource = stripTypeScriptModuleTypes(source, kEvalTag);
// If the moduleWrap was successfully created, execute the module job.
// outside the try-catch block to avoid catching runtime errors.
moduleWrap = loader.createModuleWrap(strippedSource, url);
// Emit the experimental warning after the code was successfully compiled.
emitExperimentalWarning('Type Stripping');
} catch (tsError) {
// If it's invalid or unsupported TypeScript syntax, rethrow the original error
// with the TypeScript error message added to the stack.

View File

@ -11,7 +11,7 @@ test('eval TypeScript ESM syntax', async () => {
const text: string = 'Hello, TypeScript!'
console.log(util.styleText('red', text));`]);
match(result.stderr, /Type Stripping is an experimental feature and might change at any time/);
strictEqual(result.stderr, '');
match(result.stdout, /Hello, TypeScript!/);
strictEqual(result.code, 0);
});
@ -24,7 +24,7 @@ test('eval TypeScript ESM syntax with input-type module', async () => {
const text: string = 'Hello, TypeScript!'
console.log(util.styleText('red', text));`]);
match(result.stderr, /Type Stripping is an experimental feature and might change at any time/);
strictEqual(result.stderr, '');
match(result.stdout, /Hello, TypeScript!/);
strictEqual(result.code, 0);
});
@ -36,7 +36,7 @@ test('eval TypeScript CommonJS syntax', async () => {
const text: string = 'Hello, TypeScript!'
console.log(util.styleText('red', text));`]);
match(result.stdout, /Hello, TypeScript!/);
match(result.stderr, /ExperimentalWarning: Type Stripping is an experimental/);
strictEqual(result.stderr, '');
strictEqual(result.code, 0);
});
@ -72,7 +72,7 @@ test('TypeScript ESM syntax not specified', async () => {
`import util from 'node:util'
const text: string = 'Hello, TypeScript!'
console.log(text);`]);
match(result.stderr, /ExperimentalWarning: Type Stripping is an experimental/);
strictEqual(result.stderr, '');
match(result.stdout, /Hello, TypeScript!/);
strictEqual(result.code, 0);
});
@ -162,7 +162,7 @@ test('check warning is emitted when eval TypeScript CommonJS syntax', async () =
`const util = require('node:util');
const text: string = 'Hello, TypeScript!'
console.log(util.styleText('red', text));`]);
match(result.stderr, /ExperimentalWarning: Type Stripping is an experimental/);
strictEqual(result.stderr, '');
match(result.stdout, /Hello, TypeScript!/);
strictEqual(result.code, 0);
});

View File

@ -20,7 +20,7 @@ test('execute an .mts file importing an .mts file', async () => {
fixtures.path('typescript/mts/test-import-module.mts'),
]);
match(result.stderr, /Type Stripping is an experimental feature and might change at any time/);
strictEqual(result.stderr, '');
match(result.stdout, /Hello, TypeScript!/);
strictEqual(result.code, 0);
});

View File

@ -35,7 +35,7 @@ test('execute a TypeScript file', async () => {
fixtures.path('typescript/ts/test-typescript.ts'),
]);
match(result.stderr, /Type Stripping is an experimental feature and might change at any time/);
strictEqual(result.stderr, '');
match(result.stdout, /Hello, TypeScript!/);
strictEqual(result.code, 0);
});
@ -331,3 +331,14 @@ test('execute invalid TypeScript syntax', async () => {
strictEqual(result.stdout, '');
strictEqual(result.code, 1);
});
test('check transform types warning', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-transform-types',
fixtures.path('typescript/ts/test-typescript.ts'),
]);
match(result.stderr, /Transform Types is an experimental feature and might change at any time/);
match(result.stdout, /Hello, TypeScript!/);
strictEqual(result.code, 0);
});