From c62af40790852473add74bc6048788a981cfac89 Mon Sep 17 00:00:00 2001 From: Marco Ippolito Date: Fri, 13 Feb 2026 12:33:07 -0400 Subject: [PATCH] module: remove --experimental-transform-types This PR removes the `--experimental-transform-types` flag and all related code, tests, and documentation. It also changes the following user facing APIs: - `stripTypeScriptTypes` now only accepts the code to transform, and not the options object. It also does not add a sourceURL comment at the end of the transformed code. - `process.features.typescript` now only returns a boolean. --- .../fixtures/transform-types-benchmark.js | 28 ---- .../fixtures/transform-types-benchmark.ts | 30 ---- benchmark/ts/transform-typescript.js | 26 ---- doc/api/cli.md | 12 -- doc/api/module.md | 70 +--------- doc/api/process.md | 5 +- doc/api/typescript.md | 11 +- doc/api/util.md | 3 +- doc/node-config-schema.json | 4 - doc/node.1 | 6 - lib/internal/bootstrap/node.js | 8 +- lib/internal/modules/typescript.js | 64 +-------- src/compile_cache.cc | 8 +- src/compile_cache.h | 4 +- src/node_options.cc | 7 - test/es-module/test-typescript-transform.mjs | 129 ----------------- test/es-module/test-typescript.mjs | 26 +--- .../options-as-flags/test-config.json | 2 +- test/fixtures/rc/override-property.json | 4 +- test/fixtures/rc/sneaky-flag.json | 2 +- test/fixtures/rc/strip-types.json | 5 + test/fixtures/rc/transform-types.json | 5 - .../source_map_assert_source_line.snapshot | 14 -- .../output/source_map_assert_source_line.ts | 14 -- .../typescript/cts/test-import-require.cts | 5 - .../ts/transformation/test-decorator.ts | 10 -- .../ts/transformation/test-enum-stacktrace.ts | 4 - .../typescript/ts/transformation/test-enum.ts | 4 - .../ts/transformation/test-legacy-module.ts | 12 -- .../transformation/test-modern-typescript.ts | 12 -- .../ts/transformation/test-namespace.ts | 7 - .../test-transformed-typescript.js | 36 ----- .../ts/transformation/test-unused-import.ts | 3 - .../module-hooks/test-module-hooks-preload.js | 2 - ...load-import-inline-typescript-override.mjs | 3 +- ...-resolve-load-import-inline-typescript.mjs | 4 +- ...load-require-inline-typescript-override.js | 3 +- ...-resolve-load-require-inline-typescript.js | 2 +- test/parallel/test-cli-options-as-flags.js | 2 - ...est-compile-cache-typescript-strip-miss.js | 107 -------------- ...test-compile-cache-typescript-transform.js | 130 ------------------ test/parallel/test-config-file.js | 28 ++-- test/parallel/test-module-strip-types.js | 78 +---------- test/parallel/test-node-output-sourcemaps.mjs | 1 - test/parallel/test-runner-cli.js | 4 +- test/parallel/test-util-getcallsites.js | 51 ------- .../test-output-coverage-with-mock.mjs | 1 - .../test-output-typescript-coverage.mjs | 1 - 48 files changed, 53 insertions(+), 944 deletions(-) delete mode 100644 benchmark/fixtures/transform-types-benchmark.js delete mode 100644 benchmark/fixtures/transform-types-benchmark.ts delete mode 100644 benchmark/ts/transform-typescript.js delete mode 100644 test/es-module/test-typescript-transform.mjs create mode 100644 test/fixtures/rc/strip-types.json delete mode 100644 test/fixtures/rc/transform-types.json delete mode 100644 test/fixtures/source-map/output/source_map_assert_source_line.snapshot delete mode 100644 test/fixtures/source-map/output/source_map_assert_source_line.ts delete mode 100644 test/fixtures/typescript/cts/test-import-require.cts delete mode 100644 test/fixtures/typescript/ts/transformation/test-decorator.ts delete mode 100644 test/fixtures/typescript/ts/transformation/test-enum-stacktrace.ts delete mode 100644 test/fixtures/typescript/ts/transformation/test-enum.ts delete mode 100644 test/fixtures/typescript/ts/transformation/test-legacy-module.ts delete mode 100644 test/fixtures/typescript/ts/transformation/test-modern-typescript.ts delete mode 100644 test/fixtures/typescript/ts/transformation/test-namespace.ts delete mode 100644 test/fixtures/typescript/ts/transformation/test-transformed-typescript.js delete mode 100644 test/fixtures/typescript/ts/transformation/test-unused-import.ts delete mode 100644 test/parallel/test-compile-cache-typescript-strip-miss.js delete mode 100644 test/parallel/test-compile-cache-typescript-transform.js diff --git a/benchmark/fixtures/transform-types-benchmark.js b/benchmark/fixtures/transform-types-benchmark.js deleted file mode 100644 index c0946942179fe3..00000000000000 --- a/benchmark/fixtures/transform-types-benchmark.js +++ /dev/null @@ -1,28 +0,0 @@ -var Color; -(function (Color) { - Color[Color["Red"] = 0] = "Red"; - Color[Color["Green"] = 1] = "Green"; - Color[Color["Blue"] = 2] = "Blue"; -})(Color || (Color = {})); -var Geometry; -(function (Geometry) { - class Circle { - constructor(center, radius) { - this.center = center; - this.radius = radius; - } - area() { - return Math.PI * Math.pow(this.radius, 2); - } - } - Geometry.Circle = Circle; -})(Geometry || (Geometry = {})); -function processShape(color, shape) { - const colorName = Color[color]; - const area = shape.area().toFixed(2); - return `A ${colorName} circle with area ${area}`; -} - -const point = { x: 0, y: 0 }; -const circle = new Geometry.Circle(point, 5); -export const result = processShape(Color.Blue, circle); diff --git a/benchmark/fixtures/transform-types-benchmark.ts b/benchmark/fixtures/transform-types-benchmark.ts deleted file mode 100644 index 69c13af4ee4d7c..00000000000000 --- a/benchmark/fixtures/transform-types-benchmark.ts +++ /dev/null @@ -1,30 +0,0 @@ -enum Color { - Red, - Green, - Blue -} - -namespace Geometry { - export interface Point { - x: number; - y: number; - } - - export class Circle { - constructor(public center: Point, public radius: number) { } - - area(): number { - return Math.PI * this.radius ** 2; - } - } -} - -function processShape(color: Color, shape: Geometry.Circle): string { - const colorName = Color[color]; - const area = shape.area().toFixed(2); - return `A ${colorName} circle with area ${area}`; -} - -const point: Geometry.Point = { x: 0, y: 0 }; -const circle = new Geometry.Circle(point, 5); -export const result = processShape(Color.Blue, circle); diff --git a/benchmark/ts/transform-typescript.js b/benchmark/ts/transform-typescript.js deleted file mode 100644 index 59a78eccae3ff1..00000000000000 --- a/benchmark/ts/transform-typescript.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -const common = require('../common'); -const path = require('path'); -const assert = require('node:assert'); - -const js = path.resolve(__dirname, '../fixtures/transform-types-benchmark.js'); -const ts = path.resolve(__dirname, '../fixtures/transform-types-benchmark.ts'); - -const bench = common.createBenchmark(main, { - filepath: [js, ts], - n: [1e4], -}, { - flags: ['--experimental-transform-types', '--disable-warning=ExperimentalWarning'], -}); - -async function main({ n, filepath }) { - let output; - bench.start(); - for (let i = 0; i < n; i++) { - const { result } = await import(`${filepath}?${i}`); - output = result; - } - bench.end(n); - assert.ok(output); -} diff --git a/doc/api/cli.md b/doc/api/cli.md index 651e06f6910ebe..a09d5127f1aac4 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -1315,17 +1315,6 @@ Enable module mocking in the test runner. This feature requires `--allow-worker` if used with the [Permission Model][]. -### `--experimental-transform-types` - - - -> Stability: 1.2 - Release candidate - -Enables the transformation of TypeScript-only syntax into JavaScript code. -Implies `--enable-source-maps`. - ### `--experimental-vm-modules` > Stability: 1.2 - Release candidate * `code` {string} The code to strip type annotations from. -* `options` {Object} - * `mode` {string} **Default:** `'strip'`. Possible values are: - * `'strip'` Only strip type annotations without performing the transformation of TypeScript features. - * `'transform'` Strip type annotations and transform TypeScript features to JavaScript. - * `sourceMap` {boolean} **Default:** `false`. Only when `mode` is `'transform'`, if `true`, a source map - will be generated for the transformed code. - * `sourceUrl` {string} Specifies the source url used in the source map. * Returns: {string} The code with type annotations stripped. `module.stripTypeScriptTypes()` removes type annotations from TypeScript code. It can be used to strip type annotations from TypeScript code before running it @@ -264,10 +261,6 @@ added: By default, it will throw an error if the code contains TypeScript features that require transformation such as `Enums`, see [type-stripping][] for more information. - When mode is `'transform'`, it also transforms TypeScript features to JavaScript, - see [transform TypeScript features][] for more information. - When mode is `'strip'`, source maps are not generated, because locations are preserved. - If `sourceMap` is provided, when mode is `'strip'`, an error will be thrown. _WARNING_: The output of this function should not be considered stable across Node.js versions, due to changes in the TypeScript parser. @@ -288,58 +281,6 @@ console.log(strippedCode); // Prints: const a = 1; ``` -If `sourceUrl` is provided, it will be used appended as a comment at the end of the output: - -```mjs -import { stripTypeScriptTypes } from 'node:module'; -const code = 'const a: number = 1;'; -const strippedCode = stripTypeScriptTypes(code, { mode: 'strip', sourceUrl: 'source.ts' }); -console.log(strippedCode); -// Prints: const a = 1\n\n//# sourceURL=source.ts; -``` - -```cjs -const { stripTypeScriptTypes } = require('node:module'); -const code = 'const a: number = 1;'; -const strippedCode = stripTypeScriptTypes(code, { mode: 'strip', sourceUrl: 'source.ts' }); -console.log(strippedCode); -// Prints: const a = 1\n\n//# sourceURL=source.ts; -``` - -When `mode` is `'transform'`, the code is transformed to JavaScript: - -```mjs -import { stripTypeScriptTypes } from 'node:module'; -const code = ` - namespace MathUtil { - export const add = (a: number, b: number) => a + b; - }`; -const strippedCode = stripTypeScriptTypes(code, { mode: 'transform', sourceMap: true }); -console.log(strippedCode); -// Prints: -// var MathUtil; -// (function(MathUtil) { -// MathUtil.add = (a, b)=>a + b; -// })(MathUtil || (MathUtil = {})); -// # sourceMappingURL=data:application/json;base64, ... -``` - -```cjs -const { stripTypeScriptTypes } = require('node:module'); -const code = ` - namespace MathUtil { - export const add = (a: number, b: number) => a + b; - }`; -const strippedCode = stripTypeScriptTypes(code, { mode: 'transform', sourceMap: true }); -console.log(strippedCode); -// Prints: -// var MathUtil; -// (function(MathUtil) { -// MathUtil.add = (a, b)=>a + b; -// })(MathUtil || (MathUtil = {})); -// # sourceMappingURL=data:application/json;base64, ... -``` - ### `module.syncBuiltinESMExports()`