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

--eval support #162

Closed
impaler opened this issue Dec 6, 2022 · 2 comments · Fixed by #402
Closed

--eval support #162

impaler opened this issue Dec 6, 2022 · 2 comments · Fixed by #402
Labels

Comments

@impaler
Copy link

impaler commented Dec 6, 2022

Feature request

Ability to use typescript in using the node --eval or -e feature from node:

eg api:

tsx  -e "const thing: string = 'hi'; console.log(thing);"

Currently this shows the loader is not applied with the error:

[eval]:1
const thing: string = hi; console.log(thing);
      ^^^^^

SyntaxError: Missing initializer in const declaration
    at new Script (node:vm:100:7)
    at createScript (node:vm:257:10)
    at Object.runInThisContext (node:vm:305:10)
    at node:internal/process/execution:81:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:80:60)
    at node:internal/main/eval_string:27:3

Why?

This is a feature used commonly in the node ecosystem for example code and running code snippets.

It can be also be useful for running a script without having to create a file. Right now creating a file is the only way eg related question here about Programmatic usage.

Alternatives

No response

Additional context

Initial question here https://github.com/esbuild-kit/tsx/discussions/161 where @privatenumber suggests this should be possible.

@rayrw
Copy link
Contributor

rayrw commented Feb 28, 2023

Hello! I'd like to try implementing this.

@privatenumber
Copy link
Owner

Go ahead, thanks for the heads up!

@privatenumber privatenumber mentioned this issue Sep 12, 2023
21 tasks
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants