privatenumber / tsx

⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js
https://tsx.is
MIT License
8.64k stars 132 forks source link

Parsing error when using variable `of` #556

Closed errorx666 closed 1 month ago

errorx666 commented 1 month ago

Acknowledgements

Minimal reproduction URL

https://stackblitz.com/edit/stackblitz-starters-gtalwu?file=tsconfig.json

Problem & expected behavior (under 200 words)

npm start

Expected: code runs Actual: Parse error

Works with bun

Bugs are expected to be fixed by those affected by it

Compensating engineering work financially will speed up resolution

errorx666 commented 1 month ago

I started with a real-world error and stripped out as much as possible while still preserving the error.

privatenumber commented 1 month ago

I appreciate the effort but the reproduction is not minimal at all... There's 7 files and 11 dependencies. Please minimize it so tsx is the only dependency.

errorx666 commented 1 month ago

@privatenumber I have reduced it to one file and one external dependency. Please check again.

privatenumber commented 1 month ago

Thanks, I appreciate it!

I believe the root problem is in es-module-lexer assuming of is a reserved identifier. I reported it here: https://github.com/guybedford/es-module-lexer/issues/173

I also noticed an opportunity to skip the parsing completely in your case as the parsing is only used to detect dynamic imports, which you're not using. Upgrading to tsx v4.10.3 should fix your use-case.

errorx666 commented 1 month ago

Thank you for the quick turnaround! I would never have thought of that.

privatenumber commented 1 month ago

Fixed in https://github.com/guybedford/es-module-lexer/issues/173

privatenumber commented 1 month ago

:tada: This issue has been resolved in v4.10.5

If you appreciate this project, please consider supporting this project by sponsoring :heart: :pray: