Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable noImplicitAny #14601

Merged
merged 22 commits into from Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,6 +1,7 @@
import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
import type { PluginAPI, PluginObject } from "@babel/core";

export default function ({ types: t }) {
export default function ({ types: t }: PluginAPI): PluginObject {
return {
inherits: syntaxObjectRestSpread.default,

Expand All @@ -21,10 +22,15 @@ export default function ({ types: t }) {
const arg = args[i];
const { node } = arg;

if (arg.isObjectExpression()) {
if (t.isObjectExpression(node)) {
properties.push(...node.properties);
} else {
properties.push(t.spreadElement(node));
properties.push(
t.spreadElement(
// @ts-expect-error fixme
node,
),
);
}
}

Expand Down
@@ -1,6 +1,7 @@
import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding";
import type { PluginAPI, PluginObject } from "@babel/core";

export default function ({ types: t }) {
export default function ({ types: t }: PluginAPI): PluginObject {
return {
inherits: syntaxOptionalCatchBinding.default,

Expand Down
17 changes: 17 additions & 0 deletions lib/regexpu-core.d.ts
@@ -0,0 +1,17 @@
declare module "regexpu-core" {
type RegexpuOptions = {
unicodeFlag?: "transform" | false;
unicodeSetsFlag?: "transform" | "parse" | false;
dotAllFlag?: "transform" | false;
unicodePropertyEscapes?: "transform" | false;
namedGroups?: "transform" | false;
onNamedGroup?: (name: string, index: number) => void;
};
function rewritePattern(
pattern: string,
flags: string,
options: RegexpuOptions
): string;
export = rewritePattern;
export { RegexpuOptions };
}
12 changes: 8 additions & 4 deletions packages/babel-code-frame/src/index.ts
@@ -1,5 +1,7 @@
import highlight, { shouldHighlight, getChalk } from "@babel/highlight";

type Chalk = ReturnType<typeof getChalk>;

let deprecationWarningShown = false;

type Location = {
Expand Down Expand Up @@ -37,7 +39,7 @@ export interface Options {
/**
* Chalk styles for code frame token types.
*/
function getDefs(chalk) {
function getDefs(chalk: Chalk) {
return {
gutter: chalk.grey,
marker: chalk.red.bold,
Expand All @@ -55,14 +57,16 @@ const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
* Extract what lines should be marked and highlighted.
*/

type MarkerLines = Record<number, true | [number, number]>;

function getMarkerLines(
loc: NodeLocation,
source: Array<string>,
opts: Options,
): {
start: number;
end: number;
markerLines: any;
markerLines: MarkerLines;
} {
const startLoc: Location = {
column: 0,
Expand Down Expand Up @@ -91,7 +95,7 @@ function getMarkerLines(
}

const lineDiff = endLine - startLine;
const markerLines = {};
const markerLines: MarkerLines = {};

if (lineDiff) {
for (let i = 0; i <= lineDiff; i++) {
Expand Down Expand Up @@ -135,7 +139,7 @@ export function codeFrameColumns(
(opts.highlightCode || opts.forceColor) && shouldHighlight(opts);
const chalk = getChalk(opts);
const defs = getDefs(chalk);
const maybeHighlight = (chalkFn, string) => {
const maybeHighlight = (chalkFn: Chalk, string: string) => {
return highlighted ? chalkFn(string) : string;
};
const lines = rawLines.split(NEWLINE);
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/cache-contexts.ts
Expand Up @@ -16,7 +16,7 @@ export type FullPlugin = {
// process 'ignore'/'only' and other filename-based logic.
export type SimpleConfig = {
envName: string;
caller: CallerMetadata | void;
caller: CallerMetadata | undefined;
};
export type SimplePreset = {
targets: Targets;
Expand Down
8 changes: 5 additions & 3 deletions packages/babel-core/src/config/caching.ts
Expand Up @@ -348,7 +348,7 @@ class CacheConfigurator<SideChannel = void> {
function makeSimpleConfigurator(
cache: CacheConfigurator<any>,
): SimpleCacheConfigurator {
function cacheFn(val) {
function cacheFn(val: any) {
if (typeof val === "boolean") {
if (val) cache.forever();
else cache.never();
Expand All @@ -359,8 +359,10 @@ function makeSimpleConfigurator(
}
cacheFn.forever = () => cache.forever();
cacheFn.never = () => cache.never();
cacheFn.using = cb => cache.using(() => assertSimpleType(cb()));
cacheFn.invalidate = cb => cache.invalidate(() => assertSimpleType(cb()));
cacheFn.using = (cb: { (): SimpleType }) =>
cache.using(() => assertSimpleType(cb()));
cacheFn.invalidate = (cb: { (): SimpleType }) =>
cache.invalidate(() => assertSimpleType(cb()));

return cacheFn as any;
}
Expand Down
69 changes: 49 additions & 20 deletions packages/babel-core/src/config/config-chain.ts
Expand Up @@ -55,7 +55,7 @@ export type ConfigContext = {
cwd: string;
root: string;
envName: string;
caller: CallerMetadata | void;
caller: CallerMetadata | undefined;
showConfig: boolean;
};

Expand Down Expand Up @@ -383,7 +383,12 @@ const loadFileChainWalker = makeChainWalker<ValidatedFile>({
buildFileLogger(file.filepath, context, baseLogger),
});

function* loadFileChain(input, context, files, baseLogger) {
function* loadFileChain(
input: ValidatedFile,
context: ConfigContext,
files: Set<ConfigFile>,
baseLogger: ConfigPrinter,
) {
const chain = yield* loadFileChainWalker(input, context, files, baseLogger);
if (chain) {
chain.files.add(input.filepath);
Expand Down Expand Up @@ -443,11 +448,23 @@ function buildFileLogger(
});
}

function buildRootDescriptors({ dirname, options }, alias, descriptors) {
function buildRootDescriptors(
{ dirname, options }: Partial<ValidatedFile>,
alias: string,
descriptors: (
dirname: string,
options: ValidatedOptions,
alias: string,
) => OptionsAndDescriptors,
) {
return descriptors(dirname, options, alias);
}

function buildProgrammaticLogger(_, context, baseLogger: ConfigPrinter | void) {
function buildProgrammaticLogger(
_: unknown,
context: ConfigContext,
baseLogger: ConfigPrinter | void,
) {
if (!baseLogger) {
return () => {};
}
Expand All @@ -457,20 +474,28 @@ function buildProgrammaticLogger(_, context, baseLogger: ConfigPrinter | void) {
}

function buildEnvDescriptors(
{ dirname, options },
alias,
descriptors,
envName,
{ dirname, options }: Partial<ValidatedFile>,
alias: string,
descriptors: (
dirname: string,
options: ValidatedOptions,
alias: string,
) => OptionsAndDescriptors,
envName: string,
) {
const opts = options.env && options.env[envName];
return opts ? descriptors(dirname, opts, `${alias}.env["${envName}"]`) : null;
}

function buildOverrideDescriptors(
{ dirname, options },
alias,
descriptors,
index,
{ dirname, options }: Partial<ValidatedFile>,
alias: string,
descriptors: (
dirname: string,
options: ValidatedOptions,
alias: string,
) => OptionsAndDescriptors,
index: number,
) {
const opts = options.overrides && options.overrides[index];
if (!opts) throw new Error("Assertion failure - missing override");
Expand All @@ -479,11 +504,15 @@ function buildOverrideDescriptors(
}

function buildOverrideEnvDescriptors(
{ dirname, options },
alias,
descriptors,
index,
envName,
{ dirname, options }: Partial<ValidatedFile>,
alias: string,
descriptors: (
dirname: string,
options: ValidatedOptions,
alias: string,
) => OptionsAndDescriptors,
index: number,
envName: string,
) {
const override = options.overrides && options.overrides[index];
if (!override) throw new Error("Assertion failure - missing override");
Expand Down Expand Up @@ -850,9 +879,9 @@ function matchesPatterns(
}

function matchPattern(
pattern,
dirname,
pathToTest,
pattern: IgnoreItem,
dirname: string,
pathToTest: unknown,
context: ConfigContext,
): boolean {
if (typeof pattern === "function") {
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-core/src/config/config-descriptors.ts
Expand Up @@ -126,8 +126,8 @@ export function createUncachedDescriptors(
// The returned result here is cached to represent a config object in
// memory, so we build and memoize the descriptors to ensure the same
// values are returned consistently.
let plugins;
let presets;
let plugins: UnloadedDescriptor[];
let presets: UnloadedDescriptor[];

return {
options: optionsWithResolvedBrowserslistConfigFile(options, dirname),
Expand Down
16 changes: 10 additions & 6 deletions packages/babel-core/src/config/files/configuration.ts
Expand Up @@ -57,7 +57,7 @@ export function findConfigUpwards(rootDir: string): string | null {
export function* findRelativeConfig(
packageData: FilePackageData,
envName: string,
caller: CallerMetadata | void,
caller: CallerMetadata | undefined,
): Handler<RelativeConfig> {
let config = null;
let ignore = null;
Expand Down Expand Up @@ -93,7 +93,7 @@ export function* findRelativeConfig(
export function findRootConfig(
dirname: string,
envName: string,
caller: CallerMetadata | void,
caller: CallerMetadata | undefined,
): Handler<ConfigFile | null> {
return loadOneConfig(ROOT_CONFIG_FILENAMES, dirname, envName, caller);
}
Expand All @@ -102,7 +102,7 @@ function* loadOneConfig(
names: string[],
dirname: string,
envName: string,
caller: CallerMetadata | void,
caller: CallerMetadata | undefined,
previousConfig: ConfigFile | null = null,
): Handler<ConfigFile | null> {
const configs = yield* gensync.all(
Expand Down Expand Up @@ -133,7 +133,7 @@ export function* loadConfig(
name: string,
dirname: string,
envName: string,
caller: CallerMetadata | void,
caller: CallerMetadata | undefined,
): Handler<ConfigFile> {
const filepath = require.resolve(name, { paths: [dirname] });

Expand All @@ -150,7 +150,11 @@ export function* loadConfig(
* Read the given config file, returning the result. Returns null if no config was found, but will
* throw if there are parsing errors while loading a config.
*/
function readConfig(filepath, envName, caller): Handler<ConfigFile | null> {
function readConfig(
filepath: string,
envName: string,
caller: CallerMetadata | undefined,
): Handler<ConfigFile | null> {
const ext = path.extname(filepath);
return ext === ".js" || ext === ".cjs" || ext === ".mjs"
? readConfigJS(filepath, { envName, caller })
Expand All @@ -163,7 +167,7 @@ const readConfigJS = makeStrongCache(function* readConfigJS(
filepath: string,
cache: CacheConfigurator<{
envName: string;
caller: CallerMetadata | void;
caller: CallerMetadata | undefined;
}>,
): Handler<ConfigFile | null> {
if (!nodeFs.existsSync(filepath)) {
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 => m.default || polyfill,
(m: { default: ImportMeta["resolve"] | undefined }) =>
m.default || polyfill,
() => polyfill,
)
: Promise.resolve(polyfill);
Expand Down
8 changes: 4 additions & 4 deletions packages/babel-core/src/config/files/index-browser.ts
Expand Up @@ -35,7 +35,7 @@ export function* findRelativeConfig(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
envName: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
caller: CallerMetadata | void,
caller: CallerMetadata | undefined,
): Handler<RelativeConfig> {
return { config: null, ignore: null };
}
Expand All @@ -47,7 +47,7 @@ export function* findRootConfig(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
envName: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
caller: CallerMetadata | void,
caller: CallerMetadata | undefined,
): Handler<ConfigFile | null> {
return null;
}
Expand All @@ -59,7 +59,7 @@ export function* loadConfig(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
envName: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
caller: CallerMetadata | void,
caller: CallerMetadata | undefined,
): Handler<ConfigFile> {
throw new Error(`Cannot load ${name} relative to ${dirname} in a browser`);
}
Expand All @@ -72,7 +72,7 @@ export function* resolveShowConfigPath(
return null;
}

export const ROOT_CONFIG_FILENAMES = [];
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 @@ -7,7 +7,7 @@ import semver from "semver";

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

let import_;
let import_: ((specifier: string | URL) => any) | undefined;
try {
// Old Node.js versions don't support import() syntax.
import_ = require("./import").default;
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: {};
options: InputOptions & { babel?: unknown };
};

export type IgnoreFile = {
Expand Down