Skip to content

Commit 6584d5f

Browse files
module: remove experimental warning from type stripping
PR-URL: #58643 Refs: nodejs/typescript#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>
1 parent 8c17ceb commit 6584d5f

File tree

6 files changed

+26
-20
lines changed

6 files changed

+26
-20
lines changed

doc/api/typescript.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
<!-- YAML
44
changes:
5+
- version: REPLACEME
6+
pr-url: https://github.com/nodejs/node/pull/58643
7+
description: Type stripping no longer emits an experimental warning.
58
- version: v23.6.0
69
pr-url: https://github.com/nodejs/node/pull/56350
710
description: Type stripping is enabled by default.

lib/internal/modules/typescript.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ const {
3333
* @type {string}
3434
*/
3535
const getTypeScriptParsingMode = getLazy(() =>
36-
(getOptionValue('--experimental-transform-types') ? 'transform' : 'strip-only'),
36+
(getOptionValue('--experimental-transform-types') ?
37+
(emitExperimentalWarning('Transform Types'), 'transform') : 'strip-only'),
3738
);
3839

3940
/**
@@ -174,13 +175,9 @@ function getCachedCodeType(mode, sourceMap) {
174175
* It is used by internal loaders.
175176
* @param {string} source TypeScript code to parse.
176177
* @param {string} filename The filename of the source code.
177-
* @param {boolean} emitWarning Whether to emit a warning.
178178
* @returns {TransformOutput} The stripped TypeScript code.
179179
*/
180-
function stripTypeScriptModuleTypes(source, filename, emitWarning = true) {
181-
if (emitWarning) {
182-
emitExperimentalWarning('Type Stripping');
183-
}
180+
function stripTypeScriptModuleTypes(source, filename) {
184181
assert(typeof source === 'string');
185182
if (isUnderNodeModules(filename)) {
186183
throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename);

lib/internal/process/execution.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const { getOptionValue } = require('internal/options');
3939
const {
4040
makeContextifyScript, runScriptInThisContext,
4141
} = require('internal/vm');
42-
const { emitExperimentalWarning } = require('internal/util');
4342
// shouldAbortOnUncaughtToggle is a typed array for faster
4443
// communication with JS.
4544
const { shouldAbortOnUncaughtToggle } = internalBinding('util');
@@ -261,16 +260,14 @@ function evalTypeScript(name, source, breakFirstLine, print, shouldLoadESM = fal
261260
compiledScript = compileScript(name, source, baseUrl);
262261
} catch (originalError) {
263262
try {
264-
sourceToRun = stripTypeScriptModuleTypes(source, kEvalTag, false);
263+
sourceToRun = stripTypeScriptModuleTypes(source, kEvalTag);
265264
// Retry the CJS/ESM syntax detection after stripping the types.
266265
if (shouldUseModuleEntryPoint(name, sourceToRun)) {
267266
return evalTypeScriptModuleEntryPoint(source, print);
268267
}
269268
// If the ContextifiedScript was successfully created, execute it.
270269
// outside the try-catch block to avoid catching runtime errors.
271270
compiledScript = compileScript(name, sourceToRun, baseUrl);
272-
// Emit the experimental warning after the code was successfully evaluated.
273-
emitExperimentalWarning('Type Stripping');
274271
} catch (tsError) {
275272
// If it's invalid or unsupported TypeScript syntax, rethrow the original error
276273
// with the TypeScript error message added to the stack.
@@ -324,12 +321,10 @@ function evalTypeScriptModuleEntryPoint(source, print) {
324321
moduleWrap = loader.createModuleWrap(source, url);
325322
} catch (originalError) {
326323
try {
327-
const strippedSource = stripTypeScriptModuleTypes(source, kEvalTag, false);
324+
const strippedSource = stripTypeScriptModuleTypes(source, kEvalTag);
328325
// If the moduleWrap was successfully created, execute the module job.
329326
// outside the try-catch block to avoid catching runtime errors.
330327
moduleWrap = loader.createModuleWrap(strippedSource, url);
331-
// Emit the experimental warning after the code was successfully compiled.
332-
emitExperimentalWarning('Type Stripping');
333328
} catch (tsError) {
334329
// If it's invalid or unsupported TypeScript syntax, rethrow the original error
335330
// with the TypeScript error message added to the stack.

test/es-module/test-typescript-eval.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test('eval TypeScript ESM syntax', async () => {
1111
const text: string = 'Hello, TypeScript!'
1212
console.log(util.styleText('red', text));`]);
1313

14-
match(result.stderr, /Type Stripping is an experimental feature and might change at any time/);
14+
strictEqual(result.stderr, '');
1515
match(result.stdout, /Hello, TypeScript!/);
1616
strictEqual(result.code, 0);
1717
});
@@ -24,7 +24,7 @@ test('eval TypeScript ESM syntax with input-type module', async () => {
2424
const text: string = 'Hello, TypeScript!'
2525
console.log(util.styleText('red', text));`]);
2626

27-
match(result.stderr, /Type Stripping is an experimental feature and might change at any time/);
27+
strictEqual(result.stderr, '');
2828
match(result.stdout, /Hello, TypeScript!/);
2929
strictEqual(result.code, 0);
3030
});
@@ -36,7 +36,7 @@ test('eval TypeScript CommonJS syntax', async () => {
3636
const text: string = 'Hello, TypeScript!'
3737
console.log(util.styleText('red', text));`]);
3838
match(result.stdout, /Hello, TypeScript!/);
39-
match(result.stderr, /ExperimentalWarning: Type Stripping is an experimental/);
39+
strictEqual(result.stderr, '');
4040
strictEqual(result.code, 0);
4141
});
4242

@@ -72,7 +72,7 @@ test('TypeScript ESM syntax not specified', async () => {
7272
`import util from 'node:util'
7373
const text: string = 'Hello, TypeScript!'
7474
console.log(text);`]);
75-
match(result.stderr, /ExperimentalWarning: Type Stripping is an experimental/);
75+
strictEqual(result.stderr, '');
7676
match(result.stdout, /Hello, TypeScript!/);
7777
strictEqual(result.code, 0);
7878
});
@@ -162,7 +162,7 @@ test('check warning is emitted when eval TypeScript CommonJS syntax', async () =
162162
`const util = require('node:util');
163163
const text: string = 'Hello, TypeScript!'
164164
console.log(util.styleText('red', text));`]);
165-
match(result.stderr, /ExperimentalWarning: Type Stripping is an experimental/);
165+
strictEqual(result.stderr, '');
166166
match(result.stdout, /Hello, TypeScript!/);
167167
strictEqual(result.code, 0);
168168
});

test/es-module/test-typescript-module.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test('execute an .mts file importing an .mts file', async () => {
2020
fixtures.path('typescript/mts/test-import-module.mts'),
2121
]);
2222

23-
match(result.stderr, /Type Stripping is an experimental feature and might change at any time/);
23+
strictEqual(result.stderr, '');
2424
match(result.stdout, /Hello, TypeScript!/);
2525
strictEqual(result.code, 0);
2626
});

test/es-module/test-typescript.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test('execute a TypeScript file', async () => {
3535
fixtures.path('typescript/ts/test-typescript.ts'),
3636
]);
3737

38-
match(result.stderr, /Type Stripping is an experimental feature and might change at any time/);
38+
strictEqual(result.stderr, '');
3939
match(result.stdout, /Hello, TypeScript!/);
4040
strictEqual(result.code, 0);
4141
});
@@ -331,3 +331,14 @@ test('execute invalid TypeScript syntax', async () => {
331331
strictEqual(result.stdout, '');
332332
strictEqual(result.code, 1);
333333
});
334+
335+
test('check transform types warning', async () => {
336+
const result = await spawnPromisified(process.execPath, [
337+
'--experimental-transform-types',
338+
fixtures.path('typescript/ts/test-typescript.ts'),
339+
]);
340+
341+
match(result.stderr, /Transform Types is an experimental feature and might change at any time/);
342+
match(result.stdout, /Hello, TypeScript!/);
343+
strictEqual(result.code, 0);
344+
});

0 commit comments

Comments
 (0)