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
Conversation
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:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/49440/ |
Marking as draft since I also need to implement https://twitter.com/atcb/status/1447645229503315973. |
b34b337
to
1db66f6
Compare
@@ -245,7 +246,7 @@ function run(task) { | |||
filename: self.loc, | |||
filenameRelative: self.filename, | |||
sourceFileName: self.filename, | |||
sourceType: "script", | |||
...(doNotSetSourceType ? {} : { sourceType: "script" }), |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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*
)
This PR can be reviewed commit-by-commit. I had to add a new parser option because
[mc]ts
files are parsed differently fromts
: 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
.