Skip to content

Commit 588e2a7

Browse files
module: add --experimental-strip-input-types
1 parent 547a634 commit 588e2a7

File tree

7 files changed

+33
-11
lines changed

7 files changed

+33
-11
lines changed

doc/api/cli.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,18 @@ added:
995995

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

998+
### `--experimental-strip-input-types`
999+
1000+
<!-- YAML
1001+
added: REPLACEME
1002+
-->
1003+
1004+
> Stability: 1.1 - Active development
1005+
1006+
Enable experimental type-stripping for `--eval`.
1007+
Implies [`--experimental-strip-types`][].
1008+
For more information, see the [TypeScript type-stripping][] documentation.
1009+
9981010
### `--experimental-strip-types`
9991011

10001012
<!-- YAML

doc/api/typescript.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ import { fn, FnParams } from './fn.ts';
153153

154154
### Non-file forms of input
155155

156-
Type stripping can be enabled for `--eval`. The module system
156+
Type stripping can be enabled for `--eval` by using the flag [`--experimental-strip-input-types`][]. The module system
157157
will be determined by `--input-type`, as it is for JavaScript.
158158

159159
TypeScript syntax is unsupported in the REPL, STDIN input, `--print`, `--check`, and
@@ -181,6 +181,7 @@ with `#`.
181181
[CommonJS]: modules.md
182182
[ES Modules]: esm.md
183183
[Full TypeScript support]: #full-typescript-support
184+
[`--experimental-strip-input-types`]: cli.md#--experimental-strip-input-types
184185
[`--experimental-strip-types`]: cli.md#--experimental-strip-types
185186
[`--experimental-transform-types`]: cli.md#--experimental-transform-types
186187
[`tsconfig` "paths"]: https://www.typescriptlang.org/tsconfig/#paths

doc/node.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ Configures the type of test isolation used in the test runner.
186186
.It Fl -experimental-test-module-mocks
187187
Enable module mocking in the test runner.
188188
.
189+
.It Fl -experimental-strip-input-types
190+
Enable experimental type-stripping for eval input.
191+
.
189192
.It Fl -experimental-strip-types
190193
Enable experimental type-stripping for TypeScript files.
191194
.

lib/internal/main/eval_string.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ addBuiltinLibsToObject(globalThis, '<eval>');
2323
markBootstrapComplete();
2424

2525
const code = getOptionValue('--eval');
26-
const source = getOptionValue('--experimental-strip-types') ?
26+
const source = getOptionValue('--experimental-strip-input-types') ?
2727
stripTypeScriptModuleTypes(code) :
2828
code;
2929

