Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: unflag --experimental-strip-types #56350

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion benchmark/ts/strip-typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const bench = common.createBenchmark(main, {
filepath: [ts, js],
n: [1e4],
}, {
flags: ['--experimental-strip-types', '--disable-warning=ExperimentalWarning'],
flags: ['--disable-warning=ExperimentalWarning'],
});

async function main({ n, filepath }) {
Expand Down
42 changes: 23 additions & 19 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ Any query parameter or hash in the URL will be accessible via [`import.meta.url`

```bash
node --entry-url 'file:///path/to/file.js?queryparams=work#and-hashes-too'
node --entry-url --experimental-strip-types 'file.ts?query#hash'
node --entry-url 'file.ts?query#hash'
node --entry-url 'data:text/javascript,console.log("Hello")'
```

Expand Down Expand Up @@ -880,8 +880,8 @@ On Windows, using `cmd.exe` a single quote will not work correctly because it
only recognizes double `"` for quoting. In Powershell or Git bash, both `'`
and `"` are usable.

It is possible to run code containing inline types by passing
[`--experimental-strip-types`][].
It is possible to run code containing inline types unless the
[`--no-experimental-strip-types`][] flag is provided.

### `--experimental-addon-modules`

Expand Down Expand Up @@ -1008,17 +1008,6 @@ added:

Use this flag to enable [ShadowRealm][] support.

### `--experimental-strip-types`

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

> Stability: 1.1 - Active development
Enable experimental type-stripping for TypeScript files.
For more information, see the [TypeScript type-stripping][] documentation.

### `--experimental-test-coverage`

<!-- YAML
Expand Down Expand Up @@ -1059,7 +1048,7 @@ added: v22.7.0
> Stability: 1.1 - Active development
Enables the transformation of TypeScript-only syntax into JavaScript code.
Implies `--experimental-strip-types` and `--enable-source-maps`.
Implies `--enable-source-maps`.

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

Expand Down Expand Up @@ -1370,10 +1359,10 @@ added: v12.0.0

This configures Node.js to interpret `--eval` or `STDIN` input as CommonJS or
as an ES module. Valid values are `"commonjs"`, `"module"`, `"module-typescript"` and `"commonjs-typescript"`.
The `"-typescript"` values are available only in combination with the flag `--experimental-strip-types`.
The `"-typescript"` values are not available with the flag `--no-experimental-strip-types`.
The default is `"commonjs"`.

If `--experimental-strip-types` is enabled and `--input-type` is not provided,
If `--input-type` is not provided,
Node.js will try to detect the syntax with the following steps:

1. Run the input as CommonJS.
Expand Down Expand Up @@ -1663,6 +1652,21 @@ changes:

Disable the experimental [`node:sqlite`][] module.

### `--no-experimental-strip-types`

<!-- YAML
added: v22.6.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/56350
description: Type stripping is enabled by default.
-->

> Stability: 1.1 - Active development
marco-ippolito marked this conversation as resolved.
Show resolved Hide resolved
Disable experimental type-stripping for TypeScript files.
For more information, see the [TypeScript type-stripping][] documentation.

### `--no-experimental-websocket`

<!-- YAML
Expand Down Expand Up @@ -3089,7 +3093,6 @@ one is included in the list below.
* `--experimental-require-module`
* `--experimental-shadow-realm`
* `--experimental-specifier-resolution`
* `--experimental-strip-types`
* `--experimental-test-isolation`
* `--experimental-top-level-await`
* `--experimental-transform-types`
Expand Down Expand Up @@ -3127,6 +3130,7 @@ one is included in the list below.
* `--no-experimental-global-navigator`
* `--no-experimental-repl-await`
* `--no-experimental-sqlite`
* `--no-experimental-strip-types`
* `--no-experimental-websocket`
* `--no-extra-info-on-fatal-exception`
* `--no-force-async-hooks-checks`
Expand Down Expand Up @@ -3651,10 +3655,10 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
[`--env-file`]: #--env-fileconfig
[`--experimental-addon-modules`]: #--experimental-addon-modules
[`--experimental-sea-config`]: single-executable-applications.md#generating-single-executable-preparation-blobs
[`--experimental-strip-types`]: #--experimental-strip-types
[`--experimental-wasm-modules`]: #--experimental-wasm-modules
[`--heap-prof-dir`]: #--heap-prof-dir
[`--import`]: #--importmodule
[`--no-experimental-strip-types`]: #--no-experimental-strip-types
bmuenzenmeyer marked this conversation as resolved.
Show resolved Hide resolved
[`--openssl-config`]: #--openssl-configfile
[`--preserve-symlinks`]: #--preserve-symlinks
[`--print`]: #-p---print-script
Expand Down
5 changes: 3 additions & 2 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -2025,8 +2025,9 @@ added:
* {boolean|string}
A value that is `"strip"` if Node.js is run with `--experimental-strip-types`,
`"transform"` if Node.js is run with `--experimental-transform-types`, and `false` otherwise.
A value that is `"strip"` by default,
`"transform"` if Node.js is run with `--experimental-transform-types`, and `false` if
Node.js is run with `--no-experimental-strip-types`.
## `process.features.uv`
Expand Down
6 changes: 3 additions & 3 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ By default, Node.js will run all files matching these patterns:
* `**/test.{cjs,mjs,js}`
* `**/test/**/*.{cjs,mjs,js}`

When [`--experimental-strip-types`][] is supplied, the following
additional patterns are matched:
Unless [`--no-experimental-strip-types`][] is supplied, the following
additional patterns are also matched:

* `**/*.test.{cts,mts,ts}`
* `**/*-test.{cts,mts,ts}`
Expand Down Expand Up @@ -3591,10 +3591,10 @@ added:
Can be used to abort test subtasks when the test has been aborted.

[TAP]: https://testanything.org/
[`--experimental-strip-types`]: cli.md#--experimental-strip-types
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
[`--experimental-test-module-mocks`]: cli.md#--experimental-test-module-mocks
[`--import`]: cli.md#--importmodule
[`--no-experimental-strip-types`]: cli.md#--no-experimental-strip-types
[`--test-concurrency`]: cli.md#--test-concurrency
[`--test-coverage-exclude`]: cli.md#--test-coverage-exclude
[`--test-coverage-include`]: cli.md#--test-coverage-include
Expand Down
4 changes: 2 additions & 2 deletions doc/api/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ added: v22.6.0

> Stability: 1.1 - Active development
Copy link
Contributor

@aduh95 aduh95 Dec 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add an entry in this document that says on what version type stripping was enabled by default


The flag [`--experimental-strip-types`][] enables Node.js to run TypeScript
The flag [`--no-experimental-strip-types`][] prevents Node.js from running TypeScript
files. By default Node.js will execute only files that contain no
TypeScript features that require transformation, such as enums or namespaces.
Node.js will replace inline type annotations with whitespace,
Expand Down Expand Up @@ -181,8 +181,8 @@ with `#`.
[CommonJS]: modules.md
[ES Modules]: esm.md
[Full TypeScript support]: #full-typescript-support
[`--experimental-strip-types`]: cli.md#--experimental-strip-types
[`--experimental-transform-types`]: cli.md#--experimental-transform-types
[`--no-experimental-strip-types`]: cli.md#--no-experimental-strip-types
[`tsconfig` "paths"]: https://www.typescriptlang.org/tsconfig/#paths
[`tsx`]: https://tsx.is/
[`verbatimModuleSyntax`]: https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax
Expand Down
6 changes: 3 additions & 3 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ Enable code coverage in the test runner.
.It Fl -experimental-test-module-mocks
Enable module mocking in the test runner.
.
.It Fl -experimental-strip-types
Enable experimental type-stripping for TypeScript files.
.
.It Fl -experimental-transform-types
Enable transformation of TypeScript-only syntax into JavaScript code.
.
Expand All @@ -207,6 +204,9 @@ Disable top-level await keyword support in REPL.
.It Fl -no-experimental-sqlite
Disable the experimental node:sqlite module.
.
.It Fl -no-experimental-strip-types
Disable experimental type-stripping for TypeScript files.
.
.It Fl -experimental-vm-modules
Enable experimental ES module support in VM module.
.
Expand Down
3 changes: 2 additions & 1 deletion src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,8 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
AddOption("--experimental-strip-types",
"Experimental type-stripping for TypeScript files.",
&EnvironmentOptions::experimental_strip_types,
kAllowedInEnvvar);
kAllowedInEnvvar,
true);
AddOption("--experimental-transform-types",
"enable transformation of TypeScript-only"
"syntax into JavaScript code",
Expand Down
2 changes: 1 addition & 1 deletion src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class EnvironmentOptions : public Options {

std::vector<std::string> preload_esm_modules;

bool experimental_strip_types = false;
bool experimental_strip_types = true;
bool experimental_transform_types = false;

std::vector<std::string> user_argv;
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-loader-entry-url.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('--entry-url', { concurrency: true }, () => {

for (const url of typescriptUrls) {
await assertSpawnedProcess(
['--entry-url', '--experimental-strip-types', fixtures.fileURL(url)],
['--entry-url', fixtures.fileURL(url)],
{},
{
...experimentalFeatureWarning,
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-resolve-type.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ try {
[ 'qmod', 'index.js', 'imp.js', 'commonjs', 'module', 'module', '?k=v'],
[ 'hmod', 'index.js', 'imp.js', 'commonjs', 'module', 'module', '#Key'],
[ 'qhmod', 'index.js', 'imp.js', 'commonjs', 'module', 'module', '?k=v#h'],
[ 'ts-mod-com', 'index.js', 'imp.ts', 'module', 'commonjs', undefined],
[ 'ts-mod-com', 'index.js', 'imp.ts', 'module', 'commonjs', 'commonjs-typescript'],
].forEach((testVariant) => {
const [
moduleName,
Expand Down
13 changes: 0 additions & 13 deletions test/es-module/test-typescript-commonjs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ if (!process.config.variables.node_use_amaro) skip('Requires Amaro');

test('require a .ts file with explicit extension succeeds', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
'--eval',
'require("./test-typescript.ts")',
'--no-warnings',
Expand All @@ -22,7 +21,6 @@ test('require a .ts file with explicit extension succeeds', async () => {

test('eval require a .ts file with implicit extension fails', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
'--eval',
'require("./test-typescript")',
'--no-warnings',
Expand All @@ -37,7 +35,6 @@ test('eval require a .ts file with implicit extension fails', async () => {

test('eval require a .cts file with implicit extension fails', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
'--eval',
'require("./test-cts-typescript")',
'--no-warnings',
Expand All @@ -52,7 +49,6 @@ test('eval require a .cts file with implicit extension fails', async () => {

test('require a .ts file with implicit extension fails', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
'--no-warnings',
fixtures.path('typescript/cts/test-extensionless-require.ts'),
]);
Expand All @@ -64,7 +60,6 @@ test('require a .ts file with implicit extension fails', async () => {

test('expect failure of an .mts file with CommonJS syntax', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
fixtures.path('typescript/cts/test-cts-but-module-syntax.cts'),
]);

Expand All @@ -75,7 +70,6 @@ test('expect failure of an .mts file with CommonJS syntax', async () => {

test('execute a .cts file importing a .cts file', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
'--no-warnings',
fixtures.path('typescript/cts/test-require-commonjs.cts'),
]);
Expand All @@ -87,7 +81,6 @@ test('execute a .cts file importing a .cts file', async () => {

test('execute a .cts file importing a .ts file export', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
'--no-warnings',
fixtures.path('typescript/cts/test-require-ts-file.cts'),
]);
Expand All @@ -99,7 +92,6 @@ test('execute a .cts file importing a .ts file export', async () => {

test('execute a .cts file importing a .mts file export', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
'--no-experimental-require-module',
fixtures.path('typescript/cts/test-require-mts-module.cts'),
]);
Expand All @@ -111,7 +103,6 @@ test('execute a .cts file importing a .mts file export', async () => {

test('execute a .cts file importing a .mts file export', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
'--experimental-require-module',
fixtures.path('typescript/cts/test-require-mts-module.cts'),
]);
Expand All @@ -122,7 +113,6 @@ test('execute a .cts file importing a .mts file export', async () => {

test('expect failure of a .cts file in node_modules', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
fixtures.path('typescript/cts/test-cts-node_modules.cts'),
]);

Expand All @@ -133,7 +123,6 @@ test('expect failure of a .cts file in node_modules', async () => {

test('expect failure of a .ts file in node_modules', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
fixtures.path('typescript/cts/test-ts-node_modules.cts'),
]);

Expand All @@ -144,7 +133,6 @@ test('expect failure of a .ts file in node_modules', async () => {

test('expect failure of a .cts requiring esm without default type module', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
'--no-experimental-require-module',
fixtures.path('typescript/cts/test-mts-node_modules.cts'),
]);
Expand All @@ -156,7 +144,6 @@ test('expect failure of a .cts requiring esm without default type module', async

test('expect failure of a .cts file requiring esm in node_modules', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
'--experimental-require-module',
fixtures.path('typescript/cts/test-mts-node_modules.cts'),
]);
Expand Down
Loading
Loading