-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathvisitor-keys.ts
55 lines (52 loc) · 1.77 KB
/
visitor-keys.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import type { SourceCode } from "eslint";
import { unionWith } from "eslint-visitor-keys";
import type { SvelteNode } from "./ast";
type SvelteKeysType<T extends SvelteNode = SvelteNode> = {
[key in SvelteNode["type"]]: T extends { type: key }
? KeyofObject<T>[]
: never;
};
type KeyofObject<T> = { [key in keyof T]: key }[keyof T];
const svelteKeys: SvelteKeysType = {
Program: ["body"],
SvelteScriptElement: ["name", "startTag", "body", "endTag"],
SvelteStyleElement: ["name", "startTag", "body", "children", "endTag"],
SvelteElement: ["name", "startTag", "children", "endTag"],
SvelteStartTag: ["attributes"],
SvelteEndTag: [],
SvelteName: [],
SvelteMemberExpressionName: ["object", "property"],
SvelteLiteral: [],
SvelteMustacheTag: ["expression"],
SvelteDebugTag: ["identifiers"],
SvelteConstTag: ["declaration"],
SvelteIfBlock: ["expression", "children", "else"],
SvelteElseBlock: ["children"],
SvelteEachBlock: [
"expression",
"context",
"index",
"key",
"children",
"else",
],
SvelteAwaitBlock: ["expression", "pending", "then", "catch"],
SvelteAwaitPendingBlock: ["children"],
SvelteAwaitThenBlock: ["value", "children"],
SvelteAwaitCatchBlock: ["error", "children"],
SvelteKeyBlock: ["expression", "children"],
SvelteAttribute: ["key", "value"],
SvelteShorthandAttribute: ["key", "value"],
SvelteSpreadAttribute: ["argument"],
SvelteDirective: ["key", "expression"],
SvelteStyleDirective: ["key", "value"],
SvelteSpecialDirective: ["key", "expression"],
SvelteDirectiveKey: ["name"],
SvelteSpecialDirectiveKey: [],
SvelteText: [],
SvelteHTMLComment: [],
SvelteReactiveStatement: ["label", "body"],
};
export const KEYS: SourceCode.VisitorKeys = unionWith(
svelteKeys
) as SourceCode.VisitorKeys;