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 8c3f035 commit 0385034
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,27 +11,21 @@ export default declarePreset((api, opts) => {
const {
all,
allowDeclareFields,
ignoreExtensions = false,
ignoreExtensions = process.env.BABEL_8_BREAKING ? false : true,
} = normalizeOptions(opts);

const flowPlugin = [transformFlowStripTypes, { all, allowDeclareFields }];

// 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: [flowPlugin] };
}

if (process.env.BABEL_8_BREAKING) {
return {
overrides: [
{
test: filename => filename == null || !/\.tsx?$/.test(filename),
plugins: [flowPlugin],
},
],
};
} else {
// unreachable
}
return {
overrides: [
{
test: filename => filename == null || !/\.tsx?$/.test(filename),
plugins: [flowPlugin],
},
],
};
});
@@ -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 0385034

Please sign in to comment.