Skip to content

Commit

Permalink
[babel 7] Allow setting ignoreExtensions in Flow preset
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Feb 27, 2024
1 parent 1332da5 commit 9dc9261
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 65 deletions.
24 changes: 10 additions & 14 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 @@ -35,20 +35,16 @@ export default declarePreset((api, opts) => {

// 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 9dc9261

Please sign in to comment.