-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
targets
and browserslist* options to @babel/core
- Loading branch information
1 parent
8aa8df4
commit 3e16400
Showing
15 changed files
with
370 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// @flow | ||
|
||
import type { ValidatedOptions } from "./validation/options"; | ||
import getTargets, { type Targets } from "@babel/helper-compilation-targets"; | ||
|
||
export function resolveTargets( | ||
options: ValidatedOptions, | ||
// eslint-disable-next-line no-unused-vars | ||
root: string, | ||
// eslint-disable-next-line no-unused-vars | ||
filename: string | void, | ||
): Targets { | ||
let { targets } = options; | ||
if (typeof targets === "string" || Array.isArray(targets)) { | ||
targets = { browsers: targets }; | ||
} | ||
// $FlowIgnore it thinks that targets.esmodules doesn't exist. | ||
if (targets && targets.esmodules) { | ||
targets = { ...targets, esmodules: "intersect" }; | ||
} | ||
|
||
return getTargets((targets: any), { | ||
ignoreBrowserslistConfig: true, | ||
browserslistEnv: options.browserslistEnv, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// @flow | ||
|
||
import typeof * as browserType from "./resolve-targets-browser"; | ||
import typeof * as nodeType from "./resolve-targets"; | ||
|
||
// Kind of gross, but essentially asserting that the exports of this module are the same as the | ||
// exports of index-browser, since this file may be replaced at bundle time with index-browser. | ||
((({}: any): $Exact<browserType>): $Exact<nodeType>); | ||
|
||
import type { ValidatedOptions } from "./validation/options"; | ||
import path from "path"; | ||
import getTargets, { type Targets } from "@babel/helper-compilation-targets"; | ||
|
||
export function resolveTargets( | ||
options: ValidatedOptions, | ||
root: string, | ||
filename: string | void, | ||
): Targets { | ||
let { targets } = options; | ||
if (typeof targets === "string" || Array.isArray(targets)) { | ||
targets = { browsers: targets }; | ||
} | ||
// $FlowIgnore it thinks that targets.esmodules doesn't exist. | ||
if (targets && targets.esmodules) { | ||
targets = { ...targets, esmodules: "intersect" }; | ||
} | ||
|
||
let configFile; | ||
if (typeof options.browserslistConfigFile === "string") { | ||
configFile = path.resolve(root, options.browserslistConfigFile); | ||
} | ||
|
||
return getTargets((targets: any), { | ||
ignoreBrowserslistConfig: options.browserslistConfigFile === false, | ||
configFile, | ||
configPath: filename ?? root, | ||
browserslistEnv: options.browserslistEnv, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
chrome 80 | ||
|
||
[browserslist-loading-test] | ||
chrome 70 |
1 change: 1 addition & 0 deletions
1
packages/babel-core/test/fixtures/targets/.browserslistrc-firefox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
firefox 74 |
1 change: 1 addition & 0 deletions
1
packages/babel-core/test/fixtures/targets/nested/.browserslistrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
edge 14 |
Oops, something went wrong.