|
3 | 3 | * These extend the base acorn types with the properties we need to access. |
4 | 4 | */ |
5 | 5 |
|
6 | | -import type { Node, SourceLocation } from "acorn"; |
| 6 | +import type { Node, SourceLocation } from 'acorn'; |
7 | 7 |
|
8 | 8 | export interface BaseNode extends Node { |
9 | 9 | loc: SourceLocation; |
10 | 10 | } |
11 | 11 |
|
12 | 12 | export interface Identifier extends BaseNode { |
13 | | - type: "Identifier"; |
| 13 | + type: 'Identifier'; |
14 | 14 | name: string; |
15 | 15 | } |
16 | 16 |
|
17 | 17 | export interface VariableDeclarator extends BaseNode { |
18 | | - type: "VariableDeclarator"; |
| 18 | + type: 'VariableDeclarator'; |
19 | 19 | id: Identifier | Pattern; |
20 | 20 | init?: Expression; |
21 | 21 | } |
22 | 22 |
|
23 | 23 | export interface VariableDeclaration extends BaseNode { |
24 | | - type: "VariableDeclaration"; |
| 24 | + type: 'VariableDeclaration'; |
25 | 25 | declarations: VariableDeclarator[]; |
26 | | - kind: "const" | "let" | "var"; |
| 26 | + kind: 'const' | 'let' | 'var'; |
27 | 27 | } |
28 | 28 |
|
29 | 29 | export interface BlockStatement extends BaseNode { |
30 | | - type: "BlockStatement"; |
| 30 | + type: 'BlockStatement'; |
31 | 31 | body: Statement[]; |
32 | 32 | } |
33 | 33 |
|
34 | 34 | export interface FunctionDeclaration extends BaseNode { |
35 | | - type: "FunctionDeclaration"; |
| 35 | + type: 'FunctionDeclaration'; |
36 | 36 | id: Identifier | null; |
37 | 37 | params: Pattern[]; |
38 | 38 | body: BlockStatement; |
39 | 39 | } |
40 | 40 |
|
41 | 41 | export interface FunctionExpression extends BaseNode { |
42 | | - type: "FunctionExpression"; |
| 42 | + type: 'FunctionExpression'; |
43 | 43 | id?: Identifier | null; |
44 | 44 | params: Pattern[]; |
45 | 45 | body: BlockStatement; |
46 | 46 | } |
47 | 47 |
|
48 | 48 | export interface ArrowFunctionExpression extends BaseNode { |
49 | | - type: "ArrowFunctionExpression"; |
| 49 | + type: 'ArrowFunctionExpression'; |
50 | 50 | params: Pattern[]; |
51 | 51 | body: BlockStatement | Expression; |
52 | 52 | } |
53 | 53 |
|
54 | 54 | export interface ClassDeclaration extends BaseNode { |
55 | | - type: "ClassDeclaration"; |
| 55 | + type: 'ClassDeclaration'; |
56 | 56 | id: Identifier | null; |
57 | 57 | body: ClassBody; |
58 | 58 | } |
59 | 59 |
|
60 | 60 | export interface ClassExpression extends BaseNode { |
61 | | - type: "ClassExpression"; |
| 61 | + type: 'ClassExpression'; |
62 | 62 | id?: Identifier | null; |
63 | 63 | body: ClassBody; |
64 | 64 | } |
65 | 65 |
|
66 | 66 | export interface ClassBody extends BaseNode { |
67 | | - type: "ClassBody"; |
| 67 | + type: 'ClassBody'; |
68 | 68 | body: MethodDefinition[]; |
69 | 69 | } |
70 | 70 |
|
71 | 71 | export interface MethodDefinition extends BaseNode { |
72 | | - type: "MethodDefinition"; |
| 72 | + type: 'MethodDefinition'; |
73 | 73 | key: Identifier | Expression; |
74 | 74 | value: FunctionExpression; |
75 | | - kind: "constructor" | "method" | "get" | "set"; |
| 75 | + kind: 'constructor' | 'method' | 'get' | 'set'; |
76 | 76 | static: boolean; |
77 | 77 | } |
78 | 78 |
|
79 | 79 | export interface IfStatement extends BaseNode { |
80 | | - type: "IfStatement"; |
| 80 | + type: 'IfStatement'; |
81 | 81 | test: Expression; |
82 | 82 | consequent: Statement; |
83 | 83 | alternate?: Statement | null; |
84 | 84 | } |
85 | 85 |
|
86 | 86 | export interface ForStatement extends BaseNode { |
87 | | - type: "ForStatement"; |
| 87 | + type: 'ForStatement'; |
88 | 88 | init?: VariableDeclaration | Expression | null; |
89 | 89 | test?: Expression | null; |
90 | 90 | update?: Expression | null; |
91 | 91 | body: Statement; |
92 | 92 | } |
93 | 93 |
|
94 | 94 | export interface ForInStatement extends BaseNode { |
95 | | - type: "ForInStatement"; |
| 95 | + type: 'ForInStatement'; |
96 | 96 | left: VariableDeclaration | Pattern; |
97 | 97 | right: Expression; |
98 | 98 | body: Statement; |
99 | 99 | } |
100 | 100 |
|
101 | 101 | export interface ForOfStatement extends BaseNode { |
102 | | - type: "ForOfStatement"; |
| 102 | + type: 'ForOfStatement'; |
103 | 103 | left: VariableDeclaration | Pattern; |
104 | 104 | right: Expression; |
105 | 105 | body: Statement; |
106 | 106 | } |
107 | 107 |
|
108 | 108 | export interface WhileStatement extends BaseNode { |
109 | | - type: "WhileStatement"; |
| 109 | + type: 'WhileStatement'; |
110 | 110 | test: Expression; |
111 | 111 | body: Statement; |
112 | 112 | } |
113 | 113 |
|
114 | 114 | export interface DoWhileStatement extends BaseNode { |
115 | | - type: "DoWhileStatement"; |
| 115 | + type: 'DoWhileStatement'; |
116 | 116 | body: Statement; |
117 | 117 | test: Expression; |
118 | 118 | } |
119 | 119 |
|
120 | 120 | export interface TryStatement extends BaseNode { |
121 | | - type: "TryStatement"; |
| 121 | + type: 'TryStatement'; |
122 | 122 | block: BlockStatement; |
123 | 123 | handler?: CatchClause | null; |
124 | 124 | finalizer?: BlockStatement | null; |
125 | 125 | } |
126 | 126 |
|
127 | 127 | export interface CatchClause extends BaseNode { |
128 | | - type: "CatchClause"; |
| 128 | + type: 'CatchClause'; |
129 | 129 | param?: Pattern | null; |
130 | 130 | body: BlockStatement; |
131 | 131 | } |
132 | 132 |
|
133 | 133 | export interface SwitchStatement extends BaseNode { |
134 | | - type: "SwitchStatement"; |
| 134 | + type: 'SwitchStatement'; |
135 | 135 | discriminant: Expression; |
136 | 136 | cases: SwitchCase[]; |
137 | 137 | } |
138 | 138 |
|
139 | 139 | export interface SwitchCase extends BaseNode { |
140 | | - type: "SwitchCase"; |
| 140 | + type: 'SwitchCase'; |
141 | 141 | test?: Expression | null; |
142 | 142 | consequent: Statement[]; |
143 | 143 | } |
144 | 144 |
|
145 | 145 | export interface WithStatement extends BaseNode { |
146 | | - type: "WithStatement"; |
| 146 | + type: 'WithStatement'; |
147 | 147 | object: Expression; |
148 | 148 | body: Statement; |
149 | 149 | } |
150 | 150 |
|
151 | 151 | export interface NewExpression extends BaseNode { |
152 | | - type: "NewExpression"; |
| 152 | + type: 'NewExpression'; |
153 | 153 | callee: Expression | Identifier; |
154 | 154 | arguments: Expression[]; |
155 | 155 | } |
156 | 156 |
|
157 | 157 | export interface Program extends BaseNode { |
158 | | - type: "Program"; |
| 158 | + type: 'Program'; |
159 | 159 | body: Statement[]; |
160 | | - sourceType: "script" | "module"; |
| 160 | + sourceType: 'script' | 'module'; |
161 | 161 | } |
162 | 162 |
|
163 | 163 | // Union types for categories |
@@ -199,136 +199,131 @@ export type Expression = |
199 | 199 | | ObjectExpression |
200 | 200 | | Literal; |
201 | 201 |
|
202 | | -export type Pattern = |
203 | | - | Identifier |
204 | | - | ObjectPattern |
205 | | - | ArrayPattern |
206 | | - | RestElement |
207 | | - | AssignmentPattern; |
| 202 | +export type Pattern = Identifier | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern; |
208 | 203 |
|
209 | 204 | // Additional types we reference but don't fully define |
210 | 205 | export interface ExpressionStatement extends BaseNode { |
211 | | - type: "ExpressionStatement"; |
| 206 | + type: 'ExpressionStatement'; |
212 | 207 | expression: Expression; |
213 | 208 | } |
214 | 209 |
|
215 | 210 | export interface ReturnStatement extends BaseNode { |
216 | | - type: "ReturnStatement"; |
| 211 | + type: 'ReturnStatement'; |
217 | 212 | argument?: Expression | null; |
218 | 213 | } |
219 | 214 |
|
220 | 215 | export interface ThrowStatement extends BaseNode { |
221 | | - type: "ThrowStatement"; |
| 216 | + type: 'ThrowStatement'; |
222 | 217 | argument: Expression; |
223 | 218 | } |
224 | 219 |
|
225 | 220 | export interface BreakStatement extends BaseNode { |
226 | | - type: "BreakStatement"; |
| 221 | + type: 'BreakStatement'; |
227 | 222 | label?: Identifier | null; |
228 | 223 | } |
229 | 224 |
|
230 | 225 | export interface ContinueStatement extends BaseNode { |
231 | | - type: "ContinueStatement"; |
| 226 | + type: 'ContinueStatement'; |
232 | 227 | label?: Identifier | null; |
233 | 228 | } |
234 | 229 |
|
235 | 230 | export interface CallExpression extends BaseNode { |
236 | | - type: "CallExpression"; |
| 231 | + type: 'CallExpression'; |
237 | 232 | callee: Expression; |
238 | 233 | arguments: Expression[]; |
239 | 234 | } |
240 | 235 |
|
241 | 236 | export interface MemberExpression extends BaseNode { |
242 | | - type: "MemberExpression"; |
| 237 | + type: 'MemberExpression'; |
243 | 238 | object: Expression; |
244 | 239 | property: Expression; |
245 | 240 | computed: boolean; |
246 | 241 | } |
247 | 242 |
|
248 | 243 | export interface AssignmentExpression extends BaseNode { |
249 | | - type: "AssignmentExpression"; |
| 244 | + type: 'AssignmentExpression'; |
250 | 245 | operator: string; |
251 | 246 | left: Pattern | Expression; |
252 | 247 | right: Expression; |
253 | 248 | } |
254 | 249 |
|
255 | 250 | export interface BinaryExpression extends BaseNode { |
256 | | - type: "BinaryExpression"; |
| 251 | + type: 'BinaryExpression'; |
257 | 252 | operator: string; |
258 | 253 | left: Expression; |
259 | 254 | right: Expression; |
260 | 255 | } |
261 | 256 |
|
262 | 257 | export interface UnaryExpression extends BaseNode { |
263 | | - type: "UnaryExpression"; |
| 258 | + type: 'UnaryExpression'; |
264 | 259 | operator: string; |
265 | 260 | argument: Expression; |
266 | 261 | prefix: boolean; |
267 | 262 | } |
268 | 263 |
|
269 | 264 | export interface UpdateExpression extends BaseNode { |
270 | | - type: "UpdateExpression"; |
271 | | - operator: "++" | "--"; |
| 265 | + type: 'UpdateExpression'; |
| 266 | + operator: '++' | '--'; |
272 | 267 | argument: Expression; |
273 | 268 | prefix: boolean; |
274 | 269 | } |
275 | 270 |
|
276 | 271 | export interface LogicalExpression extends BaseNode { |
277 | | - type: "LogicalExpression"; |
278 | | - operator: "||" | "&&" | "??"; |
| 272 | + type: 'LogicalExpression'; |
| 273 | + operator: '||' | '&&' | '??'; |
279 | 274 | left: Expression; |
280 | 275 | right: Expression; |
281 | 276 | } |
282 | 277 |
|
283 | 278 | export interface ConditionalExpression extends BaseNode { |
284 | | - type: "ConditionalExpression"; |
| 279 | + type: 'ConditionalExpression'; |
285 | 280 | test: Expression; |
286 | 281 | consequent: Expression; |
287 | 282 | alternate: Expression; |
288 | 283 | } |
289 | 284 |
|
290 | 285 | export interface ArrayExpression extends BaseNode { |
291 | | - type: "ArrayExpression"; |
| 286 | + type: 'ArrayExpression'; |
292 | 287 | elements: (Expression | null)[]; |
293 | 288 | } |
294 | 289 |
|
295 | 290 | export interface ObjectExpression extends BaseNode { |
296 | | - type: "ObjectExpression"; |
| 291 | + type: 'ObjectExpression'; |
297 | 292 | properties: Property[]; |
298 | 293 | } |
299 | 294 |
|
300 | 295 | export interface Property extends BaseNode { |
301 | | - type: "Property"; |
| 296 | + type: 'Property'; |
302 | 297 | key: Expression; |
303 | 298 | value: Expression; |
304 | | - kind: "init" | "get" | "set"; |
| 299 | + kind: 'init' | 'get' | 'set'; |
305 | 300 | shorthand: boolean; |
306 | 301 | computed: boolean; |
307 | 302 | } |
308 | 303 |
|
309 | 304 | export interface Literal extends BaseNode { |
310 | | - type: "Literal"; |
| 305 | + type: 'Literal'; |
311 | 306 | value: string | number | boolean | null | RegExp; |
312 | 307 | raw: string; |
313 | 308 | } |
314 | 309 |
|
315 | 310 | export interface ObjectPattern extends BaseNode { |
316 | | - type: "ObjectPattern"; |
| 311 | + type: 'ObjectPattern'; |
317 | 312 | properties: Property[]; |
318 | 313 | } |
319 | 314 |
|
320 | 315 | export interface ArrayPattern extends BaseNode { |
321 | | - type: "ArrayPattern"; |
| 316 | + type: 'ArrayPattern'; |
322 | 317 | elements: (Pattern | null)[]; |
323 | 318 | } |
324 | 319 |
|
325 | 320 | export interface RestElement extends BaseNode { |
326 | | - type: "RestElement"; |
| 321 | + type: 'RestElement'; |
327 | 322 | argument: Pattern; |
328 | 323 | } |
329 | 324 |
|
330 | 325 | export interface AssignmentPattern extends BaseNode { |
331 | | - type: "AssignmentPattern"; |
| 326 | + type: 'AssignmentPattern'; |
332 | 327 | left: Pattern; |
333 | 328 | right: Expression; |
334 | 329 | } |
0 commit comments