Skip to content

Commit acd0d56

Browse files
committed
Overriden the rest of Container properties
1 parent 003418f commit acd0d56

File tree

1 file changed

+99
-7
lines changed

1 file changed

+99
-7
lines changed

src/ast/style.ts

+99-7
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,119 @@
1-
import type { ChildNode, Container, Node, Root } from "postcss";
1+
import type {
2+
AtRule,
3+
ChildNode,
4+
ChildProps,
5+
Comment,
6+
Container,
7+
Declaration,
8+
Node,
9+
Root,
10+
Rule,
11+
} from "postcss";
212
import type { Locations } from "./common";
313
import type { SvelteStyleElement } from "./html";
414

5-
type ESLintCompatiblePostCSSContainer<Child extends Node> = Omit<
6-
Container<ESLintCompatiblePostCSSNode<Child>>,
7-
"parent" | "type" | "walk"
8-
> & {
15+
type RedefinedProperties =
16+
| "type" // Redefined for all nodes to include the "SvelteStyle-" prefix
17+
| "parent" // Redefined for Root
18+
| "walk" // The rest are redefined for Container
19+
| "walkDecls"
20+
| "walkRules"
21+
| "walkAtRules"
22+
| "walkComments"
23+
| "append"
24+
| "prepend";
25+
26+
type ESLintCompatiblePostCSSContainer<
27+
PostCSSNode extends Node,
28+
Child extends Node
29+
> = Omit<Container<ESLintCompatiblePostCSSNode<Child>>, RedefinedProperties> & {
930
walk(
1031
callback: (
1132
node: ESLintCompatiblePostCSSNode<ChildNode>,
1233
index: number
1334
) => false | void
1435
): false | undefined;
36+
walkDecls(
37+
propFilter: string | RegExp,
38+
callback: (
39+
decl: ESLintCompatiblePostCSSNode<Declaration>,
40+
index: number
41+
) => false | void
42+
): false | undefined;
43+
walkDecls(
44+
callback: (
45+
decl: ESLintCompatiblePostCSSNode<Declaration>,
46+
index: number
47+
) => false | void
48+
): false | undefined;
49+
walkRules(
50+
selectorFilter: string | RegExp,
51+
callback: (
52+
rule: ESLintCompatiblePostCSSNode<Rule>,
53+
index: number
54+
) => false | void
55+
): false | undefined;
56+
walkRules(
57+
callback: (
58+
rule: ESLintCompatiblePostCSSNode<Rule>,
59+
index: number
60+
) => false | void
61+
): false | undefined;
62+
walkAtRules(
63+
nameFilter: string | RegExp,
64+
callback: (
65+
atRule: ESLintCompatiblePostCSSNode<AtRule>,
66+
index: number
67+
) => false | void
68+
): false | undefined;
69+
walkAtRules(
70+
callback: (
71+
atRule: ESLintCompatiblePostCSSNode<AtRule>,
72+
index: number
73+
) => false | void
74+
): false | undefined;
75+
walkComments(
76+
callback: (
77+
comment: ESLintCompatiblePostCSSNode<Comment>,
78+
indexed: number
79+
) => false | void
80+
): false | undefined;
81+
walkComments(
82+
callback: (
83+
comment: ESLintCompatiblePostCSSNode<Comment>,
84+
indexed: number
85+
) => false | void
86+
): false | undefined;
87+
append(
88+
...nodes: (
89+
| ESLintCompatiblePostCSSNode<Node>
90+
| ESLintCompatiblePostCSSNode<Node>[]
91+
| ChildProps
92+
| ChildProps[]
93+
| string
94+
| string[]
95+
)[]
96+
): ESLintCompatiblePostCSSNode<PostCSSNode>;
97+
prepend(
98+
...nodes: (
99+
| ESLintCompatiblePostCSSNode<Node>
100+
| ESLintCompatiblePostCSSNode<Node>[]
101+
| ChildProps
102+
| ChildProps[]
103+
| string
104+
| string[]
105+
)[]
106+
): ESLintCompatiblePostCSSNode<PostCSSNode>;
15107
};
16108

17109
export type ESLintCompatiblePostCSSNode<PostCSSNode extends Node> =
18110
// The following hack makes the `type` property work for type narrowing, see microsoft/TypeScript#53887.
19111
PostCSSNode extends any
20112
? Locations &
21-
Omit<PostCSSNode, "parent" | "type" | "walk"> & {
113+
Omit<PostCSSNode, RedefinedProperties> & {
22114
type: `SvelteStyle-${PostCSSNode["type"]}`;
23115
} & (PostCSSNode extends Container<infer Child>
24-
? ESLintCompatiblePostCSSContainer<Child>
116+
? ESLintCompatiblePostCSSContainer<PostCSSNode, Child>
25117
: unknown) &
26118
(PostCSSNode extends Root
27119
? {

0 commit comments

Comments
 (0)