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

tsx REPL does not respect NODE_REPL_MODE environment variable or --use_strict CLI flag at transpile time #477

Open
4 of 6 tasks
jhmaster2000 opened this issue Feb 13, 2024 · 0 comments
Labels
bug Something isn't working pending triage

Comments

@jhmaster2000
Copy link

Acknowledgements

  • I searched existing issues before opening this one to avoid duplicates
  • I understand this is not a place for seek help, but to report a bug
  • I understand that the bug must be proven first with a minimal reproduction
  • I will be polite, respectful, and considerate of people's time and effort

Minimal reproduction URL

N/A

Version

v4.7.1

Node.js version

v20.10.0

Package manager

N/A

Operating system

Windows

Problem & Expected behavior

Put simply, tsx has the same issue I myself reported to deno a while back here: denoland/deno#13775

But I'll re-explain it here anyway just in case.

Node.js supports the NODE_REPL_MODE flag documented here or the --use_strict CLI flag (seemingly undocumented at the time?) to configure the REPL to run in strict mode instead of the default sloppy mode, you can test this with:

  1. Make sure NODE_REPL_MODE is unset to not interfere with the reproduction
  2. node -> 01 -> Returns 1
  3. Exit the REPL
  4. node --use_strict -> 01 -> Strict mode error (expected)

Reproducing the same steps above but with tsx in place of node results in step 4 still returning 1 instead of the expected error. Notice however the following alternative reproduction:

  1. Make sure NODE_REPL_MODE is unset to not interfere with the reproduction
  2. tsx -> eval('01') -> Returns 1
  3. Exit the REPL
  4. tsx --use_strict -> eval('01') -> Strict mode error (expected, it works now!)

Note: Both reproductions can also be done through the environment variable instead of the flag with identical results.

The conclusion here is that the runtime itself is respecting the options and running in strict mode, after all it is just regular Node.js in the end, but tsx is not running transpilation in strict mode in accordance to these REPL flags, so it transpiles these strict-mode-invalid literals into "resolved" literals that are valid in strict mode, causing unintended odd looking behavior.

Contributions

  • I plan to open a pull request for this issue
  • I plan to make a financial contribution to this project
@jhmaster2000 jhmaster2000 added bug Something isn't working pending triage labels Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending triage
Projects
None yet
Development

No branches or pull requests

1 participant