Load .browserslistrc when using old @babel/core versions (#12934)

This commit is contained in:
Nicolò Ribaudo
2021-03-01 20:46:02 +01:00
committed by GitHub
parent efdca01409
commit c155caf1e8
5 changed files with 65 additions and 12 deletions

View File

@@ -90,6 +90,7 @@
},
"devDependencies": {
"@babel/core": "workspace:*",
"@babel/core-7.12": "npm:@babel/core@7.12.9",
"@babel/helper-plugin-test-runner": "workspace:*",
"@babel/plugin-syntax-dynamic-import": "^7.8.3"
}

View File

@@ -1,6 +1,6 @@
//@flow
import { SemVer } from "semver";
import { SemVer, lt } from "semver";
import { logPluginOrPolyfill } from "./debug";
import getOptionSpecificExcludesFor from "./get-option-specific-excludes";
import { removeUnnecessaryItems } from "./filter-items";
@@ -295,6 +295,10 @@ export default declare((api, opts) => {
let targets = babelTargets;
if (
// @babel/core < 7.13.0 doesn't load targets (api.targets() always
// returns {} thanks to @babel/helper-plugin-utils), so we always want
// to fallback to the old targets behavior in this case.
lt(api.version, "7.13.0") ||
// If any browserslist-related option is specified, fallback to the old
// behavior of not using the targets specified in the top-level options.
opts.targets ||

View File

@@ -0,0 +1,22 @@
import * as babel7_12 from "@babel/core";
import env from "..";
import path from "path";
describe("#12880", () => {
it("read the .browserslistrc file when using @babel/core < 7.13.0", () => {
// The browserslistrc file contains "firefox 50".
// a ** b is supported starting from firefox 52;
// a => b is supported starting from firefox 45.
const out = babel7_12.transformSync("a ** b; a => b;", {
configFile: false,
presets: [[env, { modules: false }]],
filename: path.join(__dirname, "regressions", "input.js"),
});
expect(out.code).toMatchInlineSnapshot(`
"Math.pow(a, b);
a => b;"
`);
});
});

View File

@@ -0,0 +1 @@
firefox 50