mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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 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];
|
||||||
|
@ -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'));
|
||||||
|
Loading…
Reference in New Issue
Block a user