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:
parent
be7626bad8
commit
17f31a9ee4
@ -135,32 +135,36 @@ type BeginSubclassSelectorTokens = ['.', '#', '[', ':'];
|
||||
|
||||
type CombinatorTokens = [' ', '>', '+', '~', '|', '|'];
|
||||
|
||||
type Drop<Arr extends readonly unknown[], Remove> = Arr extends [
|
||||
infer Head,
|
||||
...infer Tail
|
||||
]
|
||||
type Drop<
|
||||
Arr extends readonly unknown[],
|
||||
Remove,
|
||||
Acc extends unknown[] = []
|
||||
> = Arr extends [infer Head, ...infer Tail]
|
||||
? Head extends Remove
|
||||
? Drop<Tail, Remove>
|
||||
: [Head, ...Drop<Tail, Remove>]
|
||||
: [];
|
||||
: Drop<Tail, Remove, [...Acc, Head]>
|
||||
: Acc;
|
||||
|
||||
type FlatmapSplitWithDelemiters<
|
||||
Inputs extends readonly string[],
|
||||
Delemiters extends readonly string[]
|
||||
Delemiters extends readonly string[],
|
||||
Acc extends string[] = []
|
||||
> = Inputs extends [infer FirstInput, ...infer RestInputs]
|
||||
? FirstInput extends string
|
||||
? RestInputs extends readonly string[]
|
||||
? [
|
||||
...SplitWithDelemiters<FirstInput, Delemiters>,
|
||||
...FlatmapSplitWithDelemiters<RestInputs, Delemiters>
|
||||
]
|
||||
: never
|
||||
: never
|
||||
: [];
|
||||
? FlatmapSplitWithDelemiters<
|
||||
RestInputs,
|
||||
Delemiters,
|
||||
[...Acc, ...SplitWithDelemiters<FirstInput, Delemiters>]
|
||||
>
|
||||
: Acc
|
||||
: Acc
|
||||
: Acc;
|
||||
|
||||
type Split<
|
||||
Input extends string,
|
||||
Delemiter extends string
|
||||
Delemiter extends string,
|
||||
Acc extends string[] = []
|
||||
> = Input extends `${infer Prefix}${Delemiter}${infer Suffix}`
|
||||
? [Prefix, ...Split<Suffix, Delemiter>]
|
||||
: [Input];
|
||||
? Split<Suffix, Delemiter, [...Acc, Prefix]>
|
||||
: [...Acc, Input];
|
||||
|
@ -6,6 +6,18 @@ declare const nodeFor: <Selector extends string>(
|
||||
) => 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'));
|
||||
expectNotType<Element>(nodeFor('a'));
|
||||
|
Loading…
Reference in New Issue
Block a user