Skip to content

Commit

Permalink
[babel 7] Allow setting ignoreExtensions in Flow preset (babel#16309)
Browse files Browse the repository at this point in the history
* [babel 7] Allow setting `ignoreExtensions` in Flow preset

* Discard changes to packages/babel-types/src/ast-types/generated/index.ts
  • Loading branch information
nicolo-ribaudo authored and liuxingbaoyu committed Mar 5, 2024
1 parent 69df2bb commit 9be48d1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
26 changes: 10 additions & 16 deletions packages/babel-preset-flow/src/index.ts
Expand Up @@ -11,7 +11,7 @@ export default declarePreset((api, opts) => {
const {
all,
allowDeclareFields,
ignoreExtensions = false,
ignoreExtensions = process.env.BABEL_8_BREAKING ? false : true,
experimental_useHermesParser: useHermesParser = false,
} = normalizeOptions(opts);

Expand All @@ -33,22 +33,16 @@ export default declarePreset((api, opts) => {
plugins.unshift("babel-plugin-syntax-hermes-parser");
}

// TODO: In Babel 7, ignoreExtensions is always true.
// Allow setting it to false in the next minor.
if (process.env.BABEL_8_BREAKING ? ignoreExtensions : true) {
if (ignoreExtensions) {
return { plugins };
}

if (process.env.BABEL_8_BREAKING) {
return {
overrides: [
{
test: filename => filename == null || !/\.tsx?$/.test(filename),
plugins,
},
],
};
} else {
// unreachable
}
return {
overrides: [
{
test: filename => filename == null || !/\.tsx?$/.test(filename),
plugins,
},
],
};
});
@@ -0,0 +1,3 @@
// The TS plugin is not enabled, so this will throw because
// the Flow preset will not enable Flow support in TS files.
type A = string;
@@ -0,0 +1,4 @@
{
"presets": [["flow", { "ignoreExtensions": false }]],
"throws": "Missing semicolon. (3:4)"
}
@@ -0,0 +1 @@
type A = string;
@@ -0,0 +1,3 @@
{
"presets": [["flow", { "ignoreExtensions": true }]]
}

0 comments on commit 9be48d1

Please sign in to comment.