Handle .mts and .cts files in @babel/preset-typescript#13838
Handle .mts and .cts files in @babel/preset-typescript#13838nicolo-ribaudo merged 4 commits intobabel:mainfrom
.mts and .cts files in @babel/preset-typescript#13838Conversation
|
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
| filenameRelative: self.filename, | ||
| sourceFileName: self.filename, | ||
| sourceType: "script", | ||
| ...(doNotSetSourceType ? {} : { sourceType: "script" }), |
There was a problem hiding this comment.
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.
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; |
There was a problem hiding this comment.
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.
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.
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]tsfiles 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.