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

refactor(typescript): packages/rspack/src/util/StatsFactory #7381

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 7 additions & 5 deletions packages/rspack/src/stats/StatsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import type { JsStats, JsStatsError, JsStatsWarning } from "@rspack/binding";
import { HookMap, SyncBailHook, SyncWaterfallHook } from "@rspack/lite-tapable";

import type { Compilation } from "../Compilation";
import { type Comparator, concatComparators } from "../util/comparators";
import {
type AtLeastTwo,
type Comparator,
concatComparators
} from "../util/comparators";
import { type GroupConfig, smartGrouping } from "../util/smartGrouping";

export type KnownStatsFactoryContext = {
Expand Down Expand Up @@ -286,8 +290,7 @@ export class StatsFactory {
);
if (comparators.length > 0) {
items.sort(
// @ts-expect-error number of arguments is correct
concatComparators(...comparators)
concatComparators(...(comparators as AtLeastTwo<Comparator>))
);
}

Expand Down Expand Up @@ -345,8 +348,7 @@ export class StatsFactory {
);
if (comparators2.length > 0) {
resultItems.sort(
// @ts-expect-error number of arguments is correct
concatComparators(...comparators2)
concatComparators(...(comparators2 as AtLeastTwo<Comparator>))
);
}

Expand Down
8 changes: 5 additions & 3 deletions packages/rspack/src/util/comparators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ const concatComparatorsCache: TwoKeyWeakMap<
Comparator
> = new TwoKeyWeakMap();

export type AtLeastTwo<T> = [T, T, ...T[]];

export const concatComparators = (
c1: Comparator,
c2: Comparator,
...cRest: Comparator[]
...comps: AtLeastTwo<Comparator>
wxiaoyun marked this conversation as resolved.
Show resolved Hide resolved
): Comparator => {
const [c1, c2, ...cRest] = comps;

if (cRest.length > 0) {
const [c3, ...cRest2] = cRest;
return concatComparators(c1, concatComparators(c2, c3, ...cRest2));
Expand Down
Loading