Skip to content

Comments

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

Merged
nicolo-ribaudo merged 4 commits intobabel:mainfrom
nicolo-ribaudo:mcts
Oct 28, 2021
Merged

Handle .mts and .cts files in @babel/preset-typescript#13838
nicolo-ribaudo merged 4 commits intobabel:mainfrom
nicolo-ribaudo:mcts

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

@nicolo-ribaudo nicolo-ribaudo marked this pull request as draft October 11, 2021 19:33
@nicolo-ribaudo nicolo-ribaudo force-pushed the mcts branch 2 times, most recently from b34b337 to 1db66f6 Compare October 11, 2021 21:36
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

@nicolo-ribaudo nicolo-ribaudo Oct 11, 2021

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.


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
@nicolo-ribaudo nicolo-ribaudo deleted the mcts branch October 28, 2021 23:13
@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.

5 participants