Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Jun 3, 2022
1 parent 352273d commit 89f08e7
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 19 deletions.
26 changes: 21 additions & 5 deletions packages/babel-core/src/config/config-chain.ts
Expand Up @@ -451,7 +451,11 @@ function buildFileLogger(
function buildRootDescriptors(
{ dirname, options }: Partial<ValidatedFile>,
alias: string,
descriptors: Function,
descriptors: (
dirname: string,
options: ValidatedOptions,
alias: string,
) => OptionsAndDescriptors,
) {
return descriptors(dirname, options, alias);
}
Expand All @@ -465,15 +469,19 @@ function buildProgrammaticLogger(
return () => {};
}
return baseLogger.configure(context.showConfig, ChainFormatter.Programmatic, {
// @ts-expect-error caller maybe void
// @ts-expect-error caller may be void
callerName: context.caller?.name,
});
}

function buildEnvDescriptors(
{ dirname, options }: Partial<ValidatedFile>,
alias: string,
descriptors: Function,
descriptors: (
dirname: string,
options: ValidatedOptions,
alias: string,
) => OptionsAndDescriptors,
envName: string,
) {
const opts = options.env && options.env[envName];
Expand All @@ -483,7 +491,11 @@ function buildEnvDescriptors(
function buildOverrideDescriptors(
{ dirname, options }: Partial<ValidatedFile>,
alias: string,
descriptors: Function,
descriptors: (
dirname: string,
options: ValidatedOptions,
alias: string,
) => OptionsAndDescriptors,
index: number,
) {
const opts = options.overrides && options.overrides[index];
Expand All @@ -495,7 +507,11 @@ function buildOverrideDescriptors(
function buildOverrideEnvDescriptors(
{ dirname, options }: Partial<ValidatedFile>,
alias: string,
descriptors: Function,
descriptors: (
dirname: string,
options: ValidatedOptions,
alias: string,
) => OptionsAndDescriptors,
index: number,
envName: string,
) {
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-core/src/config/files/import-meta-resolve.ts
Expand Up @@ -34,7 +34,8 @@ const importMetaResolveP: Promise<ImportMeta["resolve"]> =
// it throws because it's a module, will fallback to import().
process.execArgv.includes("--experimental-import-meta-resolve")
? import_("data:text/javascript,export default import.meta.resolve").then(
(m: any) => m.default || polyfill,
(m: { default: ImportMeta["resolve"] | undefined }) =>
m.default || polyfill,
() => polyfill,
)
: Promise.resolve(polyfill);
Expand Down
4 changes: 3 additions & 1 deletion packages/babel-core/src/config/files/types.ts
@@ -1,7 +1,9 @@
import type { InputOptions } from "..";

export type ConfigFile = {
filepath: string;
dirname: string;
options: { [key: string]: any };
options: InputOptions;
};

export type IgnoreFile = {
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-core/src/config/full.ts
Expand Up @@ -392,8 +392,8 @@ const instantiatePlugin = makeWeakCache(function* (
return cache.invalidate(data => run(inheritsDescriptor, data));
});

plugin.pre = chain(inherits.pre as (...args: any[]) => void, plugin.pre);
plugin.post = chain(inherits.post as (...args: any[]) => void, plugin.post);
plugin.pre = chain(inherits.pre, plugin.pre);
plugin.post = chain(inherits.post, plugin.post);
plugin.manipulateOptions = chain(
inherits.manipulateOptions,
plugin.manipulateOptions,
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-core/src/config/plugin.ts
Expand Up @@ -5,9 +5,9 @@ import type { PluginObject } from "./validation/plugins";
export default class Plugin {
key: string | undefined | null;
manipulateOptions?: (options: unknown, parserOpts: unknown) => void;
post?: Function;
pre?: Function;
visitor: {};
post?: PluginObject["post"];
pre?: PluginObject["pre"];
visitor: PluginObject["visitor"];

parserOverride?: Function;
generatorOverride?: Function;
Expand Down
16 changes: 12 additions & 4 deletions packages/babel-core/src/tools/build-external-helpers.ts
Expand Up @@ -95,10 +95,7 @@ function buildModule(allowlist?: Array<string>) {
exportNamedDeclaration(
null,
Object.keys(refs).map(name => {
return exportSpecifier(
cloneNode(refs[name] as t.Identifier),
identifier(name),
);
return exportSpecifier(cloneNode(refs[name]), identifier(name));
}),
),
);
Expand Down Expand Up @@ -149,6 +146,17 @@ function buildVar(allowlist?: Array<string>) {
return tree;
}

function buildHelpers(
body: t.Statement[],
namespace: t.Expression,
allowlist?: Array<string>,
): Record<string, t.MemberExpression>;
function buildHelpers(
body: t.Statement[],
namespace: null,
allowlist?: Array<string>,
): Record<string, t.Identifier>;

function buildHelpers(
body: t.Statement[],
namespace: t.Expression | null,
Expand Down
10 changes: 7 additions & 3 deletions packages/babel-core/src/transform-file-browser.ts
@@ -1,13 +1,17 @@
// duplicated from transform-file so we do not have to import anything here
type TransformFile = {
(filename: string, callback: Function): void;
(filename: string, opts: any, callback: Function): void;
(filename: string, callback: (error: Error, file: null) => void): void;
(
filename: string,
opts: any,
callback: (error: Error, file: null) => void,
): void;
};

export const transformFile: TransformFile = function transformFile(
filename,
opts,
callback?: Function,
callback?: (error: Error, file: null) => void,
) {
if (typeof opts === "function") {
callback = opts;
Expand Down

0 comments on commit 89f08e7

Please sign in to comment.