codesandbox / codesandbox-client

An online IDE for rapid web development
https://codesandbox.io
Other
13.04k stars 2.27k forks source link

[sandbox] Vanilla TypeScript template yields ‘Unexpected keyword or identifier typescript(1434)’ error when using `await` keyword #8433

Closed steveluscher closed 5 months ago

steveluscher commented 5 months ago

Description of the problem

Using the ‘Vanilla TypeScript’ template and authoring a sandbox with the await keyword, I get this TypeScript error:

Unexpected keyword or identifier typescript(1434)

image

How has this issue affected you? What are you trying to accomplish?

I can't create sandboxes that use async/await.

To Reproduce

https://codesandbox.io/p/sandbox/hungry-forest-7djrph

karl-police commented 5 months ago

This happens on every project

steveluscher commented 5 months ago

This happens on every project

I wonder if that's even true. I haven't tested this rigorously, but I seem to remember forking an await-using sandbox like this one, and having it go from not working to… working.

CompuIves commented 5 months ago

I'm taking a look. It looks like it only affects the TS language server, meaning that the editor is giving an error but the project should work as expected.

CompuIves commented 5 months ago

This is so interesting! TypeScript just doesn't recognize the await keyword at all, even though it's defined in its parser. I'm getting closer though.

CompuIves commented 5 months ago

Wooow, I finally found the bug to this. Since TypeScript 5, TypeScript uses a keyword list for await to know if something is a keyword of identifier. Our transpiler in Nodebox mistakingly transpiles the TypeScript source code, though. As a result, you get this:

Nodebox:

Screenshot 2024-04-29 at 14 16 45

Real source code:

Screenshot 2024-04-29 at 14 16 23

await was replaced with yield. For now, I've downgraded TypeScript to fix it, and we're going to build a fix in our transpiler.

CompuIves commented 5 months ago

Fix should be live now!

steveluscher commented 5 months ago

5FDtMRu1

Thank you!