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:
parent
8c17ceb38f
commit
6584d5f811
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
<!-- YAML
|
<!-- YAML
|
||||||
changes:
|
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
|
- version: v23.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/56350
|
pr-url: https://github.com/nodejs/node/pull/56350
|
||||||
description: Type stripping is enabled by default.
|
description: Type stripping is enabled by default.
|
||||||
|
@ -33,7 +33,8 @@ const {
|
|||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
const getTypeScriptParsingMode = getLazy(() =>
|
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.
|
* It is used by internal loaders.
|
||||||
* @param {string} source TypeScript code to parse.
|
* @param {string} source TypeScript code to parse.
|
||||||
* @param {string} filename The filename of the source code.
|
* @param {string} filename The filename of the source code.
|
||||||
* @param {boolean} emitWarning Whether to emit a warning.
|
|
||||||
* @returns {TransformOutput} The stripped TypeScript code.
|
* @returns {TransformOutput} The stripped TypeScript code.
|
||||||
*/
|
*/
|
||||||
function stripTypeScriptModuleTypes(source, filename, emitWarning = true) {
|
function stripTypeScriptModuleTypes(source, filename) {
|
||||||
if (emitWarning) {
|
|
||||||
emitExperimentalWarning('Type Stripping');
|
|
||||||
}
|
|
||||||
assert(typeof source === 'string');
|
assert(typeof source === 'string');
|
||||||
if (isUnderNodeModules(filename)) {
|
if (isUnderNodeModules(filename)) {
|
||||||
throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename);
|
throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename);
|
||||||
|
@ -39,7 +39,6 @@ const { getOptionValue } = require('internal/options');
|
|||||||
const {
|
const {
|
||||||
makeContextifyScript, runScriptInThisContext,
|
makeContextifyScript, runScriptInThisContext,
|
||||||
} = require('internal/vm');
|
} = require('internal/vm');
|
||||||
const { emitExperimentalWarning } = require('internal/util');
|
|
||||||
// shouldAbortOnUncaughtToggle is a typed array for faster
|
// shouldAbortOnUncaughtToggle is a typed array for faster
|
||||||
// communication with JS.
|
// communication with JS.
|
||||||
const { shouldAbortOnUncaughtToggle } = internalBinding('util');
|
const { shouldAbortOnUncaughtToggle } = internalBinding('util');
|
||||||
@ -261,7 +260,7 @@ function evalTypeScript(name, source, breakFirstLine, print, shouldLoadESM = fal
|
|||||||
compiledScript = compileScript(name, source, baseUrl);
|
compiledScript = compileScript(name, source, baseUrl);
|
||||||
} catch (originalError) {
|
} catch (originalError) {
|
||||||
try {
|
try {
|
||||||
sourceToRun = stripTypeScriptModuleTypes(source, kEvalTag, false);
|
sourceToRun = stripTypeScriptModuleTypes(source, kEvalTag);
|
||||||
// Retry the CJS/ESM syntax detection after stripping the types.
|
// Retry the CJS/ESM syntax detection after stripping the types.
|
||||||
if (shouldUseModuleEntryPoint(name, sourceToRun)) {
|
if (shouldUseModuleEntryPoint(name, sourceToRun)) {
|
||||||
return evalTypeScriptModuleEntryPoint(source, print);
|
return evalTypeScriptModuleEntryPoint(source, print);
|
||||||
@ -269,8 +268,6 @@ function evalTypeScript(name, source, breakFirstLine, print, shouldLoadESM = fal
|
|||||||
// If the ContextifiedScript was successfully created, execute it.
|
// If the ContextifiedScript was successfully created, execute it.
|
||||||
// outside the try-catch block to avoid catching runtime errors.
|
// outside the try-catch block to avoid catching runtime errors.
|
||||||
compiledScript = compileScript(name, sourceToRun, baseUrl);
|
compiledScript = compileScript(name, sourceToRun, baseUrl);
|
||||||
// Emit the experimental warning after the code was successfully evaluated.
|
|
||||||
emitExperimentalWarning('Type Stripping');
|
|
||||||
} catch (tsError) {
|
} catch (tsError) {
|
||||||
// If it's invalid or unsupported TypeScript syntax, rethrow the original error
|
// If it's invalid or unsupported TypeScript syntax, rethrow the original error
|
||||||
// with the TypeScript error message added to the stack.
|
// with the TypeScript error message added to the stack.
|
||||||
@ -324,12 +321,10 @@ function evalTypeScriptModuleEntryPoint(source, print) {
|
|||||||
moduleWrap = loader.createModuleWrap(source, url);
|
moduleWrap = loader.createModuleWrap(source, url);
|
||||||
} catch (originalError) {
|
} catch (originalError) {
|
||||||
try {
|
try {
|
||||||
const strippedSource = stripTypeScriptModuleTypes(source, kEvalTag, false);
|
const strippedSource = stripTypeScriptModuleTypes(source, kEvalTag);
|
||||||
// If the moduleWrap was successfully created, execute the module job.
|
// If the moduleWrap was successfully created, execute the module job.
|
||||||
// outside the try-catch block to avoid catching runtime errors.
|
// outside the try-catch block to avoid catching runtime errors.
|
||||||
moduleWrap = loader.createModuleWrap(strippedSource, url);
|
moduleWrap = loader.createModuleWrap(strippedSource, url);
|
||||||
// Emit the experimental warning after the code was successfully compiled.
|
|
||||||
emitExperimentalWarning('Type Stripping');
|
|
||||||
} catch (tsError) {
|
} catch (tsError) {
|
||||||
// If it's invalid or unsupported TypeScript syntax, rethrow the original error
|
// If it's invalid or unsupported TypeScript syntax, rethrow the original error
|
||||||
// with the TypeScript error message added to the stack.
|
// with the TypeScript error message added to the stack.
|
||||||
|
@ -11,7 +11,7 @@ test('eval TypeScript ESM syntax', async () => {
|
|||||||
const text: string = 'Hello, TypeScript!'
|
const text: string = 'Hello, TypeScript!'
|
||||||
console.log(util.styleText('red', text));`]);
|
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!/);
|
match(result.stdout, /Hello, TypeScript!/);
|
||||||
strictEqual(result.code, 0);
|
strictEqual(result.code, 0);
|
||||||
});
|
});
|
||||||
@ -24,7 +24,7 @@ test('eval TypeScript ESM syntax with input-type module', async () => {
|
|||||||
const text: string = 'Hello, TypeScript!'
|
const text: string = 'Hello, TypeScript!'
|
||||||
console.log(util.styleText('red', text));`]);
|
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!/);
|
match(result.stdout, /Hello, TypeScript!/);
|
||||||
strictEqual(result.code, 0);
|
strictEqual(result.code, 0);
|
||||||
});
|
});
|
||||||
@ -36,7 +36,7 @@ test('eval TypeScript CommonJS syntax', async () => {
|
|||||||
const text: string = 'Hello, TypeScript!'
|
const text: string = 'Hello, TypeScript!'
|
||||||
console.log(util.styleText('red', text));`]);
|
console.log(util.styleText('red', text));`]);
|
||||||
match(result.stdout, /Hello, TypeScript!/);
|
match(result.stdout, /Hello, TypeScript!/);
|
||||||
match(result.stderr, /ExperimentalWarning: Type Stripping is an experimental/);
|
strictEqual(result.stderr, '');
|
||||||
strictEqual(result.code, 0);
|
strictEqual(result.code, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ test('TypeScript ESM syntax not specified', async () => {
|
|||||||
`import util from 'node:util'
|
`import util from 'node:util'
|
||||||
const text: string = 'Hello, TypeScript!'
|
const text: string = 'Hello, TypeScript!'
|
||||||
console.log(text);`]);
|
console.log(text);`]);
|
||||||
match(result.stderr, /ExperimentalWarning: Type Stripping is an experimental/);
|
strictEqual(result.stderr, '');
|
||||||
match(result.stdout, /Hello, TypeScript!/);
|
match(result.stdout, /Hello, TypeScript!/);
|
||||||
strictEqual(result.code, 0);
|
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 util = require('node:util');
|
||||||
const text: string = 'Hello, TypeScript!'
|
const text: string = 'Hello, TypeScript!'
|
||||||
console.log(util.styleText('red', text));`]);
|
console.log(util.styleText('red', text));`]);
|
||||||
match(result.stderr, /ExperimentalWarning: Type Stripping is an experimental/);
|
strictEqual(result.stderr, '');
|
||||||
match(result.stdout, /Hello, TypeScript!/);
|
match(result.stdout, /Hello, TypeScript!/);
|
||||||
strictEqual(result.code, 0);
|
strictEqual(result.code, 0);
|
||||||
});
|
});
|
||||||
|
@ -20,7 +20,7 @@ test('execute an .mts file importing an .mts file', async () => {
|
|||||||
fixtures.path('typescript/mts/test-import-module.mts'),
|
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!/);
|
match(result.stdout, /Hello, TypeScript!/);
|
||||||
strictEqual(result.code, 0);
|
strictEqual(result.code, 0);
|
||||||
});
|
});
|
||||||
|
@ -35,7 +35,7 @@ test('execute a TypeScript file', async () => {
|
|||||||
fixtures.path('typescript/ts/test-typescript.ts'),
|
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!/);
|
match(result.stdout, /Hello, TypeScript!/);
|
||||||
strictEqual(result.code, 0);
|
strictEqual(result.code, 0);
|
||||||
});
|
});
|
||||||
@ -331,3 +331,14 @@ test('execute invalid TypeScript syntax', async () => {
|
|||||||
strictEqual(result.stdout, '');
|
strictEqual(result.stdout, '');
|
||||||
strictEqual(result.code, 1);
|
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…
x
Reference in New Issue
Block a user