Skip to content
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

[babel 7] Allow setting ignoreExtensions in Flow preset #16309

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 }]]
}