Skip to content

Commit

Permalink
enable TS compiler option: noImplicitAny (#14601)
Browse files Browse the repository at this point in the history
* enable noImplicitAny

* codemod (#14602)

* Improve preset/plugin-typescript typings (#14603)

* preset-typescript

* transform-typescript

* Update packages/babel-plugin-transform-typescript/src/enum.ts

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>

* prettier

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>

* Improve transform-runtime typings (#14605)

* enable noImplicitAny

* codemod (#14602)

* Improve preset/plugin-typescript typings (#14603)

* preset-typescript

* transform-typescript

* Update packages/babel-plugin-transform-typescript/src/enum.ts

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>

* prettier

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>

* improve transform-runtime typings

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>

* jsx (#14607)

* Improve module transform packages typings (#14608)

* improve babel-template typings (#14621)

* Improve @babel/helper-* typings (#14620)

* improve helper-function-name typings

* helper hoist variables

* helper-member-expression-to-functions

* helper-simple-access

* remap-async-to-generator

* helper-annotate-as-pure

* helper-builder-binary-assignment-operator-visitor

* helper-check-duplicate-nodes

* early return when export declaration is export all

* split-export-declaration

* helper-define-map

* define-map

* Update packages/babel-helper-builder-binary-assignment-operator-visitor/src/index.ts

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>

* review comments

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>

* improve helper-module-imports typings (#14623)

* refactor: simplify ImportInjector._applyDefaults

* helper-module-imports

* map globals to the one used in Babel 8

* Improve fixture-test-runner typings (#14625)

* plugin-test-runner

* fixture-test-runner

* Update packages/babel-helper-fixtures/src/index.ts

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>

* Improve preset-env typings (#14606)

* refactor: move shipped-proposals to ts

* preset-env

* address review comments

* Improve pipeline-operator typings (#14629)

* refactor: simplify buildOptimizedSequenceExpression

* proposal-pipeline-operator

* address review comments

* improve standalone typings (#14630)

* babel-standalone

* address review comment

* Improve plugins typings (Part 1) (#14633)

* change AssumptionFunction return type

* helper-create-regexp-features-plugin

* create-class-features-plugin

* transform-for-of

* improve unicode-escapes typings

* transform-object-super

* transform-react-constant-elements

* proto-to-assign

* function-name

* flow-comments

TS cannot infer Flow visitor type because we have both Flow type and Flow virtual type.

* Improve code-frame/hightlight typings (#14643)

* code-frame

* map js-tokens to Babel 8

* highlight

* Improve `@babel/types` typings (#14645)

* bump to-fast-properties to v4

* types

* mark node comments as mutable

* Improve babel-core typings (#14622)

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>

* improve transform-classes typings (#14624)

* Improve `@babel/generator` typings (#14644)

* generator

* refactor: merge {start,end}Terminatorless to printTerminatorless

* inline buildYieldAwait

* inline ExportDeclaration

* also export Pos

* let getPossibleRaw return string | void

* Apply suggestions from code review

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>

* address review comments

* do not export internal printer method

* simplify needsWhitespace

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>

* Improve plugins typings (Part 2) (#14639)

* exponentiation-operator

* duplicate-keys

* computed-properties

* replace-supers

* block-scoping

* block-scoped-functions

* syntax-typescript

* record-and-tuple

* private-property-in-object

* partial-application

* json-strings

* function-sent

* function-bind

* class-static-block

* async-generator-functions

* Update packages/babel-plugin-transform-block-scoping/src/index.ts

* address review comments

* helper-replace-supers

* Improve plugins typings (Part 3) (#14642)

* external-helpers

* bugfix

* transform-parameters

* object-rest-spread

* destructuring-private

* transform-destructuring

* proposal-decorators

* optional-chaining

* helper-wrap-function

* explode-assignable-expression

* helper-compilation-targets

* helper-plugin-utils

* helpers

* helper-validator-option

* fix: allow "+" and "-" in MappedType .readonly/.optional

* fixture-test-runner

* remove charcodes from dependencies

the charcodes transform will inline charCodes.* so we can remove it from dependencies

* Improve traverse typings (#14648)

* export removeProperties options

* traverse

* fix other packages typings

* fix gatherNodeParts

* downgrade to-fast-properties to v3

* fix typo

* babel-core/normalize-file

* add ignore comment property used by flow plugin

* refine getLastStatement typings

* fix babel-standalone rebase typing error

* fix assert.rejects polyfill

* simplify _param typings

* supress Babel 7 AST errors

* loosen defineType typings

The AST typings are generated from defineType calls, so defineType should accept a string as type.

* restore legacy code

* Suppress data/core-js-compat importing errors

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 21, 2022
1 parent 171215f commit b1e73d6
Show file tree
Hide file tree
Showing 234 changed files with 4,085 additions and 2,108 deletions.
@@ -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

0 comments on commit b1e73d6

Please sign in to comment.