src/node_options.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
844844
"ES module to preload (option can be repeated)",
845845
&EnvironmentOptions::preload_esm_modules,
846846
kAllowedInEnvvar);
847+
AddOption("--experimental-strip-input-types",
848+
"Experimental type-stripping for eval",
849+
&EnvironmentOptions::experimental_strip_input_types,
850+
kAllowedInEnvvar);
847851
AddOption("--experimental-strip-types",
848852
"Experimental type-stripping for TypeScript files.",
849853
&EnvironmentOptions::experimental_strip_types,
@@ -855,6 +859,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
855859
kAllowedInEnvvar);
856860
Implies("--experimental-transform-types", "--experimental-strip-types");
857861
Implies("--experimental-transform-types", "--enable-source-maps");
862+
Implies("--experimental-strip-input-types", "--experimental-strip-types");
858863
AddOption("--interactive",
859864
"always enter the REPL even if stdin does not appear "
860865
"to be a terminal",

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class EnvironmentOptions : public Options {
247247
std::vector<std::string> preload_esm_modules;
248248

249249
bool experimental_strip_types = false;
250+
bool experimental_strip_input_types = false;
250251
bool experimental_transform_types = false;
251252

252253
std::vector<std::string> user_argv;

test/es-module/test-typescript-eval.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if (!process.config.variables.node_use_amaro) skip('Requires Amaro');
66

77
test('eval TypeScript ESM syntax', async () => {
88
const result = await spawnPromisified(process.execPath, [
9-
'--experimental-strip-types',
9+
'--experimental-strip-input-types',
1010
'--eval',
1111
`import util from 'node:util'
1212
const text: string = 'Hello, TypeScript!'
@@ -19,7 +19,7 @@ test('eval TypeScript ESM syntax', async () => {
1919

2020
test('eval TypeScript ESM syntax with input-type module', async () => {
2121
const result = await spawnPromisified(process.execPath, [
22-
'--experimental-strip-types',
22+
'--experimental-strip-input-types',
2323
'--input-type=module',
2424
'--eval',
2525
`import util from 'node:util'
@@ -33,7 +33,7 @@ test('eval TypeScript ESM syntax with input-type module', async () => {
3333

3434
test('eval TypeScript CommonJS syntax', async () => {
3535
const result = await spawnPromisified(process.execPath, [
36-
'--experimental-strip-types',
36+
'--experimental-strip-input-types',
3737
'--eval',
3838
`const util = require('node:util');
3939
const text: string = 'Hello, TypeScript!'
@@ -46,7 +46,7 @@ test('eval TypeScript CommonJS syntax', async () => {
4646

4747
test('eval TypeScript CommonJS syntax with input-type commonjs', async () => {
4848
const result = await spawnPromisified(process.execPath, [
49-
'--experimental-strip-types',
49+
'--experimental-strip-input-types',
5050
'--input-type=commonjs',
5151
'--eval',
5252
`const util = require('node:util');
@@ -60,7 +60,7 @@ test('eval TypeScript CommonJS syntax with input-type commonjs', async () => {
6060

6161
test('eval TypeScript CommonJS syntax by default', async () => {
6262
const result = await spawnPromisified(process.execPath, [
63-
'--experimental-strip-types',
63+
'--experimental-strip-input-types',
6464
'--eval',
6565
`const util = require('node:util');
6666
const text: string = 'Hello, TypeScript!'
@@ -74,7 +74,7 @@ test('eval TypeScript CommonJS syntax by default', async () => {
7474

7575
test('TypeScript ESM syntax not specified', async () => {
7676
const result = await spawnPromisified(process.execPath, [
77-
'--experimental-strip-types',
77+
'--experimental-strip-input-types',
7878
'--eval',
7979
`import util from 'node:util'
8080
const text: string = 'Hello, TypeScript!'
@@ -86,7 +86,7 @@ test('TypeScript ESM syntax not specified', async () => {
8686

8787
test('expect fail eval TypeScript CommonJS syntax with input-type module', async () => {
8888
const result = await spawnPromisified(process.execPath, [
89-
'--experimental-strip-types',
89+
'--experimental-strip-input-types',
9090
'--input-type=module',
9191
'--eval',
9292
`const util = require('node:util');
@@ -100,7 +100,7 @@ test('expect fail eval TypeScript CommonJS syntax with input-type module', async
100100

101101
test('expect fail eval TypeScript ESM syntax with input-type commonjs', async () => {
102102
const result = await spawnPromisified(process.execPath, [
103-
'--experimental-strip-types',
103+
'--experimental-strip-input-types',
104104
'--input-type=commonjs',
105105
'--eval',
106106
`import util from 'node:util'
@@ -113,7 +113,7 @@ test('expect fail eval TypeScript ESM syntax with input-type commonjs', async ()
113113

114114
test('check syntax error is thrown when passing invalid syntax', async () => {
115115
const result = await spawnPromisified(process.execPath, [
116-
'--experimental-strip-types',
116+
'--experimental-strip-input-types',
117117
'--eval',
118118
'enum Foo { A, B, C }']);
119119
strictEqual(result.stdout, '');

0 commit comments

Comments
 (0)