Skip to content

Commit 2ea1afe

Browse files
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.
1 parent e687680 commit 2ea1afe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+52
-943
lines changed

benchmark/fixtures/transform-types-benchmark.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

benchmark/fixtures/transform-types-benchmark.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

benchmark/ts/transform-typescript.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

doc/api/cli.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,17 +1315,6 @@ Enable module mocking in the test runner.
13151315

13161316
This feature requires `--allow-worker` if used with the [Permission Model][].
13171317

1318-
### `--experimental-transform-types`
1319-
1320-
<!-- YAML
1321-
added: v22.7.0
1322-
-->
1323-
1324-
> Stability: 1.2 - Release candidate
1325-
1326-
Enables the transformation of TypeScript-only syntax into JavaScript code.
1327-
Implies `--enable-source-maps`.
1328-
13291318
### `--experimental-vm-modules`
13301319

13311320
<!-- YAML
@@ -3611,7 +3600,6 @@ one is included in the list below.
36113600
* `--experimental-specifier-resolution`
36123601
* `--experimental-test-isolation`
36133602
* `--experimental-top-level-await`
3614-
* `--experimental-transform-types`
36153603
* `--experimental-vm-modules`
36163604
* `--experimental-wasi-unstable-preview1`
36173605
* `--force-context-aware`

doc/api/module.md

Lines changed: 5 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -239,35 +239,28 @@ changes:
239239
Register [hooks][] that customize Node.js module resolution and loading behavior.
240240
See [Customization hooks][].
241241
242-
### `module.stripTypeScriptTypes(code[, options])`
242+
### `module.stripTypeScriptTypes(code)`
243243
244244
<!-- YAML
245245
added:
246246
- v23.2.0
247247
- v22.13.0
248+
changes:
249+
- version: REPLACEME
250+
pr-url: https://github.com/nodejs/node/pull/9999999999999
251+
description: Remove `mode` input argument and support for TypeScript features that require transformation and source map.
248252
-->
249253
250254
> Stability: 1.2 - Release candidate
251255
252256
* `code` {string} The code to strip type annotations from.
253-
* `options` {Object}
254-
* `mode` {string} **Default:** `'strip'`. Possible values are:
255-
* `'strip'` Only strip type annotations without performing the transformation of TypeScript features.
256-
* `'transform'` Strip type annotations and transform TypeScript features to JavaScript.
257-
* `sourceMap` {boolean} **Default:** `false`. Only when `mode` is `'transform'`, if `true`, a source map
258-
will be generated for the transformed code.
259-
* `sourceUrl` {string} Specifies the source url used in the source map.
260257
* Returns: {string} The code with type annotations stripped.
261258
`module.stripTypeScriptTypes()` removes type annotations from TypeScript code. It
262259
can be used to strip type annotations from TypeScript code before running it
263260
with `vm.runInContext()` or `vm.compileFunction()`.
264261
By default, it will throw an error if the code contains TypeScript features
265262
that require transformation such as `Enums`,
266263
see [type-stripping][] for more information.
267-
When mode is `'transform'`, it also transforms TypeScript features to JavaScript,
268-
see [transform TypeScript features][] for more information.
269-
When mode is `'strip'`, source maps are not generated, because locations are preserved.
270-
If `sourceMap` is provided, when mode is `'strip'`, an error will be thrown.
271264
272265
_WARNING_: The output of this function should not be considered stable across Node.js versions,
273266
due to changes in the TypeScript parser.
@@ -288,58 +281,6 @@ console.log(strippedCode);
288281
// Prints: const a = 1;
289282
```
290283
291-
If `sourceUrl` is provided, it will be used appended as a comment at the end of the output:
292-
293-
```mjs
294-
import { stripTypeScriptTypes } from 'node:module';
295-
const code = 'const a: number = 1;';
296-
const strippedCode = stripTypeScriptTypes(code, { mode: 'strip', sourceUrl: 'source.ts' });
297-
console.log(strippedCode);
298-
// Prints: const a = 1\n\n//# sourceURL=source.ts;
299-
```
300-
301-
```cjs
302-
const { stripTypeScriptTypes } = require('node:module');
303-
const code = 'const a: number = 1;';
304-
const strippedCode = stripTypeScriptTypes(code, { mode: 'strip', sourceUrl: 'source.ts' });
305-
console.log(strippedCode);
306-
// Prints: const a = 1\n\n//# sourceURL=source.ts;
307-
```
308-
309-
When `mode` is `'transform'`, the code is transformed to JavaScript:
310-
311-
```mjs
312-
import { stripTypeScriptTypes } from 'node:module';
313-
const code = `
314-
namespace MathUtil {
315-
export const add = (a: number, b: number) => a + b;
316-
}`;
317-
const strippedCode = stripTypeScriptTypes(code, { mode: 'transform', sourceMap: true });
318-
console.log(strippedCode);
319-
// Prints:
320-
// var MathUtil;
321-
// (function(MathUtil) {
322-
// MathUtil.add = (a, b)=>a + b;
323-
// })(MathUtil || (MathUtil = {}));
324-
// # sourceMappingURL=data:application/json;base64, ...
325-
```
326-
327-
```cjs
328-
const { stripTypeScriptTypes } = require('node:module');
329-
const code = `
330-
namespace MathUtil {
331-
export const add = (a: number, b: number) => a + b;
332-
}`;
333-
const strippedCode = stripTypeScriptTypes(code, { mode: 'transform', sourceMap: true });
334-
console.log(strippedCode);
335-
// Prints:
336-
// var MathUtil;
337-
// (function(MathUtil) {
338-
// MathUtil.add = (a, b)=>a + b;
339-
// })(MathUtil || (MathUtil = {}));
340-
// # sourceMappingURL=data:application/json;base64, ...
341-
```
342-
343284
### `module.syncBuiltinESMExports()`
344285
345286
<!-- YAML
@@ -2041,5 +1982,4 @@ returned object contains the following keys:
20411982
[synchronous hook functions]: #hook-functions-accepted-by-moduleregisterhooks
20421983
[the documentation of `Worker`]: worker_threads.md#new-workerfilename-options
20431984
[transferable objects]: worker_threads.md#portpostmessagevalue-transferlist
2044-
[transform TypeScript features]: typescript.md#typescript-features
20451985
[type-stripping]: typescript.md#type-stripping

doc/api/process.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,10 +2011,9 @@ changes:
20112011
20122012
> Stability: 1.2 - Release candidate
20132013
2014-
* Type: {boolean|string}
2014+
* Type: {boolean}
20152015
2016-
A value that is `"strip"` by default,
2017-
`"transform"` if Node.js is run with `--experimental-transform-types`, and `false` if
2016+
A value that is `true` by default, and `false` if
20182017
Node.js is run with `--no-strip-types`.
20192018
20202019
## `process.features.uv`

doc/api/typescript.md

Lines changed: 4 additions & 7 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/9999999999999
7+
description: Removed `--experimental-transform-types` flag.
58
- version:
69
- v25.2.0
710
- v24.12.0
@@ -77,8 +80,6 @@ By default Node.js will execute TypeScript files that contains only
7780
erasable TypeScript syntax.
7881
Node.js will replace TypeScript syntax with whitespace,
7982
and no type checking is performed.
80-
To enable the transformation of non erasable TypeScript syntax, which requires JavaScript code generation,
81-
such as `enum` declarations, parameter properties use the flag [`--experimental-transform-types`][].
8283
To disable this feature, use the flag [`--no-strip-types`][].
8384

8485
Node.js ignores `tsconfig.json` files and therefore
@@ -139,8 +140,7 @@ include the `.ts` extension.
139140
### TypeScript features
140141

141142
Since Node.js is only removing inline types, any TypeScript features that
142-
involve _replacing_ TypeScript syntax with new JavaScript syntax will error,
143-
unless the flag [`--experimental-transform-types`][] is passed.
143+
involve _replacing_ TypeScript syntax with new JavaScript syntax will error.
144144

145145
The most prominent features that require transformation are:
146146

@@ -211,8 +211,6 @@ TypeScript syntax is unsupported in the REPL, `--check`, and
211211

212212
Since inline types are replaced by whitespace, source maps are unnecessary for
213213
correct line numbers in stack traces; and Node.js does not generate them.
214-
When [`--experimental-transform-types`][] is enabled, source-maps
215-
are enabled by default.
216214

217215
### Type stripping in dependencies
218216

@@ -229,7 +227,6 @@ with `#`.
229227
[CommonJS]: modules.md
230228
[ES Modules]: esm.md
231229
[Full TypeScript support]: #full-typescript-support
232-
[`--experimental-transform-types`]: cli.md#--experimental-transform-types
233230
[`--no-strip-types`]: cli.md#--no-strip-types
234231
[`ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX`]: errors.md#err_unsupported_typescript_syntax
235232
[`tsconfig` "paths"]: https://www.typescriptlang.org/tsconfig/#paths

