Skip to content

Commit 20aa0c5

Browse files
committed
Re-implemented PostCSS container
1 parent 9cfc436 commit 20aa0c5

File tree

2 files changed

+85
-14
lines changed

2 files changed

+85
-14
lines changed

src/ast/style.ts

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,87 @@
1-
import type { Node, Container } from "postcss";
2-
import type { BaseNode } from "./base";
1+
import type { Node, ChildProps, Container } from "postcss";
2+
import type { Locations } from "./common";
3+
4+
type ESLintCompatiblePostCSSContainer<
5+
PostCSSNode extends Node,
6+
Child extends Node
7+
> = {
8+
each(
9+
callback: (
10+
node: ESLintCompatiblePostCSSNode<Child>,
11+
index: number
12+
) => false | void
13+
): false | undefined;
14+
every(
15+
condition: (
16+
node: ESLintCompatiblePostCSSNode<Child>,
17+
index: number,
18+
nodes: ESLintCompatiblePostCSSNode<Child>[]
19+
) => boolean
20+
): boolean;
21+
get first(): ESLintCompatiblePostCSSNode<Child> | undefined;
22+
index(child: ESLintCompatiblePostCSSNode<Child> | number): number;
23+
insertAfter(
24+
oldNode: ESLintCompatiblePostCSSNode<Child> | number,
25+
newNode:
26+
| ESLintCompatiblePostCSSNode<Child>
27+
| ChildProps
28+
| string
29+
| ESLintCompatiblePostCSSNode<Child>[]
30+
| ChildProps[]
31+
| string[]
32+
): ESLintCompatiblePostCSSNode<PostCSSNode>;
33+
insertBefore(
34+
oldNode: ESLintCompatiblePostCSSNode<Child> | number,
35+
newNode:
36+
| ESLintCompatiblePostCSSNode<Child>
37+
| ChildProps
38+
| string
39+
| ESLintCompatiblePostCSSNode<Child>[]
40+
| ChildProps[]
41+
| string[]
42+
): ESLintCompatiblePostCSSNode<PostCSSNode>;
43+
get last(): ESLintCompatiblePostCSSNode<Child> | undefined;
44+
nodes: ESLintCompatiblePostCSSNode<Child>[];
45+
push(
46+
child: ESLintCompatiblePostCSSNode<Child>
47+
): ESLintCompatiblePostCSSNode<PostCSSNode>;
48+
removeChild(
49+
child: ESLintCompatiblePostCSSNode<Child> | number
50+
): ESLintCompatiblePostCSSNode<PostCSSNode>;
51+
some(
52+
condition: (
53+
node: ESLintCompatiblePostCSSNode<Child>,
54+
index: number,
55+
nodes: ESLintCompatiblePostCSSNode<Child>[]
56+
) => boolean
57+
): boolean;
58+
walk(
59+
callback: (
60+
node: ESLintCompatiblePostCSSNode<Child>,
61+
index: number
62+
) => false | void
63+
): false | undefined;
64+
};
365

466
export type ESLintCompatiblePostCSSNode<PostCSSNode extends Node = Node> =
5-
BaseNode &
6-
Omit<PostCSSNode, "walk"> &
7-
(PostCSSNode extends Container<infer Child>
8-
? {
9-
walk(
10-
callback: (
11-
node: ESLintCompatiblePostCSSNode<Child>,
12-
index: number
13-
) => false | void
14-
): false | undefined;
15-
}
67+
Locations &
68+
Omit<
69+
PostCSSNode,
70+
| "each"
71+
| "every"
72+
| "first"
73+
| "index"
74+
| "insertAfter"
75+
| "insertBefore"
76+
| "last"
77+
| "nodes"
78+
| "push"
79+
| "removeChild"
80+
| "some"
81+
| "type"
82+
| "walk"
83+
> & {
84+
type: `SvelteStyle-${PostCSSNode["type"]}`;
85+
} & (PostCSSNode extends Container<infer Child>
86+
? ESLintCompatiblePostCSSContainer<PostCSSNode, Child>
1687
: unknown);

src/parser/converts/root.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function convertPostCSSNodeToESLintNode<PostCSSNode extends Node>(
209209
styleLoc: SourceLocation,
210210
styleRange: { start: number; end: number }
211211
) {
212-
node.type = `SvelteStyle-${node.type}`;
212+
node.type = `SvelteStyle-${node.type as PostCSSNode["type"]}`;
213213
const startOffset = styleRange.start + (node.source?.start?.offset ?? 0);
214214
const endOffset =
215215
node.source?.end !== undefined

0 commit comments

Comments
 (0)