Skip to content

--experimental-strip-types does not work for STDIN #54035

Closed
@tchetwin

Description

@tchetwin

Version

v23.0.0-nightly202407253de7a4c374

Platform

Linux <machineName> 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

typescript

What steps will reproduce the bug?

Good:

node --experimental-strip-types --eval 'const greeting: string = "hello"; console.log(greeting);'
hello
(node:9012) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

Bad:

 echo 'const greeting: string = "hello"; console.log(greeting);' | node --experimental-strip-types
(node:8861) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
[stdin]:1
const greeting: string = "hello"; console.log(greeting);
      ^^^^^^^^

SyntaxError: Missing initializer in const declaration
    at makeContextifyScript (node:internal/vm:185:14)
    at node:internal/process/execution:107:22
    at [stdin]-wrapper:6:24
    at runScript (node:internal/process/execution:101:62)
    at evalScript (node:internal/process/execution:136:3)
    at node:internal/main/eval_stdin:32:5
    at Socket.<anonymous> (node:internal/process/execution:237:5)
    at Socket.emit (node:events:532:35)
    at endReadableNT (node:internal/streams/readable:1696:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v23.0.0-nightly202407253de7a4c374

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

Per the docs, the expected behaviour is that --eval and STDIN are both supported:

Type stripping can be enabled for --eval and STDIN input. The module system will be determined by --input-type, as it is for JavaScript.

What do you see instead?

Instead we receive an error as if we had not passed the flag --experimental-strip-types.

It is clear from the (red) stderr that the flag was acknowledged by node.

Additional information

I wasn't sure from the docs if --input-type should be passed, but the CLI feedback is that only values of "module" or "commonjs" would work, and neither helped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    strip-typesIssues or PRs related to strip-types support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions