fix(puppeteer-core): avoid type instantiation errors (#9370)

Using the accumulator allows enabling the tail-recursion optimization in
the TypeScript compiler.

Closes #9369
This commit is contained in:
Alex Rudenko 2022-12-06 19:21:08 +01:00 committed by GitHub
parent be7626bad8
commit 17f31a9ee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 17 deletions

View File

@ -135,32 +135,36 @@ type BeginSubclassSelectorTokens = ['.', '#', '[', ':'];
type CombinatorTokens = [' ', '>', '+', '~', '|', '|']; type CombinatorTokens = [' ', '>', '+', '~', '|', '|'];
type Drop<Arr extends readonly unknown[], Remove> = Arr extends [ type Drop<
infer Head, Arr extends readonly unknown[],
...infer Tail Remove,
] Acc extends unknown[] = []
> = Arr extends [infer Head, ...infer Tail]
? Head extends Remove ? Head extends Remove
? Drop<Tail, Remove> ? Drop<Tail, Remove>
: [Head, ...Drop<Tail, Remove>] : Drop<Tail, Remove, [...Acc, Head]>
: []; : Acc;
type FlatmapSplitWithDelemiters< type FlatmapSplitWithDelemiters<
Inputs extends readonly string[], Inputs extends readonly string[],
Delemiters extends readonly string[] Delemiters extends readonly string[],
Acc extends string[] = []
> = Inputs extends [infer FirstInput, ...infer RestInputs] > = Inputs extends [infer FirstInput, ...infer RestInputs]
? FirstInput extends string ? FirstInput extends string
? RestInputs extends readonly string[] ? RestInputs extends readonly string[]
? [ ? FlatmapSplitWithDelemiters<
...SplitWithDelemiters<FirstInput, Delemiters>, RestInputs,
...FlatmapSplitWithDelemiters<RestInputs, Delemiters> Delemiters,
] [...Acc, ...SplitWithDelemiters<FirstInput, Delemiters>]
: never >
: never : Acc
: []; : Acc
: Acc;
type Split< type Split<
Input extends string, Input extends string,
Delemiter extends string Delemiter extends string,
Acc extends string[] = []
> = Input extends `${infer Prefix}${Delemiter}${infer Suffix}` > = Input extends `${infer Prefix}${Delemiter}${infer Suffix}`
? [Prefix, ...Split<Suffix, Delemiter>] ? Split<Suffix, Delemiter, [...Acc, Prefix]>
: [Input]; : [...Acc, Input];

View File

@ -6,6 +6,18 @@ declare const nodeFor: <Selector extends string>(
) => NodeFor<Selector>; ) => NodeFor<Selector>;
{ {
{
expectType<HTMLTableRowElement>(
nodeFor(
'[data-testid="my-component"] div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div tbody tr'
)
);
expectNotType<Element>(
nodeFor(
'[data-testid="my-component"] div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div tbody tr'
)
);
}
{ {
expectType<HTMLAnchorElement>(nodeFor('a')); expectType<HTMLAnchorElement>(nodeFor('a'));
expectNotType<Element>(nodeFor('a')); expectNotType<Element>(nodeFor('a'));