Skip to content

Commit c898491

Browse files
marco-ippolitoRafaelGSS
authored andcommitted
module: remove experimental warning from type stripping
PR-URL: #58643 Backport-PR-URL: #57298 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> PR-URL: #56350 Fixes: nodejs/typescript#17
1 parent c07745a commit c898491

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: REPLACEME
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
@@ -28,7 +28,8 @@ const { Buffer } = require('buffer');
2828
* @type {string}
2929
*/
3030
const getTypeScriptParsingMode = getLazy(() =>
31-
(getOptionValue('--experimental-transform-types') ? 'transform' : 'strip-only'),
31+
(getOptionValue('--experimental-transform-types') ?
32+
(emitExperimentalWarning('Transform Types'), 'transform') : 'strip-only'),
3233
);
3334

3435
/**
@@ -131,13 +132,9 @@ function processTypeScriptCode(code, options) {
131132
* It is used by internal loaders.
132133
* @param {string} source TypeScript code to parse.
133134
* @param {string} filename The filename of the source code.
134-
* @param {boolean} emitWarning Whether to emit a warning.
135135
* @returns {TransformOutput} The stripped TypeScript code.
136136
*/
137-
function stripTypeScriptModuleTypes(source, filename, emitWarning = true) {
138-
if (emitWarning) {
139-
emitExperimentalWarning('Type Stripping');
140-
}
137+
function stripTypeScriptModuleTypes(source, filename) {
141138
assert(typeof source === 'string');
142139
if (isUnderNodeModules(filename)) {
143140
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
@@ -35,7 +35,6 @@ const { getOptionValue } = require('internal/options');
3535
const {
3636
makeContextifyScript, runScriptInThisContext,
3737
} = require('internal/vm');
38-
const { emitExperimentalWarning } = require('internal/util');
3938
// shouldAbortOnUncaughtToggle is a typed array for faster
4039
// communication with JS.
4140
const { shouldAbortOnUncaughtToggle } = internalBinding('util');
@@ -255,16 +254,14 @@ function evalTypeScript(name, source, breakFirstLine, print, shouldLoadESM = fal
255254
compiledScript = compileScript(name, source, baseUrl);
256255
} catch (originalError) {
257256
try {
258-
sourceToRun = stripTypeScriptModuleTypes(source, name, false);
257+
sourceToRun = stripTypeScriptModuleTypes(source, kEvalTag);
259258
// Retry the CJS/ESM syntax detection after stripping the types.
260259
if (shouldUseModuleEntryPoint(name, sourceToRun)) {
261260
return evalTypeScriptModuleEntryPoint(source, print);
262261
}
263262
// If the ContextifiedScript was successfully created, execute it.
264263
// outside the try-catch block to avoid catching runtime errors.
265264
compiledScript = compileScript(name, sourceToRun, baseUrl);
266-
// Emit the experimental warning after the code was successfully evaluated.
267-
emitExperimentalWarning('Type Stripping');
268265
} catch (tsError) {
269266
// If it's invalid or unsupported TypeScript syntax, rethrow the original error
270267
// with the TypeScript error message added to the stack.
@@ -318,12 +315,10 @@ function evalTypeScriptModuleEntryPoint(source, print) {
318315
moduleWrap = loader.createModuleWrap(source, url);
319316
} catch (originalError) {
320317
try {
321-
const strippedSource = stripTypeScriptModuleTypes(source, url, false);
318+
const strippedSource = stripTypeScriptModuleTypes(source, kEvalTag);
322319
// If the moduleWrap was successfully created, execute the module job.
323320
// outside the try-catch block to avoid catching runtime errors.
324321
moduleWrap = loader.createModuleWrap(strippedSource, url);
325-
// Emit the experimental warning after the code was successfully compiled.
326-
emitExperimentalWarning('Type Stripping');
327322
} catch (tsError) {
328323
// If it's invalid or unsupported TypeScript syntax, rethrow the original error
329324
// 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
});
@@ -412,3 +412,14 @@ test('execute invalid TypeScript syntax', async () => {
412412
strictEqual(result.stdout, '');
413413
strictEqual(result.code, 1);
414414
});
415+
416+
test('check transform types warning', async () => {
417+
const result = await spawnPromisified(process.execPath, [
418+
'--experimental-transform-types',
419+
fixtures.path('typescript/ts/test-typescript.ts'),
420+
]);
421+
422+
match(result.stderr, /Transform Types is an experimental feature and might change at any time/);
423+
match(result.stdout, /Hello, TypeScript!/);
424+
strictEqual(result.code, 0);
425+
});

0 commit comments

Comments
 (0)