Skip to content

Handle synthetic tslib and JSX factory imports #780

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

Merged
merged 4 commits into from
Apr 9, 2025

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented Apr 9, 2025

Fixes #765
Fixes #767

This implements import helper and JSX factory import node synthesis and resolution. Since the AST node is immutable, we cannot modify SourceFile.Imports. This info is now stored on the Program rather than at special fixed offsets in imports that's mutated after parse.

This could allow us to reuse ASTs more often, and means we stop having to work around these synthesized imports in other parts of the code (LS features, mainly).

This PR isn't perfect; it turns out we're missing implementations of moduleDetection and externalModuleIndicator, so we're not correctly determining that JSX files are modules because the jsx setting plays a part in determining if a file is a module (yay).

Fixing that will have to be a follow-up PR but that's going to be a lot more invasive. This PR fixes most stuff as it is now.

@@ -0,0 +1,44 @@
--- old.commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).errors.txt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is broken because we do not correctly set the module indicators.

@jakebailey jakebailey changed the title Handle import helpers and JSX factory imports Handle synthetic tslib and JSX factory imports Apr 9, 2025
@jakebailey jakebailey force-pushed the jabaile/jsx-loading-fixes branch from 863c22d to ecc1236 Compare April 9, 2025 19:27
@jakebailey jakebailey marked this pull request as ready for review April 9, 2025 19:51
Comment on lines 7 to +8
->notAHelper : Symbol(notAHelper, Decl(tslib.d.ts, --, --))
-
+>notAHelper : Symbol(notAHelper, Decl(tslib.d.ts, 0, 12))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny, Strada's regex here is bad, while in Corsa we "fixed" this.

@jakebailey
Copy link
Member Author

Future TODO: stop using synthetic nodes for this, because we only use them to then plug into module resolution anyway. There's no real reason to use a Node here other than "the code used to work this way and it's not very trivial to change", but changing it will be faster and make the loader lock-free again.

@jakebailey jakebailey added this pull request to the merge queue Apr 9, 2025
Merged via the queue into main with commit a88fef7 Apr 9, 2025
23 checks passed
@jakebailey jakebailey deleted the jabaile/jsx-loading-fixes branch April 9, 2025 23:36
shinichy pushed a commit to shinichy/typescript-go that referenced this pull request Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] failing to resolve react/jsx-runtime when type checking TSX files [bug] JSX support in preserve mode w/ custom jsxImportSource causing TS2875
2 participants