Load .browserslistrc when using old @babel/core versions (#12934)
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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 ||
|
||||
|
||||
22
packages/babel-preset-env/test/regressions.js
Normal file
22
packages/babel-preset-env/test/regressions.js
Normal 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;"
|
||||
`);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
firefox 50
|
||||
Reference in New Issue
Block a user