Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed May 31, 2022
1 parent ca3a09d commit e8ec5bf
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
5 changes: 3 additions & 2 deletions packages/babel-core/src/config/caching.ts
Expand Up @@ -359,8 +359,9 @@ function makeSimpleConfigurator(
}
cacheFn.forever = () => cache.forever();
cacheFn.never = () => cache.never();
cacheFn.using = (cb: Function) => cache.using(() => assertSimpleType(cb()));
cacheFn.invalidate = (cb: Function) =>
cacheFn.using = (cb: { (): SimpleType }) =>
cache.using(() => assertSimpleType(cb()));
cacheFn.invalidate = (cb: { (): SimpleType }) =>
cache.invalidate(() => assertSimpleType(cb()));

return cacheFn as any;
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/config-chain.ts
Expand Up @@ -465,7 +465,7 @@ function buildProgrammaticLogger(
return () => {};
}
return baseLogger.configure(context.showConfig, ChainFormatter.Programmatic, {
// @ts-expect-error
// @ts-expect-error caller maybe void
callerName: context.caller?.name,
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/files/index-browser.ts
Expand Up @@ -72,7 +72,7 @@ export function* resolveShowConfigPath(
return null;
}

export const ROOT_CONFIG_FILENAMES: any[] = [];
export const ROOT_CONFIG_FILENAMES: string[] = [];

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function resolvePlugin(name: string, dirname: string): string | null {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/files/module-types.ts
Expand Up @@ -6,7 +6,7 @@ import { createRequire } from "module";

const require = createRequire(import.meta.url);

let import_: any;
let import_: ((specifier: string | URL) => any) | undefined;
try {
// Node < 13.3 doesn't support import() syntax.
import_ = require("./import").default;
Expand Down
11 changes: 7 additions & 4 deletions packages/babel-core/src/config/full.ts
Expand Up @@ -223,7 +223,7 @@ export default gensync<(inputOpts: unknown) => ResolvedConfig | null>(
},
);

function enhanceError<T extends Function>(context: any, fn: T): T {
function enhanceError<T extends Function>(context: ConfigContext, fn: T): T {
return function* (arg1: unknown, arg2: unknown) {
try {
return yield* fn(arg1, arg2);
Expand Down Expand Up @@ -392,8 +392,8 @@ const instantiatePlugin = makeWeakCache(function* (
return cache.invalidate(data => run(inheritsDescriptor, data));
});

plugin.pre = chain(inherits.pre, plugin.pre);
plugin.post = chain(inherits.post, plugin.post);
plugin.pre = chain(inherits.pre as (...args: any[]) => void, plugin.pre);
plugin.post = chain(inherits.post as (...args: any[]) => void, plugin.post);
plugin.manipulateOptions = chain(
inherits.manipulateOptions,
plugin.manipulateOptions,
Expand Down Expand Up @@ -490,7 +490,10 @@ const instantiatePreset = makeWeakCacheSync(
},
);

function chain(a: any, b: any) {
function chain<Args extends any[]>(
a: undefined | ((...args: Args) => void),
b: undefined | ((...args: Args) => void),
) {
const fns = [a, b].filter(Boolean);
if (fns.length <= 1) return fns[0];

Expand Down
5 changes: 3 additions & 2 deletions packages/babel-core/src/config/helpers/config-api.ts
Expand Up @@ -63,8 +63,9 @@ export function makeConfigAPI<SideChannel extends Context.SimpleConfig>(
});
});

const caller = (cb: Function) =>
cache.using(data => assertSimpleType(cb(data.caller)));
const caller = (cb: {
(CallerMetadata: void | CallerMetadata): SimpleType;
}) => cache.using(data => assertSimpleType(cb(data.caller)));

return {
version: coreVersion,
Expand Down

0 comments on commit e8ec5bf

Please sign in to comment.