Update Flow to 0.123.0 (#11500)
This commit is contained in:
parent
96ccf56436
commit
90a9103e55
@ -43,7 +43,7 @@
|
|||||||
"eslint-plugin-jest": "^23.8.2",
|
"eslint-plugin-jest": "^23.8.2",
|
||||||
"eslint-plugin-prettier": "^3.1.2",
|
"eslint-plugin-prettier": "^3.1.2",
|
||||||
"fancy-log": "^1.3.3",
|
"fancy-log": "^1.3.3",
|
||||||
"flow-bin": "^0.108.0",
|
"flow-bin": "^0.123.0",
|
||||||
"gulp": "^4.0.2",
|
"gulp": "^4.0.2",
|
||||||
"gulp-babel": "^8.0.0",
|
"gulp-babel": "^8.0.0",
|
||||||
"gulp-filter": "^5.1.0",
|
"gulp-filter": "^5.1.0",
|
||||||
|
|||||||
@ -268,7 +268,6 @@ export function createDescriptor(
|
|||||||
let value = pair;
|
let value = pair;
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
if (value.length === 3) {
|
if (value.length === 3) {
|
||||||
// $FlowIgnore - Flow doesn't like the multiple tuple types.
|
|
||||||
[value, options, name] = value;
|
[value, options, name] = value;
|
||||||
} else {
|
} else {
|
||||||
[value, options] = value;
|
[value, options] = value;
|
||||||
|
|||||||
@ -17,13 +17,14 @@ type EnvFunction = {
|
|||||||
(Array<string>): boolean,
|
(Array<string>): boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PluginAPI = {
|
export type PluginAPI = {|
|
||||||
version: string,
|
version: string,
|
||||||
cache: SimpleCacheConfigurator,
|
cache: SimpleCacheConfigurator,
|
||||||
env: EnvFunction,
|
env: EnvFunction,
|
||||||
async: () => boolean,
|
async: () => boolean,
|
||||||
assertVersion: typeof assertVersion,
|
assertVersion: typeof assertVersion,
|
||||||
};
|
caller?: any,
|
||||||
|
|};
|
||||||
|
|
||||||
export default function makeAPI(
|
export default function makeAPI(
|
||||||
cache: CacheConfigurator<{ envName: string, caller: CallerMetadata | void }>,
|
cache: CacheConfigurator<{ envName: string, caller: CallerMetadata | void }>,
|
||||||
@ -55,7 +56,6 @@ export default function makeAPI(
|
|||||||
async: () => false,
|
async: () => false,
|
||||||
caller,
|
caller,
|
||||||
assertVersion,
|
assertVersion,
|
||||||
tokTypes: undefined,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,9 +13,9 @@ import {
|
|||||||
} from "./utils";
|
} from "./utils";
|
||||||
import { browserNameMap } from "./targets";
|
import { browserNameMap } from "./targets";
|
||||||
import { TargetNames } from "./options";
|
import { TargetNames } from "./options";
|
||||||
import type { Targets } from "./types";
|
import type { Target, Targets, InputTargets, Browsers } from "./types";
|
||||||
|
|
||||||
export type { Targets };
|
export type { Targets, InputTargets };
|
||||||
|
|
||||||
export { prettifyTargets } from "./pretty";
|
export { prettifyTargets } from "./pretty";
|
||||||
export { getInclusionReasons } from "./debug";
|
export { getInclusionReasons } from "./debug";
|
||||||
@ -39,7 +39,7 @@ function objectToBrowserslist(object: Targets): Array<string> {
|
|||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateTargetNames(targets: Targets): void {
|
function validateTargetNames(targets: InputTargets): Targets {
|
||||||
const validTargets = Object.keys(TargetNames);
|
const validTargets = Object.keys(TargetNames);
|
||||||
for (const target in targets) {
|
for (const target in targets) {
|
||||||
if (!TargetNames[target]) {
|
if (!TargetNames[target]) {
|
||||||
@ -49,32 +49,24 @@ function validateTargetNames(targets: Targets): void {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// $FlowIgnore
|
||||||
|
return targets;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isBrowsersQueryValid(
|
export function isBrowsersQueryValid(browsers: Browsers | Targets): boolean {
|
||||||
browsers: string | Array<string> | Targets,
|
|
||||||
): boolean {
|
|
||||||
return typeof browsers === "string" || Array.isArray(browsers);
|
return typeof browsers === "string" || Array.isArray(browsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateBrowsers(browsers) {
|
function validateBrowsers(browsers: Browsers | void) {
|
||||||
invariant(
|
invariant(
|
||||||
typeof browsers === "undefined" || isBrowsersQueryValid(browsers),
|
typeof browsers === "undefined" || isBrowsersQueryValid(browsers),
|
||||||
`Invalid Option: '${browsers}' is not a valid browserslist query`,
|
`Invalid Option: '${String(browsers)}' is not a valid browserslist query`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return browsers;
|
return browsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeBrowsers(fromQuery: Targets, fromTarget: Targets) {
|
|
||||||
return Object.keys(fromTarget).reduce((queryObj, targKey) => {
|
|
||||||
if (targKey !== TargetNames.browsers) {
|
|
||||||
queryObj[targKey] = fromTarget[targKey];
|
|
||||||
}
|
|
||||||
return queryObj;
|
|
||||||
}, fromQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getLowestVersions(browsers: Array<string>): Targets {
|
function getLowestVersions(browsers: Array<string>): Targets {
|
||||||
return browsers.reduce((all: Object, browser: string): Object => {
|
return browsers.reduce((all: Object, browser: string): Object => {
|
||||||
const [browserName, browserVersion] = browser.split(" ");
|
const [browserName, browserVersion] = browser.split(" ");
|
||||||
@ -170,30 +162,31 @@ type ParsedResult = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function getTargets(
|
export default function getTargets(
|
||||||
targets: Object = {},
|
inputTargets: InputTargets = {},
|
||||||
options: Object = {},
|
options: Object = {},
|
||||||
): Targets {
|
): Targets {
|
||||||
const targetOpts: Targets = {};
|
const targetOpts: Targets = {};
|
||||||
|
|
||||||
validateTargetNames(targets);
|
|
||||||
|
|
||||||
// `esmodules` as a target indicates the specific set of browsers supporting ES Modules.
|
// `esmodules` as a target indicates the specific set of browsers supporting ES Modules.
|
||||||
// These values OVERRIDE the `browsers` field.
|
// These values OVERRIDE the `browsers` field.
|
||||||
if (targets.esmodules) {
|
if (inputTargets.esmodules) {
|
||||||
const supportsESModules = browserModulesData["es6.module"];
|
const supportsESModules = browserModulesData["es6.module"];
|
||||||
targets.browsers = Object.keys(supportsESModules)
|
inputTargets.browsers = Object.keys(supportsESModules)
|
||||||
.map(browser => `${browser} ${supportsESModules[browser]}`)
|
.map(browser => `${browser} ${supportsESModules[browser]}`)
|
||||||
.join(", ");
|
.join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove esmodules after being consumed to fix `hasTargets` below
|
// Remove esmodules after being consumed to fix `hasTargets` below
|
||||||
delete targets.esmodules;
|
delete inputTargets.esmodules;
|
||||||
|
|
||||||
// Parse browsers target via browserslist
|
// Parse browsers target via browserslist
|
||||||
const browsersquery = validateBrowsers(targets.browsers);
|
const browsersquery = validateBrowsers(inputTargets.browsers);
|
||||||
|
delete inputTargets.browsers;
|
||||||
|
|
||||||
const hasTargets = Object.keys(targets).length > 0;
|
let targets: Targets = validateTargetNames(inputTargets);
|
||||||
const shouldParseBrowsers = !!targets.browsers;
|
|
||||||
|
const shouldParseBrowsers = !!browsersquery;
|
||||||
|
const hasTargets = shouldParseBrowsers || Object.keys(targets).length > 0;
|
||||||
const shouldSearchForConfig =
|
const shouldSearchForConfig =
|
||||||
!options.ignoreBrowserslistConfig && !hasTargets;
|
!options.ignoreBrowserslistConfig && !hasTargets;
|
||||||
|
|
||||||
@ -215,43 +208,39 @@ export default function getTargets(
|
|||||||
});
|
});
|
||||||
|
|
||||||
const queryBrowsers = getLowestVersions(browsers);
|
const queryBrowsers = getLowestVersions(browsers);
|
||||||
targets = mergeBrowsers(queryBrowsers, targets);
|
targets = Object.assign(queryBrowsers, targets);
|
||||||
|
|
||||||
// Reset browserslist defaults
|
// Reset browserslist defaults
|
||||||
browserslist.defaults = browserslistDefaults;
|
browserslist.defaults = browserslistDefaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse remaining targets
|
// Parse remaining targets
|
||||||
const parsed = Object.keys(targets)
|
const parsed = (Object.keys(targets): Array<Target>).sort().reduce(
|
||||||
.filter(value => value !== TargetNames.esmodules)
|
(results: ParsedResult, target: $Keys<Targets>): ParsedResult => {
|
||||||
.sort()
|
const value = targets[target];
|
||||||
.reduce(
|
|
||||||
(results: ParsedResult, target: string): ParsedResult => {
|
|
||||||
if (target !== TargetNames.browsers) {
|
|
||||||
const value = targets[target];
|
|
||||||
|
|
||||||
// Warn when specifying minor/patch as a decimal
|
// Warn when specifying minor/patch as a decimal
|
||||||
if (typeof value === "number" && value % 1 !== 0) {
|
if (typeof value === "number" && value % 1 !== 0) {
|
||||||
results.decimalWarnings.push({ target, value });
|
results.decimalWarnings.push({ target, value });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we have a target parser?
|
// Check if we have a target parser?
|
||||||
const parser = targetParserMap[target] || targetParserMap.__default;
|
// $FlowIgnore - Flow doesn't like that some targetParserMap[target] might be missing
|
||||||
const [parsedTarget, parsedValue] = parser(target, value);
|
const parser = targetParserMap[target] ?? targetParserMap.__default;
|
||||||
|
const [parsedTarget, parsedValue] = parser(target, value);
|
||||||
|
|
||||||
if (parsedValue) {
|
if (parsedValue) {
|
||||||
// Merge (lowest wins)
|
// Merge (lowest wins)
|
||||||
results.targets[parsedTarget] = parsedValue;
|
results.targets[parsedTarget] = parsedValue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
targets: targetOpts,
|
targets: targetOpts,
|
||||||
decimalWarnings: [],
|
decimalWarnings: [],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
outputDecimalWarning(parsed.decimalWarnings);
|
outputDecimalWarning(parsed.decimalWarnings);
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
export const TargetNames = {
|
export const TargetNames = {
|
||||||
esmodules: "esmodules",
|
|
||||||
node: "node",
|
node: "node",
|
||||||
browsers: "browsers",
|
|
||||||
chrome: "chrome",
|
chrome: "chrome",
|
||||||
opera: "opera",
|
opera: "opera",
|
||||||
edge: "edge",
|
edge: "edge",
|
||||||
@ -14,7 +12,4 @@ export const TargetNames = {
|
|||||||
android: "android",
|
android: "android",
|
||||||
electron: "electron",
|
electron: "electron",
|
||||||
samsung: "samsung",
|
samsung: "samsung",
|
||||||
|
|
||||||
// deprecated
|
|
||||||
uglify: "uglify",
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -17,3 +17,12 @@ export type Target =
|
|||||||
export type Targets = {
|
export type Targets = {
|
||||||
[target: Target]: string,
|
[target: Target]: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Browsers = string | Array<string>;
|
||||||
|
|
||||||
|
export type InputTargets = {
|
||||||
|
...Targets,
|
||||||
|
|
||||||
|
browsers?: Browsers,
|
||||||
|
esmodules?: boolean,
|
||||||
|
};
|
||||||
|
|||||||
@ -208,6 +208,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
this.directiveToStmt(d),
|
this.directiveToStmt(d),
|
||||||
);
|
);
|
||||||
node.body = directiveStatements.concat(node.body);
|
node.body = directiveStatements.concat(node.body);
|
||||||
|
// $FlowIgnore - directives isn't optional in the type definition
|
||||||
delete node.directives;
|
delete node.directives;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,7 +390,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
if (node.callee.type === "Import") {
|
if (node.callee.type === "Import") {
|
||||||
((node: N.Node): N.EstreeImportExpression).type = "ImportExpression";
|
((node: N.Node): N.EstreeImportExpression).type = "ImportExpression";
|
||||||
((node: N.Node): N.EstreeImportExpression).source = node.arguments[0];
|
((node: N.Node): N.EstreeImportExpression).source = node.arguments[0];
|
||||||
|
// $FlowIgnore - arguments isn't optional in the type definition
|
||||||
delete node.arguments;
|
delete node.arguments;
|
||||||
|
// $FlowIgnore - callee isn't optional in the type definition
|
||||||
delete node.callee;
|
delete node.callee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
|
/*:: declare var invariant; */
|
||||||
|
|
||||||
import type { Options } from "../options";
|
import type { Options } from "../options";
|
||||||
import * as N from "../types";
|
import * as N from "../types";
|
||||||
import type { Position } from "../util/location";
|
import type { Position } from "../util/location";
|
||||||
@ -1360,10 +1362,14 @@ export default class Tokenizer extends LocationParser {
|
|||||||
default:
|
default:
|
||||||
if (ch >= charCodes.digit0 && ch <= charCodes.digit7) {
|
if (ch >= charCodes.digit0 && ch <= charCodes.digit7) {
|
||||||
const codePos = this.state.pos - 1;
|
const codePos = this.state.pos - 1;
|
||||||
// $FlowFixMe
|
const match = this.input
|
||||||
let octalStr = this.input
|
|
||||||
.substr(this.state.pos - 1, 3)
|
.substr(this.state.pos - 1, 3)
|
||||||
.match(/^[0-7]+/)[0];
|
.match(/^[0-7]+/);
|
||||||
|
|
||||||
|
// This is never null, because of the if condition above.
|
||||||
|
/*:: invariant(match !== null) */
|
||||||
|
let octalStr = match[0];
|
||||||
|
|
||||||
let octal = parseInt(octalStr, 8);
|
let octal = parseInt(octalStr, 8);
|
||||||
if (octal > 255) {
|
if (octal > 255) {
|
||||||
octalStr = octalStr.slice(0, -1);
|
octalStr = octalStr.slice(0, -1);
|
||||||
|
|||||||
@ -5,7 +5,6 @@ export function removeUnnecessaryItems(
|
|||||||
overlapping: { [name: string]: string[] },
|
overlapping: { [name: string]: string[] },
|
||||||
) {
|
) {
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
// $FlowIgnore Flow doesn't support calls in optional chains
|
|
||||||
overlapping[item]?.forEach(name => items.delete(name));
|
overlapping[item]?.forEach(name => items.delete(name));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import getTargets, {
|
|||||||
filterItems,
|
filterItems,
|
||||||
isRequired,
|
isRequired,
|
||||||
type Targets,
|
type Targets,
|
||||||
|
type InputTargets,
|
||||||
} from "@babel/helper-compilation-targets";
|
} from "@babel/helper-compilation-targets";
|
||||||
import availablePlugins from "./available-plugins";
|
import availablePlugins from "./available-plugins";
|
||||||
import { filterStageFromList } from "./utils";
|
import { filterStageFromList } from "./utils";
|
||||||
@ -247,15 +248,17 @@ export default declare((api, opts) => {
|
|||||||
"@babel/preset-env: esmodules and browsers targets have been specified together.",
|
"@babel/preset-env: esmodules and browsers targets have been specified together.",
|
||||||
);
|
);
|
||||||
console.log(
|
console.log(
|
||||||
|
// $FlowIgnore
|
||||||
`\`browsers\` target, \`${optionsTargets.browsers}\` will be ignored.`,
|
`\`browsers\` target, \`${optionsTargets.browsers}\` will be ignored.`,
|
||||||
);
|
);
|
||||||
console.log("");
|
console.log("");
|
||||||
}
|
}
|
||||||
|
|
||||||
const targets = getTargets(optionsTargets, {
|
const targets = getTargets(
|
||||||
ignoreBrowserslistConfig,
|
// $FlowIgnore optionsTargets doesn't have an "uglify" property anymore
|
||||||
configPath,
|
(optionsTargets: InputTargets),
|
||||||
});
|
{ ignoreBrowserslistConfig, configPath },
|
||||||
|
);
|
||||||
const include = transformIncludesAndExcludes(optionsInclude);
|
const include = transformIncludesAndExcludes(optionsInclude);
|
||||||
const exclude = transformIncludesAndExcludes(optionsExclude);
|
const exclude = transformIncludesAndExcludes(optionsExclude);
|
||||||
|
|
||||||
|
|||||||
@ -123,9 +123,7 @@ const normalizeTargets = targets => {
|
|||||||
if (typeof targets === "string" || Array.isArray(targets)) {
|
if (typeof targets === "string" || Array.isArray(targets)) {
|
||||||
return { browsers: targets };
|
return { browsers: targets };
|
||||||
}
|
}
|
||||||
return {
|
return { ...targets };
|
||||||
...targets,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const validateConfigPathOption = (
|
export const validateConfigPathOption = (
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { ModulesOption, UseBuiltInsOption } from "./options";
|
import { ModulesOption, UseBuiltInsOption } from "./options";
|
||||||
import type { NormalizedCorejsOption } from "./normalize-options";
|
import type { NormalizedCorejsOption } from "./normalize-options";
|
||||||
import type { Targets } from "@babel/helper-compilation-targets";
|
import type { Targets, InputTargets } from "@babel/helper-compilation-targets";
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
// Use explicit modules to prevent typo errors.
|
// Use explicit modules to prevent typo errors.
|
||||||
@ -32,7 +32,7 @@ export type Options = {
|
|||||||
modules: ModuleOption,
|
modules: ModuleOption,
|
||||||
shippedProposals: boolean,
|
shippedProposals: boolean,
|
||||||
spec: boolean,
|
spec: boolean,
|
||||||
targets: Targets,
|
targets: { ...InputTargets, uglify?: boolean },
|
||||||
useBuiltIns: BuiltInsOption,
|
useBuiltIns: BuiltInsOption,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,7 @@ export default function removeProperties(
|
|||||||
if (key[0] === "_" && node[key] != null) node[key] = undefined;
|
if (key[0] === "_" && node[key] != null) node[key] = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const symbols: Array<Symbol> = Object.getOwnPropertySymbols(node);
|
const symbols: Array<symbol> = Object.getOwnPropertySymbols(node);
|
||||||
for (const sym of symbols) {
|
for (const sym of symbols) {
|
||||||
node[sym] = null;
|
node[sym] = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4784,10 +4784,10 @@ flatted@^2.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.1.tgz#69e57caa8f0eacbc281d2e2cb458d46fdb449e08"
|
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.1.tgz#69e57caa8f0eacbc281d2e2cb458d46fdb449e08"
|
||||||
integrity sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==
|
integrity sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==
|
||||||
|
|
||||||
flow-bin@^0.108.0:
|
flow-bin@^0.123.0:
|
||||||
version "0.108.0"
|
version "0.123.0"
|
||||||
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.108.0.tgz#6a42c85fd664d23dd937d925851e8e6ab5d71393"
|
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.123.0.tgz#7ba61a0b8775928cf4943ccf78eed2b1b05f7b3a"
|
||||||
integrity sha512-hPEyCP1J8rdhNDfCAA5w7bN6HUNBDcHVg/ABU5JVo0gUFMx+uRewpyEH8LlLBGjVQuIpbaPpaqpoaQhAVyaYww==
|
integrity sha512-Ylcf8YDIM/KrqtxkPuq+f8O+6sdYA2Nuz5f+sWHlp539DatZz3YMcsO1EiXaf1C11HJgpT/3YGYe7xZ9/UZmvQ==
|
||||||
|
|
||||||
flush-write-stream@^1.0.0, flush-write-stream@^1.0.2:
|
flush-write-stream@^1.0.0, flush-write-stream@^1.0.2:
|
||||||
version "1.1.1"
|
version "1.1.1"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user