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()`