Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,20 @@ export default [
parser: typescriptEslint.parser,
parserOptions: {
allowAutomaticSingleRunInference: true,
// @ts-expect-error types are old
EXPERIMENTAL_useProjectService: {
maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING: 1000,
},
projectService: true,
},
},
plugins: {
"@typescript-eslint": typescriptEslint.plugin,
},
rules: {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{
caughtErrorsIgnorePattern: "^_",
},
],
"no-dupe-class-members": "off",
"@typescript-eslint/no-dupe-class-members": "error",
"no-undef": "off",
Expand Down Expand Up @@ -165,6 +167,9 @@ export default [
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-return": "off",

// v8
"@typescript-eslint/no-require-imports": "off",
},
}),
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"shelljs": "^0.8.5",
"test262-stream": "^1.4.0",
"typescript": "5.5.1-rc",
"typescript-eslint": "^7.8.0"
"typescript-eslint": "rc-v8"
},
"workspaces": [
"codemods/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-cli/src/babel/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { FileResult, InputOptions } from "@babel/core";
export function chmod(src: string, dest: string): void {
try {
fs.chmodSync(dest, fs.statSync(src).mode);
} catch (err) {
} catch (_) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question] Is there a reason not to:

Suggested change
} catch (_) {
} catch {

...since you're transpiling from TypeScript anyway?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only enabled the typescript plugin to avoid accidental auto-transformations increasing the output size. :)

console.warn(`Cannot change permissions of ${dest}`);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-core/src/config/config-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function babelrcLoadEnabled(
// Fast path to avoid having to match patterns if the babelrc is just
// loading in the standard root directory.
if (babelrcRoots === undefined) {
return pkgData.directories.indexOf(absoluteRoot) !== -1;
return pkgData.directories.includes(absoluteRoot);
}

let babelrcPatterns = babelrcRoots;
Expand All @@ -317,7 +317,7 @@ function babelrcLoadEnabled(
// Fast path to avoid having to match patterns if the babelrc is just
// loading in the standard root directory.
if (babelrcPatterns.length === 1 && babelrcPatterns[0] === absoluteRoot) {
return pkgData.directories.indexOf(absoluteRoot) !== -1;
return pkgData.directories.includes(absoluteRoot);
}

return babelrcPatterns.some(pat => {
Expand Down
9 changes: 6 additions & 3 deletions packages/babel-core/src/config/config-descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type OptionsAndDescriptors = {
// Represents a plugin or presets at a given location in a config object.
// At this point these have been resolved to a specific object or function,
// but have not yet been executed to call functions with options.
export interface UnloadedDescriptor<API, Options = {} | undefined | false> {
export interface UnloadedDescriptor<API, Options = object | undefined | false> {
name: string | undefined;
value: object | ((api: API, options: Options, dirname: string) => unknown);
options: Options;
Expand Down Expand Up @@ -199,7 +199,10 @@ const DEFAULT_OPTIONS = {};
* next time.
*/
function loadCachedDescriptor<API>(
cache: WeakMap<{} | Function, WeakMap<{}, Array<UnloadedDescriptor<API>>>>,
cache: WeakMap<
object | Function,
WeakMap<object, Array<UnloadedDescriptor<API>>>
>,
desc: UnloadedDescriptor<API>,
) {
const { value, options = DEFAULT_OPTIONS } = desc;
Expand All @@ -217,7 +220,7 @@ function loadCachedDescriptor<API>(
cacheByOptions.set(options, possibilities);
}

if (possibilities.indexOf(desc) === -1) {
if (!possibilities.includes(desc)) {
const matches = possibilities.filter(possibility =>
isEqualDescriptor(possibility, desc),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/files/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const runConfig = makeWeakCache(function* runConfig(
yield* [];

return {
options: endHiddenCallStack(options as any as (api: ConfigAPI) => {})(
options: endHiddenCallStack(options as any as (api: ConfigAPI) => unknown)(
makeConfigAPI(cache),
),
cacheNeedsConfiguration: !cache.configured(),
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-core/src/config/full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import type * as Context from "./cache-contexts.ts";
import ConfigError from "../errors/config-error.ts";

type LoadedDescriptor = {
value: {};
options: {};
value: any;
options: object;
dirname: string;
alias: string;
externalDependencies: ReadonlyDeepArray<string>;
Expand Down Expand Up @@ -259,7 +259,7 @@ const makeDescriptorLoader = <Context, API>(
let item: unknown = value;
if (typeof value === "function") {
const factory = maybeAsync(
value as (api: API, options: {}, dirname: string) => unknown,
value as (api: API, options: object, dirname: string) => unknown,
`You appear to be using an async plugin/preset, but Babel has been called synchronously`,
);

Expand Down
4 changes: 2 additions & 2 deletions packages/babel-core/src/config/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ class ConfigItem<API> {
/**
* The resolved value of the item itself.
*/
value: {} | Function;
value: object | Function;

/**
* The options, if any, that were passed to the item.
* Mutating this will lead to undefined behavior.
*
* "false" means that this item has been disabled.
*/
options: {} | void | false;
options: object | void | false;

/**
* The directory that the options for this item are relative to.
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-core/src/config/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export default class Plugin {
parserOverride?: Function;
generatorOverride?: Function;

options: {};
options: object;

externalDependencies: ReadonlyDeepArray<string>;

constructor(
plugin: PluginObject,
options: {},
options: object,
key?: string,
externalDependencies: ReadonlyDeepArray<string> = finalize([]),
) {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function mergeOptions(
}
}

function mergeDefaultFields<T extends {}>(target: T, source: T) {
function mergeDefaultFields<T extends object>(target: T, source: T) {
for (const k of Object.keys(source) as (keyof T)[]) {
const val = source[k];
if (val !== undefined) target[k] = val;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ export function assertCallerMetadata(
export function assertInputSourceMap(
loc: OptionPath,
value: unknown,
): RootInputSourceMapOption | void {
): RootInputSourceMapOption {
if (
value !== undefined &&
typeof value !== "boolean" &&
(typeof value !== "object" || !value)
) {
throw new Error(`${msg(loc)} must be a boolean, object, or undefined`);
}
return value;
return value as RootInputSourceMapOption;
}

export function assertString(loc: GeneralPath, value: unknown): string | void {
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-core/src/config/validation/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export type BabelrcSearch = boolean | IgnoreItem | IgnoreList;
export type SourceMapsOption = boolean | "inline" | "both";
export type SourceTypeOption = "module" | "script" | "unambiguous";
export type CompactOption = boolean | "auto";
export type RootInputSourceMapOption = {} | boolean;
export type RootInputSourceMapOption = object | boolean;
export type RootMode = "root" | "upward" | "upward-optional";

export type TargetsListOrObject =
Expand Down Expand Up @@ -302,7 +302,7 @@ function getSource(loc: NestingPath): OptionsSource {

export function validate(
type: OptionsSource,
opts: {},
opts: any,
filename?: string,
): ValidatedOptions {
try {
Expand Down Expand Up @@ -397,7 +397,7 @@ function throwUnknownError(loc: OptionPath) {
}
}

function assertNoDuplicateSourcemap(opts: {}): void {
function assertNoDuplicateSourcemap(opts: any): void {
if (Object.hasOwn(opts, "sourceMap") && Object.hasOwn(opts, "sourceMaps")) {
throw new Error(".sourceMap is an alias for .sourceMaps, cannot use both");
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ if (!process.env.BABEL_8_BREAKING && !USE_ESM) {
// For easier backward-compatibility, provide an API like the one we exposed in Babel 6.
// eslint-disable-next-line no-restricted-globals
exports.OptionManager = class OptionManager {
init(opts: {}) {
init(opts: unknown) {
return loadOptionsSync(opts);
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/tools/build-external-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function buildHelpers(

const refs: { [key: string]: t.Identifier | t.MemberExpression } = {};
helpers.list.forEach(function (name) {
if (allowlist && allowlist.indexOf(name) < 0) return;
if (allowlist && !allowlist.includes(name)) return;

const ref = (refs[name] = getHelperReference(name));

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/transformation/file/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class File {
buildError: this.buildCodeFrameError.bind(this),
};

constructor(options: {}, { code, ast, inputMap }: NormalizedFile) {
constructor(options: any, { code, ast, inputMap }: NormalizedFile) {
this.opts = options;
this.code = code;
this.ast = ast;
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/transformation/normalize-opts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "path";
import type { ResolvedConfig } from "../config/index.ts";

export default function normalizeOptions(config: ResolvedConfig): {} {
export default function normalizeOptions(config: ResolvedConfig) {
const {
filename,
cwd,
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/transformation/plugin-pass.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type * as t from "@babel/types";
import type File from "./file/file.ts";

export default class PluginPass<Options = {}> {
export default class PluginPass<Options = object> {
_map: Map<unknown, unknown> = new Map();
key: string | undefined | null;
file: File;
Expand Down
1 change: 1 addition & 0 deletions packages/babel-generator/src/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export default class Buffer {
this._last = str.charCodeAt(len - 1);

if (++this._appendCount > 4096) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
+this._str; // Unexplainable huge performance boost. Ref: https://github.com/davidmarkclements/flatstr License: MIT
this._buf += this._str;
this._str = str;
Expand Down
1 change: 1 addition & 0 deletions packages/babel-generator/src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,7 @@ if (!process.env.BABEL_8_BREAKING) {
}

type GeneratorFunctions = typeof generatorFunctions;
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface Printer extends GeneratorFunctions {}
export default Printer;

Expand Down
4 changes: 2 additions & 2 deletions packages/babel-helper-compilation-targets/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function getLowestVersions(browsers: Array<string>): Targets {

all[target] = semverMin(version, parsedBrowserVersion);
}
} catch (e) {}
} catch (_) {}

return all;
},
Expand Down Expand Up @@ -129,7 +129,7 @@ getting parsed as 6.1, which can lead to unexpected behavior.
function semverifyTarget(target: Target, value: string) {
try {
return semverify(value);
} catch (error) {
} catch (_) {
throw new Error(
v.formatMessage(
`'${value}' is not a valid value for 'targets.${target}'.`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ function usesPrivateField(expression: t.Node) {
t.traverseFast(expression, node => {
if (t.isPrivateName(node)) {
// TODO: Add early return support to t.traverseFast
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw null;
}
});
Expand Down Expand Up @@ -1077,6 +1078,7 @@ function transformClass(
(t.isMetaProperty(node) && node.meta.name !== "import")
) {
// TODO: Add early return support to t.traverseFast
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw null;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,9 @@ export function buildFieldsInitNodes(
ref ??= t.cloneNode(innerBindingRef);

for (const prop of props) {
prop.isClassProperty() && ts.assertFieldTransformed(prop);
if (prop.isClassProperty()) {
ts.assertFieldTransformed(prop);
}

// @ts-expect-error: TS doesn't infer that prop.node is not a StaticBlock
const isStatic = !t.isStaticBlock?.(prop.node) && prop.node.static;
Expand Down
12 changes: 6 additions & 6 deletions packages/babel-helper-fixtures/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type Suite = {
function tryResolve(module: string) {
try {
return require.resolve(module);
} catch (e) {
} catch (_) {
return null;
}
}
Expand All @@ -82,7 +82,7 @@ function assertDirectory(loc: string) {
}

function shouldIgnore(name: string, ignore?: Array<string>) {
if (ignore && ignore.indexOf(name) >= 0) {
if (ignore?.includes(name)) {
return true;
}

Expand Down Expand Up @@ -185,7 +185,7 @@ function pushTask(
stderrLoc = taskDir + "/stderr.txt";
} else if (taskDirStats.isFile()) {
const ext = path.extname(taskDir);
if (EXTENSIONS.indexOf(ext) === -1) return;
if (!EXTENSIONS.includes(ext)) return;

execLoc = taskDir;
execLocAlias = suiteName + "/" + taskName;
Expand Down Expand Up @@ -386,7 +386,7 @@ function wrapPackagesArray(
val[0] = path.resolve(optionsDir, val[0]);
} else {
let name = val[0];
const match = name.match(/^(@babel\/(?:plugin-|preset-)?)(.*)$/);
const match = /^(@babel\/(?:plugin-|preset-)?)(.*)$/.exec(name);
if (match) {
name = match[2];
}
Expand Down Expand Up @@ -419,12 +419,12 @@ function wrapPackagesArray(
* @export
* @param {{}} options the imported options.json
* @param {string} optionsDir the directory where options.json is placed
* @returns {{}} options whose plugins/presets are resolved
* @returns {any} options whose plugins/presets are resolved
*/
export function resolveOptionPluginOrPreset(
options: any,
optionsDir: string,
): {} {
): any {
if (options.overrides) {
for (const subOption of options.overrides) {
resolveOptionPluginOrPreset(subOption, optionsDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ export interface Handler<State> {
delete(this: HandlerState<State> & State, member: Member): t.Expression;
}

export interface HandlerState<State = {}> extends Handler<State> {
export interface HandlerState<State = object> extends Handler<State> {
handle(
this: HandlerState<State> & State,
member: Member,
Expand All @@ -604,7 +604,7 @@ export interface HandlerState<State = {}> extends Handler<State> {
// get, set, and call methods.
// Optionally, a memoise method may be defined on the state, which will be
// called when the member is a self-referential update.
export default function memberExpressionToFunctions<CustomState = {}>(
export default function memberExpressionToFunctions<CustomState extends object>(
path: NodePath,
visitor: Visitor<HandlerState<CustomState>>,
state: Handler<CustomState> & CustomState,
Expand Down
Loading