-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Better file extension handling for TypeScript and Flow presets #11316
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
Better file extension handling for TypeScript and Flow presets #11316
Conversation
hzoo
left a comment
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.
👍 , good to fix issues if they somehow have flow/ts presets both enabled or if no filename
|
@nicolo-ribaudo Can you rebase? |
This PR introduces multiple changes: - When using the TS preset, the filename is not required anymore - When both the TS and Flow plugins are enabled on the same file, an error is thrown rather then giving the precedence to TS - The TypeScript plugin doesn't disable JSX anymore - By default, the Flow preset only enables the plugin when applied to a non-ts file - The .isTSX option has been removed from the TS pluginsand preset, since users can directly enable the JSX plugin. - The .allExtensions option has been removed from the TS plugin, since it was used to replace the extension test with the removed .isTSX option - A new option, .ignoreExtensions, has been added to both the TS and Flow plugins, to make it possible to run them on JS and TS files respectively
7330948 to
83a632b
Compare
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/24239/ |
|
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 5f3520d:
|
Co-authored-by: Brian Ng <[email protected]>
| throw new Error( | ||
| "The .allExtensions and .isTSX options have been removed.\n" + | ||
| "If you want to disable JSX detection based on the file extension, " + | ||
| "If you want to disable file extension-based JSX detection, " + |
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.
English needs parentheses, here the fact that between "file" and "extension" has a higher precedence than - feels... weird 😛
Co-authored-by: Brian Ng <[email protected]> Co-authored-by: Huáng Jùnliàng <[email protected]>
Co-authored-by: Brian Ng <[email protected]> Co-authored-by: Huáng Jùnliàng <[email protected]>
Co-authored-by: Brian Ng <[email protected]> Co-authored-by: Huáng Jùnliàng <[email protected]>
This PR includes two different commits, conceptually separated, but the second one relies on the first one. The first one could be backported to Babel 7 if needed, but the second one is a breaking change.
Don't require a filename for test/include/exclude _functions_Better file extension handling for TS/Flow/JSXThe first commit removes the requirement to provide a filename to Babel when a preset specifies a function in
test/include/exclude. By doing so, it's possible for presets to provide a fallback behavior in case of a missing file name.I didn't remove the restriction for strings or regular expressions, since it's not clear what the default fallback should be.
The second commit provides a better UX when using Flow, TypeScript or JSX. The two main changes are that the plugins/presets don't opaquely disable other plugins, and that a filename isn't required anymore. I also changed the options they take regarding file names: