Visitar URL original
Rewrite `.tsx` extension when using `rewriteImportExtensions` by jimmydief · Pull Request #16022 · babel/babel · GitHub
Skip to content

Rewrite .tsx extension when using rewriteImportExtensions - #16022

Merged
nicolo-ribaudo merged 2 commits into
babel:mainfrom
jimmydief:rewrite_tsx
Oct 10, 2023
Merged

nicolo-ribaudo merged 2 commits into
babel:mainfrom
jimmydief:rewrite_tsx

Conversation

@jimmydief

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? Fixes #16021
Patch: Bug Fix? Not sure
Major: Breaking Change? Not sure
Minor: New Feature? Not sure
Tests Added + Pass? Yes
Documentation PR Link N/A
Any Dependency Changes? No
License MIT

Include .tsx in the file extensions which are rewritten when using rewriteImportExtensions option of the TS preset.

@babel-bot

babel-bot commented Oct 6, 2023 •

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/55616/

: node.exportKind;
if (kind === "value" && source && /[\\/]/.test(source.value)) {
source.value = source.value.replace(/(\.[mc]?)ts$/, "$1js");
source.value = source.value.replace(/(\.[mc]?)tsx?$/, "$1js");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure if .mtsx or .ctsx are valid? Seems like no.

@nicolo-ribaudo nicolo-ribaudo Oct 9, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah they are not valid.

@liuxingbaoyu liuxingbaoyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@liuxingbaoyu liuxingbaoyu added the PR: Polish 💅 A type of pull request used for our changelog categories label Oct 8, 2023
@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories and removed PR: Polish 💅 A type of pull request used for our changelog categories labels Oct 9, 2023

@nicolo-ribaudo nicolo-ribaudo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am a little bit on the fence, since with this PR we would support .tsx but not .jsx. I think we could eventually supports JSX by adding the same option to the react preset if somebody in the future will ask for it (or we could publish extension rewriting as a separate standalone plugin).

@nicolo-ribaudo nicolo-ribaudo changed the title Rewrite .tsx extension when using rewriteImportExtensions option of TS preset Rewrite .tsx extension when using rewriteImportExtensions Oct 10, 2023
@nicolo-ribaudo
nicolo-ribaudo merged commit ccb6323 into babel:main Oct 10, 2023
@jimmydief
jimmydief deleted the rewrite_tsx branch October 11, 2023 16:12
@github-actions github-actions Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 11, 2024
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jan 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rewriteImportExtensions option for TS preset does not work with .tsx files

4 participants