doc/api/util.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,7 @@ anotherFunction();
677677

678678
It is possible to reconstruct the original locations by setting the option `sourceMap` to `true`.
679679
If the source map is not available, the original location will be the same as the current location.
680-
When the `--enable-source-maps` flag is enabled, for example when using `--experimental-transform-types`,
681-
`sourceMap` will be true by default.
680+
When the `--enable-source-maps` flag is enabled,`sourceMap` will be true by default.
682681

683682
```ts
684683
import { getCallSites } from 'node:util';

doc/node-config-schema.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,6 @@
213213
"type": "boolean",
214214
"description": "experimental node:sqlite module"
215215
},
216-
"experimental-transform-types": {
217-
"type": "boolean",
218-
"description": "enable transformation of TypeScript-onlysyntax into JavaScript code"
219-
},
220216
"experimental-vm-modules": {
221217
"type": "boolean",
222218
"description": "experimental ES Module support in vm module"

doc/node.1

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,6 @@ collecting code coverage from tests for more details.
741741
Enable module mocking in the test runner.
742742
This feature requires \fB--allow-worker\fR if used with the Permission Model.
743743
.
744-
.It Fl -experimental-transform-types
745-
Enables the transformation of TypeScript-only syntax into JavaScript code.
746-
Implies \fB--enable-source-maps\fR.
747-
.
748744
.It Fl -experimental-vm-modules
749745
Enable experimental ES Module support in the \fBnode:vm\fR module.
750746
.
@@ -1878,8 +1874,6 @@ one is included in the list below.
18781874
.It
18791875
\fB--experimental-top-level-await\fR
18801876
.It
1881-
\fB--experimental-transform-types\fR
1882-
.It
18831877
\fB--experimental-vm-modules\fR
18841878
.It
18851879
\fB--experimental-wasi-unstable-preview1\fR

0 commit comments

Comments
 (0)