|
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"; |
2 | 12 | import type { Locations } from "./common";
|
3 | 13 | import type { SvelteStyleElement } from "./html";
|
4 | 14 |
|
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> & { |
9 | 30 | walk(
|
10 | 31 | callback: (
|
11 | 32 | node: ESLintCompatiblePostCSSNode<ChildNode>,
|
12 | 33 | index: number
|
13 | 34 | ) => false | void
|
14 | 35 | ): 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>; |
15 | 107 | };
|
16 | 108 |
|
17 | 109 | export type ESLintCompatiblePostCSSNode<PostCSSNode extends Node> =
|
18 | 110 | // The following hack makes the `type` property work for type narrowing, see microsoft/TypeScript#53887.
|
19 | 111 | PostCSSNode extends any
|
20 | 112 | ? Locations &
|
21 |
| - Omit<PostCSSNode, "parent" | "type" | "walk"> & { |
| 113 | + Omit<PostCSSNode, RedefinedProperties> & { |
22 | 114 | type: `SvelteStyle-${PostCSSNode["type"]}`;
|
23 | 115 | } & (PostCSSNode extends Container<infer Child>
|
24 |
| - ? ESLintCompatiblePostCSSContainer<Child> |
| 116 | + ? ESLintCompatiblePostCSSContainer<PostCSSNode, Child> |
25 | 117 | : unknown) &
|
26 | 118 | (PostCSSNode extends Root
|
27 | 119 | ? {
|
|
0 commit comments