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

Support new "using" keyword for disposable objects #5113

Closed
hazae41 opened this issue Aug 29, 2023 · 7 comments · Fixed by #5444
Closed

Support new "using" keyword for disposable objects #5113

hazae41 opened this issue Aug 29, 2023 · 7 comments · Fixed by #5444

Comments

@hazae41
Copy link

hazae41 commented Aug 29, 2023

Rollup Version

3.28.1

Operating System (or Browser)

macOS

Node Version (if applicable)

20.3.1

Link To Reproduction

https://stackblitz.com/edit/rollup-repro-zruwr9?file=src%2Fmain.ts

Expected Behaviour

It should build successfully if using TypeScript 5.2 and latest tslib, @rollup/plugin-typescript

Actual Behaviour

Error on build: RollupError: Unexpected token (Note that you need plugins to import files that are not JavaScript)

@hazae41
Copy link
Author

hazae41 commented Aug 29, 2023

It also crashes on latest rollup@4.0.0-13

RollupError: Expected ';', '}' or <eof>

@TrickyPi
Copy link
Member

TrickyPi commented Aug 31, 2023

For Rollup V3, we need to wait for acorn.js to support parsing using. But it's in stage 3 for JavaScript, I'm not sure the team of acorn.js will support it right away. If you are stuck with this issue, you can change the option compilerOptions.target in the tsconfig.json to ES2022 as a workaround. For Rollup V4, which is under development, SWC can parse it with the option jsc.parser.usingDecl, I'll take a look at this issue on Rollup V4.

@hazae41
Copy link
Author

hazae41 commented Sep 2, 2023

Thanks for the tip, ES2022 target works! But for people reading this, for some reason ESNext doesn't 🤨

@hazae41
Copy link
Author

hazae41 commented Sep 2, 2023

microsoft/TypeScript#55609

The issue seems to be related to either tslib or @rollup/plugin-typescript, since it works in tsc

@dnalborczyk
Copy link
Contributor

Thanks for the tip, ES2022 target works! But for people reading this, for some reason ESNext doesn't 🤨

ESNext essentially only strips the types, so the runtime you are running the transpiled code in needs to support the using syntax. there is no runtime support as of today as far as I know.

@Hebilicious
Copy link

@TrickyPi I am not familiar at all with the rollup codebase, but do you have any idea on how we could have this supported in rollup 4 ? ie setting usingDecl to true in the internal rollup parser ?

Copy link

github-actions bot commented Apr 3, 2024

This issue has been resolved via #5444 as part of rollup@4.14.0. You can test it via npm install rollup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants