Skip to content

Commit 6ee87ee

Browse files
authored
[babel 8] fallback targets to "defaults, not ie 11" (#12989)
1 parent 564ca66 commit 6ee87ee

1,098 files changed

Lines changed: 21448 additions & 1369 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/babel-core/test/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ describe("api", function () {
311311
},
312312

313313
// env preset
314-
presetEnv,
314+
[presetEnv, { targets: { browsers: "ie 6" } }],
315315

316316
// Third preset for Flow.
317317
() => ({

packages/babel-core/test/config-chain.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from "path";
44
import { fileURLToPath } from "url";
55
import escapeRegExp from "lodash/escapeRegExp";
66
import * as babel from "../lib";
7+
import getTargets from "@babel/helper-compilation-targets";
78

89
const dirname = path.dirname(fileURLToPath(import.meta.url));
910

@@ -976,6 +977,7 @@ describe("buildConfigChain", function () {
976977
});
977978

978979
describe("config files", () => {
980+
const defaultTargets = getTargets();
979981
const getDefaults = () => ({
980982
babelrc: false,
981983
configFile: false,
@@ -988,7 +990,7 @@ describe("buildConfigChain", function () {
988990
plugins: [],
989991
presets: [],
990992
cloneInputAst: true,
991-
targets: {},
993+
targets: defaultTargets,
992994
assumptions: {},
993995
});
994996
const realEnv = process.env.NODE_ENV;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"compact": false,
3-
"presets": ["env"],
3+
"presets": [["env", { "targets": { "browsers": "ie 6" } }]],
44
"plugins": ["proposal-object-rest-spread"]
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"plugins": ["transform-async-to-generator"],
3-
"presets": ["env"]
3+
"presets": [["env", { "targets": { "browsers": "ie 6" } }]]
44
}

packages/babel-helper-compilation-targets/src/index.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,23 @@ export default function getTargets(
191191
!options.ignoreBrowserslistConfig && !hasTargets;
192192

193193
if (!browsers && shouldSearchForConfig) {
194-
browsers =
195-
browserslist.loadConfig({
196-
config: options.configFile,
197-
path: options.configPath,
198-
env: options.browserslistEnv,
199-
}) ??
200-
// If no targets are passed, we need to overwrite browserslist's defaults
201-
// so that we enable all transforms (acting like the now deprecated
202-
// preset-latest).
203-
[];
194+
browsers = browserslist.loadConfig({
195+
config: options.configFile,
196+
path: options.configPath,
197+
env: options.browserslistEnv,
198+
});
199+
if (browsers == null) {
200+
if (process.env.BABEL_8_BREAKING) {
201+
// In Babel 8, if no targets are passed, we use browserslist's defaults
202+
// and exclude IE 11.
203+
browsers = ["defaults, not ie 11"];
204+
} else {
205+
// If no targets are passed, we need to overwrite browserslist's defaults
206+
// so that we enable all transforms (acting like the now deprecated
207+
// preset-latest).
208+
browsers = [];
209+
}
210+
}
204211
}
205212

206213
// `esmodules` as a target indicates the specific set of browsers supporting ES Modules.

packages/babel-helper-compilation-targets/test/targets-parser.spec.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,21 @@ describe("getTargets", () => {
282282
).toMatchSnapshot();
283283
});
284284

285-
it("'intersect' behaves like 'true' if no browsers are specified", () => {
286-
expect(getTargets({ esmodules: "intersect" })).toEqual(
287-
getTargets({ esmodules: true }, { ignoreBrowserslistConfig: true }),
288-
);
289-
});
285+
(process.env.BABEL_8_BREAKING ? it.skip : it)(
286+
"'intersect' behaves like 'true' if no browsers are specified - Babel 7",
287+
() => {
288+
expect(getTargets({ esmodules: "intersect" })).toEqual(
289+
getTargets({ esmodules: true }, { ignoreBrowserslistConfig: true }),
290+
);
291+
},
292+
);
293+
294+
(process.env.BABEL_8_BREAKING ? it : it.skip)(
295+
"'intersect' behaves like no-op if no browsers are specified",
296+
() => {
297+
expect(getTargets({ esmodules: "intersect" })).toEqual(getTargets({}));
298+
},
299+
);
290300

291301
it("'intersect' behaves like 'true' if no browsers are specified and the browserslist config is ignored", () => {
292302
expect(

packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/declaration-exec/options.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"transform-async-to-generator",
44
"proposal-async-generator-functions"
55
],
6-
"presets": ["env"],
6+
"presets": [["env", { "targets": { "browsers": "ie 6" } }]],
77
"parserOpts": {
88
"allowReturnOutsideFunction": true
99
}

packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/yield-exec/options.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"transform-async-to-generator",
44
"proposal-async-generator-functions"
55
],
6-
"presets": ["env"],
6+
"presets": [["env", { "targets": { "browsers": "ie 6" } }]],
77
"parserOpts": {
88
"allowReturnOutsideFunction": true
99
}

packages/babel-plugin-proposal-async-generator-functions/test/fixtures/for-await/async-generator-exec/options.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"transform-async-to-generator",
44
"proposal-async-generator-functions"
55
],
6-
"presets": ["env"],
6+
"presets": [["env", { "targets": { "browsers": "ie 6" } }]],
77
"parserOpts": {
88
"allowReturnOutsideFunction": true
99
}

packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/foobar/options.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"plugins": ["proposal-class-properties"],
3-
"presets": ["env"],
3+
"presets": [["env", { "targets": { "browsers": "ie 6" } }]],
44
"assumptions": {
55
"setPublicClassFields": true
66
}

0 commit comments

Comments
 (0)