-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathast.ts
180 lines (161 loc) · 4.17 KB
/
ast.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import type { AST as ESLintAST } from "eslint";
import type { Comment } from "estree";
export interface Locations {
loc: SourceLocation;
range: [number, number];
}
interface BaseJSONNode extends Locations {
type: string;
}
export interface SourceLocation {
start: Position;
end: Position;
}
export interface Position {
/** >= 1 */
line: number;
/** >= 0 */
column: number;
}
export type JSONNode =
| JSONProgram
| JSONExpressionStatement
| JSONExpression
| JSONProperty
| JSONIdentifier
| JSONTemplateLiteral
| JSONTemplateElement;
export interface JSONProgram extends BaseJSONNode {
type: "Program";
body: [JSONExpressionStatement];
comments: Comment[];
tokens: ESLintAST.Token[];
parent: null;
}
export interface JSONExpressionStatement extends BaseJSONNode {
type: "JSONExpressionStatement";
expression: JSONExpression;
parent: JSONProgram;
}
export type JSONExpression =
| JSONArrayExpression
| JSONObjectExpression
| JSONLiteral
| JSONUnaryExpression
| JSONNumberIdentifier
| JSONUndefinedIdentifier
| JSONTemplateLiteral
| JSONBinaryExpression;
export interface JSONArrayExpression extends BaseJSONNode {
type: "JSONArrayExpression";
elements: (JSONExpression | null)[];
parent: JSONArrayExpression | JSONProperty | JSONExpressionStatement;
}
export interface JSONObjectExpression extends BaseJSONNode {
type: "JSONObjectExpression";
properties: JSONProperty[];
parent: JSONArrayExpression | JSONProperty | JSONExpressionStatement;
}
export interface JSONProperty extends BaseJSONNode {
type: "JSONProperty";
key: JSONIdentifier | JSONStringLiteral | JSONNumberLiteral;
value: JSONExpression;
kind: "init";
method: false;
shorthand: false;
computed: false;
parent: JSONObjectExpression;
}
export interface JSONIdentifier extends BaseJSONNode {
type: "JSONIdentifier";
name: string;
parent?:
| JSONArrayExpression
| JSONProperty
| JSONExpressionStatement
| JSONUnaryExpression;
}
export interface JSONNumberIdentifier extends JSONIdentifier {
name: "Infinity" | "NaN";
}
export interface JSONUndefinedIdentifier extends JSONIdentifier {
name: "undefined";
}
interface JSONLiteralBase extends BaseJSONNode {
type: "JSONLiteral";
raw: string;
parent?:
| JSONArrayExpression
| JSONProperty
| JSONExpressionStatement
| JSONUnaryExpression
| JSONBinaryExpression;
}
export interface JSONStringLiteral extends JSONLiteralBase {
value: string;
regex: null;
bigint: null;
}
export interface JSONNumberLiteral extends JSONLiteralBase {
value: number;
regex: null;
bigint: null;
}
export interface JSONKeywordLiteral extends JSONLiteralBase {
value: boolean | null;
regex: null;
bigint: null;
}
export interface JSONRegExpLiteral extends JSONLiteralBase {
value: null;
regex: {
pattern: string;
flags: string;
};
bigint: null;
}
export interface JSONBigIntLiteral extends JSONLiteralBase {
value: null;
regex: null;
bigint: string;
}
export type JSONLiteral =
| JSONStringLiteral
| JSONNumberLiteral
| JSONKeywordLiteral
| JSONRegExpLiteral
| JSONBigIntLiteral;
export interface JSONUnaryExpression extends BaseJSONNode {
type: "JSONUnaryExpression";
operator: "-" | "+";
prefix: true;
argument: JSONNumberLiteral | JSONNumberIdentifier;
parent: JSONArrayExpression | JSONProperty | JSONExpressionStatement;
}
export interface JSONTemplateLiteral extends BaseJSONNode {
type: "JSONTemplateLiteral";
quasis: [JSONTemplateElement];
expressions: [];
parent: JSONArrayExpression | JSONProperty | JSONExpressionStatement;
}
export interface JSONTemplateElement extends BaseJSONNode {
type: "JSONTemplateElement";
tail: boolean;
value: {
cooked: string;
raw: string;
};
parent: JSONTemplateLiteral;
}
export interface JSONBinaryExpression extends BaseJSONNode {
type: "JSONBinaryExpression";
operator: "-" | "+" | "*" | "/" | "%" | "**";
left: JSONNumberLiteral | JSONUnaryExpression | JSONBinaryExpression;
right: JSONNumberLiteral | JSONUnaryExpression | JSONBinaryExpression;
parent:
| JSONArrayExpression
| JSONProperty
| JSONExpressionStatement
| JSONUnaryExpression
| JSONBinaryExpression;
}