Skip to content

module: remove experimental warning from type stripping #58643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/api/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 3 additions & 6 deletions lib/internal/modules/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);

/**
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 2 additions & 7 deletions lib/internal/process/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -261,16 +260,14 @@ 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);
}
// 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.
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions test/es-module/test-typescript-eval.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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);
});

Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-typescript-module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
13 changes: 12 additions & 1 deletion test/es-module/test-typescript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Loading