Use ?. where it represents the intended semantics (#11512)

This commit is contained in:
Nicolò Ribaudo
2020-05-09 23:31:50 +02:00
committed by GitHub
parent aeb51f463c
commit 31b361b736
47 changed files with 99 additions and 118 deletions

View File

@@ -71,8 +71,9 @@ export function* findRelativeConfig(
loc,
envName,
caller,
packageData.pkg && packageData.pkg.dirname === loc
? packageToBabelConfig(packageData.pkg)
packageData.pkg?.dirname === loc
? // $FlowIgnore - packageData.pkg is not null
packageToBabelConfig((packageData.pkg: ConfigFile))
: null,
);
}

View File

@@ -17,7 +17,8 @@ export type { PartialConfig } from "./partial";
const loadOptionsRunner = gensync<[mixed], Object | null>(function*(opts) {
const config = yield* loadFullConfig(opts);
return config ? config.options : null;
// NOTE: We want to return "null" explicitly, while ?. alone returns undefined
return config?.options ?? null;
});
const maybeErrback = runner => (opts: mixed, callback: Function) => {

View File

@@ -25,15 +25,7 @@ type TransformFile = {
const transformFileRunner = gensync<[string, ?InputOptions], FileResult | null>(
function*(filename, opts) {
let options;
if (opts == null) {
options = { filename };
} else if (opts && typeof opts === "object") {
options = {
...opts,
filename,
};
}
const options = { ...opts, filename };
const config: ResolvedConfig | null = yield* loadConfig(options);
if (config === null) return null;

View File

@@ -44,7 +44,7 @@ const blockHoistPlugin = {
let hasChange = false;
for (let i = 0; i < node.body.length; i++) {
const bodyNode = node.body[i];
if (bodyNode && bodyNode._blockHoist != null) {
if (bodyNode?._blockHoist != null) {
hasChange = true;
break;
}
@@ -52,7 +52,7 @@ const blockHoistPlugin = {
if (!hasChange) return;
node.body = sortBy(node.body, function(bodyNode) {
let priority = bodyNode && bodyNode._blockHoist;
let priority = bodyNode?._blockHoist;
if (priority == null) priority = 1;
if (priority === true) priority = 2;