Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions benchmark/fixtures/transform-types-benchmark.js

This file was deleted.

30 changes: 0 additions & 30 deletions benchmark/fixtures/transform-types-benchmark.ts

This file was deleted.

26 changes: 0 additions & 26 deletions benchmark/ts/transform-typescript.js

This file was deleted.

12 changes: 0 additions & 12 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

<!-- YAML
added: v22.7.0
-->

> Stability: 1.2 - Release candidate
Enables the transformation of TypeScript-only syntax into JavaScript code.
Implies `--enable-source-maps`.

### `--experimental-vm-modules`

<!-- YAML
Expand Down Expand Up @@ -3611,7 +3600,6 @@ one is included in the list below.
* `--experimental-specifier-resolution`
* `--experimental-test-isolation`
* `--experimental-top-level-await`
* `--experimental-transform-types`
* `--experimental-vm-modules`
* `--experimental-wasi-unstable-preview1`
* `--force-context-aware`
Expand Down
70 changes: 5 additions & 65 deletions doc/api/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,35 +239,28 @@
Register [hooks][] that customize Node.js module resolution and loading behavior.
See [Customization hooks][].

### `module.stripTypeScriptTypes(code[, options])`
### `module.stripTypeScriptTypes(code)`

<!-- YAML
added:
- v23.2.0
- v22.13.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/9999999999999

Check warning on line 250 in doc/api/module.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: Remove `mode` input argument and support for TypeScript features that require transformation and source map.
-->

> 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
with `vm.runInContext()` or `vm.compileFunction()`.
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.
Expand All @@ -288,58 +281,6 @@
// 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()`

<!-- YAML
Expand Down Expand Up @@ -2041,5 +1982,4 @@
[synchronous hook functions]: #hook-functions-accepted-by-moduleregisterhooks
[the documentation of `Worker`]: worker_threads.md#new-workerfilename-options
[transferable objects]: worker_threads.md#portpostmessagevalue-transferlist
[transform TypeScript features]: typescript.md#typescript-features
[type-stripping]: typescript.md#type-stripping
5 changes: 2 additions & 3 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -2011,10 +2011,9 @@ changes:

> Stability: 1.2 - Release candidate

* Type: {boolean|string}
* Type: {boolean}

A value that is `"strip"` by default,
`"transform"` if Node.js is run with `--experimental-transform-types`, and `false` if
A value that is `true` by default, and `false` if
Node.js is run with `--no-strip-types`.

## `process.features.uv`
Expand Down
11 changes: 4 additions & 7 deletions doc/api/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/9999999999999

Check warning on line 6 in doc/api/typescript.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: Removed `--experimental-transform-types` flag.
- version:
- v25.2.0
- v24.12.0
Expand Down Expand Up @@ -77,8 +80,6 @@
erasable TypeScript syntax.
Node.js will replace TypeScript syntax with whitespace,
and no type checking is performed.
To enable the transformation of non erasable TypeScript syntax, which requires JavaScript code generation,
such as `enum` declarations, parameter properties use the flag [`--experimental-transform-types`][].
To disable this feature, use the flag [`--no-strip-types`][].

Node.js ignores `tsconfig.json` files and therefore
Expand Down Expand Up @@ -139,8 +140,7 @@
### TypeScript features

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

The most prominent features that require transformation are:

Expand Down Expand Up @@ -211,8 +211,6 @@

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

### Type stripping in dependencies

Expand All @@ -229,7 +227,6 @@
[CommonJS]: modules.md
[ES Modules]: esm.md
[Full TypeScript support]: #full-typescript-support
[`--experimental-transform-types`]: cli.md#--experimental-transform-types
[`--no-strip-types`]: cli.md#--no-strip-types
[`ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX`]: errors.md#err_unsupported_typescript_syntax
[`tsconfig` "paths"]: https://www.typescriptlang.org/tsconfig/#paths
Expand Down
3 changes: 1 addition & 2 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,7 @@ anotherFunction();

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

```ts
import { getCallSites } from 'node:util';
Expand Down
4 changes: 0 additions & 4 deletions doc/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,6 @@
"type": "boolean",
"description": "experimental node:sqlite module"
},
"experimental-transform-types": {
"type": "boolean",
"description": "enable transformation of TypeScript-onlysyntax into JavaScript code"
},
"experimental-vm-modules": {
"type": "boolean",
"description": "experimental ES Module support in vm module"
Expand Down
6 changes: 0 additions & 6 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,6 @@ collecting code coverage from tests for more details.
Enable module mocking in the test runner.
This feature requires \fB--allow-worker\fR if used with the Permission Model.
.
.It Fl -experimental-transform-types
Enables the transformation of TypeScript-only syntax into JavaScript code.
Implies \fB--enable-source-maps\fR.
.
.It Fl -experimental-vm-modules
Enable experimental ES Module support in the \fBnode:vm\fR module.
.
Expand Down Expand Up @@ -1878,8 +1874,6 @@ one is included in the list below.
.It
\fB--experimental-top-level-await\fR
.It
\fB--experimental-transform-types\fR
.It
\fB--experimental-vm-modules\fR
.It
\fB--experimental-wasi-unstable-preview1\fR
Expand Down
8 changes: 1 addition & 7 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,7 @@ ObjectDefineProperty(process.features, 'typescript', {
__proto__: null,
get() {
if (kTypeStrippingMode === null) {
if (getOptionValue('--experimental-transform-types')) {
kTypeStrippingMode = 'transform';
} else if (getOptionValue('--strip-types')) {
kTypeStrippingMode = 'strip';
} else {
kTypeStrippingMode = false;
}
kTypeStrippingMode = getOptionValue('--strip-types');
}
return kTypeStrippingMode;
},
Expand Down
Loading
Loading