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

Handle .mts and .cts files in @babel/preset-typescript #13838

Merged
merged 4 commits into from Oct 28, 2021

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Oct 11, 2021

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link babel/website#2585
Any Dependency Changes?
License MIT

This PR can be reviewed commit-by-commit. I had to add a new parser option because [mc]ts files are parsed differently from ts: they don't support neither JSX nor type assertions (https://twitter.com/atcb/status/1447645229503315973).
The preset automatically sets this parser option and the sourceType.

@nicolo-ribaudo nicolo-ribaudo added the PR: New Feature 🚀 A type of pull request used for our changelog categories label Oct 11, 2021
@nicolo-ribaudo nicolo-ribaudo added this to the v7.16.0 milestone Oct 11, 2021
@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 11, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 07343ca:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@babel-bot
Copy link
Collaborator

babel-bot commented Oct 11, 2021

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

@nicolo-ribaudo
Copy link
Member Author

Marking as draft since I also need to implement https://twitter.com/atcb/status/1447645229503315973.

@nicolo-ribaudo nicolo-ribaudo marked this pull request as draft October 11, 2021 19:33
@@ -245,7 +246,7 @@ function run(task) {
filename: self.loc,
filenameRelative: self.filename,
sourceFileName: self.filename,
sourceType: "script",
...(doNotSetSourceType ? {} : { sourceType: "script" }),
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 was quite annoying: since user-defined options have precedence over preset-defined options, it disabled preset-typescript's extension-based sourceType inference.

Removing this default makes all the tests fail because of the output.js file extension (Babel defaults to modules, so the test runner expects .mjs extensions) -- I'll handle it in a separate PR.

}
],
"extra": {
"trailingComma": 2
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 could be just a boolean, but having it as a number makes it consistent with the other places where we define node.extra.trailingComma (for example function calls).

This extra info can then be used to fix #13778.

@@ -185,6 +185,7 @@ export interface FlowPluginOptions {

export interface TypeScriptPluginOptions {
dts?: boolean;
disallowJSXAmbiguity?: boolean;
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't like this option name, but I needed a name which says "disallow non-JSX code that would be ambiguous with JSX if it was enabled".

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe noAmbiguousJSXLike? The current name feels like it is an option to disallow ambiguous code when JSX is enabled.

Copy link
Member Author

Choose a reason for hiding this comment

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

disallowAmbiguousJSXLike, so that the TS preset has consistent option names (disallow* and allow*)

@JLHwung JLHwung added the PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release label Oct 28, 2021
@nicolo-ribaudo nicolo-ribaudo merged commit 718c6cb into babel:main Oct 28, 2021
@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 28, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants