@samitouri / QOS-React-2 / commits / 0c1193ecd7

[rust] estree codegen for improved serialization

This is meant to replace the initial `estree` crate with a version that is generated from a JSON description of ESTree. The idea is to make it easy to experiment with slightly different representations to balance ergonomic usage of the data at runtime with serialization compatible with ESTree spec. The JSON schema looks like this (somewhat abbreviated): ``` { // Objects are struct types that don't have a `type` and can't appear as an enum variant objects: { Position: { line: {type: "NonZeroU32"}, column: {type: "u32"} }, ... }, // Nodes are struct types with a `type` and which can appear as enum variants (statements, expressions, patterns, etc) nodes: { ArrayExpression: { elements: { type: "Expression", plural: true, nullable_item: true, } } ... }, // Categories of nodes with multiple variants, represented as enums. // Can be recursive, eg ForInit can be VariableDeclaration or Expression, // where Expression is also an enum enums: { Expression: [ "ArrayExpression", ... ] }, // Simple enums which have a corresponding string value. Used primarily for operators (binary/unary/logical/etc) // but also for things like variable declaration kind (var/const/let) operators: { BinaryOperator: { Plus: "+", Instanceof: "instanceof", } } } ``` The core estree files are now generated using Cargo's build script mechanism. Right now i only defined the types and fields from ES5, so i'll have to flush out the rest of the modern JS spec and extensions like JSX, TypeScript, and Flow. But already the for-statement example works, showing that this approach can handle complex cases such as unions of types or other unions (ForStatement initializer is tricky bc it can be a VariableDeclaration or an Expression - that works now!). This is still WIP a bit - now that the ESTree definition is more precise i can go back and clean up some other code (have to, because the swc -> estree conversion needs some tweaks now).

Joe Savona committed Jul 8, 2023 at 22:59 UTC 0c1193ecd7a1712e0097e075fcddb7f4c4fb2a8a
20 files changed +3496 -6586
compiler/forget/Cargo.lock
+28 -4
@@ -461,12 +461,25 @@ version = "0.1.0"
461 dependencies = [
462 "bumpalo",
463 "elsa",
464 + "estree-codegen",
465 "insta",
466 "serde",
467 "serde_json",
468 "static_assertions",
469 ]
470
471 +[[package]]
472 +name = "estree-codegen"
473 +version = "0.1.0"
474 +dependencies = [
475 + "indexmap 2.0.0",
476 + "prettyplease",
477 + "quote",
478 + "serde",
479 + "serde_json",
480 + "syn 2.0.23",
481 +]
482 +
483 [[package]]
484 name = "estree-swc"
485 version = "0.1.0"
@@ -683,6 +696,7 @@ checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
696 dependencies = [
697 "equivalent",
698 "hashbrown 0.14.0",
699 + "serde",
700 ]
701
702 [[package]]
@@ -1219,6 +1233,16 @@ dependencies = [
1233 "tracing",
1234 ]
1235
1236 +[[package]]
1237 +name = "prettyplease"
1238 +version = "0.2.10"
1239 +source = "registry+https://github.com/rust-lang/crates.io-index"
1240 +checksum = "92139198957b410250d43fad93e630d956499a625c527eda65175c8680f83387"
1241 +dependencies = [
1242 + "proc-macro2",
1243 + "syn 2.0.23",
1244 +]
1245 +
1246 [[package]]
1247 name = "proc-macro-error"
1248 version = "1.0.4"
@@ -1460,9 +1484,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
1484
1485 [[package]]
1486 name = "serde"
1463 -version = "1.0.166"
1487 +version = "1.0.167"
1488 source = "registry+https://github.com/rust-lang/crates.io-index"
1465 -checksum = "d01b7404f9d441d3ad40e6a636a7782c377d2abdbe4fa2440e2edcc2f4f10db8"
1489 +checksum = "7daf513456463b42aa1d94cff7e0c24d682b429f020b9afa4f5ba5c40a22b237"
1490 dependencies = [
1491 "serde_derive",
1492 ]
@@ -1480,9 +1504,9 @@ dependencies = [
1504
1505 [[package]]
1506 name = "serde_derive"
1483 -version = "1.0.166"
1507 +version = "1.0.167"
1508 source = "registry+https://github.com/rust-lang/crates.io-index"
1485 -checksum = "5dd83d6dde2b6b2d466e14d9d1acce8816dedee94f735eac6395808b3483c6d6"
1509 +checksum = "b69b106b68bc8054f0e974e70d19984040f8a5cf9215ca82626ea4853f82c4b9"
1510 dependencies = [
1511 "proc-macro2",
1512 "quote",
compiler/forget/Cargo.toml
+1
@@ -6,6 +6,7 @@ members = [
6 "crates/hir",
7 "crates/swc-demo",
8 "crates/estree",
9 + "crates/estree-codegen",
10 "crates/estree-swc",
11 ]
12
compiler/forget/crates/estree-codegen/Cargo.toml new
+14
@@ -0,0 +1,14 @@
1 +[package]
2 +name = "estree-codegen"
3 +version = "0.1.0"
4 +edition = "2021"
5 +
6 +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 +
8 +[dependencies]
9 +indexmap = { version = "2.0.0", features = ["serde"] }
10 +prettyplease = "0.2.10"
11 +quote = "1.0.29"
12 +serde = { version = "1.0.167", features = ["serde_derive"] }
13 +serde_json = "1.0.100"
14 +syn = "2.0.23"
compiler/forget/crates/estree-codegen/src/codegen.rs new
+416
@@ -0,0 +1,416 @@
1 +use std::collections::HashSet;
2 +
3 +use indexmap::IndexMap;
4 +use quote::{__private::TokenStream, format_ident, quote};
5 +use serde::{Deserialize, Serialize};
6 +
7 +/// Returns prettyplease-formatted Rust source for estree
8 +pub fn estree() -> String {
9 + let src = include_str!("./ecmascript.json");
10 + let grammar: Grammar = serde_json::from_str(src).unwrap();
11 + let raw = grammar.codegen().to_string();
12 +
13 + let parsed = syn::parse_file(&raw).unwrap();
14 + prettyplease::unparse(&parsed)
15 +}
16 +
17 +#[derive(Serialize, Deserialize, Debug)]
18 +pub struct Grammar {
19 + pub objects: IndexMap<String, Object>,
20 + pub nodes: IndexMap<String, Node>,
21 + pub enums: IndexMap<String, Enum>,
22 + pub operators: IndexMap<String, Operator>,
23 +}
24 +
25 +impl Grammar {
26 + pub fn codegen(self) -> TokenStream {
27 + let Self {
28 + objects,
29 + nodes,
30 + enums,
31 + operators,
32 + } = self;
33 +
34 + let nodelike: HashSet<String> =
35 + // nodes.keys().cloned().chain(enums.keys().cloned()).collect();
36 + Default::default();
37 +
38 + let enum_names: HashSet<String> = enums.keys().cloned().collect();
39 +
40 + let mut node_names: Vec<_> = nodes.keys().cloned().collect();
41 + node_names.sort();
42 + let node_variants: Vec<_> = node_names
43 + .iter()
44 + .map(|name| {
45 + let name = format_ident!("{}", name);
46 + quote!(#name(Box<#name>))
47 + })
48 + .collect();
49 +
50 + let objects: Vec<_> = objects
51 + .iter()
52 + .map(|(name, object)| object.codegen(name, &nodelike))
53 + .collect();
54 + let nodes: Vec<_> = nodes
55 + .iter()
56 + .map(|(name, node)| node.codegen(name, &nodelike))
57 + .collect();
58 + let enums: Vec<_> = enums
59 + .iter()
60 + .map(|(name, enum_)| enum_.codegen(name, &enum_names))
61 + .collect();
62 + let operators: Vec<_> = operators
63 + .iter()
64 + .map(|(name, operator)| operator.codegen(name))
65 + .collect();
66 +
67 + quote! {
68 + use std::num::NonZeroU32;
69 + use serde::{Serialize, Deserialize};
70 + use crate::{JsValue, Binding, SourceRange};
71 +
72 + #(#objects)*
73 +
74 + #(#nodes)*
75 +
76 + #(#enums)*
77 +
78 + #(#operators)*
79 +
80 + // #[derive(Serialize, Deserialize, Clone, Debug)]
81 + // #[serde(tag = "type")]
82 + // pub enum Node {
83 + // #(#node_variants),*
84 + // }
85 + }
86 + }
87 +}
88 +
89 +#[derive(Serialize, Deserialize, Debug)]
90 +pub struct Object {
91 + #[serde(default)]
92 + pub fields: IndexMap<String, Field>,
93 +}
94 +
95 +impl Object {
96 + pub fn codegen(&self, name: &str, nodes: &HashSet<String>) -> TokenStream {
97 + let name = format_ident!("{}", name);
98 + let fields: Vec<_> = self
99 + .fields
100 + .iter()
101 + .map(|(name, field)| field.codegen(name, nodes))
102 + .collect();
103 +
104 + quote! {
105 + #[derive(Serialize, Deserialize, Clone, Debug)]
106 + pub struct #name {
107 + #(#fields),*
108 + }
109 + }
110 + }
111 +}
112 +
113 +#[derive(Serialize, Deserialize, Debug)]
114 +pub struct Node {
115 + #[serde(default)]
116 + pub fields: IndexMap<String, Field>,
117 +}
118 +
119 +impl Node {
120 + pub fn codegen(&self, name: &str, nodes: &HashSet<String>) -> TokenStream {
121 + let name = format_ident!("{}", name);
122 + let fields: Vec<_> = self
123 + .fields
124 + .iter()
125 + .map(|(name, field)| field.codegen_node(name, nodes))
126 + .collect();
127 +
128 + quote! {
129 + #[derive(Serialize, Deserialize, Clone, Debug)]
130 + pub struct #name {
131 + #(#fields,)*
132 +
133 + #[serde(default)]
134 + pub loc: Option<SourceLocation>,
135 +
136 + #[serde(default)]
137 + pub range: Option<SourceRange>,
138 + }
139 +
140 + // impl #name {
141 + // pub fn from_node(node: Node) -> Option<Box<Self>> {
142 + // match node {
143 + // Node::#name(node) => Some(node),
144 + // _ => None
145 + // }
146 + // }
147 + // }
148 + }
149 + }
150 +}
151 +
152 +#[derive(Serialize, Deserialize, Debug)]
153 +pub struct Field {
154 + #[serde(rename = "type")]
155 + pub type_: String,
156 +
157 + #[serde(default)]
158 + pub nullable: bool,
159 +
160 + #[serde(default)]
161 + pub optional: bool,
162 +
163 + #[serde(default)]
164 + pub plural: bool,
165 +
166 + #[serde(default)]
167 + pub nullable_item: bool,
168 +
169 + #[serde(default)]
170 + pub flatten: bool,
171 +}
172 +
173 +impl Field {
174 + pub fn codegen(&self, name: &str, nodes: &HashSet<String>) -> TokenStream {
175 + let name = format_ident!("{}", name);
176 + let type_name = format_ident!(
177 + "{}",
178 + if nodes.contains(&self.type_) {
179 + "Node"
180 + } else {
181 + &self.type_
182 + }
183 + );
184 + let mut type_ = quote!(#type_name);
185 + if self.plural {
186 + if self.nullable_item {
187 + type_ = quote!(Option<#type_>);
188 + }
189 + type_ = quote! { Vec<#type_> };
190 + } else {
191 + assert_eq!(
192 + self.nullable_item, false,
193 + "Can only set nullable_item if plural"
194 + )
195 + }
196 + if self.nullable || self.optional {
197 + assert_eq!(
198 + self.optional, false,
199 + "Expected field to be nullable if optional"
200 + );
201 + type_ = quote!(Option<#type_>);
202 + }
203 + let mut field = quote!(#name: #type_);
204 + if self.optional {
205 + field = quote! {
206 + #[serde(default)]
207 + #field
208 + }
209 + }
210 + if self.flatten {
211 + field = quote! {
212 + #[serde(flatten)]
213 + #field
214 + }
215 + }
216 + field
217 + }
218 +
219 + pub fn codegen_node(&self, name: &str, nodes: &HashSet<String>) -> TokenStream {
220 + let name = format_ident!("{}", name);
221 + let type_name = format_ident!(
222 + "{}",
223 + if nodes.contains(&self.type_) {
224 + "Node"
225 + } else {
226 + &self.type_
227 + }
228 + );
229 + let mut type_ = quote!(#type_name);
230 + if self.plural {
231 + if self.nullable_item {
232 + type_ = quote!(Option<#type_>);
233 + }
234 + type_ = quote! { Vec<#type_> };
235 + } else {
236 + assert_eq!(
237 + self.nullable_item, false,
238 + "Can only set nullable_item if plural"
239 + )
240 + }
241 + if self.nullable || self.optional {
242 + assert_eq!(
243 + self.nullable, true,
244 + "Expected field to be nullable if optional"
245 + );
246 + type_ = quote!(Option<#type_>);
247 + }
248 + let mut field = quote!(#name: #type_);
249 + if self.optional {
250 + field = quote! {
251 + #[serde(default)]
252 + #field
253 + }
254 + }
255 + if self.flatten {
256 + field = quote! {
257 + #[serde(flatten)]
258 + #field
259 + }
260 + }
261 + if nodes.contains(&self.type_) {
262 + let comment = format!(" {}", &self.type_);
263 + field = quote! {
264 + #[doc = #comment]
265 + #field
266 + }
267 + }
268 + field
269 + }
270 +}
271 +
272 +#[derive(Serialize, Deserialize, Debug)]
273 +#[serde(transparent)]
274 +pub struct Enum {
275 + pub variants: Vec<String>,
276 +}
277 +
278 +impl Enum {
279 + pub fn codegen(&self, name: &str, enums: &HashSet<String>) -> TokenStream {
280 + let mut sorted_variants: Vec<_> = self.variants.iter().collect();
281 + sorted_variants.sort();
282 +
283 + let name = format_ident!("{}", name);
284 + let variants: Vec<_> = sorted_variants
285 + .iter()
286 + .map(|name| {
287 + let variant = format_ident!("{}", name);
288 + if enums.contains(*name) {
289 + quote!(#variant(#variant))
290 + } else {
291 + quote!(#variant(Box<#variant>))
292 + }
293 + })
294 + .collect();
295 +
296 + let from_node_matches: Vec<_> = sorted_variants
297 + .iter()
298 + .map(|name| {
299 + let variant = format_ident!("{}", name);
300 + if enums.contains(*name) {
301 + quote! {
302 + if let Some(node) = #variant::from_node(node) {
303 + return Some(Self::#variant(node));
304 + }
305 + }
306 + } else {
307 + quote! {
308 + if let Some(node) = #variant::from_node(node) {
309 + return Some(Self::#variant(node));
310 + }
311 + }
312 + }
313 + })
314 + .collect();
315 +
316 + let enum_ = quote! {
317 + pub enum #name {
318 + #(#variants),*
319 + }
320 + };
321 + let enum_ = if sorted_variants.iter().any(|name| enums.contains(*name)) {
322 + // contains recursive enum, use untagged serialization
323 + quote! {
324 + #[serde(untagged)]
325 + #enum_
326 + }
327 + } else {
328 + quote! {
329 + #[serde(tag = "type")]
330 + #enum_
331 + }
332 + };
333 +
334 + quote! {
335 + #[derive(Serialize, Deserialize, Clone, Debug)]
336 + #enum_
337 +
338 + // impl #name {
339 + // pub fn from_node(node: Node) -> Option<Self> {
340 + // #(#from_node_matches)*
341 + // None
342 + // }
343 + // }
344 + }
345 + }
346 +}
347 +
348 +#[derive(Serialize, Deserialize, Debug)]
349 +#[serde(transparent)]
350 +pub struct Operator {
351 + pub variants: IndexMap<String, String>,
352 +}
353 +
354 +impl Operator {
355 + pub fn codegen(&self, name: &str) -> TokenStream {
356 + let mut sorted_variants: Vec<_> = self.variants.iter().collect();
357 + sorted_variants.sort();
358 +
359 + let name = format_ident!("{}", name);
360 + let variants: Vec<_> = sorted_variants
361 + .iter()
362 + .map(|(name, operator)| {
363 + let name = format_ident!("{}", name);
364 + let comment = format!(" {}", &operator);
365 + quote! {
366 + #[doc = #comment]
367 + #[serde(rename = #operator)]
368 + #name
369 + }
370 + })
371 + .collect();
372 +
373 + let display_matches: Vec<_> = sorted_variants
374 + .iter()
375 + .map(|(name, operator)| {
376 + let name = format_ident!("{}", name);
377 + quote!(Self::#name => #operator)
378 + })
379 + .collect();
380 +
381 + let fromstr_matches: Vec<_> = sorted_variants
382 + .iter()
383 + .map(|(name, operator)| {
384 + let name = format_ident!("{}", name);
385 + quote!(#operator => Ok(Self::#name))
386 + })
387 + .collect();
388 +
389 + quote! {
390 + #[derive(Serialize, Deserialize, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
391 + pub enum #name {
392 + #(#variants),*
393 + }
394 +
395 + impl std::fmt::Display for #name {
396 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
397 + let name = match self {
398 + #(#display_matches),*
399 + };
400 + f.write_str(name)
401 + }
402 + }
403 +
404 + impl std::str::FromStr for #name {
405 + type Err = ();
406 +
407 + fn from_str(s: &str) -> Result<Self, Self::Err> {
408 + match s {
409 + #(#fromstr_matches,)*
410 + _ => Err(()),
411 + }
412 + }
413 + }
414 + }
415 + }
416 +}
compiler/forget/crates/estree-codegen/src/ecmascript.json new
+596
@@ -0,0 +1,596 @@
1 +{
2 + "objects": {
3 + "SourceLocation": {
4 + "fields": {
5 + "source": {
6 + "type": "String",
7 + "nullable": true
8 + },
9 + "start": {
10 + "type": "Position"
11 + },
12 + "end": {
13 + "type": "Position"
14 + }
15 + }
16 + },
17 + "Position": {
18 + "fields": {
19 + "line": {
20 + "type": "NonZeroU32"
21 + },
22 + "column": {
23 + "type": "u32"
24 + }
25 + }
26 + },
27 + "Function": {
28 + "fields": {
29 + "id": {
30 + "type": "Identifier",
31 + "nullable": true
32 + },
33 + "params": {
34 + "type": "Pattern",
35 + "plural": true
36 + },
37 + "body": {
38 + "type": "BlockStatement",
39 + "nullable": true
40 + }
41 + }
42 + },
43 + "RegExpValue": {
44 + "fields": {
45 + "pattern": {
46 + "type": "String"
47 + },
48 + "flags": {
49 + "type": "String"
50 + }
51 + }
52 + }
53 + },
54 + "nodes": {
55 + "Identifier": {
56 + "fields": {
57 + "name": {
58 + "type": "String"
59 + },
60 + "binding": {
61 + "type": "Binding",
62 + "nullable": true,
63 + "optional": true,
64 + "skip": true
65 + }
66 + }
67 + },
68 + "Literal": {
69 + "fields": {
70 + "value": {
71 + "type": "JsValue"
72 + },
73 + "raw": {
74 + "type": "String",
75 + "nullable": true,
76 + "optional": true
77 + },
78 + "regex": {
79 + "type": "RegExpValue",
80 + "nullable": true,
81 + "optional": true
82 + }
83 + }
84 + },
85 + "Program": {
86 + "fields": {
87 + "body": {
88 + "type": "Statement",
89 + "plural": true
90 + }
91 + }
92 + },
93 + "ExpressionStatement": {
94 + "fields": {
95 + "expression": {
96 + "type": "Expression"
97 + }
98 + }
99 + },
100 + "BlockStatement": {
101 + "fields": {
102 + "body": {
103 + "type": "Statement",
104 + "plural": true
105 + }
106 + }
107 + },
108 + "EmptyStatement": {},
109 + "DebuggerStatement": {},
110 + "WithStatement": {
111 + "fields": {
112 + "object": {
113 + "type": "Expression"
114 + },
115 + "body": {
116 + "type": "Statement"
117 + }
118 + }
119 + },
120 + "ReturnStatement": {
121 + "fields": {
122 + "argument": {
123 + "type": "Expression",
124 + "nullable": true
125 + }
126 + }
127 + },
128 + "LabeledStatement": {
129 + "fields": {
130 + "label": {
131 + "type": "Identifier"
132 + },
133 + "body": {
134 + "type": "Statement"
135 + }
136 + }
137 + },
138 + "BreakStatement": {
139 + "fields": {
140 + "label": {
141 + "type": "Identifier",
142 + "nullable": true
143 + }
144 + }
145 + },
146 + "ContinueStatement": {
147 + "fields": {
148 + "label": {
149 + "type": "Identifier",
150 + "nullable": true
151 + }
152 + }
153 + },
154 + "IfStatement": {
155 + "fields": {
156 + "test": {
157 + "type": "Expression"
158 + },
159 + "consequent": {
160 + "type": "Statement"
161 + },
162 + "alternate": {
163 + "type": "Statement",
164 + "nullable": true
165 + }
166 + }
167 + },
168 + "SwitchStatement": {
169 + "fields": {
170 + "discriminant": {
171 + "type": "Expression"
172 + },
173 + "cases": {
174 + "type": "SwitchCase",
175 + "plural": true
176 + }
177 + }
178 + },
179 + "SwitchCase": {
180 + "fields": {
181 + "test": {
182 + "type": "Expression",
183 + "nullable": true
184 + },
185 + "consequent": {
186 + "type": "Statement",
187 + "plural": true
188 + }
189 + }
190 + },
191 + "ThrowStatement": {
192 + "fields": {
193 + "argument": {
194 + "type": "Expression"
195 + }
196 + }
197 + },
198 + "TryStatement": {
199 + "fields": {
200 + "block": {
201 + "type": "BlockStatement"
202 + },
203 + "handler": {
204 + "type": "CatchClause",
205 + "nullable": true
206 + },
207 + "finalizer": {
208 + "type": "BlockStatement",
209 + "nullable": true
210 + }
211 + }
212 + },
213 + "CatchClause": {
214 + "fields": {
215 + "param": {
216 + "type": "Pattern"
217 + },
218 + "body": {
219 + "type": "BlockStatement"
220 + }
221 + }
222 + },
223 + "WhileStatement": {
224 + "fields": {
225 + "test": {
226 + "type": "Expression"
227 + },
228 + "body": {
229 + "type": "Statement"
230 + }
231 + }
232 + },
233 + "DoWhileStatement": {
234 + "fields": {
235 + "body": {
236 + "type": "Statement"
237 + },
238 + "test": {
239 + "type": "Expression"
240 + }
241 + }
242 + },
243 + "ForStatement": {
244 + "fields": {
245 + "init": {
246 + "type": "ForInit",
247 + "nullable": true
248 + },
249 + "test": {
250 + "type": "Expression",
251 + "nullable": true
252 + },
253 + "update": {
254 + "type": "Expression",
255 + "nullable": true
256 + },
257 + "body": {
258 + "type": "Statement"
259 + }
260 + }
261 + },
262 + "ForInStatement": {
263 + "fields": {
264 + "left": {
265 + "type": "ForInInit"
266 + },
267 + "right": {
268 + "type": "Expression"
269 + },
270 + "body": {
271 + "type": "Statement"
272 + }
273 + }
274 + },
275 + "FunctionDeclaration": {
276 + "fields": {
277 + "function": {
278 + "type": "Function",
279 + "flatten": true
280 + }
281 + }
282 + },
283 + "VariableDeclaration": {
284 + "fields": {
285 + "kind": {
286 + "type": "VariableDeclarationKind"
287 + },
288 + "declarations": {
289 + "type": "VariableDeclarator",
290 + "plural": true
291 + }
292 + }
293 + },
294 + "VariableDeclarator": {
295 + "fields": {
296 + "id": {
297 + "type": "Pattern"
298 + },
299 + "init": {
300 + "type": "Expression",
301 + "nullable": true
302 + }
303 + }
304 + },
305 + "ThisExpression": {},
306 + "ArrayExpression": {
307 + "fields": {
308 + "elements": {
309 + "type": "Expression",
310 + "plural": true,
311 + "nullable_item": true
312 + }
313 + }
314 + },
315 + "ObjectExpression": {
316 + "fields": {
317 + "properties": {
318 + "type": "Property",
319 + "plural": true
320 + }
321 + }
322 + },
323 + "Property": {
324 + "fields": {
325 + "key": {
326 + "type": "PropertyKey"
327 + },
328 + "value": {
329 + "type": "Expression"
330 + },
331 + "kind": {
332 + "type": "PropertyKind"
333 + }
334 + }
335 + },
336 + "FunctionExpression": {
337 + "fields": {
338 + "function": {
339 + "type": "Function",
340 + "flatten": true
341 + }
342 + }
343 + },
344 + "UnaryExpression": {
345 + "fields": {
346 + "operator": {
347 + "type": "UnaryOperator"
348 + },
349 + "prefix": {
350 + "type": "bool"
351 + },
352 + "argument": {
353 + "type": "Expression"
354 + }
355 + }
356 + },
357 + "UpdateExpression": {
358 + "fields": {
359 + "operator": {
360 + "type": "UpdateOperator"
361 + },
362 + "argument": {
363 + "type": "Expression"
364 + },
365 + "prefix": {
366 + "type": "bool"
367 + }
368 + }
369 + },
370 + "BinaryExpression": {
371 + "fields": {
372 + "left": {
373 + "type": "Expression"
374 + },
375 + "operator": {
376 + "type": "BinaryOperator"
377 + },
378 + "right": {
379 + "type": "Expression"
380 + }
381 + }
382 + },
383 + "AssignmentExpression": {
384 + "fields": {
385 + "operator": {
386 + "type": "AssignmentOperator"
387 + },
388 + "left": {
389 + "type": "AssignmentTarget"
390 + },
391 + "right": {
392 + "type": "Expression"
393 + }
394 + }
395 + },
396 + "LogicalExpression": {
397 + "fields": {
398 + "operator": {
399 + "type": "LogicalOperator"
400 + },
401 + "left": {
402 + "type": "Expression"
403 + },
404 + "right": {
405 + "type": "Expression"
406 + }
407 + }
408 + },
409 + "MemberExpression": {
410 + "fields": {
411 + "object": {
412 + "type": "Expression"
413 + },
414 + "property": {
415 + "type": "Expression"
416 + },
417 + "computed": {
418 + "type": "bool"
419 + }
420 + }
421 + },
422 + "ConditionalExpression": {
423 + "fields": {
424 + "test": {
425 + "type": "Expression"
426 + },
427 + "alternate": {
428 + "type": "Expression"
429 + },
430 + "consequent": {
431 + "type": "Expression"
432 + }
433 + }
434 + },
435 + "CallExpression": {
436 + "type": true,
437 + "fields": {
438 + "callee": {
439 + "type": "Expression"
440 + },
441 + "arguments": {
442 + "type": "Expression",
443 + "plural": true
444 + }
445 + }
446 + },
447 + "NewExpression": {
448 + "type": true,
449 + "fields": {
450 + "callee": {
451 + "type": "Expression"
452 + },
453 + "arguments": {
454 + "type": "Expression",
455 + "plural": true
456 + }
457 + }
458 + },
459 + "SequenceExpression": {
460 + "type": true,
461 + "fields": {
462 + "expressions": {
463 + "type": "Expression",
464 + "plural": true
465 + }
466 + }
467 + }
468 + },
469 + "enums": {
470 + "Statement": [
471 + "BlockStatement",
472 + "BreakStatement",
473 + "ContinueStatement",
474 + "DebuggerStatement",
475 + "DoWhileStatement",
476 + "EmptyStatement",
477 + "ExpressionStatement",
478 + "ForInStatement",
479 + "ForStatement",
480 + "FunctionDeclaration",
481 + "IfStatement",
482 + "LabeledStatement",
483 + "ReturnStatement",
484 + "SwitchStatement",
485 + "ThrowStatement",
486 + "TryStatement",
487 + "VariableDeclaration",
488 + "WhileStatement",
489 + "WithStatement"
490 + ],
491 + "Expression": [
492 + "ArrayExpression",
493 + "AssignmentExpression",
494 + "BinaryExpression",
495 + "CallExpression",
496 + "ConditionalExpression",
497 + "FunctionExpression",
498 + "Identifier",
499 + "Literal",
500 + "LogicalExpression",
501 + "MemberExpression",
502 + "NewExpression",
503 + "ObjectExpression",
504 + "SequenceExpression",
505 + "ThisExpression",
506 + "UnaryExpression",
507 + "UpdateExpression"
508 + ],
509 + "Pattern": [
510 + "Identifier"
511 + ],
512 + "ForInit": [
513 + "Expression",
514 + "VariableDeclaration"
515 + ],
516 + "ForInInit": [
517 + "Pattern",
518 + "VariableDeclaration"
519 + ],
520 + "PropertyKey": [
521 + "Identifier",
522 + "Literal"
523 + ],
524 + "AssignmentTarget": [
525 + "Expression",
526 + "Pattern"
527 + ]
528 + },
529 + "operators": {
530 + "VariableDeclarationKind": {
531 + "Const": "const",
532 + "Let": "let",
533 + "Var": "var"
534 + },
535 + "PropertyKind": {
536 + "Get": "get",
537 + "Init": "init",
538 + "Set": "set"
539 + },
540 + "UnaryOperator": {
541 + "Delete": "delete",
542 + "Minus": "-",
543 + "Negation": "!",
544 + "Plus": "+",
545 + "Tilde": "~",
546 + "Typeof": "typeof",
547 + "Void": "void"
548 + },
549 + "UpdateOperator": {
550 + "Decrement": "--",
551 + "Increment": "++"
552 + },
553 + "BinaryOperator": {
554 + "Add": "+",
555 + "BinaryAnd": "&",
556 + "BinaryOr": "|",
557 + "BinaryXor": "^",
558 + "Divide": "/",
559 + "Equals": "==",
560 + "GreaterThan": ">",
561 + "GreaterThanOrEqual": ">=",
562 + "In": "in",
563 + "Instanceof": "instanceof",
564 + "LessThan": "<",
565 + "LessThanOrEqual": "<=",
566 + "Modulo": "%",
567 + "Multiply": "*",
568 + "NotEquals": "!=",
569 + "NotStrictEquals": "!==",
570 + "ShiftLeft": "<<",
571 + "ShiftRight": ">>",
572 + "StrictEquals": "===",
573 + "Subtract": "-",
574 + "UnsignedShiftRight": ">>>"
575 + },
576 + "AssignmentOperator": {
577 + "BinaryAndEquals": "&=",
578 + "BinaryOrEquals": "|=",
579 + "BinaryXorEquals": "^=",
580 + "DivideEquals": "/=",
581 + "Equals": "=",
582 + "MinusEquals": "-=",
583 + "ModuloEquals": "%=",
584 + "MultiplyEquals": "*=",
585 + "PlusEquals": "+=",
586 + "ShiftLeftEquals": "<<=",
587 + "ShiftRightEquals": ">>=",
588 + "UnsignedShiftRightEquals": ">>>="
589 + },
590 + "LogicalOperator": {
591 + "And": "&&",
592 + "NullCoalescing": "??",
593 + "Or": "||"
594 + }
595 + }
596 +}
\ No newline at end of file
compiler/forget/crates/estree-codegen/src/lib.rs new
+3
@@ -0,0 +1,3 @@
1 +mod codegen;
2 +
3 +pub use codegen::estree;
compiler/forget/crates/estree/Cargo.toml
+3
@@ -12,3 +12,6 @@ insta = { version = "1.30.0", features = ["glob"] }
12 serde = { version = "1.0.164", features = ["derive"] }
13 serde_json = "1.0.99"
14 static_assertions = "1.1.0"
15 +
16 +[build-dependencies]
17 +estree-codegen = { path = "../estree-codegen" }
\ No newline at end of file
compiler/forget/crates/estree/build.rs new
+13
@@ -0,0 +1,13 @@
1 +use estree_codegen::estree;
2 +
3 +// Example custom build script.
4 +fn main() {
5 + // Re-run if the codegen files change
6 + println!("cargo:rerun-if-changed=../estree-codegen/src/codegen.rs");
7 + println!("cargo:rerun-if-changed=../estree-codegen/src/lib.rs");
8 + println!("cargo:rerun-if-changed=../estree-codegen/src/ecmascript.json");
9 + println!("cargo:rerun-if-changed=../estree-codegen");
10 +
11 + let src = estree();
12 + std::fs::write("src/generated.rs", src).unwrap();
13 +}
compiler/forget/crates/estree/src/binding.rs new
+4
@@ -0,0 +1,4 @@
1 +use serde::{Deserialize, Serialize};
2 +
3 +#[derive(Serialize, Deserialize, Clone, Debug)]
4 +pub struct Binding;
compiler/forget/crates/estree/src/for-statement.json deleted
-528
@@ -1,528 +0,0 @@
1 -{
2 - "type": "Program",
3 - "loc": {
4 - "source": null,
5 - "start": {
6 - "line": 1,
7 - "column": 0
8 - },
9 - "end": {
10 - "line": 7,
11 - "column": 1
12 - }
13 - },
14 - "body": [
15 - {
16 - "type": "FunctionDeclaration",
17 - "loc": {
18 - "source": null,
19 - "start": {
20 - "line": 1,
21 - "column": 0
22 - },
23 - "end": {
24 - "line": 7,
25 - "column": 1
26 - }
27 - },
28 - "id": {
29 - "type": "Identifier",
30 - "loc": {
31 - "source": null,
32 - "start": {
33 - "line": 1,
34 - "column": 9
35 - },
36 - "end": {
37 - "line": 1,
38 - "column": 18
39 - }
40 - },
41 - "name": "Component",
42 - "typeAnnotation": null,
43 - "optional": false,
44 - "range": [
45 - 9,
46 - 18
47 - ]
48 - },
49 - "params": [
50 - {
51 - "type": "Identifier",
52 - "loc": {
53 - "source": null,
54 - "start": {
55 - "line": 1,
56 - "column": 19
57 - },
58 - "end": {
59 - "line": 1,
60 - "column": 24
61 - }
62 - },
63 - "name": "props",
64 - "typeAnnotation": null,
65 - "optional": false,
66 - "range": [
67 - 19,
68 - 24
69 - ]
70 - }
71 - ],
72 - "body": {
73 - "type": "BlockStatement",
74 - "loc": {
75 - "source": null,
76 - "start": {
77 - "line": 1,
78 - "column": 26
79 - },
80 - "end": {
81 - "line": 7,
82 - "column": 1
83 - }
84 - },
85 - "body": [
86 - {
87 - "type": "VariableDeclaration",
88 - "loc": {
89 - "source": null,
90 - "start": {
91 - "line": 2,
92 - "column": 2
93 - },
94 - "end": {
95 - "line": 2,
96 - "column": 12
97 - }
98 - },
99 - "kind": "let",
100 - "declarations": [
101 - {
102 - "type": "VariableDeclarator",
103 - "loc": {
104 - "source": null,
105 - "start": {
106 - "line": 2,
107 - "column": 6
108 - },
109 - "end": {
110 - "line": 2,
111 - "column": 11
112 - }
113 - },
114 - "init": {
115 - "type": "Literal",
116 - "loc": {
117 - "source": null,
118 - "start": {
119 - "line": 2,
120 - "column": 10
121 - },
122 - "end": {
123 - "line": 2,
124 - "column": 11
125 - }
126 - },
127 - "value": 0,
128 - "range": [
129 - 38,
130 - 39
131 - ],
132 - "raw": "0"
133 - },
134 - "id": {
135 - "type": "Identifier",
136 - "loc": {
137 - "source": null,
138 - "start": {
139 - "line": 2,
140 - "column": 6
141 - },
142 - "end": {
143 - "line": 2,
144 - "column": 7
145 - }
146 - },
147 - "name": "x",
148 - "typeAnnotation": null,
149 - "optional": false,
150 - "range": [
151 - 34,
152 - 35
153 - ]
154 - },
155 - "range": [
156 - 34,
157 - 39
158 - ]
159 - }
160 - ],
161 - "range": [
162 - 30,
163 - 40
164 - ]
165 - },
166 - {
167 - "type": "ForStatement",
168 - "loc": {
169 - "source": null,
170 - "start": {
171 - "line": 3,
172 - "column": 2
173 - },
174 - "end": {
175 - "line": 5,
176 - "column": 3
177 - }
178 - },
179 - "init": {
180 - "type": "VariableDeclaration",
181 - "loc": {
182 - "source": null,
183 - "start": {
184 - "line": 3,
185 - "column": 7
186 - },
187 - "end": {
188 - "line": 3,
189 - "column": 16
190 - }
191 - },
192 - "kind": "let",
193 - "declarations": [
194 - {
195 - "type": "VariableDeclarator",
196 - "loc": {
197 - "source": null,
198 - "start": {
199 - "line": 3,
200 - "column": 11
201 - },
202 - "end": {
203 - "line": 3,
204 - "column": 16
205 - }
206 - },
207 - "init": {
208 - "type": "Literal",
209 - "loc": {
210 - "source": null,
211 - "start": {
212 - "line": 3,
213 - "column": 15
214 - },
215 - "end": {
216 - "line": 3,
217 - "column": 16
218 - }
219 - },
220 - "value": 0,
221 - "range": [
222 - 56,
223 - 57
224 - ],
225 - "raw": "0"
226 - },
227 - "id": {
228 - "type": "Identifier",
229 - "loc": {
230 - "source": null,
231 - "start": {
232 - "line": 3,
233 - "column": 11
234 - },
235 - "end": {
236 - "line": 3,
237 - "column": 12
238 - }
239 - },
240 - "name": "i",
241 - "typeAnnotation": null,
242 - "optional": false,
243 - "range": [
244 - 52,
245 - 53
246 - ]
247 - },
248 - "range": [
249 - 52,
250 - 57
251 - ]
252 - }
253 - ],
254 - "range": [
255 - 48,
256 - 57
257 - ]
258 - },
259 - "test": {
260 - "type": "BinaryExpression",
261 - "loc": {
262 - "source": null,
263 - "start": {
264 - "line": 3,
265 - "column": 18
266 - },
267 - "end": {
268 - "line": 3,
269 - "column": 24
270 - }
271 - },
272 - "left": {
273 - "type": "Identifier",
274 - "loc": {
275 - "source": null,
276 - "start": {
277 - "line": 3,
278 - "column": 18
279 - },
280 - "end": {
281 - "line": 3,
282 - "column": 19
283 - }
284 - },
285 - "name": "i",
286 - "typeAnnotation": null,
287 - "optional": false,
288 - "range": [
289 - 59,
290 - 60
291 - ]
292 - },
293 - "right": {
294 - "type": "Literal",
295 - "loc": {
296 - "source": null,
297 - "start": {
298 - "line": 3,
299 - "column": 22
300 - },
301 - "end": {
302 - "line": 3,
303 - "column": 24
304 - }
305 - },
306 - "value": 10,
307 - "range": [
308 - 63,
309 - 65
310 - ],
311 - "raw": "10"
312 - },
313 - "operator": "<",
314 - "range": [
315 - 59,
316 - 65
317 - ]
318 - },
319 - "update": {
320 - "type": "UpdateExpression",
321 - "loc": {
322 - "source": null,
323 - "start": {
324 - "line": 3,
325 - "column": 26
326 - },
327 - "end": {
328 - "line": 3,
329 - "column": 29
330 - }
331 - },
332 - "operator": "++",
333 - "argument": {
334 - "type": "Identifier",
335 - "loc": {
336 - "source": null,
337 - "start": {
338 - "line": 3,
339 - "column": 26
340 - },
341 - "end": {
342 - "line": 3,
343 - "column": 27
344 - }
345 - },
346 - "name": "i",
347 - "typeAnnotation": null,
348 - "optional": false,
349 - "range": [
350 - 67,
351 - 68
352 - ]
353 - },
354 - "prefix": false,
355 - "range": [
356 - 67,
357 - 70
358 - ]
359 - },
360 - "body": {
361 - "type": "BlockStatement",
362 - "loc": {
363 - "source": null,
364 - "start": {
365 - "line": 3,
366 - "column": 31
367 - },
368 - "end": {
369 - "line": 5,
370 - "column": 3
371 - }
372 - },
373 - "body": [
374 - {
375 - "type": "ExpressionStatement",
376 - "loc": {
377 - "source": null,
378 - "start": {
379 - "line": 4,
380 - "column": 4
381 - },
382 - "end": {
383 - "line": 4,
384 - "column": 11
385 - }
386 - },
387 - "expression": {
388 - "type": "AssignmentExpression",
389 - "loc": {
390 - "source": null,
391 - "start": {
392 - "line": 4,
393 - "column": 4
394 - },
395 - "end": {
396 - "line": 4,
397 - "column": 10
398 - }
399 - },
400 - "operator": "+=",
401 - "left": {
402 - "type": "Identifier",
403 - "loc": {
404 - "source": null,
405 - "start": {
406 - "line": 4,
407 - "column": 4
408 - },
409 - "end": {
410 - "line": 4,
411 - "column": 5
412 - }
413 - },
414 - "name": "x",
415 - "typeAnnotation": null,
416 - "optional": false,
417 - "range": [
418 - 78,
419 - 79
420 - ]
421 - },
422 - "right": {
423 - "type": "Identifier",
424 - "loc": {
425 - "source": null,
426 - "start": {
427 - "line": 4,
428 - "column": 9
429 - },
430 - "end": {
431 - "line": 4,
432 - "column": 10
433 - }
434 - },
435 - "name": "i",
436 - "typeAnnotation": null,
437 - "optional": false,
438 - "range": [
439 - 83,
440 - 84
441 - ]
442 - },
443 - "range": [
444 - 78,
445 - 84
446 - ]
447 - },
448 - "directive": null,
449 - "range": [
450 - 78,
451 - 85
452 - ]
453 - }
454 - ],
455 - "range": [
456 - 72,
457 - 89
458 - ]
459 - },
460 - "range": [
461 - 43,
462 - 89
463 - ]
464 - },
465 - {
466 - "type": "ReturnStatement",
467 - "loc": {
468 - "source": null,
469 - "start": {
470 - "line": 6,
471 - "column": 2
472 - },
473 - "end": {
474 - "line": 6,
475 - "column": 11
476 - }
477 - },
478 - "argument": {
479 - "type": "Identifier",
480 - "loc": {
481 - "source": null,
482 - "start": {
483 - "line": 6,
484 - "column": 9
485 - },
486 - "end": {
487 - "line": 6,
488 - "column": 10
489 - }
490 - },
491 - "name": "x",
492 - "typeAnnotation": null,
493 - "optional": false,
494 - "range": [
495 - 99,
496 - 100
497 - ]
498 - },
499 - "range": [
500 - 92,
501 - 101
502 - ]
503 - }
504 - ],
505 - "range": [
506 - 26,
507 - 103
508 - ]
509 - },
510 - "typeParameters": null,
511 - "returnType": null,
512 - "predicate": null,
513 - "generator": false,
514 - "async": false,
515 - "range": [
516 - 0,
517 - 103
518 - ]
519 - }
520 - ],
521 - "comments": [],
522 - "interpreter": null,
523 - "range": [
524 - 0,
525 - 103
526 - ],
527 - "sourceType": "script"
528 - }
\ No newline at end of file
compiler/forget/crates/estree/src/generated.rs new
+916
@@ -0,0 +1,916 @@
1 +use std::num::NonZeroU32;
2 +use serde::{Serialize, Deserialize};
3 +use crate::{JsValue, Binding, SourceRange};
4 +#[derive(Serialize, Deserialize, Clone, Debug)]
5 +pub struct SourceLocation {
6 + source: Option<String>,
7 + start: Position,
8 + end: Position,
9 +}
10 +#[derive(Serialize, Deserialize, Clone, Debug)]
11 +pub struct Position {
12 + line: NonZeroU32,
13 + column: u32,
14 +}
15 +#[derive(Serialize, Deserialize, Clone, Debug)]
16 +pub struct Function {
17 + id: Option<Identifier>,
18 + params: Vec<Pattern>,
19 + body: Option<BlockStatement>,
20 +}
21 +#[derive(Serialize, Deserialize, Clone, Debug)]
22 +pub struct RegExpValue {
23 + pattern: String,
24 + flags: String,
25 +}
26 +#[derive(Serialize, Deserialize, Clone, Debug)]
27 +pub struct Identifier {
28 + name: String,
29 + #[serde(default)]
30 + binding: Option<Binding>,
31 + #[serde(default)]
32 + pub loc: Option<SourceLocation>,
33 + #[serde(default)]
34 + pub range: Option<SourceRange>,
35 +}
36 +#[derive(Serialize, Deserialize, Clone, Debug)]
37 +pub struct Literal {
38 + value: JsValue,
39 + #[serde(default)]
40 + raw: Option<String>,
41 + #[serde(default)]
42 + regex: Option<RegExpValue>,
43 + #[serde(default)]
44 + pub loc: Option<SourceLocation>,
45 + #[serde(default)]
46 + pub range: Option<SourceRange>,
47 +}
48 +#[derive(Serialize, Deserialize, Clone, Debug)]
49 +pub struct Program {
50 + body: Vec<Statement>,
51 + #[serde(default)]
52 + pub loc: Option<SourceLocation>,
53 + #[serde(default)]
54 + pub range: Option<SourceRange>,
55 +}
56 +#[derive(Serialize, Deserialize, Clone, Debug)]
57 +pub struct ExpressionStatement {
58 + expression: Expression,
59 + #[serde(default)]
60 + pub loc: Option<SourceLocation>,
61 + #[serde(default)]
62 + pub range: Option<SourceRange>,
63 +}
64 +#[derive(Serialize, Deserialize, Clone, Debug)]
65 +pub struct BlockStatement {
66 + body: Vec<Statement>,
67 + #[serde(default)]
68 + pub loc: Option<SourceLocation>,
69 + #[serde(default)]
70 + pub range: Option<SourceRange>,
71 +}
72 +#[derive(Serialize, Deserialize, Clone, Debug)]
73 +pub struct EmptyStatement {
74 + #[serde(default)]
75 + pub loc: Option<SourceLocation>,
76 + #[serde(default)]
77 + pub range: Option<SourceRange>,
78 +}
79 +#[derive(Serialize, Deserialize, Clone, Debug)]
80 +pub struct DebuggerStatement {
81 + #[serde(default)]
82 + pub loc: Option<SourceLocation>,
83 + #[serde(default)]
84 + pub range: Option<SourceRange>,
85 +}
86 +#[derive(Serialize, Deserialize, Clone, Debug)]
87 +pub struct WithStatement {
88 + object: Expression,
89 + body: Statement,
90 + #[serde(default)]
91 + pub loc: Option<SourceLocation>,
92 + #[serde(default)]
93 + pub range: Option<SourceRange>,
94 +}
95 +#[derive(Serialize, Deserialize, Clone, Debug)]
96 +pub struct ReturnStatement {
97 + argument: Option<Expression>,
98 + #[serde(default)]
99 + pub loc: Option<SourceLocation>,
100 + #[serde(default)]
101 + pub range: Option<SourceRange>,
102 +}
103 +#[derive(Serialize, Deserialize, Clone, Debug)]
104 +pub struct LabeledStatement {
105 + label: Identifier,
106 + body: Statement,
107 + #[serde(default)]
108 + pub loc: Option<SourceLocation>,
109 + #[serde(default)]
110 + pub range: Option<SourceRange>,
111 +}
112 +#[derive(Serialize, Deserialize, Clone, Debug)]
113 +pub struct BreakStatement {
114 + label: Option<Identifier>,
115 + #[serde(default)]
116 + pub loc: Option<SourceLocation>,
117 + #[serde(default)]
118 + pub range: Option<SourceRange>,
119 +}
120 +#[derive(Serialize, Deserialize, Clone, Debug)]
121 +pub struct ContinueStatement {
122 + label: Option<Identifier>,
123 + #[serde(default)]
124 + pub loc: Option<SourceLocation>,
125 + #[serde(default)]
126 + pub range: Option<SourceRange>,
127 +}
128 +#[derive(Serialize, Deserialize, Clone, Debug)]
129 +pub struct IfStatement {
130 + test: Expression,
131 + consequent: Statement,
132 + alternate: Option<Statement>,
133 + #[serde(default)]
134 + pub loc: Option<SourceLocation>,
135 + #[serde(default)]
136 + pub range: Option<SourceRange>,
137 +}
138 +#[derive(Serialize, Deserialize, Clone, Debug)]
139 +pub struct SwitchStatement {
140 + discriminant: Expression,
141 + cases: Vec<SwitchCase>,
142 + #[serde(default)]
143 + pub loc: Option<SourceLocation>,
144 + #[serde(default)]
145 + pub range: Option<SourceRange>,
146 +}
147 +#[derive(Serialize, Deserialize, Clone, Debug)]
148 +pub struct SwitchCase {
149 + test: Option<Expression>,
150 + consequent: Vec<Statement>,
151 + #[serde(default)]
152 + pub loc: Option<SourceLocation>,
153 + #[serde(default)]
154 + pub range: Option<SourceRange>,
155 +}
156 +#[derive(Serialize, Deserialize, Clone, Debug)]
157 +pub struct ThrowStatement {
158 + argument: Expression,
159 + #[serde(default)]
160 + pub loc: Option<SourceLocation>,
161 + #[serde(default)]
162 + pub range: Option<SourceRange>,
163 +}
164 +#[derive(Serialize, Deserialize, Clone, Debug)]
165 +pub struct TryStatement {
166 + block: BlockStatement,
167 + handler: Option<CatchClause>,
168 + finalizer: Option<BlockStatement>,
169 + #[serde(default)]
170 + pub loc: Option<SourceLocation>,
171 + #[serde(default)]
172 + pub range: Option<SourceRange>,
173 +}
174 +#[derive(Serialize, Deserialize, Clone, Debug)]
175 +pub struct CatchClause {
176 + param: Pattern,
177 + body: BlockStatement,
178 + #[serde(default)]
179 + pub loc: Option<SourceLocation>,
180 + #[serde(default)]
181 + pub range: Option<SourceRange>,
182 +}
183 +#[derive(Serialize, Deserialize, Clone, Debug)]
184 +pub struct WhileStatement {
185 + test: Expression,
186 + body: Statement,
187 + #[serde(default)]
188 + pub loc: Option<SourceLocation>,
189 + #[serde(default)]
190 + pub range: Option<SourceRange>,
191 +}
192 +#[derive(Serialize, Deserialize, Clone, Debug)]
193 +pub struct DoWhileStatement {
194 + body: Statement,
195 + test: Expression,
196 + #[serde(default)]
197 + pub loc: Option<SourceLocation>,
198 + #[serde(default)]
199 + pub range: Option<SourceRange>,
200 +}
201 +#[derive(Serialize, Deserialize, Clone, Debug)]
202 +pub struct ForStatement {
203 + init: Option<ForInit>,
204 + test: Option<Expression>,
205 + update: Option<Expression>,
206 + body: Statement,
207 + #[serde(default)]
208 + pub loc: Option<SourceLocation>,
209 + #[serde(default)]
210 + pub range: Option<SourceRange>,
211 +}
212 +#[derive(Serialize, Deserialize, Clone, Debug)]
213 +pub struct ForInStatement {
214 + left: ForInInit,
215 + right: Expression,
216 + body: Statement,
217 + #[serde(default)]
218 + pub loc: Option<SourceLocation>,
219 + #[serde(default)]
220 + pub range: Option<SourceRange>,
221 +}
222 +#[derive(Serialize, Deserialize, Clone, Debug)]
223 +pub struct FunctionDeclaration {
224 + #[serde(flatten)]
225 + function: Function,
226 + #[serde(default)]
227 + pub loc: Option<SourceLocation>,
228 + #[serde(default)]
229 + pub range: Option<SourceRange>,
230 +}
231 +#[derive(Serialize, Deserialize, Clone, Debug)]
232 +pub struct VariableDeclaration {
233 + kind: VariableDeclarationKind,
234 + declarations: Vec<VariableDeclarator>,
235 + #[serde(default)]
236 + pub loc: Option<SourceLocation>,
237 + #[serde(default)]
238 + pub range: Option<SourceRange>,
239 +}
240 +#[derive(Serialize, Deserialize, Clone, Debug)]
241 +pub struct VariableDeclarator {
242 + id: Pattern,
243 + init: Option<Expression>,
244 + #[serde(default)]
245 + pub loc: Option<SourceLocation>,
246 + #[serde(default)]
247 + pub range: Option<SourceRange>,
248 +}
249 +#[derive(Serialize, Deserialize, Clone, Debug)]
250 +pub struct ThisExpression {
251 + #[serde(default)]
252 + pub loc: Option<SourceLocation>,
253 + #[serde(default)]
254 + pub range: Option<SourceRange>,
255 +}
256 +#[derive(Serialize, Deserialize, Clone, Debug)]
257 +pub struct ArrayExpression {
258 + elements: Vec<Option<Expression>>,
259 + #[serde(default)]
260 + pub loc: Option<SourceLocation>,
261 + #[serde(default)]
262 + pub range: Option<SourceRange>,
263 +}
264 +#[derive(Serialize, Deserialize, Clone, Debug)]
265 +pub struct ObjectExpression {
266 + properties: Vec<Property>,
267 + #[serde(default)]
268 + pub loc: Option<SourceLocation>,
269 + #[serde(default)]
270 + pub range: Option<SourceRange>,
271 +}
272 +#[derive(Serialize, Deserialize, Clone, Debug)]
273 +pub struct Property {
274 + key: PropertyKey,
275 + value: Expression,
276 + kind: PropertyKind,
277 + #[serde(default)]
278 + pub loc: Option<SourceLocation>,
279 + #[serde(default)]
280 + pub range: Option<SourceRange>,
281 +}
282 +#[derive(Serialize, Deserialize, Clone, Debug)]
283 +pub struct FunctionExpression {
284 + #[serde(flatten)]
285 + function: Function,
286 + #[serde(default)]
287 + pub loc: Option<SourceLocation>,
288 + #[serde(default)]
289 + pub range: Option<SourceRange>,
290 +}
291 +#[derive(Serialize, Deserialize, Clone, Debug)]
292 +pub struct UnaryExpression {
293 + operator: UnaryOperator,
294 + prefix: bool,
295 + argument: Expression,
296 + #[serde(default)]
297 + pub loc: Option<SourceLocation>,
298 + #[serde(default)]
299 + pub range: Option<SourceRange>,
300 +}
301 +#[derive(Serialize, Deserialize, Clone, Debug)]
302 +pub struct UpdateExpression {
303 + operator: UpdateOperator,
304 + argument: Expression,
305 + prefix: bool,
306 + #[serde(default)]
307 + pub loc: Option<SourceLocation>,
308 + #[serde(default)]
309 + pub range: Option<SourceRange>,
310 +}
311 +#[derive(Serialize, Deserialize, Clone, Debug)]
312 +pub struct BinaryExpression {
313 + left: Expression,
314 + operator: BinaryOperator,
315 + right: Expression,
316 + #[serde(default)]
317 + pub loc: Option<SourceLocation>,
318 + #[serde(default)]
319 + pub range: Option<SourceRange>,
320 +}
321 +#[derive(Serialize, Deserialize, Clone, Debug)]
322 +pub struct AssignmentExpression {
323 + operator: AssignmentOperator,
324 + left: AssignmentTarget,
325 + right: Expression,
326 + #[serde(default)]
327 + pub loc: Option<SourceLocation>,
328 + #[serde(default)]
329 + pub range: Option<SourceRange>,
330 +}
331 +#[derive(Serialize, Deserialize, Clone, Debug)]
332 +pub struct LogicalExpression {
333 + operator: LogicalOperator,
334 + left: Expression,
335 + right: Expression,
336 + #[serde(default)]
337 + pub loc: Option<SourceLocation>,
338 + #[serde(default)]
339 + pub range: Option<SourceRange>,
340 +}
341 +#[derive(Serialize, Deserialize, Clone, Debug)]
342 +pub struct MemberExpression {
343 + object: Expression,
344 + property: Expression,
345 + computed: bool,
346 + #[serde(default)]
347 + pub loc: Option<SourceLocation>,
348 + #[serde(default)]
349 + pub range: Option<SourceRange>,
350 +}
351 +#[derive(Serialize, Deserialize, Clone, Debug)]
352 +pub struct ConditionalExpression {
353 + test: Expression,
354 + alternate: Expression,
355 + consequent: Expression,
356 + #[serde(default)]
357 + pub loc: Option<SourceLocation>,
358 + #[serde(default)]
359 + pub range: Option<SourceRange>,
360 +}
361 +#[derive(Serialize, Deserialize, Clone, Debug)]
362 +pub struct CallExpression {
363 + callee: Expression,
364 + arguments: Vec<Expression>,
365 + #[serde(default)]
366 + pub loc: Option<SourceLocation>,
367 + #[serde(default)]
368 + pub range: Option<SourceRange>,
369 +}
370 +#[derive(Serialize, Deserialize, Clone, Debug)]
371 +pub struct NewExpression {
372 + callee: Expression,
373 + arguments: Vec<Expression>,
374 + #[serde(default)]
375 + pub loc: Option<SourceLocation>,
376 + #[serde(default)]
377 + pub range: Option<SourceRange>,
378 +}
379 +#[derive(Serialize, Deserialize, Clone, Debug)]
380 +pub struct SequenceExpression {
381 + expressions: Vec<Expression>,
382 + #[serde(default)]
383 + pub loc: Option<SourceLocation>,
384 + #[serde(default)]
385 + pub range: Option<SourceRange>,
386 +}
387 +#[derive(Serialize, Deserialize, Clone, Debug)]
388 +#[serde(tag = "type")]
389 +pub enum Statement {
390 + BlockStatement(Box<BlockStatement>),
391 + BreakStatement(Box<BreakStatement>),
392 + ContinueStatement(Box<ContinueStatement>),
393 + DebuggerStatement(Box<DebuggerStatement>),
394 + DoWhileStatement(Box<DoWhileStatement>),
395 + EmptyStatement(Box<EmptyStatement>),
396 + ExpressionStatement(Box<ExpressionStatement>),
397 + ForInStatement(Box<ForInStatement>),
398 + ForStatement(Box<ForStatement>),
399 + FunctionDeclaration(Box<FunctionDeclaration>),
400 + IfStatement(Box<IfStatement>),
401 + LabeledStatement(Box<LabeledStatement>),
402 + ReturnStatement(Box<ReturnStatement>),
403 + SwitchStatement(Box<SwitchStatement>),
404 + ThrowStatement(Box<ThrowStatement>),
405 + TryStatement(Box<TryStatement>),
406 + VariableDeclaration(Box<VariableDeclaration>),
407 + WhileStatement(Box<WhileStatement>),
408 + WithStatement(Box<WithStatement>),
409 +}
410 +#[derive(Serialize, Deserialize, Clone, Debug)]
411 +#[serde(tag = "type")]
412 +pub enum Expression {
413 + ArrayExpression(Box<ArrayExpression>),
414 + AssignmentExpression(Box<AssignmentExpression>),
415 + BinaryExpression(Box<BinaryExpression>),
416 + CallExpression(Box<CallExpression>),
417 + ConditionalExpression(Box<ConditionalExpression>),
418 + FunctionExpression(Box<FunctionExpression>),
419 + Identifier(Box<Identifier>),
420 + Literal(Box<Literal>),
421 + LogicalExpression(Box<LogicalExpression>),
422 + MemberExpression(Box<MemberExpression>),
423 + NewExpression(Box<NewExpression>),
424 + ObjectExpression(Box<ObjectExpression>),
425 + SequenceExpression(Box<SequenceExpression>),
426 + ThisExpression(Box<ThisExpression>),
427 + UnaryExpression(Box<UnaryExpression>),
428 + UpdateExpression(Box<UpdateExpression>),
429 +}
430 +#[derive(Serialize, Deserialize, Clone, Debug)]
431 +#[serde(tag = "type")]
432 +pub enum Pattern {
433 + Identifier(Box<Identifier>),
434 +}
435 +#[derive(Serialize, Deserialize, Clone, Debug)]
436 +#[serde(untagged)]
437 +pub enum ForInit {
438 + Expression(Expression),
439 + VariableDeclaration(Box<VariableDeclaration>),
440 +}
441 +#[derive(Serialize, Deserialize, Clone, Debug)]
442 +#[serde(untagged)]
443 +pub enum ForInInit {
444 + Pattern(Pattern),
445 + VariableDeclaration(Box<VariableDeclaration>),
446 +}
447 +#[derive(Serialize, Deserialize, Clone, Debug)]
448 +#[serde(tag = "type")]
449 +pub enum PropertyKey {
450 + Identifier(Box<Identifier>),
451 + Literal(Box<Literal>),
452 +}
453 +#[derive(Serialize, Deserialize, Clone, Debug)]
454 +#[serde(untagged)]
455 +pub enum AssignmentTarget {
456 + Expression(Expression),
457 + Pattern(Pattern),
458 +}
459 +#[derive(
460 + Serialize,
461 + Deserialize,
462 + Clone,
463 + Copy,
464 + Eq,
465 + PartialEq,
466 + Ord,
467 + PartialOrd,
468 + Hash,
469 + Debug
470 +)]
471 +pub enum VariableDeclarationKind {
472 + /// const
473 + #[serde(rename = "const")]
474 + Const,
475 + /// let
476 + #[serde(rename = "let")]
477 + Let,
478 + /// var
479 + #[serde(rename = "var")]
480 + Var,
481 +}
482 +impl std::fmt::Display for VariableDeclarationKind {
483 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
484 + let name = match self {
485 + Self::Const => "const",
486 + Self::Let => "let",
487 + Self::Var => "var",
488 + };
489 + f.write_str(name)
490 + }
491 +}
492 +impl std::str::FromStr for VariableDeclarationKind {
493 + type Err = ();
494 + fn from_str(s: &str) -> Result<Self, Self::Err> {
495 + match s {
496 + "const" => Ok(Self::Const),
497 + "let" => Ok(Self::Let),
498 + "var" => Ok(Self::Var),
499 + _ => Err(()),
500 + }
501 + }
502 +}
503 +#[derive(
504 + Serialize,
505 + Deserialize,
506 + Clone,
507 + Copy,
508 + Eq,
509 + PartialEq,
510 + Ord,
511 + PartialOrd,
512 + Hash,
513 + Debug
514 +)]
515 +pub enum PropertyKind {
516 + /// get
517 + #[serde(rename = "get")]
518 + Get,
519 + /// init
520 + #[serde(rename = "init")]
521 + Init,
522 + /// set
523 + #[serde(rename = "set")]
524 + Set,
525 +}
526 +impl std::fmt::Display for PropertyKind {
527 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
528 + let name = match self {
529 + Self::Get => "get",
530 + Self::Init => "init",
531 + Self::Set => "set",
532 + };
533 + f.write_str(name)
534 + }
535 +}
536 +impl std::str::FromStr for PropertyKind {
537 + type Err = ();
538 + fn from_str(s: &str) -> Result<Self, Self::Err> {
539 + match s {
540 + "get" => Ok(Self::Get),
541 + "init" => Ok(Self::Init),
542 + "set" => Ok(Self::Set),
543 + _ => Err(()),
544 + }
545 + }
546 +}
547 +#[derive(
548 + Serialize,
549 + Deserialize,
550 + Clone,
551 + Copy,
552 + Eq,
553 + PartialEq,
554 + Ord,
555 + PartialOrd,
556 + Hash,
557 + Debug
558 +)]
559 +pub enum UnaryOperator {
560 + /// delete
561 + #[serde(rename = "delete")]
562 + Delete,
563 + /// -
564 + #[serde(rename = "-")]
565 + Minus,
566 + /// !
567 + #[serde(rename = "!")]
568 + Negation,
569 + /// +
570 + #[serde(rename = "+")]
571 + Plus,
572 + /// ~
573 + #[serde(rename = "~")]
574 + Tilde,
575 + /// typeof
576 + #[serde(rename = "typeof")]
577 + Typeof,
578 + /// void
579 + #[serde(rename = "void")]
580 + Void,
581 +}
582 +impl std::fmt::Display for UnaryOperator {
583 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
584 + let name = match self {
585 + Self::Delete => "delete",
586 + Self::Minus => "-",
587 + Self::Negation => "!",
588 + Self::Plus => "+",
589 + Self::Tilde => "~",
590 + Self::Typeof => "typeof",
591 + Self::Void => "void",
592 + };
593 + f.write_str(name)
594 + }
595 +}
596 +impl std::str::FromStr for UnaryOperator {
597 + type Err = ();
598 + fn from_str(s: &str) -> Result<Self, Self::Err> {
599 + match s {
600 + "delete" => Ok(Self::Delete),
601 + "-" => Ok(Self::Minus),
602 + "!" => Ok(Self::Negation),
603 + "+" => Ok(Self::Plus),
604 + "~" => Ok(Self::Tilde),
605 + "typeof" => Ok(Self::Typeof),
606 + "void" => Ok(Self::Void),
607 + _ => Err(()),
608 + }
609 + }
610 +}
611 +#[derive(
612 + Serialize,
613 + Deserialize,
614 + Clone,
615 + Copy,
616 + Eq,
617 + PartialEq,
618 + Ord,
619 + PartialOrd,
620 + Hash,
621 + Debug
622 +)]
623 +pub enum UpdateOperator {
624 + /// --
625 + #[serde(rename = "--")]
626 + Decrement,
627 + /// ++
628 + #[serde(rename = "++")]
629 + Increment,
630 +}
631 +impl std::fmt::Display for UpdateOperator {
632 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
633 + let name = match self {
634 + Self::Decrement => "--",
635 + Self::Increment => "++",
636 + };
637 + f.write_str(name)
638 + }
639 +}
640 +impl std::str::FromStr for UpdateOperator {
641 + type Err = ();
642 + fn from_str(s: &str) -> Result<Self, Self::Err> {
643 + match s {
644 + "--" => Ok(Self::Decrement),
645 + "++" => Ok(Self::Increment),
646 + _ => Err(()),
647 + }
648 + }
649 +}
650 +#[derive(
651 + Serialize,
652 + Deserialize,
653 + Clone,
654 + Copy,
655 + Eq,
656 + PartialEq,
657 + Ord,
658 + PartialOrd,
659 + Hash,
660 + Debug
661 +)]
662 +pub enum BinaryOperator {
663 + /// +
664 + #[serde(rename = "+")]
665 + Add,
666 + /// &
667 + #[serde(rename = "&")]
668 + BinaryAnd,
669 + /// |
670 + #[serde(rename = "|")]
671 + BinaryOr,
672 + /// ^
673 + #[serde(rename = "^")]
674 + BinaryXor,
675 + /// /
676 + #[serde(rename = "/")]
677 + Divide,
678 + /// ==
679 + #[serde(rename = "==")]
680 + Equals,
681 + /// >
682 + #[serde(rename = ">")]
683 + GreaterThan,
684 + /// >=
685 + #[serde(rename = ">=")]
686 + GreaterThanOrEqual,
687 + /// in
688 + #[serde(rename = "in")]
689 + In,
690 + /// instanceof
691 + #[serde(rename = "instanceof")]
692 + Instanceof,
693 + /// <
694 + #[serde(rename = "<")]
695 + LessThan,
696 + /// <=
697 + #[serde(rename = "<=")]
698 + LessThanOrEqual,
699 + /// %
700 + #[serde(rename = "%")]
701 + Modulo,
702 + /// *
703 + #[serde(rename = "*")]
704 + Multiply,
705 + /// !=
706 + #[serde(rename = "!=")]
707 + NotEquals,
708 + /// !==
709 + #[serde(rename = "!==")]
710 + NotStrictEquals,
711 + /// <<
712 + #[serde(rename = "<<")]
713 + ShiftLeft,
714 + /// >>
715 + #[serde(rename = ">>")]
716 + ShiftRight,
717 + /// ===
718 + #[serde(rename = "===")]
719 + StrictEquals,
720 + /// -
721 + #[serde(rename = "-")]
722 + Subtract,
723 + /// >>>
724 + #[serde(rename = ">>>")]
725 + UnsignedShiftRight,
726 +}
727 +impl std::fmt::Display for BinaryOperator {
728 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
729 + let name = match self {
730 + Self::Add => "+",
731 + Self::BinaryAnd => "&",
732 + Self::BinaryOr => "|",
733 + Self::BinaryXor => "^",
734 + Self::Divide => "/",
735 + Self::Equals => "==",
736 + Self::GreaterThan => ">",
737 + Self::GreaterThanOrEqual => ">=",
738 + Self::In => "in",
739 + Self::Instanceof => "instanceof",
740 + Self::LessThan => "<",
741 + Self::LessThanOrEqual => "<=",
742 + Self::Modulo => "%",
743 + Self::Multiply => "*",
744 + Self::NotEquals => "!=",
745 + Self::NotStrictEquals => "!==",
746 + Self::ShiftLeft => "<<",
747 + Self::ShiftRight => ">>",
748 + Self::StrictEquals => "===",
749 + Self::Subtract => "-",
750 + Self::UnsignedShiftRight => ">>>",
751 + };
752 + f.write_str(name)
753 + }
754 +}
755 +impl std::str::FromStr for BinaryOperator {
756 + type Err = ();
757 + fn from_str(s: &str) -> Result<Self, Self::Err> {
758 + match s {
759 + "+" => Ok(Self::Add),
760 + "&" => Ok(Self::BinaryAnd),
761 + "|" => Ok(Self::BinaryOr),
762 + "^" => Ok(Self::BinaryXor),
763 + "/" => Ok(Self::Divide),
764 + "==" => Ok(Self::Equals),
765 + ">" => Ok(Self::GreaterThan),
766 + ">=" => Ok(Self::GreaterThanOrEqual),
767 + "in" => Ok(Self::In),
768 + "instanceof" => Ok(Self::Instanceof),
769 + "<" => Ok(Self::LessThan),
770 + "<=" => Ok(Self::LessThanOrEqual),
771 + "%" => Ok(Self::Modulo),
772 + "*" => Ok(Self::Multiply),
773 + "!=" => Ok(Self::NotEquals),
774 + "!==" => Ok(Self::NotStrictEquals),
775 + "<<" => Ok(Self::ShiftLeft),
776 + ">>" => Ok(Self::ShiftRight),
777 + "===" => Ok(Self::StrictEquals),
778 + "-" => Ok(Self::Subtract),
779 + ">>>" => Ok(Self::UnsignedShiftRight),
780 + _ => Err(()),
781 + }
782 + }
783 +}
784 +#[derive(
785 + Serialize,
786 + Deserialize,
787 + Clone,
788 + Copy,
789 + Eq,
790 + PartialEq,
791 + Ord,
792 + PartialOrd,
793 + Hash,
794 + Debug
795 +)]
796 +pub enum AssignmentOperator {
797 + /// &=
798 + #[serde(rename = "&=")]
799 + BinaryAndEquals,
800 + /// |=
801 + #[serde(rename = "|=")]
802 + BinaryOrEquals,
803 + /// ^=
804 + #[serde(rename = "^=")]
805 + BinaryXorEquals,
806 + /// /=
807 + #[serde(rename = "/=")]
808 + DivideEquals,
809 + /// =
810 + #[serde(rename = "=")]
811 + Equals,
812 + /// -=
813 + #[serde(rename = "-=")]
814 + MinusEquals,
815 + /// %=
816 + #[serde(rename = "%=")]
817 + ModuloEquals,
818 + /// *=
819 + #[serde(rename = "*=")]
820 + MultiplyEquals,
821 + /// +=
822 + #[serde(rename = "+=")]
823 + PlusEquals,
824 + /// <<=
825 + #[serde(rename = "<<=")]
826 + ShiftLeftEquals,
827 + /// >>=
828 + #[serde(rename = ">>=")]
829 + ShiftRightEquals,
830 + /// >>>=
831 + #[serde(rename = ">>>=")]
832 + UnsignedShiftRightEquals,
833 +}
834 +impl std::fmt::Display for AssignmentOperator {
835 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
836 + let name = match self {
837 + Self::BinaryAndEquals => "&=",
838 + Self::BinaryOrEquals => "|=",
839 + Self::BinaryXorEquals => "^=",
840 + Self::DivideEquals => "/=",
841 + Self::Equals => "=",
842 + Self::MinusEquals => "-=",
843 + Self::ModuloEquals => "%=",
844 + Self::MultiplyEquals => "*=",
845 + Self::PlusEquals => "+=",
846 + Self::ShiftLeftEquals => "<<=",
847 + Self::ShiftRightEquals => ">>=",
848 + Self::UnsignedShiftRightEquals => ">>>=",
849 + };
850 + f.write_str(name)
851 + }
852 +}
853 +impl std::str::FromStr for AssignmentOperator {
854 + type Err = ();
855 + fn from_str(s: &str) -> Result<Self, Self::Err> {
856 + match s {
857 + "&=" => Ok(Self::BinaryAndEquals),
858 + "|=" => Ok(Self::BinaryOrEquals),
859 + "^=" => Ok(Self::BinaryXorEquals),
860 + "/=" => Ok(Self::DivideEquals),
861 + "=" => Ok(Self::Equals),
862 + "-=" => Ok(Self::MinusEquals),
863 + "%=" => Ok(Self::ModuloEquals),
864 + "*=" => Ok(Self::MultiplyEquals),
865 + "+=" => Ok(Self::PlusEquals),
866 + "<<=" => Ok(Self::ShiftLeftEquals),
867 + ">>=" => Ok(Self::ShiftRightEquals),
868 + ">>>=" => Ok(Self::UnsignedShiftRightEquals),
869 + _ => Err(()),
870 + }
871 + }
872 +}
873 +#[derive(
874 + Serialize,
875 + Deserialize,
876 + Clone,
877 + Copy,
878 + Eq,
879 + PartialEq,
880 + Ord,
881 + PartialOrd,
882 + Hash,
883 + Debug
884 +)]
885 +pub enum LogicalOperator {
886 + /// &&
887 + #[serde(rename = "&&")]
888 + And,
889 + /// ??
890 + #[serde(rename = "??")]
891 + NullCoalescing,
892 + /// ||
893 + #[serde(rename = "||")]
894 + Or,
895 +}
896 +impl std::fmt::Display for LogicalOperator {
897 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
898 + let name = match self {
899 + Self::And => "&&",
900 + Self::NullCoalescing => "??",
901 + Self::Or => "||",
902 + };
903 + f.write_str(name)
904 + }
905 +}
906 +impl std::str::FromStr for LogicalOperator {
907 + type Err = ();
908 + fn from_str(s: &str) -> Result<Self, Self::Err> {
909 + match s {
910 + "&&" => Ok(Self::And),
911 + "??" => Ok(Self::NullCoalescing),
912 + "||" => Ok(Self::Or),
913 + _ => Err(()),
914 + }
915 + }
916 +}
compiler/forget/crates/estree/src/import.json deleted
-104
@@ -1,104 +0,0 @@
1 -{
2 - "type": "Program",
3 - "loc": {
4 - "source": null,
5 - "start": {
6 - "line": 1,
7 - "column": 0
8 - },
9 - "end": {
10 - "line": 1,
11 - "column": 26
12 - }
13 - },
14 - "body": [
15 - {
16 - "type": "ImportDeclaration",
17 - "loc": {
18 - "source": null,
19 - "start": {
20 - "line": 1,
21 - "column": 0
22 - },
23 - "end": {
24 - "line": 1,
25 - "column": 26
26 - }
27 - },
28 - "specifiers": [
29 - {
30 - "type": "ImportDefaultSpecifier",
31 - "loc": {
32 - "source": null,
33 - "start": {
34 - "line": 1,
35 - "column": 7
36 - },
37 - "end": {
38 - "line": 1,
39 - "column": 12
40 - }
41 - },
42 - "local": {
43 - "type": "Identifier",
44 - "loc": {
45 - "source": null,
46 - "start": {
47 - "line": 1,
48 - "column": 7
49 - },
50 - "end": {
51 - "line": 1,
52 - "column": 12
53 - }
54 - },
55 - "name": "React",
56 - "typeAnnotation": null,
57 - "optional": false,
58 - "range": [
59 - 7,
60 - 12
61 - ]
62 - },
63 - "range": [
64 - 7,
65 - 12
66 - ]
67 - }
68 - ],
69 - "source": {
70 - "type": "Literal",
71 - "loc": {
72 - "source": null,
73 - "start": {
74 - "line": 1,
75 - "column": 18
76 - },
77 - "end": {
78 - "line": 1,
79 - "column": 25
80 - }
81 - },
82 - "value": "react",
83 - "range": [
84 - 18,
85 - 25
86 - ],
87 - "raw": "'react'"
88 - },
89 - "attributes": [],
90 - "importKind": "value",
91 - "range": [
92 - 0,
93 - 26
94 - ]
95 - }
96 - ],
97 - "comments": [],
98 - "interpreter": null,
99 - "range": [
100 - 0,
101 - 26
102 - ],
103 - "sourceType": "module"
104 - }
\ No newline at end of file
compiler/forget/crates/estree/src/js_value.rs new
+112
@@ -0,0 +1,112 @@
1 +use serde::{de::Visitor, Deserialize, Serialize};
2 +
3 +#[derive(Serialize, Clone, Debug, PartialEq, PartialOrd, Hash)]
4 +pub enum JsValue {
5 + Undefined,
6 + Null,
7 + Bool(bool),
8 + Number(Number),
9 + String(String),
10 +}
11 +
12 +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Debug)]
13 +pub struct Number(u64);
14 +
15 +impl From<u32> for Number {
16 + fn from(value: u32) -> Self {
17 + Number(value.into())
18 + }
19 +}
20 +
21 +impl From<u64> for Number {
22 + fn from(value: u64) -> Self {
23 + Number(value)
24 + }
25 +}
26 +
27 +impl From<f64> for Number {
28 + fn from(value: f64) -> Self {
29 + Number(value.to_bits())
30 + }
31 +}
32 +
33 +impl From<Number> for f64 {
34 + fn from(value: Number) -> Self {
35 + f64::from_bits(value.0)
36 + }
37 +}
38 +
39 +impl<'de> Deserialize<'de> for JsValue {
40 + #[inline]
41 + fn deserialize<D>(deserializer: D) -> Result<JsValue, D::Error>
42 + where
43 + D: serde::Deserializer<'de>,
44 + {
45 + struct ValueVisitor;
46 +
47 + impl<'de> Visitor<'de> for ValueVisitor {
48 + type Value = JsValue;
49 +
50 + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
51 + formatter.write_str("valid primitive JSON value (null, boolean, number, or string")
52 + }
53 +
54 + #[inline]
55 + fn visit_bool<E>(self, value: bool) -> Result<JsValue, E> {
56 + Ok(JsValue::Bool(value))
57 + }
58 +
59 + #[inline]
60 + fn visit_i64<E>(self, value: i64) -> Result<JsValue, E> {
61 + if value < u32::MAX as i64 {
62 + Ok(JsValue::Number((value as u32).into()))
63 + } else {
64 + panic!("Invalid number")
65 + }
66 + }
67 +
68 + #[inline]
69 + fn visit_u64<E>(self, value: u64) -> Result<JsValue, E> {
70 + Ok(JsValue::Number(value.into()))
71 + }
72 +
73 + #[inline]
74 + fn visit_f64<E>(self, value: f64) -> Result<JsValue, E> {
75 + Ok(JsValue::Number(value.into()))
76 + }
77 +
78 + #[inline]
79 + fn visit_str<E>(self, value: &str) -> Result<JsValue, E>
80 + where
81 + E: serde::de::Error,
82 + {
83 + self.visit_string(String::from(value))
84 + }
85 +
86 + #[inline]
87 + fn visit_string<E>(self, value: String) -> Result<JsValue, E> {
88 + Ok(JsValue::String(value))
89 + }
90 +
91 + #[inline]
92 + fn visit_none<E>(self) -> Result<JsValue, E> {
93 + Ok(JsValue::Null)
94 + }
95 +
96 + #[inline]
97 + fn visit_some<D>(self, deserializer: D) -> Result<JsValue, D::Error>
98 + where
99 + D: serde::Deserializer<'de>,
100 + {
101 + Deserialize::deserialize(deserializer)
102 + }
103 +
104 + #[inline]
105 + fn visit_unit<E>(self) -> Result<JsValue, E> {
106 + Ok(JsValue::Undefined)
107 + }
108 + }
109 +
110 + deserializer.deserialize_any(ValueVisitor)
111 + }
112 +}
compiler/forget/crates/estree/src/kitchen-sink.json deleted
-4069
@@ -1,4069 +0,0 @@
1 -{
2 - "type": "Program",
3 - "loc": {
4 - "source": null,
5 - "start": {
6 - "line": 2,
7 - "column": 0
8 - },
9 - "end": {
10 - "line": 45,
11 - "column": 1
12 - }
13 - },
14 - "body": [
15 - {
16 - "type": "FunctionDeclaration",
17 - "loc": {
18 - "source": null,
19 - "start": {
20 - "line": 2,
21 - "column": 0
22 - },
23 - "end": {
24 - "line": 45,
25 - "column": 1
26 - }
27 - },
28 - "id": {
29 - "type": "Identifier",
30 - "loc": {
31 - "source": null,
32 - "start": {
33 - "line": 2,
34 - "column": 9
35 - },
36 - "end": {
37 - "line": 2,
38 - "column": 12
39 - }
40 - },
41 - "name": "foo",
42 - "typeAnnotation": null,
43 - "optional": false,
44 - "range": [
45 - 10,
46 - 13
47 - ]
48 - },
49 - "params": [
50 - {
51 - "type": "ArrayPattern",
52 - "loc": {
53 - "source": null,
54 - "start": {
55 - "line": 2,
56 - "column": 13
57 - },
58 - "end": {
59 - "line": 2,
60 - "column": 19
61 - }
62 - },
63 - "elements": [
64 - {
65 - "type": "Identifier",
66 - "loc": {
67 - "source": null,
68 - "start": {
69 - "line": 2,
70 - "column": 14
71 - },
72 - "end": {
73 - "line": 2,
74 - "column": 15
75 - }
76 - },
77 - "name": "a",
78 - "typeAnnotation": null,
79 - "optional": false,
80 - "range": [
81 - 15,
82 - 16
83 - ]
84 - },
85 - {
86 - "type": "Identifier",
87 - "loc": {
88 - "source": null,
89 - "start": {
90 - "line": 2,
91 - "column": 17
92 - },
93 - "end": {
94 - "line": 2,
95 - "column": 18
96 - }
97 - },
98 - "name": "b",
99 - "typeAnnotation": null,
100 - "optional": false,
101 - "range": [
102 - 18,
103 - 19
104 - ]
105 - }
106 - ],
107 - "typeAnnotation": null,
108 - "range": [
109 - 14,
110 - 20
111 - ]
112 - },
113 - {
114 - "type": "ObjectPattern",
115 - "loc": {
116 - "source": null,
117 - "start": {
118 - "line": 2,
119 - "column": 21
120 - },
121 - "end": {
122 - "line": 2,
123 - "column": 38
124 - }
125 - },
126 - "properties": [
127 - {
128 - "type": "Property",
129 - "loc": {
130 - "source": null,
131 - "start": {
132 - "line": 2,
133 - "column": 23
134 - },
135 - "end": {
136 - "line": 2,
137 - "column": 24
138 - }
139 - },
140 - "key": {
141 - "type": "Identifier",
142 - "loc": {
143 - "source": null,
144 - "start": {
145 - "line": 2,
146 - "column": 23
147 - },
148 - "end": {
149 - "line": 2,
150 - "column": 24
151 - }
152 - },
153 - "name": "c",
154 - "typeAnnotation": null,
155 - "optional": false,
156 - "range": [
157 - 24,
158 - 25
159 - ]
160 - },
161 - "value": {
162 - "type": "Identifier",
163 - "loc": {
164 - "source": null,
165 - "start": {
166 - "line": 2,
167 - "column": 23
168 - },
169 - "end": {
170 - "line": 2,
171 - "column": 24
172 - }
173 - },
174 - "name": "c",
175 - "typeAnnotation": null,
176 - "optional": false,
177 - "range": [
178 - 24,
179 - 25
180 - ]
181 - },
182 - "kind": "init",
183 - "computed": false,
184 - "method": false,
185 - "shorthand": true,
186 - "range": [
187 - 24,
188 - 25
189 - ]
190 - },
191 - {
192 - "type": "Property",
193 - "loc": {
194 - "source": null,
195 - "start": {
196 - "line": 2,
197 - "column": 26
198 - },
199 - "end": {
200 - "line": 2,
201 - "column": 27
202 - }
203 - },
204 - "key": {
205 - "type": "Identifier",
206 - "loc": {
207 - "source": null,
208 - "start": {
209 - "line": 2,
210 - "column": 26
211 - },
212 - "end": {
213 - "line": 2,
214 - "column": 27
215 - }
216 - },
217 - "name": "d",
218 - "typeAnnotation": null,
219 - "optional": false,
220 - "range": [
221 - 27,
222 - 28
223 - ]
224 - },
225 - "value": {
226 - "type": "Identifier",
227 - "loc": {
228 - "source": null,
229 - "start": {
230 - "line": 2,
231 - "column": 26
232 - },
233 - "end": {
234 - "line": 2,
235 - "column": 27
236 - }
237 - },
238 - "name": "d",
239 - "typeAnnotation": null,
240 - "optional": false,
241 - "range": [
242 - 27,
243 - 28
244 - ]
245 - },
246 - "kind": "init",
247 - "computed": false,
248 - "method": false,
249 - "shorthand": true,
250 - "range": [
251 - 27,
252 - 28
253 - ]
254 - },
255 - {
256 - "type": "Property",
257 - "loc": {
258 - "source": null,
259 - "start": {
260 - "line": 2,
261 - "column": 29
262 - },
263 - "end": {
264 - "line": 2,
265 - "column": 36
266 - }
267 - },
268 - "key": {
269 - "type": "Identifier",
270 - "loc": {
271 - "source": null,
272 - "start": {
273 - "line": 2,
274 - "column": 29
275 - },
276 - "end": {
277 - "line": 2,
278 - "column": 30
279 - }
280 - },
281 - "name": "e",
282 - "typeAnnotation": null,
283 - "optional": false,
284 - "range": [
285 - 30,
286 - 31
287 - ]
288 - },
289 - "value": {
290 - "type": "AssignmentPattern",
291 - "loc": {
292 - "source": null,
293 - "start": {
294 - "line": 2,
295 - "column": 29
296 - },
297 - "end": {
298 - "line": 2,
299 - "column": 36
300 - }
301 - },
302 - "left": {
303 - "type": "Identifier",
304 - "loc": {
305 - "source": null,
306 - "start": {
307 - "line": 2,
308 - "column": 29
309 - },
310 - "end": {
311 - "line": 2,
312 - "column": 30
313 - }
314 - },
315 - "name": "e",
316 - "typeAnnotation": null,
317 - "optional": false,
318 - "range": [
319 - 30,
320 - 31
321 - ]
322 - },
323 - "right": {
324 - "type": "Literal",
325 - "loc": {
326 - "source": null,
327 - "start": {
328 - "line": 2,
329 - "column": 33
330 - },
331 - "end": {
332 - "line": 2,
333 - "column": 36
334 - }
335 - },
336 - "value": "e",
337 - "range": [
338 - 34,
339 - 37
340 - ],
341 - "raw": "\"e\""
342 - },
343 - "range": [
344 - 30,
345 - 37
346 - ]
347 - },
348 - "kind": "init",
349 - "computed": false,
350 - "method": false,
351 - "shorthand": true,
352 - "range": [
353 - 30,
354 - 37
355 - ]
356 - }
357 - ],
358 - "typeAnnotation": null,
359 - "range": [
360 - 22,
361 - 39
362 - ]
363 - },
364 - {
365 - "type": "AssignmentPattern",
366 - "loc": {
367 - "source": null,
368 - "start": {
369 - "line": 2,
370 - "column": 40
371 - },
372 - "end": {
373 - "line": 2,
374 - "column": 47
375 - }
376 - },
377 - "left": {
378 - "type": "Identifier",
379 - "loc": {
380 - "source": null,
381 - "start": {
382 - "line": 2,
383 - "column": 40
384 - },
385 - "end": {
386 - "line": 2,
387 - "column": 41
388 - }
389 - },
390 - "name": "f",
391 - "typeAnnotation": null,
392 - "optional": false,
393 - "range": [
394 - 41,
395 - 42
396 - ]
397 - },
398 - "right": {
399 - "type": "Literal",
400 - "loc": {
401 - "source": null,
402 - "start": {
403 - "line": 2,
404 - "column": 44
405 - },
406 - "end": {
407 - "line": 2,
408 - "column": 47
409 - }
410 - },
411 - "value": "f",
412 - "range": [
413 - 45,
414 - 48
415 - ],
416 - "raw": "\"f\""
417 - },
418 - "range": [
419 - 41,
420 - 48
421 - ]
422 - },
423 - {
424 - "type": "RestElement",
425 - "loc": {
426 - "source": null,
427 - "start": {
428 - "line": 2,
429 - "column": 49
430 - },
431 - "end": {
432 - "line": 2,
433 - "column": 56
434 - }
435 - },
436 - "argument": {
437 - "type": "Identifier",
438 - "loc": {
439 - "source": null,
440 - "start": {
441 - "line": 2,
442 - "column": 52
443 - },
444 - "end": {
445 - "line": 2,
446 - "column": 56
447 - }
448 - },
449 - "name": "args",
450 - "typeAnnotation": null,
451 - "optional": false,
452 - "range": [
453 - 53,
454 - 57
455 - ]
456 - },
457 - "range": [
458 - 50,
459 - 57
460 - ]
461 - }
462 - ],
463 - "body": {
464 - "type": "BlockStatement",
465 - "loc": {
466 - "source": null,
467 - "start": {
468 - "line": 2,
469 - "column": 58
470 - },
471 - "end": {
472 - "line": 45,
473 - "column": 1
474 - }
475 - },
476 - "body": [
477 - {
478 - "type": "ExpressionStatement",
479 - "loc": {
480 - "source": null,
481 - "start": {
482 - "line": 3,
483 - "column": 2
484 - },
485 - "end": {
486 - "line": 3,
487 - "column": 18
488 - }
489 - },
490 - "expression": {
491 - "type": "Literal",
492 - "loc": {
493 - "source": null,
494 - "start": {
495 - "line": 3,
496 - "column": 2
497 - },
498 - "end": {
499 - "line": 3,
500 - "column": 18
501 - }
502 - },
503 - "value": "use P780731197",
504 - "range": [
505 - 63,
506 - 79
507 - ],
508 - "raw": "\"use P780731197\""
509 - },
510 - "directive": "use P780731197",
511 - "range": [
512 - 63,
513 - 79
514 - ]
515 - },
516 - {
517 - "type": "VariableDeclaration",
518 - "loc": {
519 - "source": null,
520 - "start": {
521 - "line": 4,
522 - "column": 2
523 - },
524 - "end": {
525 - "line": 4,
526 - "column": 12
527 - }
528 - },
529 - "kind": "let",
530 - "declarations": [
531 - {
532 - "type": "VariableDeclarator",
533 - "loc": {
534 - "source": null,
535 - "start": {
536 - "line": 4,
537 - "column": 6
538 - },
539 - "end": {
540 - "line": 4,
541 - "column": 11
542 - }
543 - },
544 - "init": {
545 - "type": "Literal",
546 - "loc": {
547 - "source": null,
548 - "start": {
549 - "line": 4,
550 - "column": 10
551 - },
552 - "end": {
553 - "line": 4,
554 - "column": 11
555 - }
556 - },
557 - "value": 0,
558 - "range": [
559 - 90,
560 - 91
561 - ],
562 - "raw": "0"
563 - },
564 - "id": {
565 - "type": "Identifier",
566 - "loc": {
567 - "source": null,
568 - "start": {
569 - "line": 4,
570 - "column": 6
571 - },
572 - "end": {
573 - "line": 4,
574 - "column": 7
575 - }
576 - },
577 - "name": "i",
578 - "typeAnnotation": null,
579 - "optional": false,
580 - "range": [
581 - 86,
582 - 87
583 - ]
584 - },
585 - "range": [
586 - 86,
587 - 91
588 - ]
589 - }
590 - ],
591 - "range": [
592 - 82,
593 - 92
594 - ]
595 - },
596 - {
597 - "type": "VariableDeclaration",
598 - "loc": {
599 - "source": null,
600 - "start": {
601 - "line": 5,
602 - "column": 2
603 - },
604 - "end": {
605 - "line": 5,
606 - "column": 13
607 - }
608 - },
609 - "kind": "var",
610 - "declarations": [
611 - {
612 - "type": "VariableDeclarator",
613 - "loc": {
614 - "source": null,
615 - "start": {
616 - "line": 5,
617 - "column": 6
618 - },
619 - "end": {
620 - "line": 5,
621 - "column": 12
622 - }
623 - },
624 - "init": {
625 - "type": "ArrayExpression",
626 - "loc": {
627 - "source": null,
628 - "start": {
629 - "line": 5,
630 - "column": 10
631 - },
632 - "end": {
633 - "line": 5,
634 - "column": 12
635 - }
636 - },
637 - "elements": [],
638 - "trailingComma": false,
639 - "range": [
640 - 103,
641 - 105
642 - ]
643 - },
644 - "id": {
645 - "type": "Identifier",
646 - "loc": {
647 - "source": null,
648 - "start": {
649 - "line": 5,
650 - "column": 6
651 - },
652 - "end": {
653 - "line": 5,
654 - "column": 7
655 - }
656 - },
657 - "name": "x",
658 - "typeAnnotation": null,
659 - "optional": false,
660 - "range": [
661 - 99,
662 - 100
663 - ]
664 - },
665 - "range": [
666 - 99,
667 - 105
668 - ]
669 - }
670 - ],
671 - "range": [
672 - 95,
673 - 106
674 - ]
675 - },
676 - {
677 - "type": "ClassDeclaration",
678 - "loc": {
679 - "source": null,
680 - "start": {
681 - "line": 7,
682 - "column": 2
683 - },
684 - "end": {
685 - "line": 12,
686 - "column": 3
687 - }
688 - },
689 - "id": {
690 - "type": "Identifier",
691 - "loc": {
692 - "source": null,
693 - "start": {
694 - "line": 7,
695 - "column": 8
696 - },
697 - "end": {
698 - "line": 7,
699 - "column": 11
700 - }
701 - },
702 - "name": "Bar",
703 - "typeAnnotation": null,
704 - "optional": false,
705 - "range": [
706 - 116,
707 - 119
708 - ]
709 - },
710 - "typeParameters": null,
711 - "superClass": null,
712 - "superTypeParameters": null,
713 - "implements": [],
714 - "decorators": [],
715 - "body": {
716 - "type": "ClassBody",
717 - "loc": {
718 - "source": null,
719 - "start": {
720 - "line": 7,
721 - "column": 12
722 - },
723 - "end": {
724 - "line": 12,
725 - "column": 3
726 - }
727 - },
728 - "body": [
729 - {
730 - "type": "ClassProperty",
731 - "loc": {
732 - "source": null,
733 - "start": {
734 - "line": 8,
735 - "column": 4
736 - },
737 - "end": {
738 - "line": 8,
739 - "column": 21
740 - }
741 - },
742 - "key": {
743 - "type": "Identifier",
744 - "loc": {
745 - "source": null,
746 - "start": {
747 - "line": 8,
748 - "column": 4
749 - },
750 - "end": {
751 - "line": 8,
752 - "column": 15
753 - }
754 - },
755 - "name": "secretSauce",
756 - "typeAnnotation": null,
757 - "optional": false,
758 - "range": [
759 - 126,
760 - 137
761 - ]
762 - },
763 - "value": {
764 - "type": "Literal",
765 - "loc": {
766 - "source": null,
767 - "start": {
768 - "line": 8,
769 - "column": 18
770 - },
771 - "end": {
772 - "line": 8,
773 - "column": 20
774 - }
775 - },
776 - "value": 42,
777 - "range": [
778 - 140,
779 - 142
780 - ],
781 - "raw": "42"
782 - },
783 - "computed": false,
784 - "static": false,
785 - "declare": false,
786 - "optional": false,
787 - "variance": null,
788 - "typeAnnotation": null,
789 - "range": [
790 - 126,
791 - 143
792 - ]
793 - },
794 - {
795 - "type": "MethodDefinition",
796 - "loc": {
797 - "source": null,
798 - "start": {
799 - "line": 9,
800 - "column": 4
801 - },
802 - "end": {
803 - "line": 11,
804 - "column": 5
805 - }
806 - },
807 - "key": {
808 - "type": "Identifier",
809 - "loc": {
810 - "source": null,
811 - "start": {
812 - "line": 9,
813 - "column": 4
814 - },
815 - "end": {
816 - "line": 9,
817 - "column": 15
818 - }
819 - },
820 - "name": "constructor",
821 - "typeAnnotation": null,
822 - "optional": false,
823 - "range": [
824 - 148,
825 - 159
826 - ]
827 - },
828 - "value": {
829 - "type": "FunctionExpression",
830 - "loc": {
831 - "source": null,
832 - "start": {
833 - "line": 9,
834 - "column": 15
835 - },
836 - "end": {
837 - "line": 11,
838 - "column": 5
839 - }
840 - },
841 - "id": null,
842 - "params": [],
843 - "body": {
844 - "type": "BlockStatement",
845 - "loc": {
846 - "source": null,
847 - "start": {
848 - "line": 9,
849 - "column": 18
850 - },
851 - "end": {
852 - "line": 11,
853 - "column": 5
854 - }
855 - },
856 - "body": [
857 - {
858 - "type": "ExpressionStatement",
859 - "loc": {
860 - "source": null,
861 - "start": {
862 - "line": 10,
863 - "column": 6
864 - },
865 - "end": {
866 - "line": 10,
867 - "column": 36
868 - }
869 - },
870 - "expression": {
871 - "type": "CallExpression",
872 - "loc": {
873 - "source": null,
874 - "start": {
875 - "line": 10,
876 - "column": 6
877 - },
878 - "end": {
879 - "line": 10,
880 - "column": 35
881 - }
882 - },
883 - "callee": {
884 - "type": "MemberExpression",
885 - "loc": {
886 - "source": null,
887 - "start": {
888 - "line": 10,
889 - "column": 6
890 - },
891 - "end": {
892 - "line": 10,
893 - "column": 17
894 - }
895 - },
896 - "object": {
897 - "type": "Identifier",
898 - "loc": {
899 - "source": null,
900 - "start": {
901 - "line": 10,
902 - "column": 6
903 - },
904 - "end": {
905 - "line": 10,
906 - "column": 13
907 - }
908 - },
909 - "name": "console",
910 - "typeAnnotation": null,
911 - "optional": false,
912 - "range": [
913 - 170,
914 - 177
915 - ]
916 - },
917 - "property": {
918 - "type": "Identifier",
919 - "loc": {
920 - "source": null,
921 - "start": {
922 - "line": 10,
923 - "column": 14
924 - },
925 - "end": {
926 - "line": 10,
927 - "column": 17
928 - }
929 - },
930 - "name": "log",
931 - "typeAnnotation": null,
932 - "optional": false,
933 - "range": [
934 - 178,
935 - 181
936 - ]
937 - },
938 - "computed": false,
939 - "range": [
940 - 170,
941 - 181
942 - ]
943 - },
944 - "typeArguments": null,
945 - "arguments": [
946 - {
947 - "type": "MemberExpression",
948 - "loc": {
949 - "source": null,
950 - "start": {
951 - "line": 10,
952 - "column": 18
953 - },
954 - "end": {
955 - "line": 10,
956 - "column": 34
957 - }
958 - },
959 - "object": {
960 - "type": "ThisExpression",
961 - "loc": {
962 - "source": null,
963 - "start": {
964 - "line": 10,
965 - "column": 18
966 - },
967 - "end": {
968 - "line": 10,
969 - "column": 22
970 - }
971 - },
972 - "range": [
973 - 182,
974 - 186
975 - ]
976 - },
977 - "property": {
978 - "type": "Identifier",
979 - "loc": {
980 - "source": null,
981 - "start": {
982 - "line": 10,
983 - "column": 23
984 - },
985 - "end": {
986 - "line": 10,
987 - "column": 34
988 - }
989 - },
990 - "name": "secretSauce",
991 - "typeAnnotation": null,
992 - "optional": false,
993 - "range": [
994 - 187,
995 - 198
996 - ]
997 - },
998 - "computed": false,
999 - "range": [
1000 - 182,
1001 - 198
1002 - ]
1003 - }
1004 - ],
1005 - "range": [
1006 - 170,
1007 - 199
1008 - ]
1009 - },
1010 - "directive": null,
1011 - "range": [
1012 - 170,
1013 - 200
1014 - ]
1015 - }
1016 - ],
1017 - "range": [
1018 - 162,
1019 - 206
1020 - ]
1021 - },
1022 - "typeParameters": null,
1023 - "returnType": null,
1024 - "predicate": null,
1025 - "generator": false,
1026 - "async": false,
1027 - "range": [
1028 - 159,
1029 - 206
1030 - ]
1031 - },
1032 - "kind": "constructor",
1033 - "computed": false,
1034 - "static": false,
1035 - "range": [
1036 - 148,
1037 - 206
1038 - ]
1039 - }
1040 - ],
1041 - "range": [
1042 - 120,
1043 - 210
1044 - ]
1045 - },
1046 - "range": [
1047 - 110,
1048 - 210
1049 - ]
1050 - },
1051 - {
1052 - "type": "VariableDeclaration",
1053 - "loc": {
1054 - "source": null,
1055 - "start": {
1056 - "line": 14,
1057 - "column": 2
1058 - },
1059 - "end": {
1060 - "line": 14,
1061 - "column": 42
1062 - }
1063 - },
1064 - "kind": "const",
1065 - "declarations": [
1066 - {
1067 - "type": "VariableDeclarator",
1068 - "loc": {
1069 - "source": null,
1070 - "start": {
1071 - "line": 14,
1072 - "column": 8
1073 - },
1074 - "end": {
1075 - "line": 14,
1076 - "column": 41
1077 - }
1078 - },
1079 - "init": {
1080 - "type": "ObjectExpression",
1081 - "loc": {
1082 - "source": null,
1083 - "start": {
1084 - "line": 14,
1085 - "column": 12
1086 - },
1087 - "end": {
1088 - "line": 14,
1089 - "column": 41
1090 - }
1091 - },
1092 - "properties": [
1093 - {
1094 - "type": "SpreadElement",
1095 - "loc": {
1096 - "source": null,
1097 - "start": {
1098 - "line": 14,
1099 - "column": 14
1100 - },
1101 - "end": {
1102 - "line": 14,
1103 - "column": 18
1104 - }
1105 - },
1106 - "argument": {
1107 - "type": "Identifier",
1108 - "loc": {
1109 - "source": null,
1110 - "start": {
1111 - "line": 14,
1112 - "column": 17
1113 - },
1114 - "end": {
1115 - "line": 14,
1116 - "column": 18
1117 - }
1118 - },
1119 - "name": "a",
1120 - "typeAnnotation": null,
1121 - "optional": false,
1122 - "range": [
1123 - 229,
1124 - 230
1125 - ]
1126 - },
1127 - "range": [
1128 - 226,
1129 - 230
1130 - ]
1131 - },
1132 - {
1133 - "type": "Property",
1134 - "loc": {
1135 - "source": null,
1136 - "start": {
1137 - "line": 14,
1138 - "column": 20
1139 - },
1140 - "end": {
1141 - "line": 14,
1142 - "column": 26
1143 - }
1144 - },
1145 - "key": {
1146 - "type": "Identifier",
1147 - "loc": {
1148 - "source": null,
1149 - "start": {
1150 - "line": 14,
1151 - "column": 20
1152 - },
1153 - "end": {
1154 - "line": 14,
1155 - "column": 21
1156 - }
1157 - },
1158 - "name": "b",
1159 - "typeAnnotation": null,
1160 - "optional": false,
1161 - "range": [
1162 - 232,
1163 - 233
1164 - ]
1165 - },
1166 - "value": {
1167 - "type": "FunctionExpression",
1168 - "loc": {
1169 - "source": null,
1170 - "start": {
1171 - "line": 14,
1172 - "column": 20
1173 - },
1174 - "end": {
1175 - "line": 14,
1176 - "column": 26
1177 - }
1178 - },
1179 - "id": null,
1180 - "params": [],
1181 - "body": {
1182 - "type": "BlockStatement",
1183 - "loc": {
1184 - "source": null,
1185 - "start": {
1186 - "line": 14,
1187 - "column": 24
1188 - },
1189 - "end": {
1190 - "line": 14,
1191 - "column": 26
1192 - }
1193 - },
1194 - "body": [],
1195 - "range": [
1196 - 236,
1197 - 238
1198 - ]
1199 - },
1200 - "typeParameters": null,
1201 - "returnType": null,
1202 - "predicate": null,
1203 - "generator": false,
1204 - "async": false,
1205 - "range": [
1206 - 232,
1207 - 238
1208 - ]
1209 - },
1210 - "kind": "init",
1211 - "computed": false,
1212 - "method": true,
1213 - "shorthand": false,
1214 - "range": [
1215 - 232,
1216 - 238
1217 - ]
1218 - },
1219 - {
1220 - "type": "Property",
1221 - "loc": {
1222 - "source": null,
1223 - "start": {
1224 - "line": 14,
1225 - "column": 28
1226 - },
1227 - "end": {
1228 - "line": 14,
1229 - "column": 39
1230 - }
1231 - },
1232 - "key": {
1233 - "type": "Identifier",
1234 - "loc": {
1235 - "source": null,
1236 - "start": {
1237 - "line": 14,
1238 - "column": 28
1239 - },
1240 - "end": {
1241 - "line": 14,
1242 - "column": 29
1243 - }
1244 - },
1245 - "name": "c",
1246 - "typeAnnotation": null,
1247 - "optional": false,
1248 - "range": [
1249 - 240,
1250 - 241
1251 - ]
1252 - },
1253 - "value": {
1254 - "type": "ArrowFunctionExpression",
1255 - "loc": {
1256 - "source": null,
1257 - "start": {
1258 - "line": 14,
1259 - "column": 31
1260 - },
1261 - "end": {
1262 - "line": 14,
1263 - "column": 39
1264 - }
1265 - },
1266 - "id": null,
1267 - "params": [],
1268 - "body": {
1269 - "type": "BlockStatement",
1270 - "loc": {
1271 - "source": null,
1272 - "start": {
1273 - "line": 14,
1274 - "column": 37
1275 - },
1276 - "end": {
1277 - "line": 14,
1278 - "column": 39
1279 - }
1280 - },
1281 - "body": [],
1282 - "range": [
1283 - 249,
1284 - 251
1285 - ]
1286 - },
1287 - "typeParameters": null,
1288 - "returnType": null,
1289 - "predicate": null,
1290 - "expression": false,
1291 - "async": false,
1292 - "range": [
1293 - 243,
1294 - 251
1295 - ]
1296 - },
1297 - "kind": "init",
1298 - "computed": false,
1299 - "method": false,
1300 - "shorthand": false,
1301 - "range": [
1302 - 240,
1303 - 251
1304 - ]
1305 - }
1306 - ],
1307 - "range": [
1308 - 224,
1309 - 253
1310 - ]
1311 - },
1312 - "id": {
1313 - "type": "Identifier",
1314 - "loc": {
1315 - "source": null,
1316 - "start": {
1317 - "line": 14,
1318 - "column": 8
1319 - },
1320 - "end": {
1321 - "line": 14,
1322 - "column": 9
1323 - }
1324 - },
1325 - "name": "g",
1326 - "typeAnnotation": null,
1327 - "optional": false,
1328 - "range": [
1329 - 220,
1330 - 221
1331 - ]
1332 - },
1333 - "range": [
1334 - 220,
1335 - 253
1336 - ]
1337 - }
1338 - ],
1339 - "range": [
1340 - 214,
1341 - 254
1342 - ]
1343 - },
1344 - {
1345 - "type": "VariableDeclaration",
1346 - "loc": {
1347 - "source": null,
1348 - "start": {
1349 - "line": 15,
1350 - "column": 2
1351 - },
1352 - "end": {
1353 - "line": 15,
1354 - "column": 19
1355 - }
1356 - },
1357 - "kind": "const",
1358 - "declarations": [
1359 - {
1360 - "type": "VariableDeclarator",
1361 - "loc": {
1362 - "source": null,
1363 - "start": {
1364 - "line": 15,
1365 - "column": 8
1366 - },
1367 - "end": {
1368 - "line": 15,
1369 - "column": 18
1370 - }
1371 - },
1372 - "init": {
1373 - "type": "ArrayExpression",
1374 - "loc": {
1375 - "source": null,
1376 - "start": {
1377 - "line": 15,
1378 - "column": 12
1379 - },
1380 - "end": {
1381 - "line": 15,
1382 - "column": 18
1383 - }
1384 - },
1385 - "elements": [
1386 - {
1387 - "type": "SpreadElement",
1388 - "loc": {
1389 - "source": null,
1390 - "start": {
1391 - "line": 15,
1392 - "column": 13
1393 - },
1394 - "end": {
1395 - "line": 15,
1396 - "column": 17
1397 - }
1398 - },
1399 - "argument": {
1400 - "type": "Identifier",
1401 - "loc": {
1402 - "source": null,
1403 - "start": {
1404 - "line": 15,
1405 - "column": 16
1406 - },
1407 - "end": {
1408 - "line": 15,
1409 - "column": 17
1410 - }
1411 - },
1412 - "name": "b",
1413 - "typeAnnotation": null,
1414 - "optional": false,
1415 - "range": [
1416 - 271,
1417 - 272
1418 - ]
1419 - },
1420 - "range": [
1421 - 268,
1422 - 272
1423 - ]
1424 - }
1425 - ],
1426 - "trailingComma": false,
1427 - "range": [
1428 - 267,
1429 - 273
1430 - ]
1431 - },
1432 - "id": {
1433 - "type": "Identifier",
1434 - "loc": {
1435 - "source": null,
1436 - "start": {
1437 - "line": 15,
1438 - "column": 8
1439 - },
1440 - "end": {
1441 - "line": 15,
1442 - "column": 9
1443 - }
1444 - },
1445 - "name": "h",
1446 - "typeAnnotation": null,
1447 - "optional": false,
1448 - "range": [
1449 - 263,
1450 - 264
1451 - ]
1452 - },
1453 - "range": [
1454 - 263,
1455 - 273
1456 - ]
1457 - }
1458 - ],
1459 - "range": [
1460 - 257,
1461 - 274
1462 - ]
1463 - },
1464 - {
1465 - "type": "ExpressionStatement",
1466 - "loc": {
1467 - "source": null,
1468 - "start": {
1469 - "line": 16,
1470 - "column": 2
1471 - },
1472 - "end": {
1473 - "line": 16,
1474 - "column": 17
1475 - }
1476 - },
1477 - "expression": {
1478 - "type": "NewExpression",
1479 - "loc": {
1480 - "source": null,
1481 - "start": {
1482 - "line": 16,
1483 - "column": 2
1484 - },
1485 - "end": {
1486 - "line": 16,
1487 - "column": 16
1488 - }
1489 - },
1490 - "callee": {
1491 - "type": "Identifier",
1492 - "loc": {
1493 - "source": null,
1494 - "start": {
1495 - "line": 16,
1496 - "column": 6
1497 - },
1498 - "end": {
1499 - "line": 16,
1500 - "column": 7
1501 - }
1502 - },
1503 - "name": "c",
1504 - "typeAnnotation": null,
1505 - "optional": false,
1506 - "range": [
1507 - 281,
1508 - 282
1509 - ]
1510 - },
1511 - "typeArguments": null,
1512 - "arguments": [
1513 - {
1514 - "type": "SpreadElement",
1515 - "loc": {
1516 - "source": null,
1517 - "start": {
1518 - "line": 16,
1519 - "column": 8
1520 - },
1521 - "end": {
1522 - "line": 16,
1523 - "column": 15
1524 - }
1525 - },
1526 - "argument": {
1527 - "type": "Identifier",
1528 - "loc": {
1529 - "source": null,
1530 - "start": {
1531 - "line": 16,
1532 - "column": 11
1533 - },
1534 - "end": {
1535 - "line": 16,
1536 - "column": 15
1537 - }
1538 - },
1539 - "name": "args",
1540 - "typeAnnotation": null,
1541 - "optional": false,
1542 - "range": [
1543 - 286,
1544 - 290
1545 - ]
1546 - },
1547 - "range": [
1548 - 283,
1549 - 290
1550 - ]
1551 - }
1552 - ],
1553 - "range": [
1554 - 277,
1555 - 291
1556 - ]
1557 - },
1558 - "directive": null,
1559 - "range": [
1560 - 277,
1561 - 292
1562 - ]
1563 - },
1564 - {
1565 - "type": "ExpressionStatement",
1566 - "loc": {
1567 - "source": null,
1568 - "start": {
1569 - "line": 17,
1570 - "column": 2
1571 - },
1572 - "end": {
1573 - "line": 17,
1574 - "column": 13
1575 - }
1576 - },
1577 - "expression": {
1578 - "type": "CallExpression",
1579 - "loc": {
1580 - "source": null,
1581 - "start": {
1582 - "line": 17,
1583 - "column": 2
1584 - },
1585 - "end": {
1586 - "line": 17,
1587 - "column": 12
1588 - }
1589 - },
1590 - "callee": {
1591 - "type": "Identifier",
1592 - "loc": {
1593 - "source": null,
1594 - "start": {
1595 - "line": 17,
1596 - "column": 2
1597 - },
1598 - "end": {
1599 - "line": 17,
1600 - "column": 3
1601 - }
1602 - },
1603 - "name": "c",
1604 - "typeAnnotation": null,
1605 - "optional": false,
1606 - "range": [
1607 - 295,
1608 - 296
1609 - ]
1610 - },
1611 - "typeArguments": null,
1612 - "arguments": [
1613 - {
1614 - "type": "SpreadElement",
1615 - "loc": {
1616 - "source": null,
1617 - "start": {
1618 - "line": 17,
1619 - "column": 4
1620 - },
1621 - "end": {
1622 - "line": 17,
1623 - "column": 11
1624 - }
1625 - },
1626 - "argument": {
1627 - "type": "Identifier",
1628 - "loc": {
1629 - "source": null,
1630 - "start": {
1631 - "line": 17,
1632 - "column": 7
1633 - },
1634 - "end": {
1635 - "line": 17,
1636 - "column": 11
1637 - }
1638 - },
1639 - "name": "args",
1640 - "typeAnnotation": null,
1641 - "optional": false,
1642 - "range": [
1643 - 300,
1644 - 304
1645 - ]
1646 - },
1647 - "range": [
1648 - 297,
1649 - 304
1650 - ]
1651 - }
1652 - ],
1653 - "range": [
1654 - 295,
1655 - 305
1656 - ]
1657 - },
1658 - "directive": null,
1659 - "range": [
1660 - 295,
1661 - 306
1662 - ]
1663 - },
1664 - {
1665 - "type": "ExpressionStatement",
1666 - "loc": {
1667 - "source": null,
1668 - "start": {
1669 - "line": 18,
1670 - "column": 2
1671 - },
1672 - "end": {
1673 - "line": 18,
1674 - "column": 14
1675 - }
1676 - },
1677 - "expression": {
1678 - "type": "AssignmentExpression",
1679 - "loc": {
1680 - "source": null,
1681 - "start": {
1682 - "line": 18,
1683 - "column": 2
1684 - },
1685 - "end": {
1686 - "line": 18,
1687 - "column": 13
1688 - }
1689 - },
1690 - "operator": "+=",
1691 - "left": {
1692 - "type": "MemberExpression",
1693 - "loc": {
1694 - "source": null,
1695 - "start": {
1696 - "line": 18,
1697 - "column": 2
1698 - },
1699 - "end": {
1700 - "line": 18,
1701 - "column": 8
1702 - }
1703 - },
1704 - "object": {
1705 - "type": "Identifier",
1706 - "loc": {
1707 - "source": null,
1708 - "start": {
1709 - "line": 18,
1710 - "column": 2
1711 - },
1712 - "end": {
1713 - "line": 18,
1714 - "column": 3
1715 - }
1716 - },
1717 - "name": "g",
1718 - "typeAnnotation": null,
1719 - "optional": false,
1720 - "range": [
1721 - 309,
1722 - 310
1723 - ]
1724 - },
1725 - "property": {
1726 - "type": "Literal",
1727 - "loc": {
1728 - "source": null,
1729 - "start": {
1730 - "line": 18,
1731 - "column": 4
1732 - },
1733 - "end": {
1734 - "line": 18,
1735 - "column": 7
1736 - }
1737 - },
1738 - "value": "e",
1739 - "range": [
1740 - 311,
1741 - 314
1742 - ],
1743 - "raw": "\"e\""
1744 - },
1745 - "computed": true,
1746 - "range": [
1747 - 309,
1748 - 315
1749 - ]
1750 - },
1751 - "right": {
1752 - "type": "Literal",
1753 - "loc": {
1754 - "source": null,
1755 - "start": {
1756 - "line": 18,
1757 - "column": 12
1758 - },
1759 - "end": {
1760 - "line": 18,
1761 - "column": 13
1762 - }
1763 - },
1764 - "value": 1,
1765 - "range": [
1766 - 319,
1767 - 320
1768 - ],
1769 - "raw": "1"
1770 - },
1771 - "range": [
1772 - 309,
1773 - 320
1774 - ]
1775 - },
1776 - "directive": null,
1777 - "range": [
1778 - 309,
1779 - 321
1780 - ]
1781 - },
1782 - {
1783 - "type": "VariableDeclaration",
1784 - "loc": {
1785 - "source": null,
1786 - "start": {
1787 - "line": 19,
1788 - "column": 2
1789 - },
1790 - "end": {
1791 - "line": 19,
1792 - "column": 33
1793 - }
1794 - },
1795 - "kind": "const",
1796 - "declarations": [
1797 - {
1798 - "type": "VariableDeclarator",
1799 - "loc": {
1800 - "source": null,
1801 - "start": {
1802 - "line": 19,
1803 - "column": 8
1804 - },
1805 - "end": {
1806 - "line": 19,
1807 - "column": 32
1808 - }
1809 - },
1810 - "init": {
1811 - "type": "CallExpression",
1812 - "loc": {
1813 - "source": null,
1814 - "start": {
1815 - "line": 19,
1816 - "column": 21
1817 - },
1818 - "end": {
1819 - "line": 19,
1820 - "column": 32
1821 - }
1822 - },
1823 - "callee": {
1824 - "type": "Identifier",
1825 - "loc": {
1826 - "source": null,
1827 - "start": {
1828 - "line": 19,
1829 - "column": 21
1830 - },
1831 - "end": {
1832 - "line": 19,
1833 - "column": 29
1834 - }
1835 - },
1836 - "name": "useState",
1837 - "typeAnnotation": null,
1838 - "optional": false,
1839 - "range": [
1840 - 343,
1841 - 351
1842 - ]
1843 - },
1844 - "typeArguments": null,
1845 - "arguments": [
1846 - {
1847 - "type": "Literal",
1848 - "loc": {
1849 - "source": null,
1850 - "start": {
1851 - "line": 19,
1852 - "column": 30
1853 - },
1854 - "end": {
1855 - "line": 19,
1856 - "column": 31
1857 - }
1858 - },
1859 - "value": 0,
1860 - "range": [
1861 - 352,
1862 - 353
1863 - ],
1864 - "raw": "0"
1865 - }
1866 - ],
1867 - "range": [
1868 - 343,
1869 - 354
1870 - ]
1871 - },
1872 - "id": {
1873 - "type": "ArrayPattern",
1874 - "loc": {
1875 - "source": null,
1876 - "start": {
1877 - "line": 19,
1878 - "column": 8
1879 - },
1880 - "end": {
1881 - "line": 19,
1882 - "column": 18
1883 - }
1884 - },
1885 - "elements": [
1886 - {
1887 - "type": "Identifier",
1888 - "loc": {
1889 - "source": null,
1890 - "start": {
1891 - "line": 19,
1892 - "column": 9
1893 - },
1894 - "end": {
1895 - "line": 19,
1896 - "column": 10
1897 - }
1898 - },
1899 - "name": "y",
1900 - "typeAnnotation": null,
1901 - "optional": false,
1902 - "range": [
1903 - 331,
1904 - 332
1905 - ]
1906 - },
1907 - {
1908 - "type": "RestElement",
1909 - "loc": {
1910 - "source": null,
1911 - "start": {
1912 - "line": 19,
1913 - "column": 12
1914 - },
1915 - "end": {
1916 - "line": 19,
1917 - "column": 17
1918 - }
1919 - },
1920 - "argument": {
1921 - "type": "Identifier",
1922 - "loc": {
1923 - "source": null,
1924 - "start": {
1925 - "line": 19,
1926 - "column": 15
1927 - },
1928 - "end": {
1929 - "line": 19,
1930 - "column": 17
1931 - }
1932 - },
1933 - "name": "yy",
1934 - "typeAnnotation": null,
1935 - "optional": false,
1936 - "range": [
1937 - 337,
1938 - 339
1939 - ]
1940 - },
1941 - "range": [
1942 - 334,
1943 - 339
1944 - ]
1945 - }
1946 - ],
1947 - "typeAnnotation": null,
1948 - "range": [
1949 - 330,
1950 - 340
1951 - ]
1952 - },
1953 - "range": [
1954 - 330,
1955 - 354
1956 - ]
1957 - }
1958 - ],
1959 - "range": [
1960 - 324,
1961 - 355
1962 - ]
1963 - },
1964 - {
1965 - "type": "VariableDeclaration",
1966 - "loc": {
1967 - "source": null,
1968 - "start": {
1969 - "line": 20,
1970 - "column": 2
1971 - },
1972 - "end": {
1973 - "line": 20,
1974 - "column": 46
1975 - }
1976 - },
1977 - "kind": "const",
1978 - "declarations": [
1979 - {
1980 - "type": "VariableDeclarator",
1981 - "loc": {
1982 - "source": null,
1983 - "start": {
1984 - "line": 20,
1985 - "column": 8
1986 - },
1987 - "end": {
1988 - "line": 20,
1989 - "column": 45
1990 - }
1991 - },
1992 - "init": {
1993 - "type": "CallExpression",
1994 - "loc": {
1995 - "source": null,
1996 - "start": {
1997 - "line": 20,
1998 - "column": 34
1999 - },
2000 - "end": {
2001 - "line": 20,
2002 - "column": 45
2003 - }
2004 - },
2005 - "callee": {
2006 - "type": "Identifier",
2007 - "loc": {
2008 - "source": null,
2009 - "start": {
2010 - "line": 20,
2011 - "column": 34
2012 - },
2013 - "end": {
2014 - "line": 20,
2015 - "column": 43
2016 - }
2017 - },
2018 - "name": "useCustom",
2019 - "typeAnnotation": null,
2020 - "optional": false,
2021 - "range": [
2022 - 390,
2023 - 399
2024 - ]
2025 - },
2026 - "typeArguments": null,
2027 - "arguments": [],
2028 - "range": [
2029 - 390,
2030 - 401
2031 - ]
2032 - },
2033 - "id": {
2034 - "type": "ObjectPattern",
2035 - "loc": {
2036 - "source": null,
2037 - "start": {
2038 - "line": 20,
2039 - "column": 8
2040 - },
2041 - "end": {
2042 - "line": 20,
2043 - "column": 31
2044 - }
2045 - },
2046 - "properties": [
2047 - {
2048 - "type": "Property",
2049 - "loc": {
2050 - "source": null,
2051 - "start": {
2052 - "line": 20,
2053 - "column": 10
2054 - },
2055 - "end": {
2056 - "line": 20,
2057 - "column": 11
2058 - }
2059 - },
2060 - "key": {
2061 - "type": "Identifier",
2062 - "loc": {
2063 - "source": null,
2064 - "start": {
2065 - "line": 20,
2066 - "column": 10
2067 - },
2068 - "end": {
2069 - "line": 20,
2070 - "column": 11
2071 - }
2072 - },
2073 - "name": "z",
2074 - "typeAnnotation": null,
2075 - "optional": false,
2076 - "range": [
2077 - 366,
2078 - 367
2079 - ]
2080 - },
2081 - "value": {
2082 - "type": "Identifier",
2083 - "loc": {
2084 - "source": null,
2085 - "start": {
2086 - "line": 20,
2087 - "column": 10
2088 - },
2089 - "end": {
2090 - "line": 20,
2091 - "column": 11
2092 - }
2093 - },
2094 - "name": "z",
2095 - "typeAnnotation": null,
2096 - "optional": false,
2097 - "range": [
2098 - 366,
2099 - 367
2100 - ]
2101 - },
2102 - "kind": "init",
2103 - "computed": false,
2104 - "method": false,
2105 - "shorthand": true,
2106 - "range": [
2107 - 366,
2108 - 367
2109 - ]
2110 - },
2111 - {
2112 - "type": "Property",
2113 - "loc": {
2114 - "source": null,
2115 - "start": {
2116 - "line": 20,
2117 - "column": 13
2118 - },
2119 - "end": {
2120 - "line": 20,
2121 - "column": 22
2122 - }
2123 - },
2124 - "key": {
2125 - "type": "Identifier",
2126 - "loc": {
2127 - "source": null,
2128 - "start": {
2129 - "line": 20,
2130 - "column": 13
2131 - },
2132 - "end": {
2133 - "line": 20,
2134 - "column": 15
2135 - }
2136 - },
2137 - "name": "aa",
2138 - "typeAnnotation": null,
2139 - "optional": false,
2140 - "range": [
2141 - 369,
2142 - 371
2143 - ]
2144 - },
2145 - "value": {
2146 - "type": "AssignmentPattern",
2147 - "loc": {
2148 - "source": null,
2149 - "start": {
2150 - "line": 20,
2151 - "column": 13
2152 - },
2153 - "end": {
2154 - "line": 20,
2155 - "column": 22
2156 - }
2157 - },
2158 - "left": {
2159 - "type": "Identifier",
2160 - "loc": {
2161 - "source": null,
2162 - "start": {
2163 - "line": 20,
2164 - "column": 13
2165 - },
2166 - "end": {
2167 - "line": 20,
2168 - "column": 15
2169 - }
2170 - },
2171 - "name": "aa",
2172 - "typeAnnotation": null,
2173 - "optional": false,
2174 - "range": [
2175 - 369,
2176 - 371
2177 - ]
2178 - },
2179 - "right": {
2180 - "type": "Literal",
2181 - "loc": {
2182 - "source": null,
2183 - "start": {
2184 - "line": 20,
2185 - "column": 18
2186 - },
2187 - "end": {
2188 - "line": 20,
2189 - "column": 22
2190 - }
2191 - },
2192 - "value": "aa",
2193 - "range": [
2194 - 374,
2195 - 378
2196 - ],
2197 - "raw": "\"aa\""
2198 - },
2199 - "range": [
2200 - 369,
2201 - 378
2202 - ]
2203 - },
2204 - "kind": "init",
2205 - "computed": false,
2206 - "method": false,
2207 - "shorthand": true,
2208 - "range": [
2209 - 369,
2210 - 378
2211 - ]
2212 - },
2213 - {
2214 - "type": "RestElement",
2215 - "loc": {
2216 - "source": null,
2217 - "start": {
2218 - "line": 20,
2219 - "column": 24
2220 - },
2221 - "end": {
2222 - "line": 20,
2223 - "column": 29
2224 - }
2225 - },
2226 - "argument": {
2227 - "type": "Identifier",
2228 - "loc": {
2229 - "source": null,
2230 - "start": {
2231 - "line": 20,
2232 - "column": 27
2233 - },
2234 - "end": {
2235 - "line": 20,
2236 - "column": 29
2237 - }
2238 - },
2239 - "name": "zz",
2240 - "typeAnnotation": null,
2241 - "optional": false,
2242 - "range": [
2243 - 383,
2244 - 385
2245 - ]
2246 - },
2247 - "range": [
2248 - 380,
2249 - 385
2250 - ]
2251 - }
2252 - ],
2253 - "typeAnnotation": null,
2254 - "range": [
2255 - 364,
2256 - 387
2257 - ]
2258 - },
2259 - "range": [
2260 - 364,
2261 - 401
2262 - ]
2263 - }
2264 - ],
2265 - "range": [
2266 - 358,
2267 - 402
2268 - ]
2269 - },
2270 - {
2271 - "type": "ExpressionStatement",
2272 - "loc": {
2273 - "source": null,
2274 - "start": {
2275 - "line": 22,
2276 - "column": 2
2277 - },
2278 - "end": {
2279 - "line": 22,
2280 - "column": 30
2281 - }
2282 - },
2283 - "expression": {
2284 - "type": "JSXElement",
2285 - "loc": {
2286 - "source": null,
2287 - "start": {
2288 - "line": 22,
2289 - "column": 2
2290 - },
2291 - "end": {
2292 - "line": 22,
2293 - "column": 29
2294 - }
2295 - },
2296 - "openingElement": {
2297 - "type": "JSXOpeningElement",
2298 - "loc": {
2299 - "source": null,
2300 - "start": {
2301 - "line": 22,
2302 - "column": 2
2303 - },
2304 - "end": {
2305 - "line": 22,
2306 - "column": 20
2307 - }
2308 - },
2309 - "name": {
2310 - "type": "JSXIdentifier",
2311 - "loc": {
2312 - "source": null,
2313 - "start": {
2314 - "line": 22,
2315 - "column": 3
2316 - },
2317 - "end": {
2318 - "line": 22,
2319 - "column": 9
2320 - }
2321 - },
2322 - "name": "Button",
2323 - "range": [
2324 - 407,
2325 - 413
2326 - ]
2327 - },
2328 - "attributes": [
2329 - {
2330 - "type": "JSXSpreadAttribute",
2331 - "loc": {
2332 - "source": null,
2333 - "start": {
2334 - "line": 22,
2335 - "column": 10
2336 - },
2337 - "end": {
2338 - "line": 22,
2339 - "column": 19
2340 - }
2341 - },
2342 - "argument": {
2343 - "type": "Identifier",
2344 - "loc": {
2345 - "source": null,
2346 - "start": {
2347 - "line": 22,
2348 - "column": 14
2349 - },
2350 - "end": {
2351 - "line": 22,
2352 - "column": 18
2353 - }
2354 - },
2355 - "name": "args",
2356 - "typeAnnotation": null,
2357 - "optional": false,
2358 - "range": [
2359 - 418,
2360 - 422
2361 - ]
2362 - },
2363 - "range": [
2364 - 414,
2365 - 423
2366 - ]
2367 - }
2368 - ],
2369 - "selfClosing": false,
2370 - "range": [
2371 - 406,
2372 - 424
2373 - ]
2374 - },
2375 - "children": [],
2376 - "closingElement": {
2377 - "type": "JSXClosingElement",
2378 - "loc": {
2379 - "source": null,
2380 - "start": {
2381 - "line": 22,
2382 - "column": 20
2383 - },
2384 - "end": {
2385 - "line": 22,
2386 - "column": 29
2387 - }
2388 - },
2389 - "name": {
2390 - "type": "JSXIdentifier",
2391 - "loc": {
2392 - "source": null,
2393 - "start": {
2394 - "line": 22,
2395 - "column": 22
2396 - },
2397 - "end": {
2398 - "line": 22,
2399 - "column": 28
2400 - }
2401 - },
2402 - "name": "Button",
2403 - "range": [
2404 - 426,
2405 - 432
2406 - ]
2407 - },
2408 - "range": [
2409 - 424,
2410 - 433
2411 - ]
2412 - },
2413 - "range": [
2414 - 406,
2415 - 433
2416 - ]
2417 - },
2418 - "directive": null,
2419 - "range": [
2420 - 406,
2421 - 434
2422 - ]
2423 - },
2424 - {
2425 - "type": "ExpressionStatement",
2426 - "loc": {
2427 - "source": null,
2428 - "start": {
2429 - "line": 23,
2430 - "column": 2
2431 - },
2432 - "end": {
2433 - "line": 23,
2434 - "column": 48
2435 - }
2436 - },
2437 - "expression": {
2438 - "type": "JSXElement",
2439 - "loc": {
2440 - "source": null,
2441 - "start": {
2442 - "line": 23,
2443 - "column": 2
2444 - },
2445 - "end": {
2446 - "line": 23,
2447 - "column": 47
2448 - }
2449 - },
2450 - "openingElement": {
2451 - "type": "JSXOpeningElement",
2452 - "loc": {
2453 - "source": null,
2454 - "start": {
2455 - "line": 23,
2456 - "column": 2
2457 - },
2458 - "end": {
2459 - "line": 23,
2460 - "column": 38
2461 - }
2462 - },
2463 - "name": {
2464 - "type": "JSXIdentifier",
2465 - "loc": {
2466 - "source": null,
2467 - "start": {
2468 - "line": 23,
2469 - "column": 3
2470 - },
2471 - "end": {
2472 - "line": 23,
2473 - "column": 9
2474 - }
2475 - },
2476 - "name": "Button",
2477 - "range": [
2478 - 438,
2479 - 444
2480 - ]
2481 - },
2482 - "attributes": [
2483 - {
2484 - "type": "JSXAttribute",
2485 - "loc": {
2486 - "source": null,
2487 - "start": {
2488 - "line": 23,
2489 - "column": 10
2490 - },
2491 - "end": {
2492 - "line": 23,
2493 - "column": 37
2494 - }
2495 - },
2496 - "name": {
2497 - "type": "JSXNamespacedName",
2498 - "loc": {
2499 - "source": null,
2500 - "start": {
2501 - "line": 23,
2502 - "column": 10
2503 - },
2504 - "end": {
2505 - "line": 23,
2506 - "column": 20
2507 - }
2508 - },
2509 - "namespace": {
2510 - "type": "JSXIdentifier",
2511 - "loc": {
2512 - "source": null,
2513 - "start": {
2514 - "line": 23,
2515 - "column": 10
2516 - },
2517 - "end": {
2518 - "line": 23,
2519 - "column": 15
2520 - }
2521 - },
2522 - "name": "xlink",
2523 - "range": [
2524 - 445,
2525 - 450
2526 - ]
2527 - },
2528 - "name": {
2529 - "type": "JSXIdentifier",
2530 - "loc": {
2531 - "source": null,
2532 - "start": {
2533 - "line": 23,
2534 - "column": 16
2535 - },
2536 - "end": {
2537 - "line": 23,
2538 - "column": 20
2539 - }
2540 - },
2541 - "name": "href",
2542 - "range": [
2543 - 451,
2544 - 455
2545 - ]
2546 - },
2547 - "range": [
2548 - 445,
2549 - 455
2550 - ]
2551 - },
2552 - "value": {
2553 - "type": "Literal",
2554 - "loc": {
2555 - "source": null,
2556 - "start": {
2557 - "line": 23,
2558 - "column": 21
2559 - },
2560 - "end": {
2561 - "line": 23,
2562 - "column": 37
2563 - }
2564 - },
2565 - "value": "localhost:3000",
2566 - "range": [
2567 - 456,
2568 - 472
2569 - ],
2570 - "raw": "\"localhost:3000\""
2571 - },
2572 - "range": [
2573 - 445,
2574 - 472
2575 - ]
2576 - }
2577 - ],
2578 - "selfClosing": false,
2579 - "range": [
2580 - 437,
2581 - 473
2582 - ]
2583 - },
2584 - "children": [],
2585 - "closingElement": {
2586 - "type": "JSXClosingElement",
2587 - "loc": {
2588 - "source": null,
2589 - "start": {
2590 - "line": 23,
2591 - "column": 38
2592 - },
2593 - "end": {
2594 - "line": 23,
2595 - "column": 47
2596 - }
2597 - },
2598 - "name": {
2599 - "type": "JSXIdentifier",
2600 - "loc": {
2601 - "source": null,
2602 - "start": {
2603 - "line": 23,
2604 - "column": 40
2605 - },
2606 - "end": {
2607 - "line": 23,
2608 - "column": 46
2609 - }
2610 - },
2611 - "name": "Button",
2612 - "range": [
2613 - 475,
2614 - 481
2615 - ]
2616 - },
2617 - "range": [
2618 - 473,
2619 - 482
2620 - ]
2621 - },
2622 - "range": [
2623 - 437,
2624 - 482
2625 - ]
2626 - },
2627 - "directive": null,
2628 - "range": [
2629 - 437,
2630 - 483
2631 - ]
2632 - },
2633 - {
2634 - "type": "ExpressionStatement",
2635 - "loc": {
2636 - "source": null,
2637 - "start": {
2638 - "line": 24,
2639 - "column": 2
2640 - },
2641 - "end": {
2642 - "line": 24,
2643 - "column": 29
2644 - }
2645 - },
2646 - "expression": {
2647 - "type": "JSXElement",
2648 - "loc": {
2649 - "source": null,
2650 - "start": {
2651 - "line": 24,
2652 - "column": 2
2653 - },
2654 - "end": {
2655 - "line": 24,
2656 - "column": 28
2657 - }
2658 - },
2659 - "openingElement": {
2660 - "type": "JSXOpeningElement",
2661 - "loc": {
2662 - "source": null,
2663 - "start": {
2664 - "line": 24,
2665 - "column": 2
2666 - },
2667 - "end": {
2668 - "line": 24,
2669 - "column": 19
2670 - }
2671 - },
2672 - "name": {
2673 - "type": "JSXIdentifier",
2674 - "loc": {
2675 - "source": null,
2676 - "start": {
2677 - "line": 24,
2678 - "column": 3
2679 - },
2680 - "end": {
2681 - "line": 24,
2682 - "column": 9
2683 - }
2684 - },
2685 - "name": "Button",
2686 - "range": [
2687 - 487,
2688 - 493
2689 - ]
2690 - },
2691 - "attributes": [
2692 - {
2693 - "type": "JSXAttribute",
2694 - "loc": {
2695 - "source": null,
2696 - "start": {
2697 - "line": 24,
2698 - "column": 10
2699 - },
2700 - "end": {
2701 - "line": 24,
2702 - "column": 18
2703 - }
2704 - },
2705 - "name": {
2706 - "type": "JSXIdentifier",
2707 - "loc": {
2708 - "source": null,
2709 - "start": {
2710 - "line": 24,
2711 - "column": 10
2712 - },
2713 - "end": {
2714 - "line": 24,
2715 - "column": 14
2716 - }
2717 - },
2718 - "name": "haha",
2719 - "range": [
2720 - 494,
2721 - 498
2722 - ]
2723 - },
2724 - "value": {
2725 - "type": "JSXExpressionContainer",
2726 - "loc": {
2727 - "source": null,
2728 - "start": {
2729 - "line": 24,
2730 - "column": 15
2731 - },
2732 - "end": {
2733 - "line": 24,
2734 - "column": 18
2735 - }
2736 - },
2737 - "expression": {
2738 - "type": "Literal",
2739 - "loc": {
2740 - "source": null,
2741 - "start": {
2742 - "line": 24,
2743 - "column": 16
2744 - },
2745 - "end": {
2746 - "line": 24,
2747 - "column": 17
2748 - }
2749 - },
2750 - "value": 1,
2751 - "range": [
2752 - 500,
2753 - 501
2754 - ],
2755 - "raw": "1"
2756 - },
2757 - "range": [
2758 - 499,
2759 - 502
2760 - ]
2761 - },
2762 - "range": [
2763 - 494,
2764 - 502
2765 - ]
2766 - }
2767 - ],
2768 - "selfClosing": false,
2769 - "range": [
2770 - 486,
2771 - 503
2772 - ]
2773 - },
2774 - "children": [],
2775 - "closingElement": {
2776 - "type": "JSXClosingElement",
2777 - "loc": {
2778 - "source": null,
2779 - "start": {
2780 - "line": 24,
2781 - "column": 19
2782 - },
2783 - "end": {
2784 - "line": 24,
2785 - "column": 28
2786 - }
2787 - },
2788 - "name": {
2789 - "type": "JSXIdentifier",
2790 - "loc": {
2791 - "source": null,
2792 - "start": {
2793 - "line": 24,
2794 - "column": 21
2795 - },
2796 - "end": {
2797 - "line": 24,
2798 - "column": 27
2799 - }
2800 - },
2801 - "name": "Button",
2802 - "range": [
2803 - 505,
2804 - 511
2805 - ]
2806 - },
2807 - "range": [
2808 - 503,
2809 - 512
2810 - ]
2811 - },
2812 - "range": [
2813 - 486,
2814 - 512
2815 - ]
2816 - },
2817 - "directive": null,
2818 - "range": [
2819 - 486,
2820 - 513
2821 - ]
2822 - },
2823 - {
2824 - "type": "ExpressionStatement",
2825 - "loc": {
2826 - "source": null,
2827 - "start": {
2828 - "line": 25,
2829 - "column": 2
2830 - },
2831 - "end": {
2832 - "line": 25,
2833 - "column": 34
2834 - }
2835 - },
2836 - "expression": {
2837 - "type": "JSXElement",
2838 - "loc": {
2839 - "source": null,
2840 - "start": {
2841 - "line": 25,
2842 - "column": 2
2843 - },
2844 - "end": {
2845 - "line": 25,
2846 - "column": 33
2847 - }
2848 - },
2849 - "openingElement": {
2850 - "type": "JSXOpeningElement",
2851 - "loc": {
2852 - "source": null,
2853 - "start": {
2854 - "line": 25,
2855 - "column": 2
2856 - },
2857 - "end": {
2858 - "line": 25,
2859 - "column": 10
2860 - }
2861 - },
2862 - "name": {
2863 - "type": "JSXIdentifier",
2864 - "loc": {
2865 - "source": null,
2866 - "start": {
2867 - "line": 25,
2868 - "column": 3
2869 - },
2870 - "end": {
2871 - "line": 25,
2872 - "column": 9
2873 - }
2874 - },
2875 - "name": "Button",
2876 - "range": [
2877 - 517,
2878 - 523
2879 - ]
2880 - },
2881 - "attributes": [],
2882 - "selfClosing": false,
2883 - "range": [
2884 - 516,
2885 - 524
2886 - ]
2887 - },
2888 - "children": [
2889 - {
2890 - "type": "JSXExpressionContainer",
2891 - "loc": {
2892 - "source": null,
2893 - "start": {
2894 - "line": 25,
2895 - "column": 10
2896 - },
2897 - "end": {
2898 - "line": 25,
2899 - "column": 24
2900 - }
2901 - },
2902 - "expression": {
2903 - "type": "JSXEmptyExpression",
2904 - "loc": {
2905 - "source": null,
2906 - "start": {
2907 - "line": 25,
2908 - "column": 11
2909 - },
2910 - "end": {
2911 - "line": 25,
2912 - "column": 23
2913 - }
2914 - },
2915 - "range": [
2916 - 525,
2917 - 537
2918 - ]
2919 - },
2920 - "range": [
2921 - 524,
2922 - 538
2923 - ]
2924 - }
2925 - ],
2926 - "closingElement": {
2927 - "type": "JSXClosingElement",
2928 - "loc": {
2929 - "source": null,
2930 - "start": {
2931 - "line": 25,
2932 - "column": 24
2933 - },
2934 - "end": {
2935 - "line": 25,
2936 - "column": 33
2937 - }
2938 - },
2939 - "name": {
2940 - "type": "JSXIdentifier",
2941 - "loc": {
2942 - "source": null,
2943 - "start": {
2944 - "line": 25,
2945 - "column": 26
2946 - },
2947 - "end": {
2948 - "line": 25,
2949 - "column": 32
2950 - }
2951 - },
2952 - "name": "Button",
2953 - "range": [
2954 - 540,
2955 - 546
2956 - ]
2957 - },
2958 - "range": [
2959 - 538,
2960 - 547
2961 - ]
2962 - },
2963 - "range": [
2964 - 516,
2965 - 547
2966 - ]
2967 - },
2968 - "directive": null,
2969 - "range": [
2970 - 516,
2971 - 548
2972 - ]
2973 - },
2974 - {
2975 - "type": "ExpressionStatement",
2976 - "loc": {
2977 - "source": null,
2978 - "start": {
2979 - "line": 26,
2980 - "column": 2
2981 - },
2982 - "end": {
2983 - "line": 26,
2984 - "column": 26
2985 - }
2986 - },
2987 - "expression": {
2988 - "type": "JSXElement",
2989 - "loc": {
2990 - "source": null,
2991 - "start": {
2992 - "line": 26,
2993 - "column": 2
2994 - },
2995 - "end": {
2996 - "line": 26,
2997 - "column": 25
2998 - }
2999 - },
3000 - "openingElement": {
3001 - "type": "JSXOpeningElement",
3002 - "loc": {
3003 - "source": null,
3004 - "start": {
3005 - "line": 26,
3006 - "column": 2
3007 - },
3008 - "end": {
3009 - "line": 26,
3010 - "column": 25
3011 - }
3012 - },
3013 - "name": {
3014 - "type": "JSXMemberExpression",
3015 - "loc": {
3016 - "source": null,
3017 - "start": {
3018 - "line": 26,
3019 - "column": 3
3020 - },
3021 - "end": {
3022 - "line": 26,
3023 - "column": 22
3024 - }
3025 - },
3026 - "object": {
3027 - "type": "JSXIdentifier",
3028 - "loc": {
3029 - "source": null,
3030 - "start": {
3031 - "line": 26,
3032 - "column": 3
3033 - },
3034 - "end": {
3035 - "line": 26,
3036 - "column": 15
3037 - }
3038 - },
3039 - "name": "DesignSystem",
3040 - "range": [
3041 - 552,
3042 - 564
3043 - ]
3044 - },
3045 - "property": {
3046 - "type": "JSXIdentifier",
3047 - "loc": {
3048 - "source": null,
3049 - "start": {
3050 - "line": 26,
3051 - "column": 16
3052 - },
3053 - "end": {
3054 - "line": 26,
3055 - "column": 22
3056 - }
3057 - },
3058 - "name": "Button",
3059 - "range": [
3060 - 565,
3061 - 571
3062 - ]
3063 - },
3064 - "range": [
3065 - 552,
3066 - 571
3067 - ]
3068 - },
3069 - "attributes": [],
3070 - "selfClosing": true,
3071 - "range": [
3072 - 551,
3073 - 574
3074 - ]
3075 - },
3076 - "children": [],
3077 - "closingElement": null,
3078 - "range": [
3079 - 551,
3080 - 574
3081 - ]
3082 - },
3083 - "directive": null,
3084 - "range": [
3085 - 551,
3086 - 575
3087 - ]
3088 - },
3089 - {
3090 - "type": "VariableDeclaration",
3091 - "loc": {
3092 - "source": null,
3093 - "start": {
3094 - "line": 28,
3095 - "column": 2
3096 - },
3097 - "end": {
3098 - "line": 28,
3099 - "column": 49
3100 - }
3101 - },
3102 - "kind": "const",
3103 - "declarations": [
3104 - {
3105 - "type": "VariableDeclarator",
3106 - "loc": {
3107 - "source": null,
3108 - "start": {
3109 - "line": 28,
3110 - "column": 8
3111 - },
3112 - "end": {
3113 - "line": 28,
3114 - "column": 48
3115 - }
3116 - },
3117 - "init": {
3118 - "type": "FunctionExpression",
3119 - "loc": {
3120 - "source": null,
3121 - "start": {
3122 - "line": 28,
3123 - "column": 12
3124 - },
3125 - "end": {
3126 - "line": 28,
3127 - "column": 48
3128 - }
3129 - },
3130 - "id": {
3131 - "type": "Identifier",
3132 - "loc": {
3133 - "source": null,
3134 - "start": {
3135 - "line": 28,
3136 - "column": 21
3137 - },
3138 - "end": {
3139 - "line": 28,
3140 - "column": 24
3141 - }
3142 - },
3143 - "name": "bar",
3144 - "typeAnnotation": null,
3145 - "optional": false,
3146 - "range": [
3147 - 598,
3148 - 601
3149 - ]
3150 - },
3151 - "params": [
3152 - {
3153 - "type": "ArrayPattern",
3154 - "loc": {
3155 - "source": null,
3156 - "start": {
3157 - "line": 28,
3158 - "column": 25
3159 - },
3160 - "end": {
3161 - "line": 28,
3162 - "column": 35
3163 - }
3164 - },
3165 - "elements": [
3166 - {
3167 - "type": "Identifier",
3168 - "loc": {
3169 - "source": null,
3170 - "start": {
3171 - "line": 28,
3172 - "column": 26
3173 - },
3174 - "end": {
3175 - "line": 28,
3176 - "column": 29
3177 - }
3178 - },
3179 - "name": "quz",
3180 - "typeAnnotation": null,
3181 - "optional": false,
3182 - "range": [
3183 - 603,
3184 - 606
3185 - ]
3186 - },
3187 - {
3188 - "type": "Identifier",
3189 - "loc": {
3190 - "source": null,
3191 - "start": {
3192 - "line": 28,
3193 - "column": 31
3194 - },
3195 - "end": {
3196 - "line": 28,
3197 - "column": 34
3198 - }
3199 - },
3200 - "name": "qux",
3201 - "typeAnnotation": null,
3202 - "optional": false,
3203 - "range": [
3204 - 608,
3205 - 611
3206 - ]
3207 - }
3208 - ],
3209 - "typeAnnotation": null,
3210 - "range": [
3211 - 602,
3212 - 612
3213 - ]
3214 - },
3215 - {
3216 - "type": "RestElement",
3217 - "loc": {
3218 - "source": null,
3219 - "start": {
3220 - "line": 28,
3221 - "column": 37
3222 - },
3223 - "end": {
3224 - "line": 28,
3225 - "column": 44
3226 - }
3227 - },
3228 - "argument": {
3229 - "type": "Identifier",
3230 - "loc": {
3231 - "source": null,
3232 - "start": {
3233 - "line": 28,
3234 - "column": 40
3235 - },
3236 - "end": {
3237 - "line": 28,
3238 - "column": 44
3239 - }
3240 - },
3241 - "name": "args",
3242 - "typeAnnotation": null,
3243 - "optional": false,
3244 - "range": [
3245 - 617,
3246 - 621
3247 - ]
3248 - },
3249 - "range": [
3250 - 614,
3251 - 621
3252 - ]
3253 - }
3254 - ],
3255 - "body": {
3256 - "type": "BlockStatement",
3257 - "loc": {
3258 - "source": null,
3259 - "start": {
3260 - "line": 28,
3261 - "column": 46
3262 - },
3263 - "end": {
3264 - "line": 28,
3265 - "column": 48
3266 - }
3267 - },
3268 - "body": [],
3269 - "range": [
3270 - 623,
3271 - 625
3272 - ]
3273 - },
3274 - "typeParameters": null,
3275 - "returnType": null,
3276 - "predicate": null,
3277 - "generator": false,
3278 - "async": false,
3279 - "range": [
3280 - 589,
3281 - 625
3282 - ]
3283 - },
3284 - "id": {
3285 - "type": "Identifier",
3286 - "loc": {
3287 - "source": null,
3288 - "start": {
3289 - "line": 28,
3290 - "column": 8
3291 - },
3292 - "end": {
3293 - "line": 28,
3294 - "column": 9
3295 - }
3296 - },
3297 - "name": "j",
3298 - "typeAnnotation": null,
3299 - "optional": false,
3300 - "range": [
3301 - 585,
3302 - 586
3303 - ]
3304 - },
3305 - "range": [
3306 - 585,
3307 - 625
3308 - ]
3309 - }
3310 - ],
3311 - "range": [
3312 - 579,
3313 - 626
3314 - ]
3315 - },
3316 - {
3317 - "type": "ForStatement",
3318 - "loc": {
3319 - "source": null,
3320 - "start": {
3321 - "line": 30,
3322 - "column": 2
3323 - },
3324 - "end": {
3325 - "line": 32,
3326 - "column": 3
3327 - }
3328 - },
3329 - "init": null,
3330 - "test": {
3331 - "type": "BinaryExpression",
3332 - "loc": {
3333 - "source": null,
3334 - "start": {
3335 - "line": 30,
3336 - "column": 9
3337 - },
3338 - "end": {
3339 - "line": 30,
3340 - "column": 14
3341 - }
3342 - },
3343 - "left": {
3344 - "type": "Identifier",
3345 - "loc": {
3346 - "source": null,
3347 - "start": {
3348 - "line": 30,
3349 - "column": 9
3350 - },
3351 - "end": {
3352 - "line": 30,
3353 - "column": 10
3354 - }
3355 - },
3356 - "name": "i",
3357 - "typeAnnotation": null,
3358 - "optional": false,
3359 - "range": [
3360 - 637,
3361 - 638
3362 - ]
3363 - },
3364 - "right": {
3365 - "type": "Literal",
3366 - "loc": {
3367 - "source": null,
3368 - "start": {
3369 - "line": 30,
3370 - "column": 13
3371 - },
3372 - "end": {
3373 - "line": 30,
3374 - "column": 14
3375 - }
3376 - },
3377 - "value": 3,
3378 - "range": [
3379 - 641,
3380 - 642
3381 - ],
3382 - "raw": "3"
3383 - },
3384 - "operator": "<",
3385 - "range": [
3386 - 637,
3387 - 642
3388 - ]
3389 - },
3390 - "update": {
3391 - "type": "AssignmentExpression",
3392 - "loc": {
3393 - "source": null,
3394 - "start": {
3395 - "line": 30,
3396 - "column": 16
3397 - },
3398 - "end": {
3399 - "line": 30,
3400 - "column": 22
3401 - }
3402 - },
3403 - "operator": "+=",
3404 - "left": {
3405 - "type": "Identifier",
3406 - "loc": {
3407 - "source": null,
3408 - "start": {
3409 - "line": 30,
3410 - "column": 16
3411 - },
3412 - "end": {
3413 - "line": 30,
3414 - "column": 17
3415 - }
3416 - },
3417 - "name": "i",
3418 - "typeAnnotation": null,
3419 - "optional": false,
3420 - "range": [
3421 - 644,
3422 - 645
3423 - ]
3424 - },
3425 - "right": {
3426 - "type": "Literal",
3427 - "loc": {
3428 - "source": null,
3429 - "start": {
3430 - "line": 30,
3431 - "column": 21
3432 - },
3433 - "end": {
3434 - "line": 30,
3435 - "column": 22
3436 - }
3437 - },
3438 - "value": 1,
3439 - "range": [
3440 - 649,
3441 - 650
3442 - ],
3443 - "raw": "1"
3444 - },
3445 - "range": [
3446 - 644,
3447 - 650
3448 - ]
3449 - },
3450 - "body": {
3451 - "type": "BlockStatement",
3452 - "loc": {
3453 - "source": null,
3454 - "start": {
3455 - "line": 30,
3456 - "column": 24
3457 - },
3458 - "end": {
3459 - "line": 32,
3460 - "column": 3
3461 - }
3462 - },
3463 - "body": [
3464 - {
3465 - "type": "ExpressionStatement",
3466 - "loc": {
3467 - "source": null,
3468 - "start": {
3469 - "line": 31,
3470 - "column": 4
3471 - },
3472 - "end": {
3473 - "line": 31,
3474 - "column": 14
3475 - }
3476 - },
3477 - "expression": {
3478 - "type": "CallExpression",
3479 - "loc": {
3480 - "source": null,
3481 - "start": {
3482 - "line": 31,
3483 - "column": 4
3484 - },
3485 - "end": {
3486 - "line": 31,
3487 - "column": 13
3488 - }
3489 - },
3490 - "callee": {
3491 - "type": "MemberExpression",
3492 - "loc": {
3493 - "source": null,
3494 - "start": {
3495 - "line": 31,
3496 - "column": 4
3497 - },
3498 - "end": {
3499 - "line": 31,
3500 - "column": 10
3501 - }
3502 - },
3503 - "object": {
3504 - "type": "Identifier",
3505 - "loc": {
3506 - "source": null,
3507 - "start": {
3508 - "line": 31,
3509 - "column": 4
3510 - },
3511 - "end": {
3512 - "line": 31,
3513 - "column": 5
3514 - }
3515 - },
3516 - "name": "x",
3517 - "typeAnnotation": null,
3518 - "optional": false,
3519 - "range": [
3520 - 658,
3521 - 659
3522 - ]
3523 - },
3524 - "property": {
3525 - "type": "Identifier",
3526 - "loc": {
3527 - "source": null,
3528 - "start": {
3529 - "line": 31,
3530 - "column": 6
3531 - },
3532 - "end": {
3533 - "line": 31,
3534 - "column": 10
3535 - }
3536 - },
3537 - "name": "push",
3538 - "typeAnnotation": null,
3539 - "optional": false,
3540 - "range": [
3541 - 660,
3542 - 664
3543 - ]
3544 - },
3545 - "computed": false,
3546 - "range": [
3547 - 658,
3548 - 664
3549 - ]
3550 - },
3551 - "typeArguments": null,
3552 - "arguments": [
3553 - {
3554 - "type": "Identifier",
3555 - "loc": {
3556 - "source": null,
3557 - "start": {
3558 - "line": 31,
3559 - "column": 11
3560 - },
3561 - "end": {
3562 - "line": 31,
3563 - "column": 12
3564 - }
3565 - },
3566 - "name": "i",
3567 - "typeAnnotation": null,
3568 - "optional": false,
3569 - "range": [
3570 - 665,
3571 - 666
3572 - ]
3573 - }
3574 - ],
3575 - "range": [
3576 - 658,
3577 - 667
3578 - ]
3579 - },
3580 - "directive": null,
3581 - "range": [
3582 - 658,
3583 - 668
3584 - ]
3585 - }
3586 - ],
3587 - "range": [
3588 - 652,
3589 - 672
3590 - ]
3591 - },
3592 - "range": [
3593 - 630,
3594 - 672
3595 - ]
3596 - },
3597 - {
3598 - "type": "ForStatement",
3599 - "loc": {
3600 - "source": null,
3601 - "start": {
3602 - "line": 33,
3603 - "column": 2
3604 - },
3605 - "end": {
3606 - "line": 35,
3607 - "column": 3
3608 - }
3609 - },
3610 - "init": null,
3611 - "test": {
3612 - "type": "BinaryExpression",
3613 - "loc": {
3614 - "source": null,
3615 - "start": {
3616 - "line": 33,
3617 - "column": 9
3618 - },
3619 - "end": {
3620 - "line": 33,
3621 - "column": 14
3622 - }
3623 - },
3624 - "left": {
3625 - "type": "Identifier",
3626 - "loc": {
3627 - "source": null,
3628 - "start": {
3629 - "line": 33,
3630 - "column": 9
3631 - },
3632 - "end": {
3633 - "line": 33,
3634 - "column": 10
3635 - }
3636 - },
3637 - "name": "i",
3638 - "typeAnnotation": null,
3639 - "optional": false,
3640 - "range": [
3641 - 682,
3642 - 683
3643 - ]
3644 - },
3645 - "right": {
3646 - "type": "Literal",
3647 - "loc": {
3648 - "source": null,
3649 - "start": {
3650 - "line": 33,
3651 - "column": 13
3652 - },
3653 - "end": {
3654 - "line": 33,
3655 - "column": 14
3656 - }
3657 - },
3658 - "value": 3,
3659 - "range": [
3660 - 686,
3661 - 687
3662 - ],
3663 - "raw": "3"
3664 - },
3665 - "operator": "<",
3666 - "range": [
3667 - 682,
3668 - 687
3669 - ]
3670 - },
3671 - "update": null,
3672 - "body": {
3673 - "type": "BlockStatement",
3674 - "loc": {
3675 - "source": null,
3676 - "start": {
3677 - "line": 33,
3678 - "column": 18
3679 - },
3680 - "end": {
3681 - "line": 35,
3682 - "column": 3
3683 - }
3684 - },
3685 - "body": [
3686 - {
3687 - "type": "BreakStatement",
3688 - "loc": {
3689 - "source": null,
3690 - "start": {
3691 - "line": 34,
3692 - "column": 4
3693 - },
3694 - "end": {
3695 - "line": 34,
3696 - "column": 10
3697 - }
3698 - },
3699 - "label": null,
3700 - "range": [
3701 - 697,
3702 - 703
3703 - ]
3704 - }
3705 - ],
3706 - "range": [
3707 - 691,
3708 - 707
3709 - ]
3710 - },
3711 - "range": [
3712 - 675,
3713 - 707
3714 - ]
3715 - },
3716 - {
3717 - "type": "ForStatement",
3718 - "loc": {
3719 - "source": null,
3720 - "start": {
3721 - "line": 36,
3722 - "column": 2
3723 - },
3724 - "end": {
3725 - "line": 38,
3726 - "column": 3
3727 - }
3728 - },
3729 - "init": null,
3730 - "test": null,
3731 - "update": null,
3732 - "body": {
3733 - "type": "BlockStatement",
3734 - "loc": {
3735 - "source": null,
3736 - "start": {
3737 - "line": 36,
3738 - "column": 11
3739 - },
3740 - "end": {
3741 - "line": 38,
3742 - "column": 3
3743 - }
3744 - },
3745 - "body": [
3746 - {
3747 - "type": "BreakStatement",
3748 - "loc": {
3749 - "source": null,
3750 - "start": {
3751 - "line": 37,
3752 - "column": 4
3753 - },
3754 - "end": {
3755 - "line": 37,
3756 - "column": 10
3757 - }
3758 - },
3759 - "label": null,
3760 - "range": [
3761 - 725,
3762 - 731
3763 - ]
3764 - }
3765 - ],
3766 - "range": [
3767 - 719,
3768 - 735
3769 - ]
3770 - },
3771 - "range": [
3772 - 710,
3773 - 735
3774 - ]
3775 - },
3776 - {
3777 - "type": "ExpressionStatement",
3778 - "loc": {
3779 - "source": null,
3780 - "start": {
3781 - "line": 40,
3782 - "column": 2
3783 - },
3784 - "end": {
3785 - "line": 42,
3786 - "column": 4
3787 - }
3788 - },
3789 - "expression": {
3790 - "type": "TaggedTemplateExpression",
3791 - "loc": {
3792 - "source": null,
3793 - "start": {
3794 - "line": 40,
3795 - "column": 2
3796 - },
3797 - "end": {
3798 - "line": 42,
3799 - "column": 3
3800 - }
3801 - },
3802 - "tag": {
3803 - "type": "Identifier",
3804 - "loc": {
3805 - "source": null,
3806 - "start": {
3807 - "line": 40,
3808 - "column": 2
3809 - },
3810 - "end": {
3811 - "line": 40,
3812 - "column": 9
3813 - }
3814 - },
3815 - "name": "graphql",
3816 - "typeAnnotation": null,
3817 - "optional": false,
3818 - "range": [
3819 - 739,
3820 - 746
3821 - ]
3822 - },
3823 - "quasi": {
3824 - "type": "TemplateLiteral",
3825 - "loc": {
3826 - "source": null,
3827 - "start": {
3828 - "line": 40,
3829 - "column": 9
3830 - },
3831 - "end": {
3832 - "line": 42,
3833 - "column": 3
3834 - }
3835 - },
3836 - "quasis": [
3837 - {
3838 - "type": "TemplateElement",
3839 - "loc": {
3840 - "source": null,
3841 - "start": {
3842 - "line": 40,
3843 - "column": 9
3844 - },
3845 - "end": {
3846 - "line": 41,
3847 - "column": 6
3848 - }
3849 - },
3850 - "range": [
3851 - 746,
3852 - 754
3853 - ],
3854 - "tail": false,
3855 - "value": {
3856 - "cooked": "\n ",
3857 - "raw": "\n "
3858 - }
3859 - },
3860 - {
3861 - "type": "TemplateElement",
3862 - "loc": {
3863 - "source": null,
3864 - "start": {
3865 - "line": 41,
3866 - "column": 7
3867 - },
3868 - "end": {
3869 - "line": 42,
3870 - "column": 3
3871 - }
3872 - },
3873 - "range": [
3874 - 755,
3875 - 760
3876 - ],
3877 - "tail": true,
3878 - "value": {
3879 - "cooked": "\n ",
3880 - "raw": "\n "
3881 - }
3882 - }
3883 - ],
3884 - "expressions": [
3885 - {
3886 - "type": "Identifier",
3887 - "loc": {
3888 - "source": null,
3889 - "start": {
3890 - "line": 41,
3891 - "column": 6
3892 - },
3893 - "end": {
3894 - "line": 41,
3895 - "column": 7
3896 - }
3897 - },
3898 - "name": "g",
3899 - "typeAnnotation": null,
3900 - "optional": false,
3901 - "range": [
3902 - 754,
3903 - 755
3904 - ]
3905 - }
3906 - ],
3907 - "range": [
3908 - 746,
3909 - 760
3910 - ]
3911 - },
3912 - "range": [
3913 - 739,
3914 - 760
3915 - ]
3916 - },
3917 - "directive": null,
3918 - "range": [
3919 - 739,
3920 - 761
3921 - ]
3922 - },
3923 - {
3924 - "type": "ExpressionStatement",
3925 - "loc": {
3926 - "source": null,
3927 - "start": {
3928 - "line": 44,
3929 - "column": 2
3930 - },
3931 - "end": {
3932 - "line": 44,
3933 - "column": 17
3934 - }
3935 - },
3936 - "expression": {
3937 - "type": "TaggedTemplateExpression",
3938 - "loc": {
3939 - "source": null,
3940 - "start": {
3941 - "line": 44,
3942 - "column": 2
3943 - },
3944 - "end": {
3945 - "line": 44,
3946 - "column": 16
3947 - }
3948 - },
3949 - "tag": {
3950 - "type": "Identifier",
3951 - "loc": {
3952 - "source": null,
3953 - "start": {
3954 - "line": 44,
3955 - "column": 2
3956 - },
3957 - "end": {
3958 - "line": 44,
3959 - "column": 9
3960 - }
3961 - },
3962 - "name": "graphql",
3963 - "typeAnnotation": null,
3964 - "optional": false,
3965 - "range": [
3966 - 765,
3967 - 772
3968 - ]
3969 - },
3970 - "quasi": {
3971 - "type": "TemplateLiteral",
3972 - "loc": {
3973 - "source": null,
3974 - "start": {
3975 - "line": 44,
3976 - "column": 9
3977 - },
3978 - "end": {
3979 - "line": 44,
3980 - "column": 16
3981 - }
3982 - },
3983 - "quasis": [
3984 - {
3985 - "type": "TemplateElement",
3986 - "loc": {
3987 - "source": null,
3988 - "start": {
3989 - "line": 44,
3990 - "column": 9
3991 - },
3992 - "end": {
3993 - "line": 44,
3994 - "column": 16
3995 - }
3996 - },
3997 - "range": [
3998 - 772,
3999 - 779
4000 - ],
4001 - "tail": true,
4002 - "value": {
4003 - "cooked": "\\t\n",
4004 - "raw": "\\\\t\\n"
4005 - }
4006 - }
4007 - ],
4008 - "expressions": [],
4009 - "range": [
4010 - 772,
4011 - 779
4012 - ]
4013 - },
4014 - "range": [
4015 - 765,
4016 - 779
4017 - ]
4018 - },
4019 - "directive": null,
4020 - "range": [
4021 - 765,
4022 - 780
4023 - ]
4024 - }
4025 - ],
4026 - "range": [
4027 - 59,
4028 - 782
4029 - ]
4030 - },
4031 - "typeParameters": null,
4032 - "returnType": null,
4033 - "predicate": null,
4034 - "generator": false,
4035 - "async": false,
4036 - "range": [
4037 - 1,
4038 - 782
4039 - ]
4040 - }
4041 - ],
4042 - "comments": [
4043 - {
4044 - "type": "Block",
4045 - "loc": {
4046 - "source": null,
4047 - "start": {
4048 - "line": 25,
4049 - "column": 11
4050 - },
4051 - "end": {
4052 - "line": 25,
4053 - "column": 23
4054 - }
4055 - },
4056 - "value": "* empty ",
4057 - "range": [
4058 - 525,
4059 - 537
4060 - ]
4061 - }
4062 - ],
4063 - "interpreter": null,
4064 - "range": [
4065 - 1,
4066 - 782
4067 - ],
4068 - "sourceType": "script"
4069 - }
\ No newline at end of file
compiler/forget/crates/estree/src/lib.rs
+8 -1328
@@ -1,1284 +1,12 @@
1 -use serde::{Deserialize, Serialize};
2 -use static_assertions::assert_eq_size;
3 -use std::{fmt::Display, num::NonZeroU32};
1 +mod binding;
2 +mod generated;
3 +mod js_value;
4 +mod range;
5
5 -#[derive(Serialize, Deserialize, Debug)]
6 -pub struct SourceLocation {
7 - pub source: Option<String>,
8 -
9 - pub start: Position,
10 -
11 - pub end: Position,
12 -}
13 -
14 -#[derive(Serialize, Deserialize, Debug, Clone)]
15 -pub struct Position {
16 - /// >= 1
17 - pub line: NonZeroU32,
18 - /// >= 0
19 - pub column: u32,
20 -}
21 -assert_eq_size!(Option<Position>, u64);
22 -
23 -#[derive(Serialize, Deserialize, Debug, Clone)]
24 -pub struct SourceRange {
25 - pub start: u32,
26 - // end is exclusive so it can always be non-zero. This allows
27 - // Option<SourceRange> to not take any additional bytes.
28 - pub end: NonZeroU32,
29 -}
30 -assert_eq_size!(Option<SourceRange>, u64);
31 -
32 -#[derive(Serialize, Deserialize, Debug)]
33 -pub struct Program {
34 - /// sourceType
35 - #[serde(rename = "sourceType")]
36 - #[serde(default)]
37 - pub source_type: SourceType,
38 -
39 - pub body: Vec<ModuleItem>,
40 -
41 - #[serde(default)]
42 - pub comments: Option<Vec<Comment>>,
43 -
44 - pub loc: Option<SourceLocation>,
45 -
46 - #[serde(default)]
47 - pub range: Option<SourceRange>,
48 -}
49 -
50 -#[derive(Serialize, Deserialize, Debug)]
51 -pub enum SourceType {
52 - /// "module"
53 - #[serde(rename = "module")]
54 - Module,
55 - /// "script"
56 - #[serde(rename = "script")]
57 - Script,
58 -}
59 -
60 -impl Default for SourceType {
61 - fn default() -> Self {
62 - Self::Module
63 - }
64 -}
65 -
66 -#[derive(Serialize, Deserialize, Debug)]
67 -pub struct Comment {
68 - pub type_: CommentType,
69 - pub value: String,
70 -}
71 -
72 -#[derive(Serialize, Deserialize, Debug)]
73 -pub enum CommentType {
74 - /// "Line"
75 - Line,
76 - /// "Block"
77 - Block,
78 -}
79 -
80 -#[derive(Serialize, Deserialize, Debug)]
81 -#[serde(untagged)]
82 -pub enum ModuleItem {
83 - Statement(Box<Statement>),
84 - ImportDeclaration(Box<ImportDeclaration>),
85 -}
86 -
87 -#[derive(Serialize, Deserialize, Debug)]
88 -#[serde(tag = "type")]
89 -pub enum ImportExportDeclaration {
90 - ImportDeclaration(Box<ImportDeclaration>),
91 - // TODO:
92 - // ExportNamedDeclaration(Box<ExportNamedDeclaration>),
93 - // ExportDefaultDeclaration(Box<ExportDefaultDeclaration>),
94 - // ExportAllDeclaration(Box<ExportAllDeclaration>),
95 -}
96 -
97 -#[derive(Serialize, Deserialize, Debug)]
98 -pub struct ImportDeclaration {
99 - pub specifiers: Vec<ImportSpecifiers>,
100 - pub source: Literal,
101 - pub loc: Option<SourceLocation>,
102 - #[serde(default)]
103 - pub range: Option<SourceRange>,
104 -}
105 -
106 -#[derive(Serialize, Deserialize, Debug)]
107 -#[serde(tag = "type")]
108 -pub enum ImportSpecifiers {
109 - ImportSpecifier(Box<ImportSpecifier>),
110 - ImportDefaultSpecifier(Box<ImportDefaultSpecifier>),
111 -}
112 -
113 -#[derive(Serialize, Deserialize, Debug)]
114 -pub struct ImportSpecifier {
115 - pub imported: Identifier,
116 -
117 - pub local: Identifier,
118 -
119 - pub loc: Option<SourceLocation>,
120 -
121 - #[serde(default)]
122 - pub range: Option<SourceRange>,
123 -}
124 -
125 -#[derive(Serialize, Deserialize, Debug)]
126 -pub struct ImportDefaultSpecifier {
127 - pub local: Identifier,
128 -
129 - pub loc: Option<SourceLocation>,
130 -
131 - #[serde(default)]
132 - pub range: Option<SourceRange>,
133 -}
134 -
135 -#[derive(Serialize, Deserialize, Debug)]
136 -#[serde(tag = "type")]
137 -pub enum Statement {
138 - BlockStatement(Box<BlockStatement>),
139 - BreakStatement(Box<BreakStatement>),
140 - ClassDeclaration(Box<ClassDeclaration>),
141 - ContinueStatement(Box<ContinueStatement>),
142 - DebuggerStatement(Box<DebuggerStatement>),
143 - DoWhileStatement(Box<DoWhileStatement>),
144 - EmptyStatement(Box<EmptyStatement>),
145 - ExpressionStatement(Box<ExpressionStatement>),
146 - ForInStatement(Box<ForInStatement>),
147 - ForOfStatement(Box<ForOfStatement>),
148 - ForStatement(Box<ForStatement>),
149 - FunctionDeclaration(Box<FunctionDeclaration>),
150 - IfStatement(Box<IfStatement>),
151 - LabeledStatement(Box<LabeledStatement>),
152 - ReturnStatement(Box<ReturnStatement>),
153 - StaticBlock(Box<StaticBlock>),
154 - SwitchStatement(Box<SwitchStatement>),
155 - ThrowStatement(Box<ThrowStatement>),
156 - TryStatement(Box<TryStatement>),
157 - VariableDeclaration(Box<VariableDeclaration>),
158 - WhileStatement(Box<WhileStatement>),
159 - WithStatement(Box<WithStatement>),
160 -}
161 -// Prevent unboxed variants from increasing the size
162 -assert_eq_size!(Statement, u128);
163 -
164 -#[derive(Serialize, Deserialize, Debug)]
165 -pub struct BlockStatement {
166 - pub body: Vec<Statement>,
167 - pub loc: Option<SourceLocation>,
168 - #[serde(default)]
169 - pub range: Option<SourceRange>,
170 -}
171 -
172 -#[derive(Serialize, Deserialize, Debug)]
173 -pub struct BreakStatement {
174 - #[serde(default)]
175 - pub label: Option<Identifier>,
176 - pub loc: Option<SourceLocation>,
177 - #[serde(default)]
178 - pub range: Option<SourceRange>,
179 -}
180 -
181 -#[derive(Serialize, Deserialize, Debug)]
182 -pub struct ClassDeclaration {
183 - pub loc: Option<SourceLocation>,
184 - #[serde(default)]
185 - pub range: Option<SourceRange>,
186 -}
187 -
188 -#[derive(Serialize, Deserialize, Debug)]
189 -pub struct ContinueStatement {
190 - #[serde(default)]
191 - pub label: Option<Identifier>,
192 - pub loc: Option<SourceLocation>,
193 - #[serde(default)]
194 - pub range: Option<SourceRange>,
195 -}
196 -
197 -#[derive(Serialize, Deserialize, Debug)]
198 -pub struct DebuggerStatement {
199 - pub loc: Option<SourceLocation>,
200 - #[serde(default)]
201 - pub range: Option<SourceRange>,
202 -}
203 -
204 -#[derive(Serialize, Deserialize, Debug)]
205 -pub struct DoWhileStatement {
206 - pub body: Statement,
207 - pub test: ExpressionLike,
208 - pub loc: Option<SourceLocation>,
209 - #[serde(default)]
210 - pub range: Option<SourceRange>,
211 -}
212 -
213 -#[derive(Serialize, Deserialize, Debug)]
214 -pub struct EmptyStatement {
215 - pub loc: Option<SourceLocation>,
216 - #[serde(default)]
217 - pub range: Option<SourceRange>,
218 -}
219 -
220 -#[derive(Serialize, Deserialize, Debug)]
221 -pub struct FunctionDeclaration {
222 - pub id: Option<Identifier>,
223 -
224 - pub params: Vec<Pattern>,
225 -
226 - #[serde(rename = "generator")]
227 - #[serde(default)]
228 - pub is_generator: bool,
229 -
230 - #[serde(rename = "async")]
231 - #[serde(default)]
232 - pub is_async: bool,
233 -
234 - // TODO: BlockStatement
235 - pub body: Option<Statement>,
236 -
237 - pub loc: Option<SourceLocation>,
238 - #[serde(default)]
239 - pub range: Option<SourceRange>,
240 -}
241 -
242 -#[derive(Serialize, Deserialize, Debug)]
243 -pub struct StaticBlock {
244 - pub body: Vec<Statement>,
245 - pub loc: Option<SourceLocation>,
246 - #[serde(default)]
247 - pub range: Option<SourceRange>,
248 -}
249 -
250 -#[derive(Serialize, Deserialize, Debug)]
251 -pub struct ExpressionStatement {
252 - pub expression: ExpressionLike,
253 -
254 - #[serde(default)]
255 - pub directive: Option<String>,
256 -
257 - pub loc: Option<SourceLocation>,
258 -
259 - #[serde(default)]
260 - pub range: Option<SourceRange>,
261 -}
262 -
263 -#[derive(Serialize, Deserialize, Debug)]
264 -pub struct ForInStatement {
265 - pub left: ForPattern,
266 - pub right: ExpressionLike,
267 - pub body: Statement,
268 - pub loc: Option<SourceLocation>,
269 - #[serde(default)]
270 - pub range: Option<SourceRange>,
271 -}
272 -
273 -#[derive(Serialize, Deserialize, Debug)]
274 -pub struct ForOfStatement {
275 - #[serde(rename = "await")]
276 - #[serde(default)]
277 - pub is_await: bool,
278 -
279 - pub left: ForPattern,
280 -
281 - pub right: ExpressionLike,
282 -
283 - pub body: Statement,
284 -
285 - pub loc: Option<SourceLocation>,
286 - #[serde(default)]
287 - pub range: Option<SourceRange>,
288 -}
289 -
290 -#[derive(Serialize, Deserialize, Debug)]
291 -#[serde(tag = "type")]
292 -pub enum ForPattern {
293 - VariableDeclaration(Box<VariableDeclaration>),
294 - Expression(Box<ExpressionLike>),
295 -}
296 -
297 -#[derive(Serialize, Deserialize, Debug)]
298 -pub struct ForStatement {
299 - pub init: Option<ForInit>,
300 - pub test: Option<ExpressionLike>,
301 - pub update: Option<ExpressionLike>,
302 - pub body: Statement,
303 - pub loc: Option<SourceLocation>,
304 - #[serde(default)]
305 - pub range: Option<SourceRange>,
306 -}
307 -
308 -#[derive(Serialize, Deserialize, Debug)]
309 -#[serde(tag = "type")]
310 -pub enum ForInit {
311 - VariableDeclaration(Box<VariableDeclaration>),
312 - Expression(Box<ExpressionLike>),
313 -}
314 -
315 -#[derive(Serialize, Deserialize, Debug)]
316 -pub struct IfStatement {
317 - pub test: ExpressionLike,
318 - pub consequent: Statement,
319 - pub alternate: Option<Statement>,
320 - pub loc: Option<SourceLocation>,
321 - #[serde(default)]
322 - pub range: Option<SourceRange>,
323 -}
324 -
325 -#[derive(Serialize, Deserialize, Debug)]
326 -pub struct LabeledStatement {
327 - pub label: Identifier,
328 - pub body: Statement,
329 - pub loc: Option<SourceLocation>,
330 - #[serde(default)]
331 - pub range: Option<SourceRange>,
332 -}
333 -
334 -#[derive(Serialize, Deserialize, Debug)]
335 -pub struct ReturnStatement {
336 - pub argument: Option<ExpressionLike>,
337 - pub loc: Option<SourceLocation>,
338 - #[serde(default)]
339 - pub range: Option<SourceRange>,
340 -}
341 -
342 -#[derive(Serialize, Deserialize, Debug)]
343 -pub struct SwitchStatement {
344 - pub discriminant: ExpressionLike,
345 - pub cases: Vec<SwitchCase>,
346 - pub loc: Option<SourceLocation>,
347 - #[serde(default)]
348 - pub range: Option<SourceRange>,
349 -}
350 -
351 -#[derive(Serialize, Deserialize, Debug)]
352 -pub struct SwitchCase {
353 - pub test: Option<ExpressionLike>,
354 - pub consequent: Vec<Statement>,
355 - pub loc: Option<SourceLocation>,
356 - #[serde(default)]
357 - pub range: Option<SourceRange>,
358 -}
359 -
360 -#[derive(Serialize, Deserialize, Debug)]
361 -pub struct ThrowStatement {
362 - pub argument: ExpressionLike,
363 - pub loc: Option<SourceLocation>,
364 - #[serde(default)]
365 - pub range: Option<SourceRange>,
366 -}
367 -
368 -#[derive(Serialize, Deserialize, Debug)]
369 -pub struct TryStatement {
370 - // TODO: block: BlockStatement
371 - pub block: Statement,
372 - pub handler: Option<CatchClause>,
373 - // TODO: finalizer: BlockStatement
374 - pub finalizer: Option<Statement>,
375 - pub loc: Option<SourceLocation>,
376 - #[serde(default)]
377 - pub range: Option<SourceRange>,
378 -}
379 -
380 -#[derive(Serialize, Deserialize, Debug)]
381 -pub struct CatchClause {
382 - pub param: Option<Pattern>,
383 - pub body: Statement,
384 - pub loc: Option<SourceLocation>,
385 - #[serde(default)]
386 - pub range: Option<SourceRange>,
387 -}
388 -
389 -#[derive(Serialize, Deserialize, Debug)]
390 -pub struct VariableDeclaration {
391 - pub declarations: Vec<VariableDeclarator>,
392 - pub kind: VariableDeclarationKind,
393 - pub loc: Option<SourceLocation>,
394 - #[serde(default)]
395 - pub range: Option<SourceRange>,
396 -}
397 -
398 -#[derive(Serialize, Deserialize, Debug)]
399 -pub struct VariableDeclarator {
400 - pub id: Pattern,
401 - pub init: Option<ExpressionLike>,
402 - pub loc: Option<SourceLocation>,
403 - #[serde(default)]
404 - pub range: Option<SourceRange>,
405 -}
406 -
407 -#[derive(Serialize, Deserialize, Debug)]
408 -pub enum VariableDeclarationKind {
409 - #[serde(rename = "const")]
410 - Const,
411 - #[serde(rename = "let")]
412 - Let,
413 - #[serde(rename = "var")]
414 - Var,
415 -}
416 -
417 -#[derive(Serialize, Deserialize, Debug)]
418 -pub struct WhileStatement {
419 - pub test: ExpressionLike,
420 - pub body: Statement,
421 - pub loc: Option<SourceLocation>,
422 - #[serde(default)]
423 - pub range: Option<SourceRange>,
424 -}
425 -
426 -#[derive(Serialize, Deserialize, Debug)]
427 -pub struct WithStatement {
428 - pub object: ExpressionLike,
429 - pub body: Statement,
430 - pub loc: Option<SourceLocation>,
431 - #[serde(default)]
432 - pub range: Option<SourceRange>,
433 -}
434 -
435 -/// Expressions and expression-like nodes
436 -/// we flatten these into a single enum to work around limits
437 -/// of serde enum format with handling arbitrary unions
438 -#[derive(Serialize, Deserialize, Debug)]
439 -#[serde(tag = "type")]
440 -pub enum ExpressionLike {
441 - ArrayExpression(Box<ArrayExpression>),
442 - ArrowFunctionExpression(Box<ArrowFunctionExpression>),
443 - AssignmentExpression(Box<AssignmentExpression>),
444 - AwaitExpression(Box<AwaitExpression>),
445 - BinaryExpression(Box<BinaryExpression>),
446 - CallExpression(Box<CallExpression>),
447 - ChainExpression(Box<ChainExpression>),
448 - ClassExpression(Box<ClassExpression>),
449 - ConditionalExpression(Box<ConditionalExpression>),
450 - FunctionExpression(Box<FunctionExpression>),
451 - Identifier(Box<Identifier>),
452 - ImportExpression(Box<ImportExpression>),
453 - Literal(Box<Literal>),
454 - LogicalExpression(Box<LogicalExpression>),
455 - MemberExpression(Box<MemberExpression>),
456 - MetaProperty(Box<MetaProperty>),
457 - NewExpression(Box<NewExpression>),
458 - ObjectExpression(Box<ObjectExpression>),
459 - SequenceExpression(Box<SequenceExpression>),
460 - TaggedTemplateExpression(Box<TaggedTemplateExpression>),
461 - TemplateLiteral(Box<TemplateLiteral>),
462 - ThisExpression(Box<ThisExpression>),
463 - UnaryExpression(Box<UnaryExpression>),
464 - UpdateExpression(Box<UpdateExpression>),
465 - YieldExpression(Box<YieldExpression>),
466 -
467 - // pseudo-expressions to work with serde
468 - Super(Box<Super>),
469 -
470 - // patterns to work with serde
471 - ArrayPattern(Box<ArrayPattern>),
472 - AssignmentPattern(Box<AssignmentPattern>),
473 - ObjectPattern(Box<ObjectPattern>),
474 - Property(Box<Property>),
475 - RestElement(Box<RestElement>),
476 - SpreadElement(Box<SpreadElement>),
477 -
478 - // jsx expression-ish types to work with serde
479 - JSXClosingElement(Box<JSXClosingElement>),
480 - JSXElement(Box<JSXElement>),
481 - JSXExpressionContainer(Box<JSXExpressionContainer>),
482 - JSXIdentifier(Box<JSXIdentifier>),
483 - JSXMemberExpression(Box<JSXMemberExpression>),
484 - JSXNamedspacedName(Box<JSXNamedspacedName>),
485 - JSXOpeningElement(Box<JSXOpeningElement>),
486 - JSXText(Box<JSXText>),
487 -}
488 -// Prevent unboxed variants from increasing the size
489 -assert_eq_size!(ExpressionLike, u128);
490 -
491 -#[derive(Serialize, Deserialize, Debug)]
492 -pub struct ArrayExpression {
493 - pub elements: Vec<ExpressionLike>,
494 - pub loc: Option<SourceLocation>,
495 - #[serde(default)]
496 - pub range: Option<SourceRange>,
497 -}
498 -
499 -#[derive(Serialize, Deserialize, Debug)]
500 -pub struct ArrowFunctionExpression {
501 - pub params: Vec<Pattern>,
502 -
503 - #[serde(rename = "generator")]
504 - #[serde(default)]
505 - pub is_generator: bool,
506 -
507 - #[serde(rename = "async")]
508 - #[serde(default)]
509 - pub is_async: bool,
510 -
511 - #[serde(rename = "expression")]
512 - #[serde(default)]
513 - pub is_expression: bool,
514 -
515 - pub body: BlockOrExpression,
516 -
517 - pub loc: Option<SourceLocation>,
518 - #[serde(default)]
519 - pub range: Option<SourceRange>,
520 -}
521 -
522 -#[derive(Serialize, Deserialize, Debug)]
523 -#[serde(tag = "type")]
524 -pub enum BlockOrExpression {
525 - BlockStatement(Box<BlockStatement>),
526 - Expression(Box<ExpressionLike>),
527 -}
528 -
529 -#[derive(Serialize, Deserialize, Debug)]
530 -pub struct AssignmentExpression {
531 - pub operator: AssignmentOperator,
532 - pub left: AssignmentTarget,
533 - pub right: ExpressionLike,
534 - pub loc: Option<SourceLocation>,
535 - #[serde(default)]
536 - pub range: Option<SourceRange>,
537 -}
538 -
539 -#[derive(Serialize, Deserialize, Debug)]
540 -pub enum AssignmentOperator {
541 - /// =
542 - #[serde(rename = "=")]
543 - Equals,
544 - /// +=
545 - #[serde(rename = "+=")]
546 - PlusEquals,
547 - // -=
548 - #[serde(rename = "-=")]
549 - MinusEquals,
550 - /// *=
551 - #[serde(rename = "*=")]
552 - AsteriskEquals,
553 - /// /=
554 - #[serde(rename = "/=")]
555 - SlashEquals,
556 - /// %=
557 - #[serde(rename = "%=")]
558 - PercentEquals,
559 - /// **=
560 - #[serde(rename = "**=")]
561 - AsteriskAsteriskEquals,
562 - /// <<=
563 - #[serde(rename = "<<=")]
564 - LtLtEquals,
565 - /// >>=
566 - #[serde(rename = ">>=")]
567 - GtGtEquals,
568 - /// >>>=
569 - #[serde(rename = ">>>=")]
570 - GtGtGtEquals,
571 - /// |=
572 - #[serde(rename = "|=")]
573 - PipeEquals,
574 - /// ^=
575 - #[serde(rename = "^=")]
576 - CaretEquals,
577 - /// &=
578 - #[serde(rename = "&&=")]
579 - AmpersandEquals,
580 - /// ||=
581 - #[serde(rename = "||=")]
582 - PipePipeEquals,
583 - /// &&=
584 - #[serde(rename = "&&=")]
585 - AmpersandAmpersandEquals,
586 - // ??=
587 - #[serde(rename = "??=")]
588 - QuestionQuestionEquals,
589 -}
590 -
591 -impl AssignmentOperator {
592 - pub fn is_simple_equals(&self) -> bool {
593 - matches!(self, AssignmentOperator::Equals)
594 - }
595 -}
596 -
597 -#[derive(Serialize, Deserialize, Debug)]
598 -#[serde(untagged)]
599 -pub enum AssignmentTarget {
600 - Pattern(Box<Pattern>),
601 - MemberExpression(Box<MemberExpression>),
602 -}
603 -
604 -#[derive(Serialize, Deserialize, Debug)]
605 -pub struct AwaitExpression {
606 - pub argument: ExpressionLike,
607 - pub loc: Option<SourceLocation>,
608 - #[serde(default)]
609 - pub range: Option<SourceRange>,
610 -}
611 -
612 -#[derive(Serialize, Deserialize, Debug)]
613 -pub struct BinaryExpression {
614 - pub operator: BinaryOperator,
615 - pub left: ExpressionLike,
616 - pub right: ExpressionLike,
617 - pub loc: Option<SourceLocation>,
618 - #[serde(default)]
619 - pub range: Option<SourceRange>,
620 -}
621 -
622 -#[derive(Serialize, Deserialize, Debug)]
623 -pub enum BinaryOperator {
624 - /// ==
625 - #[serde(rename = "==")]
626 - EqualsEquals,
627 - /// !=
628 - #[serde(rename = "!=")]
629 - NotEquals,
630 - /// ===
631 - #[serde(rename = "===")]
632 - TripleEquals,
633 - /// !==
634 - #[serde(rename = "!==")]
635 - NotTripleEquals,
636 - /// <
637 - #[serde(rename = "<")]
638 - LessThan,
639 - /// <=
640 - #[serde(rename = "<=")]
641 - LessThanEquals,
642 - /// >
643 - #[serde(rename = ">")]
644 - GreaterThan,
645 - /// >=
646 - #[serde(rename = ">=")]
647 - GreaterThanEquals,
648 - /// <<
649 - #[serde(rename = "<<")]
650 - LtLt,
651 - /// >>
652 - #[serde(rename = ">>")]
653 - GtGt,
654 - /// >>>
655 - #[serde(rename = ">>>")]
656 - GtGtGt,
657 - /// +
658 - #[serde(rename = "+")]
659 - Plus,
660 - /// -
661 - #[serde(rename = "-")]
662 - Minus,
663 - /// *
664 - #[serde(rename = "*")]
665 - Asterisk,
666 - /// /
667 - #[serde(rename = "/")]
668 - Slash,
669 - /// %
670 - #[serde(rename = "%")]
671 - Percent,
672 - /// **
673 - #[serde(rename = "**")]
674 - AsteriskAsterisk,
675 - /// |
676 - #[serde(rename = "|")]
677 - Pipe,
678 - /// ^
679 - #[serde(rename = "^")]
680 - Caret,
681 - /// &
682 - #[serde(rename = "&")]
683 - Ampersand,
684 - /// in
685 - #[serde(rename = "in")]
686 - In,
687 - /// instanceof
688 - #[serde(rename = "instanceof")]
689 - Instanceof,
690 -}
691 -
692 -impl Display for BinaryOperator {
693 - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
694 - let name = match self {
695 - Self::Plus => "+",
696 - Self::LessThan => "<",
697 - _ => todo!("display for operator: {:#?}", self),
698 - };
699 - f.write_str(name)
700 - }
701 -}
702 -
703 -#[derive(Serialize, Deserialize, Debug)]
704 -pub struct CallExpression {
705 - #[serde(rename = "optional")]
706 - #[serde(default)]
707 - pub is_optional: bool,
708 -
709 - pub callee: ExpressionLike,
710 -
711 - pub arguments: Vec<ExpressionLike>,
712 -
713 - pub loc: Option<SourceLocation>,
714 - #[serde(default)]
715 - pub range: Option<SourceRange>,
716 -}
717 -
718 -#[derive(Serialize, Deserialize, Debug)]
719 -pub struct ChainExpression {
720 - pub expression: ChainElement,
721 - pub loc: Option<SourceLocation>,
722 - #[serde(default)]
723 - pub range: Option<SourceRange>,
724 -}
725 -
726 -#[derive(Serialize, Deserialize, Debug)]
727 -#[serde(tag = "type")]
728 -pub enum ChainElement {
729 - CallExpression(Box<CallExpression>),
730 - MemberExpression(Box<MemberExpression>),
731 -}
732 -
733 -#[derive(Serialize, Deserialize, Debug)]
734 -pub struct ClassExpression {
735 - // TODO
736 - pub loc: Option<SourceLocation>,
737 - #[serde(default)]
738 - pub range: Option<SourceRange>,
739 -}
740 -
741 -#[derive(Serialize, Deserialize, Debug)]
742 -pub struct ConditionalExpression {
743 - pub test: ExpressionLike,
744 - pub alternate: ExpressionLike,
745 - pub consequent: ExpressionLike,
746 - pub loc: Option<SourceLocation>,
747 - #[serde(default)]
748 - pub range: Option<SourceRange>,
749 -}
750 -
751 -#[derive(Serialize, Deserialize, Debug)]
752 -pub struct FunctionExpression {
753 - // TODO
754 - pub loc: Option<SourceLocation>,
755 - #[serde(default)]
756 - pub range: Option<SourceRange>,
757 -}
758 -
759 -#[derive(Serialize, Deserialize, Debug)]
760 -pub struct ImportExpression {
761 - // TODO
762 - pub loc: Option<SourceLocation>,
763 - #[serde(default)]
764 - pub range: Option<SourceRange>,
765 -}
766 -
767 -#[derive(Serialize, Deserialize, Debug)]
768 -pub struct Literal {
769 - pub value: LiteralValue,
770 -
771 - #[serde(default)]
772 - pub raw: Option<String>,
773 -
774 - pub loc: Option<SourceLocation>,
775 -
776 - #[serde(default)]
777 - pub range: Option<SourceRange>,
778 -}
779 -
780 -#[derive(Serialize, Deserialize, Debug)]
781 -#[serde(untagged)]
782 -pub enum LiteralValue {
783 - BigInt(String),
784 - Boolean(bool),
785 - Null,
786 - Number(Number),
787 - RegExp(RegExp),
788 - String(String),
789 -}
790 -
791 -#[derive(Serialize, Deserialize, Debug)]
792 -pub struct Number(u64);
793 -
794 -impl From<u64> for Number {
795 - fn from(value: u64) -> Self {
796 - Number(value)
797 - }
798 -}
799 -
800 -impl From<f64> for Number {
801 - fn from(value: f64) -> Self {
802 - Number(value.to_bits())
803 - }
804 -}
805 -
806 -impl From<Number> for f64 {
807 - fn from(value: Number) -> Self {
808 - f64::from_bits(value.0)
809 - }
810 -}
811 -
812 -#[derive(Serialize, Deserialize, Debug)]
813 -pub struct RegExp {
814 - pub raw: Option<String>,
815 - pub regex: Option<RegExpValue>,
816 -}
817 -
818 -#[derive(Serialize, Deserialize, Debug)]
819 -pub struct RegExpValue {
820 - pub pattern: String,
821 - pub flags: String,
822 -}
823 -
824 -#[derive(Serialize, Deserialize, Debug)]
825 -pub struct LogicalExpression {
826 - pub operator: LogicalOperator,
827 - pub left: ExpressionLike,
828 - pub right: ExpressionLike,
829 - pub loc: Option<SourceLocation>,
830 - #[serde(default)]
831 - pub range: Option<SourceRange>,
832 -}
833 -
834 -#[derive(Serialize, Deserialize, Debug)]
835 -pub enum LogicalOperator {
836 - /// ||
837 - #[serde(rename = "||")]
838 - PipePipe,
839 - /// &&
840 - #[serde(rename = "&&")]
841 - AmpersandAmpersand,
842 - /// ??
843 - #[serde(rename = "??")]
844 - QuestionQuestion,
845 -}
846 -
847 -#[derive(Serialize, Deserialize, Debug)]
848 -pub struct MetaProperty {
849 - // TODO
850 - pub loc: Option<SourceLocation>,
851 - #[serde(default)]
852 - pub range: Option<SourceRange>,
853 -}
854 -
855 -#[derive(Serialize, Deserialize, Debug)]
856 -pub struct NewExpression {
857 - pub callee: ExpressionLike,
858 - pub arguments: Vec<ExpressionLike>,
859 - pub loc: Option<SourceLocation>,
860 - #[serde(default)]
861 - pub range: Option<SourceRange>,
862 -}
863 -
864 -#[derive(Serialize, Deserialize, Debug)]
865 -pub struct ObjectExpression {
866 - pub properties: Vec<ExpressionLike>,
867 - pub loc: Option<SourceLocation>,
868 - #[serde(default)]
869 - pub range: Option<SourceRange>,
870 -}
871 -
872 -#[derive(Serialize, Deserialize, Debug)]
873 -pub struct SequenceExpression {
874 - pub expressions: Vec<ExpressionLike>,
875 - pub loc: Option<SourceLocation>,
876 - #[serde(default)]
877 - pub range: Option<SourceRange>,
878 -}
879 -
880 -#[derive(Serialize, Deserialize, Debug)]
881 -pub struct TaggedTemplateExpression {
882 - pub tag: ExpressionLike,
883 - pub quasi: TemplateLiteral,
884 - pub loc: Option<SourceLocation>,
885 - #[serde(default)]
886 - pub range: Option<SourceRange>,
887 -}
888 -
889 -#[derive(Serialize, Deserialize, Debug)]
890 -pub struct TemplateLiteral {
891 - pub quasis: Vec<TemplateElement>,
892 - pub expressions: Vec<ExpressionLike>,
893 - pub loc: Option<SourceLocation>,
894 - #[serde(default)]
895 - pub range: Option<SourceRange>,
896 -}
897 -
898 -#[derive(Serialize, Deserialize, Debug)]
899 -pub struct TemplateElement {
900 - #[serde(rename = "tail")]
901 - #[serde(default)]
902 - pub is_tail: bool,
903 -
904 - // TODO: add value: {cooked, raw} wrapper object
905 - pub cooked: Option<String>,
906 -
907 - pub raw: String,
908 -
909 - pub loc: Option<SourceLocation>,
910 - #[serde(default)]
911 - pub range: Option<SourceRange>,
912 -}
913 -
914 -#[derive(Serialize, Deserialize, Debug)]
915 -pub struct ThisExpression {
916 - // TODO
917 - pub loc: Option<SourceLocation>,
918 - #[serde(default)]
919 - pub range: Option<SourceRange>,
920 -}
921 -
922 -#[derive(Serialize, Deserialize, Debug)]
923 -pub struct UnaryExpression {
924 - pub operator: UnaryOperator,
925 -
926 - #[serde(rename = "prefix")]
927 - #[serde(default)]
928 - pub is_prefix: bool,
929 -
930 - pub argument: ExpressionLike,
931 -
932 - pub loc: Option<SourceLocation>,
933 - #[serde(default)]
934 - pub range: Option<SourceRange>,
935 -}
936 -
937 -#[derive(Serialize, Deserialize, Debug)]
938 -pub enum UnaryOperator {
939 - /// -
940 - #[serde(rename = "+")]
941 - Minus,
942 - /// +
943 - #[serde(rename = "+")]
944 - Plus,
945 - /// !
946 - #[serde(rename = "!")]
947 - Exclamation,
948 - /// ~
949 - #[serde(rename = "~")]
950 - Tilde,
951 - /// typeof
952 - #[serde(rename = "typeof")]
953 - Typeof,
954 - /// void
955 - #[serde(rename = "void")]
956 - Void,
957 - /// delete
958 - #[serde(rename = "delete")]
959 - Delete,
960 -}
961 -
962 -#[derive(Serialize, Deserialize, Debug)]
963 -pub struct UpdateExpression {
964 - pub operator: UpdateOperator,
965 -
966 - pub argument: ExpressionLike,
967 -
968 - #[serde(rename = "prefix")]
969 - #[serde(default)]
970 - pub is_prefix: bool,
971 -
972 - pub loc: Option<SourceLocation>,
973 - #[serde(default)]
974 - pub range: Option<SourceRange>,
975 -}
976 -
977 -#[derive(Serialize, Deserialize, Debug)]
978 -pub enum UpdateOperator {
979 - /// ++
980 - #[serde(rename = "++")]
981 - PlusPlus,
982 - /// --
983 - #[serde(rename = "--")]
984 - MinusMinus,
985 -}
986 -
987 -#[derive(Serialize, Deserialize, Debug)]
988 -pub struct YieldExpression {
989 - pub argument: Option<ExpressionLike>,
990 -
991 - #[serde(rename = "delegate")]
992 - #[serde(default)]
993 - pub is_delegate: bool,
994 -
995 - pub loc: Option<SourceLocation>,
996 - #[serde(default)]
997 - pub range: Option<SourceRange>,
998 -}
999 -
1000 -// Pattern etc
1001 -
1002 -#[derive(Serialize, Deserialize, Debug)]
1003 -#[serde(tag = "type")]
1004 -pub enum Pattern {
1005 - ArrayPattern(Box<ArrayPattern>),
1006 - AssignmentPattern(Box<AssignmentPattern>),
1007 - Identifier(Box<Identifier>),
1008 - MemberExpression(Box<MemberExpression>),
1009 - ObjectPattern(Box<ObjectPattern>),
1010 - RestElement(Box<RestElement>),
1011 -}
1012 -
1013 -#[derive(Serialize, Deserialize, Debug)]
1014 -pub struct ArrayPattern {
1015 - pub elements: Vec<Pattern>,
1016 -
1017 - pub loc: Option<SourceLocation>,
1018 - #[serde(default)]
1019 - pub range: Option<SourceRange>,
1020 -}
1021 -
1022 -#[derive(Serialize, Deserialize, Debug)]
1023 -pub struct AssignmentPattern {
1024 - pub left: Pattern,
1025 - pub right: ExpressionLike,
1026 - pub loc: Option<SourceLocation>,
1027 - #[serde(default)]
1028 - pub range: Option<SourceRange>,
1029 -}
1030 -
1031 -#[derive(Serialize, Deserialize, Debug)]
1032 -pub struct Identifier {
1033 - pub name: String,
1034 -
1035 - #[serde(default)]
1036 - pub binding: Option<Binding>,
1037 -
1038 - pub loc: Option<SourceLocation>,
1039 -
1040 - #[serde(default)]
1041 - pub range: Option<SourceRange>,
1042 -}
1043 -
1044 -#[derive(Serialize, Deserialize, Debug)]
1045 -#[serde(tag = "type")]
1046 -pub enum Binding {
1047 - Local(BindingId),
1048 - Module(BindingId),
1049 - Global,
1050 -}
1051 -
1052 -#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, Copy)]
1053 -#[serde(transparent)]
1054 -pub struct BindingId(NonZeroU32);
1055 -
1056 -impl BindingId {
1057 - pub fn new(id: NonZeroU32) -> Self {
1058 - Self(id)
1059 - }
1060 -}
1061 -
1062 -impl From<BindingId> for u32 {
1063 - fn from(value: BindingId) -> Self {
1064 - value.0.into()
1065 - }
1066 -}
1067 -
1068 -#[derive(Serialize, Deserialize, Debug)]
1069 -pub struct MemberExpression {
1070 - pub object: ExpressionLike,
1071 -
1072 - pub property: ExpressionLike, // ExpressionOrPrivateIdentifier
1073 -
1074 - #[serde(rename = "computed")]
1075 - #[serde(default)]
1076 - pub is_computed: bool,
1077 -
1078 - #[serde(rename = "optional")]
1079 - #[serde(default)]
1080 - pub is_optional: bool,
1081 -
1082 - pub loc: Option<SourceLocation>,
1083 - #[serde(default)]
1084 - pub range: Option<SourceRange>,
1085 -}
1086 -
1087 -#[derive(Serialize, Deserialize, Debug)]
1088 -pub struct Super {
1089 - pub loc: Option<SourceLocation>,
1090 - #[serde(default)]
1091 - pub range: Option<SourceRange>,
1092 -}
1093 -
1094 -#[derive(Serialize, Deserialize, Debug)]
1095 -pub struct PrivateIdentifier {
1096 - pub name: String,
1097 - pub loc: Option<SourceLocation>,
1098 - #[serde(default)]
1099 - pub range: Option<SourceRange>,
1100 -}
1101 -
1102 -#[derive(Serialize, Deserialize, Debug)]
1103 -pub struct ObjectPattern {
1104 - pub properties: Vec<ExpressionLike>,
1105 - pub loc: Option<SourceLocation>,
1106 - #[serde(default)]
1107 - pub range: Option<SourceRange>,
1108 -}
1109 -
1110 -#[derive(Serialize, Deserialize, Debug)]
1111 -pub struct Property {
1112 - pub key: ExpressionLike,
1113 -
1114 - pub value: PropertyValue,
1115 -
1116 - pub kind: PropertyKind,
1117 -
1118 - #[serde(rename = "method")]
1119 - #[serde(default)]
1120 - pub is_method: bool,
1121 -
1122 - #[serde(rename = "shorthand")]
1123 - #[serde(default)]
1124 - pub is_shorthand: bool,
1125 -
1126 - #[serde(rename = "computed")]
1127 - #[serde(default)]
1128 - pub is_computed: bool,
1129 -
1130 - pub loc: Option<SourceLocation>,
1131 - #[serde(default)]
1132 - pub range: Option<SourceRange>,
1133 -}
1134 -
1135 -#[derive(Serialize, Deserialize, Debug)]
1136 -#[serde(untagged)]
1137 -pub enum PropertyValue {
1138 - Expression(Box<ExpressionLike>),
1139 - Pattern(Box<Pattern>),
1140 -}
1141 -
1142 -#[derive(Serialize, Deserialize, Debug)]
1143 -pub enum PropertyKind {
1144 - #[serde(rename = "init")]
1145 - Init,
1146 - #[serde(rename = "get")]
1147 - Get,
1148 - #[serde(rename = "set")]
1149 - Set,
1150 -}
1151 -
1152 -impl Default for PropertyKind {
1153 - fn default() -> Self {
1154 - Self::Init
1155 - }
1156 -}
1157 -
1158 -#[derive(Serialize, Deserialize, Debug)]
1159 -pub struct RestElement {
1160 - pub argument: Pattern,
1161 - pub loc: Option<SourceLocation>,
1162 - #[serde(default)]
1163 - pub range: Option<SourceRange>,
1164 -}
1165 -
1166 -#[derive(Serialize, Deserialize, Debug)]
1167 -pub struct SpreadElement {
1168 - pub argument: ExpressionLike,
1169 - pub loc: Option<SourceLocation>,
1170 - #[serde(default)]
1171 - pub range: Option<SourceRange>,
1172 -}
1173 -
1174 -#[derive(Serialize, Deserialize, Debug)]
1175 -pub struct JSXElement {
1176 - #[serde(rename = "openingElement")]
1177 - pub opening_element: ExpressionLike,
1178 -
1179 - pub children: Vec<ExpressionLike>,
1180 -
1181 - #[serde(rename = "closingElement")]
1182 - pub closing_element: Option<ExpressionLike>,
1183 -
1184 - pub loc: Option<SourceLocation>,
1185 -
1186 - #[serde(default)]
1187 - pub range: Option<SourceRange>,
1188 -}
1189 -
1190 -#[derive(Serialize, Deserialize, Debug)]
1191 -pub struct JSXOpeningElement {
1192 - pub name: ExpressionLike,
1193 -
1194 - pub attributes: Vec<JSXAttribute>,
1195 -
1196 - #[serde(rename = "selfClosing")]
1197 - #[serde(default)]
1198 - pub self_closing: bool,
1199 -
1200 - pub loc: Option<SourceLocation>,
1201 -
1202 - #[serde(default)]
1203 - pub range: Option<SourceRange>,
1204 -}
1205 -
1206 -#[derive(Serialize, Deserialize, Debug)]
1207 -pub struct JSXClosingElement {
1208 - pub name: ExpressionLike,
1209 -
1210 - pub loc: Option<SourceLocation>,
1211 -
1212 - #[serde(default)]
1213 - pub range: Option<SourceRange>,
1214 -}
1215 -
1216 -#[derive(Serialize, Deserialize, Debug)]
1217 -pub struct JSXMemberExpression {
1218 - pub object: ExpressionLike,
1219 -
1220 - pub property: ExpressionLike,
1221 -
1222 - pub loc: Option<SourceLocation>,
1223 -
1224 - #[serde(default)]
1225 - pub range: Option<SourceRange>,
1226 -}
1227 -
1228 -#[derive(Serialize, Deserialize, Debug)]
1229 -pub struct JSXIdentifier {
1230 - pub name: String,
1231 -
1232 - pub loc: Option<SourceLocation>,
1233 -
1234 - #[serde(default)]
1235 - pub range: Option<SourceRange>,
1236 -}
1237 -
1238 -#[derive(Serialize, Deserialize, Debug)]
1239 -pub struct JSXNamedspacedName {
1240 - pub namespace: ExpressionLike,
1241 -
1242 - pub name: ExpressionLike,
1243 -
1244 - pub loc: Option<SourceLocation>,
1245 -
1246 - #[serde(default)]
1247 - pub range: Option<SourceRange>,
1248 -}
1249 -
1250 -#[derive(Serialize, Deserialize, Debug)]
1251 -pub struct JSXAttribute {
1252 - pub name: ExpressionLike,
1253 -
1254 - pub value: ExpressionLike,
1255 -
1256 - pub loc: Option<SourceLocation>,
1257 -
1258 - #[serde(default)]
1259 - pub range: Option<SourceRange>,
1260 -}
1261 -
1262 -#[derive(Serialize, Deserialize, Debug)]
1263 -pub struct JSXExpressionContainer {
1264 - expression: ExpressionLike,
1265 -
1266 - pub loc: Option<SourceLocation>,
1267 -
1268 - #[serde(default)]
1269 - pub range: Option<SourceRange>,
1270 -}
1271 -
1272 -#[derive(Serialize, Deserialize, Debug)]
1273 -pub struct JSXText {
1274 - value: String,
1275 - raw: String,
1276 -
1277 - pub loc: Option<SourceLocation>,
1278 -
1279 - #[serde(default)]
1280 - pub range: Option<SourceRange>,
1281 -}
6 +pub use binding::Binding;
7 +pub use generated::*;
8 +pub use js_value::JsValue;
9 +pub use range::SourceRange;
10
11 #[cfg(test)]
12 mod tests {
@@ -1286,54 +14,6 @@ mod tests {
14 use insta::{assert_snapshot, glob};
15 use serde_json;
16
1289 - #[test]
1290 - fn for_statement() {
1291 - let source = include_str!("for-statement.json");
1292 - let ast: Program = serde_json::from_str(&source).unwrap();
1293 - println!("deserialized:\n{:#?}", ast);
1294 - let serialized = serde_json::to_string_pretty(&ast).unwrap();
1295 - println!("serialized:\n{}", serialized);
1296 - }
1297 -
1298 - #[test]
1299 - fn simple() {
1300 - let source = include_str!("simple.json");
1301 - let ast: Program = serde_json::from_str(&source).unwrap();
1302 - println!("deserialized:\n{:#?}", ast);
1303 - let serialized = serde_json::to_string_pretty(&ast).unwrap();
1304 - println!("serialized:\n{}", serialized);
1305 - }
1306 -
1307 - /// TODO: enable once this deserializes
1308 - fn _kitchen_sink() {
1309 - let source = include_str!("kitchen-sink.json");
1310 - let ast: Program = match serde_json::from_str(&source) {
1311 - Ok(ast) => ast,
1312 - Err(err) => panic!("{:#?}", err),
1313 - };
1314 - println!("deserialized:\n{:#?}", ast);
1315 - let serialized = serde_json::to_string_pretty(&ast).unwrap();
1316 - println!("serialized:\n{}", serialized);
1317 - }
1318 -
1319 - #[test]
1320 - fn import() {
1321 - let source = include_str!("import.json");
1322 - let ast: Program = serde_json::from_str(&source).unwrap();
1323 - println!("deserialized:\n{:#?}", ast);
1324 - let serialized = serde_json::to_string_pretty(&ast).unwrap();
1325 - println!("serialized:\n{}", serialized);
1326 - }
1327 -
1328 - #[test]
1329 - fn test() {
1330 - let source = include_str!("test.json");
1331 - let ast: Program = serde_json::from_str(&source).unwrap();
1332 - println!("deserialized:\n{:#?}", ast);
1333 - let serialized = serde_json::to_string_pretty(&ast).unwrap();
1334 - println!("serialized:\n{}", serialized);
1335 - }
1336 -
17 #[test]
18 fn fixtures() {
19 glob!("fixtures/**.json", |path| {
compiler/forget/crates/estree/src/old.lib.rs new
+1358
@@ -0,0 +1,1358 @@
1 +use serde::{Deserialize, Serialize};
2 +use static_assertions::assert_eq_size;
3 +use std::{fmt::Display, num::NonZeroU32};
4 +
5 +#[derive(Serialize, Deserialize, Debug)]
6 +pub struct SourceLocation {
7 + pub source: Option<String>,
8 +
9 + pub start: Position,
10 +
11 + pub end: Position,
12 +}
13 +
14 +#[derive(Serialize, Deserialize, Debug, Clone)]
15 +pub struct Position {
16 + /// >= 1
17 + pub line: NonZeroU32,
18 + /// >= 0
19 + pub column: u32,
20 +}
21 +assert_eq_size!(Option<Position>, u64);
22 +
23 +#[derive(Serialize, Deserialize, Debug, Clone)]
24 +pub struct SourceRange {
25 + pub start: u32,
26 + // end is exclusive so it can always be non-zero. This allows
27 + // Option<SourceRange> to not take any additional bytes.
28 + pub end: NonZeroU32,
29 +}
30 +assert_eq_size!(Option<SourceRange>, u64);
31 +
32 +#[derive(Serialize, Deserialize, Debug)]
33 +pub struct Program {
34 + /// sourceType
35 + #[serde(rename = "sourceType")]
36 + #[serde(default)]
37 + pub source_type: SourceType,
38 +
39 + pub body: Vec<ModuleItem>,
40 +
41 + #[serde(default)]
42 + pub comments: Option<Vec<Comment>>,
43 +
44 + pub loc: Option<SourceLocation>,
45 +
46 + #[serde(default)]
47 + pub range: Option<SourceRange>,
48 +}
49 +
50 +#[derive(Serialize, Deserialize, Debug)]
51 +pub enum SourceType {
52 + /// "module"
53 + #[serde(rename = "module")]
54 + Module,
55 + /// "script"
56 + #[serde(rename = "script")]
57 + Script,
58 +}
59 +
60 +impl Default for SourceType {
61 + fn default() -> Self {
62 + Self::Module
63 + }
64 +}
65 +
66 +#[derive(Serialize, Deserialize, Debug)]
67 +pub struct Comment {
68 + pub type_: CommentType,
69 + pub value: String,
70 +}
71 +
72 +#[derive(Serialize, Deserialize, Debug)]
73 +pub enum CommentType {
74 + /// "Line"
75 + Line,
76 + /// "Block"
77 + Block,
78 +}
79 +
80 +#[derive(Serialize, Deserialize, Debug)]
81 +#[serde(untagged)]
82 +pub enum ModuleItem {
83 + Statement(Box<Statement>),
84 + ImportDeclaration(Box<ImportDeclaration>),
85 +}
86 +
87 +#[derive(Serialize, Deserialize, Debug)]
88 +#[serde(tag = "type")]
89 +pub enum ImportExportDeclaration {
90 + ImportDeclaration(Box<ImportDeclaration>),
91 + // TODO:
92 + // ExportNamedDeclaration(Box<ExportNamedDeclaration>),
93 + // ExportDefaultDeclaration(Box<ExportDefaultDeclaration>),
94 + // ExportAllDeclaration(Box<ExportAllDeclaration>),
95 +}
96 +
97 +#[derive(Serialize, Deserialize, Debug)]
98 +pub struct ImportDeclaration {
99 + pub specifiers: Vec<ImportSpecifiers>,
100 + pub source: Literal,
101 + pub loc: Option<SourceLocation>,
102 + #[serde(default)]
103 + pub range: Option<SourceRange>,
104 +}
105 +
106 +#[derive(Serialize, Deserialize, Debug)]
107 +#[serde(tag = "type")]
108 +pub enum ImportSpecifiers {
109 + ImportSpecifier(Box<ImportSpecifier>),
110 + ImportDefaultSpecifier(Box<ImportDefaultSpecifier>),
111 +}
112 +
113 +#[derive(Serialize, Deserialize, Debug)]
114 +pub struct ImportSpecifier {
115 + pub imported: Identifier,
116 +
117 + pub local: Identifier,
118 +
119 + pub loc: Option<SourceLocation>,
120 +
121 + #[serde(default)]
122 + pub range: Option<SourceRange>,
123 +}
124 +
125 +#[derive(Serialize, Deserialize, Debug)]
126 +pub struct ImportDefaultSpecifier {
127 + pub local: Identifier,
128 +
129 + pub loc: Option<SourceLocation>,
130 +
131 + #[serde(default)]
132 + pub range: Option<SourceRange>,
133 +}
134 +
135 +#[derive(Serialize, Deserialize, Debug)]
136 +#[serde(tag = "type")]
137 +pub enum Statement {
138 + BlockStatement(Box<BlockStatement>),
139 + BreakStatement(Box<BreakStatement>),
140 + ClassDeclaration(Box<ClassDeclaration>),
141 + ContinueStatement(Box<ContinueStatement>),
142 + DebuggerStatement(Box<DebuggerStatement>),
143 + DoWhileStatement(Box<DoWhileStatement>),
144 + EmptyStatement(Box<EmptyStatement>),
145 + ExpressionStatement(Box<ExpressionStatement>),
146 + ForInStatement(Box<ForInStatement>),
147 + ForOfStatement(Box<ForOfStatement>),
148 + ForStatement(Box<ForStatement>),
149 + FunctionDeclaration(Box<FunctionDeclaration>),
150 + IfStatement(Box<IfStatement>),
151 + LabeledStatement(Box<LabeledStatement>),
152 + ReturnStatement(Box<ReturnStatement>),
153 + StaticBlock(Box<StaticBlock>),
154 + SwitchStatement(Box<SwitchStatement>),
155 + ThrowStatement(Box<ThrowStatement>),
156 + TryStatement(Box<TryStatement>),
157 + VariableDeclaration(Box<VariableDeclaration>),
158 + WhileStatement(Box<WhileStatement>),
159 + WithStatement(Box<WithStatement>),
160 +}
161 +// Prevent unboxed variants from increasing the size
162 +assert_eq_size!(Statement, u128);
163 +
164 +#[derive(Serialize, Deserialize, Debug)]
165 +pub struct BlockStatement {
166 + pub body: Vec<Statement>,
167 + pub loc: Option<SourceLocation>,
168 + #[serde(default)]
169 + pub range: Option<SourceRange>,
170 +}
171 +
172 +#[derive(Serialize, Deserialize, Debug)]
173 +pub struct BreakStatement {
174 + #[serde(default)]
175 + pub label: Option<Identifier>,
176 + pub loc: Option<SourceLocation>,
177 + #[serde(default)]
178 + pub range: Option<SourceRange>,
179 +}
180 +
181 +#[derive(Serialize, Deserialize, Debug)]
182 +pub struct ClassDeclaration {
183 + pub loc: Option<SourceLocation>,
184 + #[serde(default)]
185 + pub range: Option<SourceRange>,
186 +}
187 +
188 +#[derive(Serialize, Deserialize, Debug)]
189 +pub struct ContinueStatement {
190 + #[serde(default)]
191 + pub label: Option<Identifier>,
192 + pub loc: Option<SourceLocation>,
193 + #[serde(default)]
194 + pub range: Option<SourceRange>,
195 +}
196 +
197 +#[derive(Serialize, Deserialize, Debug)]
198 +pub struct DebuggerStatement {
199 + pub loc: Option<SourceLocation>,
200 + #[serde(default)]
201 + pub range: Option<SourceRange>,
202 +}
203 +
204 +#[derive(Serialize, Deserialize, Debug)]
205 +pub struct DoWhileStatement {
206 + pub body: Statement,
207 + pub test: ExpressionLike,
208 + pub loc: Option<SourceLocation>,
209 + #[serde(default)]
210 + pub range: Option<SourceRange>,
211 +}
212 +
213 +#[derive(Serialize, Deserialize, Debug)]
214 +pub struct EmptyStatement {
215 + pub loc: Option<SourceLocation>,
216 + #[serde(default)]
217 + pub range: Option<SourceRange>,
218 +}
219 +
220 +#[derive(Serialize, Deserialize, Debug)]
221 +pub struct FunctionDeclaration {
222 + pub id: Option<Identifier>,
223 +
224 + pub params: Vec<Pattern>,
225 +
226 + #[serde(rename = "generator")]
227 + #[serde(default)]
228 + pub is_generator: bool,
229 +
230 + #[serde(rename = "async")]
231 + #[serde(default)]
232 + pub is_async: bool,
233 +
234 + // TODO: BlockStatement
235 + pub body: Option<Statement>,
236 +
237 + pub loc: Option<SourceLocation>,
238 + #[serde(default)]
239 + pub range: Option<SourceRange>,
240 +}
241 +
242 +#[derive(Serialize, Deserialize, Debug)]
243 +pub struct StaticBlock {
244 + pub body: Vec<Statement>,
245 + pub loc: Option<SourceLocation>,
246 + #[serde(default)]
247 + pub range: Option<SourceRange>,
248 +}
249 +
250 +#[derive(Serialize, Deserialize, Debug)]
251 +pub struct ExpressionStatement {
252 + pub expression: ExpressionLike,
253 +
254 + #[serde(default)]
255 + pub directive: Option<String>,
256 +
257 + pub loc: Option<SourceLocation>,
258 +
259 + #[serde(default)]
260 + pub range: Option<SourceRange>,
261 +}
262 +
263 +#[derive(Serialize, Deserialize, Debug)]
264 +pub struct ForInStatement {
265 + pub left: ForPattern,
266 + pub right: ExpressionLike,
267 + pub body: Statement,
268 + pub loc: Option<SourceLocation>,
269 + #[serde(default)]
270 + pub range: Option<SourceRange>,
271 +}
272 +
273 +#[derive(Serialize, Deserialize, Debug)]
274 +pub struct ForOfStatement {
275 + #[serde(rename = "await")]
276 + #[serde(default)]
277 + pub is_await: bool,
278 +
279 + pub left: ForPattern,
280 +
281 + pub right: ExpressionLike,
282 +
283 + pub body: Statement,
284 +
285 + pub loc: Option<SourceLocation>,
286 + #[serde(default)]
287 + pub range: Option<SourceRange>,
288 +}
289 +
290 +#[derive(Serialize, Deserialize, Debug)]
291 +#[serde(tag = "type")]
292 +pub enum ForPattern {
293 + VariableDeclaration(Box<VariableDeclaration>),
294 + Expression(Box<ExpressionLike>),
295 +}
296 +
297 +#[derive(Serialize, Deserialize, Debug)]
298 +pub struct ForStatement {
299 + pub init: Option<ForInit>,
300 + pub test: Option<ExpressionLike>,
301 + pub update: Option<ExpressionLike>,
302 + pub body: Statement,
303 + pub loc: Option<SourceLocation>,
304 + #[serde(default)]
305 + pub range: Option<SourceRange>,
306 +}
307 +
308 +#[derive(Serialize, Deserialize, Debug)]
309 +#[serde(tag = "type")]
310 +pub enum ForInit {
311 + VariableDeclaration(Box<VariableDeclaration>),
312 + Expression(Box<ExpressionLike>),
313 +}
314 +
315 +#[derive(Serialize, Deserialize, Debug)]
316 +pub struct IfStatement {
317 + pub test: ExpressionLike,
318 + pub consequent: Statement,
319 + pub alternate: Option<Statement>,
320 + pub loc: Option<SourceLocation>,
321 + #[serde(default)]
322 + pub range: Option<SourceRange>,
323 +}
324 +
325 +#[derive(Serialize, Deserialize, Debug)]
326 +pub struct LabeledStatement {
327 + pub label: Identifier,
328 + pub body: Statement,
329 + pub loc: Option<SourceLocation>,
330 + #[serde(default)]
331 + pub range: Option<SourceRange>,
332 +}
333 +
334 +#[derive(Serialize, Deserialize, Debug)]
335 +pub struct ReturnStatement {
336 + pub argument: Option<ExpressionLike>,
337 + pub loc: Option<SourceLocation>,
338 + #[serde(default)]
339 + pub range: Option<SourceRange>,
340 +}
341 +
342 +#[derive(Serialize, Deserialize, Debug)]
343 +pub struct SwitchStatement {
344 + pub discriminant: ExpressionLike,
345 + pub cases: Vec<SwitchCase>,
346 + pub loc: Option<SourceLocation>,
347 + #[serde(default)]
348 + pub range: Option<SourceRange>,
349 +}
350 +
351 +#[derive(Serialize, Deserialize, Debug)]
352 +pub struct SwitchCase {
353 + pub test: Option<ExpressionLike>,
354 + pub consequent: Vec<Statement>,
355 + pub loc: Option<SourceLocation>,
356 + #[serde(default)]
357 + pub range: Option<SourceRange>,
358 +}
359 +
360 +#[derive(Serialize, Deserialize, Debug)]
361 +pub struct ThrowStatement {
362 + pub argument: ExpressionLike,
363 + pub loc: Option<SourceLocation>,
364 + #[serde(default)]
365 + pub range: Option<SourceRange>,
366 +}
367 +
368 +#[derive(Serialize, Deserialize, Debug)]
369 +pub struct TryStatement {
370 + // TODO: block: BlockStatement
371 + pub block: Statement,
372 + pub handler: Option<CatchClause>,
373 + // TODO: finalizer: BlockStatement
374 + pub finalizer: Option<Statement>,
375 + pub loc: Option<SourceLocation>,
376 + #[serde(default)]
377 + pub range: Option<SourceRange>,
378 +}
379 +
380 +#[derive(Serialize, Deserialize, Debug)]
381 +pub struct CatchClause {
382 + pub param: Option<Pattern>,
383 + pub body: Statement,
384 + pub loc: Option<SourceLocation>,
385 + #[serde(default)]
386 + pub range: Option<SourceRange>,
387 +}
388 +
389 +#[derive(Serialize, Deserialize, Debug)]
390 +pub struct VariableDeclaration {
391 + pub declarations: Vec<VariableDeclarator>,
392 + pub kind: VariableDeclarationKind,
393 + pub loc: Option<SourceLocation>,
394 + #[serde(default)]
395 + pub range: Option<SourceRange>,
396 +}
397 +
398 +#[derive(Serialize, Deserialize, Debug)]
399 +pub struct VariableDeclarator {
400 + pub id: Pattern,
401 + pub init: Option<ExpressionLike>,
402 + pub loc: Option<SourceLocation>,
403 + #[serde(default)]
404 + pub range: Option<SourceRange>,
405 +}
406 +
407 +#[derive(Serialize, Deserialize, Debug)]
408 +pub enum VariableDeclarationKind {
409 + #[serde(rename = "const")]
410 + Const,
411 + #[serde(rename = "let")]
412 + Let,
413 + #[serde(rename = "var")]
414 + Var,
415 +}
416 +
417 +#[derive(Serialize, Deserialize, Debug)]
418 +pub struct WhileStatement {
419 + pub test: ExpressionLike,
420 + pub body: Statement,
421 + pub loc: Option<SourceLocation>,
422 + #[serde(default)]
423 + pub range: Option<SourceRange>,
424 +}
425 +
426 +#[derive(Serialize, Deserialize, Debug)]
427 +pub struct WithStatement {
428 + pub object: ExpressionLike,
429 + pub body: Statement,
430 + pub loc: Option<SourceLocation>,
431 + #[serde(default)]
432 + pub range: Option<SourceRange>,
433 +}
434 +
435 +/// Expressions and expression-like nodes
436 +/// we flatten these into a single enum to work around limits
437 +/// of serde enum format with handling arbitrary unions
438 +#[derive(Serialize, Deserialize, Debug)]
439 +#[serde(tag = "type")]
440 +pub enum ExpressionLike {
441 + ArrayExpression(Box<ArrayExpression>),
442 + ArrowFunctionExpression(Box<ArrowFunctionExpression>),
443 + AssignmentExpression(Box<AssignmentExpression>),
444 + AwaitExpression(Box<AwaitExpression>),
445 + BinaryExpression(Box<BinaryExpression>),
446 + CallExpression(Box<CallExpression>),
447 + ChainExpression(Box<ChainExpression>),
448 + ClassExpression(Box<ClassExpression>),
449 + ConditionalExpression(Box<ConditionalExpression>),
450 + FunctionExpression(Box<FunctionExpression>),
451 + Identifier(Box<Identifier>),
452 + ImportExpression(Box<ImportExpression>),
453 + Literal(Box<Literal>),
454 + LogicalExpression(Box<LogicalExpression>),
455 + MemberExpression(Box<MemberExpression>),
456 + MetaProperty(Box<MetaProperty>),
457 + NewExpression(Box<NewExpression>),
458 + ObjectExpression(Box<ObjectExpression>),
459 + SequenceExpression(Box<SequenceExpression>),
460 + TaggedTemplateExpression(Box<TaggedTemplateExpression>),
461 + TemplateLiteral(Box<TemplateLiteral>),
462 + ThisExpression(Box<ThisExpression>),
463 + UnaryExpression(Box<UnaryExpression>),
464 + UpdateExpression(Box<UpdateExpression>),
465 + YieldExpression(Box<YieldExpression>),
466 +
467 + // pseudo-expressions to work with serde
468 + Super(Box<Super>),
469 +
470 + // patterns to work with serde
471 + ArrayPattern(Box<ArrayPattern>),
472 + AssignmentPattern(Box<AssignmentPattern>),
473 + ObjectPattern(Box<ObjectPattern>),
474 + Property(Box<Property>),
475 + RestElement(Box<RestElement>),
476 + SpreadElement(Box<SpreadElement>),
477 +
478 + // jsx expression-ish types to work with serde
479 + JSXClosingElement(Box<JSXClosingElement>),
480 + JSXElement(Box<JSXElement>),
481 + JSXExpressionContainer(Box<JSXExpressionContainer>),
482 + JSXIdentifier(Box<JSXIdentifier>),
483 + JSXMemberExpression(Box<JSXMemberExpression>),
484 + JSXNamedspacedName(Box<JSXNamedspacedName>),
485 + JSXOpeningElement(Box<JSXOpeningElement>),
486 + JSXText(Box<JSXText>),
487 +}
488 +// Prevent unboxed variants from increasing the size
489 +assert_eq_size!(ExpressionLike, u128);
490 +
491 +#[derive(Serialize, Deserialize, Debug)]
492 +pub struct ArrayExpression {
493 + pub elements: Vec<ExpressionLike>,
494 + pub loc: Option<SourceLocation>,
495 + #[serde(default)]
496 + pub range: Option<SourceRange>,
497 +}
498 +
499 +#[derive(Serialize, Deserialize, Debug)]
500 +pub struct ArrowFunctionExpression {
501 + pub params: Vec<Pattern>,
502 +
503 + #[serde(rename = "generator")]
504 + #[serde(default)]
505 + pub is_generator: bool,
506 +
507 + #[serde(rename = "async")]
508 + #[serde(default)]
509 + pub is_async: bool,
510 +
511 + #[serde(rename = "expression")]
512 + #[serde(default)]
513 + pub is_expression: bool,
514 +
515 + pub body: BlockOrExpression,
516 +
517 + pub loc: Option<SourceLocation>,
518 + #[serde(default)]
519 + pub range: Option<SourceRange>,
520 +}
521 +
522 +#[derive(Serialize, Deserialize, Debug)]
523 +#[serde(tag = "type")]
524 +pub enum BlockOrExpression {
525 + BlockStatement(Box<BlockStatement>),
526 + Expression(Box<ExpressionLike>),
527 +}
528 +
529 +#[derive(Serialize, Deserialize, Debug)]
530 +pub struct AssignmentExpression {
531 + pub operator: AssignmentOperator,
532 + pub left: AssignmentTarget,
533 + pub right: ExpressionLike,
534 + pub loc: Option<SourceLocation>,
535 + #[serde(default)]
536 + pub range: Option<SourceRange>,
537 +}
538 +
539 +#[derive(Serialize, Deserialize, Debug)]
540 +pub enum AssignmentOperator {
541 + /// =
542 + #[serde(rename = "=")]
543 + Equals,
544 + /// +=
545 + #[serde(rename = "+=")]
546 + PlusEquals,
547 + // -=
548 + #[serde(rename = "-=")]
549 + MinusEquals,
550 + /// *=
551 + #[serde(rename = "*=")]
552 + AsteriskEquals,
553 + /// /=
554 + #[serde(rename = "/=")]
555 + SlashEquals,
556 + /// %=
557 + #[serde(rename = "%=")]
558 + PercentEquals,
559 + /// **=
560 + #[serde(rename = "**=")]
561 + AsteriskAsteriskEquals,
562 + /// <<=
563 + #[serde(rename = "<<=")]
564 + LtLtEquals,
565 + /// >>=
566 + #[serde(rename = ">>=")]
567 + GtGtEquals,
568 + /// >>>=
569 + #[serde(rename = ">>>=")]
570 + GtGtGtEquals,
571 + /// |=
572 + #[serde(rename = "|=")]
573 + PipeEquals,
574 + /// ^=
575 + #[serde(rename = "^=")]
576 + CaretEquals,
577 + /// &=
578 + #[serde(rename = "&&=")]
579 + AmpersandEquals,
580 + /// ||=
581 + #[serde(rename = "||=")]
582 + PipePipeEquals,
583 + /// &&=
584 + #[serde(rename = "&&=")]
585 + AmpersandAmpersandEquals,
586 + // ??=
587 + #[serde(rename = "??=")]
588 + QuestionQuestionEquals,
589 +}
590 +
591 +impl AssignmentOperator {
592 + pub fn is_simple_equals(&self) -> bool {
593 + matches!(self, AssignmentOperator::Equals)
594 + }
595 +}
596 +
597 +#[derive(Serialize, Deserialize, Debug)]
598 +#[serde(untagged)]
599 +pub enum AssignmentTarget {
600 + Pattern(Box<Pattern>),
601 + MemberExpression(Box<MemberExpression>),
602 +}
603 +
604 +#[derive(Serialize, Deserialize, Debug)]
605 +pub struct AwaitExpression {
606 + pub argument: ExpressionLike,
607 + pub loc: Option<SourceLocation>,
608 + #[serde(default)]
609 + pub range: Option<SourceRange>,
610 +}
611 +
612 +#[derive(Serialize, Deserialize, Debug)]
613 +pub struct BinaryExpression {
614 + pub operator: BinaryOperator,
615 + pub left: ExpressionLike,
616 + pub right: ExpressionLike,
617 + pub loc: Option<SourceLocation>,
618 + #[serde(default)]
619 + pub range: Option<SourceRange>,
620 +}
621 +
622 +#[derive(Serialize, Deserialize, Debug)]
623 +pub enum BinaryOperator {
624 + /// ==
625 + #[serde(rename = "==")]
626 + EqualsEquals,
627 + /// !=
628 + #[serde(rename = "!=")]
629 + NotEquals,
630 + /// ===
631 + #[serde(rename = "===")]
632 + TripleEquals,
633 + /// !==
634 + #[serde(rename = "!==")]
635 + NotTripleEquals,
636 + /// <
637 + #[serde(rename = "<")]
638 + LessThan,
639 + /// <=
640 + #[serde(rename = "<=")]
641 + LessThanEquals,
642 + /// >
643 + #[serde(rename = ">")]
644 + GreaterThan,
645 + /// >=
646 + #[serde(rename = ">=")]
647 + GreaterThanEquals,
648 + /// <<
649 + #[serde(rename = "<<")]
650 + LtLt,
651 + /// >>
652 + #[serde(rename = ">>")]
653 + GtGt,
654 + /// >>>
655 + #[serde(rename = ">>>")]
656 + GtGtGt,
657 + /// +
658 + #[serde(rename = "+")]
659 + Plus,
660 + /// -
661 + #[serde(rename = "-")]
662 + Minus,
663 + /// *
664 + #[serde(rename = "*")]
665 + Asterisk,
666 + /// /
667 + #[serde(rename = "/")]
668 + Slash,
669 + /// %
670 + #[serde(rename = "%")]
671 + Percent,
672 + /// **
673 + #[serde(rename = "**")]
674 + AsteriskAsterisk,
675 + /// |
676 + #[serde(rename = "|")]
677 + Pipe,
678 + /// ^
679 + #[serde(rename = "^")]
680 + Caret,
681 + /// &
682 + #[serde(rename = "&")]
683 + Ampersand,
684 + /// in
685 + #[serde(rename = "in")]
686 + In,
687 + /// instanceof
688 + #[serde(rename = "instanceof")]
689 + Instanceof,
690 +}
691 +
692 +impl Display for BinaryOperator {
693 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
694 + let name = match self {
695 + Self::Plus => "+",
696 + Self::LessThan => "<",
697 + _ => todo!("display for operator: {:#?}", self),
698 + };
699 + f.write_str(name)
700 + }
701 +}
702 +
703 +impl std::str::FromStr for BinaryOperator {
704 + type Err = String;
705 +
706 + fn from_str(s: &str) -> Result<Self, Self::Err> {
707 + match s {
708 + "+" => Ok(Self::Plus),
709 + "-" => Ok(Self::Minus),
710 + _ => Err(format!("Invalid BinaryOperator: `{}`", s)),
711 + }
712 + }
713 +}
714 +
715 +#[derive(Serialize, Deserialize, Debug)]
716 +pub struct CallExpression {
717 + #[serde(rename = "optional")]
718 + #[serde(default)]
719 + pub is_optional: bool,
720 +
721 + pub callee: ExpressionLike,
722 +
723 + pub arguments: Vec<ExpressionLike>,
724 +
725 + pub loc: Option<SourceLocation>,
726 + #[serde(default)]
727 + pub range: Option<SourceRange>,
728 +}
729 +
730 +#[derive(Serialize, Deserialize, Debug)]
731 +pub struct ChainExpression {
732 + pub expression: ChainElement,
733 + pub loc: Option<SourceLocation>,
734 + #[serde(default)]
735 + pub range: Option<SourceRange>,
736 +}
737 +
738 +#[derive(Serialize, Deserialize, Debug)]
739 +#[serde(tag = "type")]
740 +pub enum ChainElement {
741 + CallExpression(Box<CallExpression>),
742 + MemberExpression(Box<MemberExpression>),
743 +}
744 +
745 +#[derive(Serialize, Deserialize, Debug)]
746 +pub struct ClassExpression {
747 + // TODO
748 + pub loc: Option<SourceLocation>,
749 + #[serde(default)]
750 + pub range: Option<SourceRange>,
751 +}
752 +
753 +#[derive(Serialize, Deserialize, Debug)]
754 +pub struct ConditionalExpression {
755 + pub test: ExpressionLike,
756 + pub alternate: ExpressionLike,
757 + pub consequent: ExpressionLike,
758 + pub loc: Option<SourceLocation>,
759 + #[serde(default)]
760 + pub range: Option<SourceRange>,
761 +}
762 +
763 +#[derive(Serialize, Deserialize, Debug)]
764 +pub struct FunctionExpression {
765 + // TODO
766 + pub loc: Option<SourceLocation>,
767 + #[serde(default)]
768 + pub range: Option<SourceRange>,
769 +}
770 +
771 +#[derive(Serialize, Deserialize, Debug)]
772 +pub struct ImportExpression {
773 + // TODO
774 + pub loc: Option<SourceLocation>,
775 + #[serde(default)]
776 + pub range: Option<SourceRange>,
777 +}
778 +
779 +#[derive(Serialize, Deserialize, Debug)]
780 +pub struct Literal {
781 + pub value: LiteralValue,
782 +
783 + #[serde(default)]
784 + pub raw: Option<String>,
785 +
786 + pub loc: Option<SourceLocation>,
787 +
788 + #[serde(default)]
789 + pub range: Option<SourceRange>,
790 +}
791 +
792 +#[derive(Serialize, Deserialize, Debug)]
793 +#[serde(untagged)]
794 +pub enum LiteralValue {
795 + BigInt(String),
796 + Boolean(bool),
797 + Null,
798 + Number(Number),
799 + RegExp(RegExp),
800 + String(String),
801 +}
802 +
803 +#[derive(Serialize, Deserialize, Debug)]
804 +pub struct Number(u64);
805 +
806 +impl From<u64> for Number {
807 + fn from(value: u64) -> Self {
808 + Number(value)
809 + }
810 +}
811 +
812 +impl From<f64> for Number {
813 + fn from(value: f64) -> Self {
814 + Number(value.to_bits())
815 + }
816 +}
817 +
818 +impl From<Number> for f64 {
819 + fn from(value: Number) -> Self {
820 + f64::from_bits(value.0)
821 + }
822 +}
823 +
824 +#[derive(Serialize, Deserialize, Debug)]
825 +pub struct RegExp {
826 + pub raw: Option<String>,
827 + pub regex: Option<RegExpValue>,
828 +}
829 +
830 +#[derive(Serialize, Deserialize, Debug)]
831 +pub struct RegExpValue {
832 + pub pattern: String,
833 + pub flags: String,
834 +}
835 +
836 +#[derive(Serialize, Deserialize, Debug)]
837 +pub struct LogicalExpression {
838 + pub operator: LogicalOperator,
839 + pub left: ExpressionLike,
840 + pub right: ExpressionLike,
841 + pub loc: Option<SourceLocation>,
842 + #[serde(default)]
843 + pub range: Option<SourceRange>,
844 +}
845 +
846 +#[derive(Serialize, Deserialize, Debug)]
847 +pub enum LogicalOperator {
848 + /// ||
849 + #[serde(rename = "||")]
850 + PipePipe,
851 + /// &&
852 + #[serde(rename = "&&")]
853 + AmpersandAmpersand,
854 + /// ??
855 + #[serde(rename = "??")]
856 + QuestionQuestion,
857 +}
858 +
859 +#[derive(Serialize, Deserialize, Debug)]
860 +pub struct MetaProperty {
861 + // TODO
862 + pub loc: Option<SourceLocation>,
863 + #[serde(default)]
864 + pub range: Option<SourceRange>,
865 +}
866 +
867 +#[derive(Serialize, Deserialize, Debug)]
868 +pub struct NewExpression {
869 + pub callee: ExpressionLike,
870 + pub arguments: Vec<ExpressionLike>,
871 + pub loc: Option<SourceLocation>,
872 + #[serde(default)]
873 + pub range: Option<SourceRange>,
874 +}
875 +
876 +#[derive(Serialize, Deserialize, Debug)]
877 +pub struct ObjectExpression {
878 + pub properties: Vec<ExpressionLike>,
879 + pub loc: Option<SourceLocation>,
880 + #[serde(default)]
881 + pub range: Option<SourceRange>,
882 +}
883 +
884 +#[derive(Serialize, Deserialize, Debug)]
885 +pub struct SequenceExpression {
886 + pub expressions: Vec<ExpressionLike>,
887 + pub loc: Option<SourceLocation>,
888 + #[serde(default)]
889 + pub range: Option<SourceRange>,
890 +}
891 +
892 +#[derive(Serialize, Deserialize, Debug)]
893 +pub struct TaggedTemplateExpression {
894 + pub tag: ExpressionLike,
895 + pub quasi: TemplateLiteral,
896 + pub loc: Option<SourceLocation>,
897 + #[serde(default)]
898 + pub range: Option<SourceRange>,
899 +}
900 +
901 +#[derive(Serialize, Deserialize, Debug)]
902 +pub struct TemplateLiteral {
903 + pub quasis: Vec<TemplateElement>,
904 + pub expressions: Vec<ExpressionLike>,
905 + pub loc: Option<SourceLocation>,
906 + #[serde(default)]
907 + pub range: Option<SourceRange>,
908 +}
909 +
910 +#[derive(Serialize, Deserialize, Debug)]
911 +pub struct TemplateElement {
912 + #[serde(rename = "tail")]
913 + #[serde(default)]
914 + pub is_tail: bool,
915 +
916 + // TODO: add value: {cooked, raw} wrapper object
917 + pub cooked: Option<String>,
918 +
919 + pub raw: String,
920 +
921 + pub loc: Option<SourceLocation>,
922 + #[serde(default)]
923 + pub range: Option<SourceRange>,
924 +}
925 +
926 +#[derive(Serialize, Deserialize, Debug)]
927 +pub struct ThisExpression {
928 + // TODO
929 + pub loc: Option<SourceLocation>,
930 + #[serde(default)]
931 + pub range: Option<SourceRange>,
932 +}
933 +
934 +#[derive(Serialize, Deserialize, Debug)]
935 +pub struct UnaryExpression {
936 + pub operator: UnaryOperator,
937 +
938 + #[serde(rename = "prefix")]
939 + #[serde(default)]
940 + pub is_prefix: bool,
941 +
942 + pub argument: ExpressionLike,
943 +
944 + pub loc: Option<SourceLocation>,
945 + #[serde(default)]
946 + pub range: Option<SourceRange>,
947 +}
948 +
949 +#[derive(Serialize, Deserialize, Debug)]
950 +pub enum UnaryOperator {
951 + /// -
952 + #[serde(rename = "+")]
953 + Minus,
954 + /// +
955 + #[serde(rename = "+")]
956 + Plus,
957 + /// !
958 + #[serde(rename = "!")]
959 + Exclamation,
960 + /// ~
961 + #[serde(rename = "~")]
962 + Tilde,
963 + /// typeof
964 + #[serde(rename = "typeof")]
965 + Typeof,
966 + /// void
967 + #[serde(rename = "void")]
968 + Void,
969 + /// delete
970 + #[serde(rename = "delete")]
971 + Delete,
972 +}
973 +
974 +#[derive(Serialize, Deserialize, Debug)]
975 +pub struct UpdateExpression {
976 + pub operator: UpdateOperator,
977 +
978 + pub argument: ExpressionLike,
979 +
980 + #[serde(rename = "prefix")]
981 + #[serde(default)]
982 + pub is_prefix: bool,
983 +
984 + pub loc: Option<SourceLocation>,
985 + #[serde(default)]
986 + pub range: Option<SourceRange>,
987 +}
988 +
989 +#[derive(Serialize, Deserialize, Debug)]
990 +pub enum UpdateOperator {
991 + /// ++
992 + #[serde(rename = "++")]
993 + PlusPlus,
994 + /// --
995 + #[serde(rename = "--")]
996 + MinusMinus,
997 +}
998 +
999 +#[derive(Serialize, Deserialize, Debug)]
1000 +pub struct YieldExpression {
1001 + pub argument: Option<ExpressionLike>,
1002 +
1003 + #[serde(rename = "delegate")]
1004 + #[serde(default)]
1005 + pub is_delegate: bool,
1006 +
1007 + pub loc: Option<SourceLocation>,
1008 + #[serde(default)]
1009 + pub range: Option<SourceRange>,
1010 +}
1011 +
1012 +// Pattern etc
1013 +
1014 +#[derive(Serialize, Deserialize, Debug)]
1015 +#[serde(tag = "type")]
1016 +pub enum Pattern {
1017 + ArrayPattern(Box<ArrayPattern>),
1018 + AssignmentPattern(Box<AssignmentPattern>),
1019 + Identifier(Box<Identifier>),
1020 + MemberExpression(Box<MemberExpression>),
1021 + ObjectPattern(Box<ObjectPattern>),
1022 + RestElement(Box<RestElement>),
1023 +}
1024 +
1025 +#[derive(Serialize, Deserialize, Debug)]
1026 +pub struct ArrayPattern {
1027 + pub elements: Vec<Pattern>,
1028 +
1029 + pub loc: Option<SourceLocation>,
1030 + #[serde(default)]
1031 + pub range: Option<SourceRange>,
1032 +}
1033 +
1034 +#[derive(Serialize, Deserialize, Debug)]
1035 +pub struct AssignmentPattern {
1036 + pub left: Pattern,
1037 + pub right: ExpressionLike,
1038 + pub loc: Option<SourceLocation>,
1039 + #[serde(default)]
1040 + pub range: Option<SourceRange>,
1041 +}
1042 +
1043 +#[derive(Serialize, Deserialize, Debug)]
1044 +pub struct Identifier {
1045 + pub name: String,
1046 +
1047 + #[serde(default)]
1048 + pub binding: Option<Binding>,
1049 +
1050 + pub loc: Option<SourceLocation>,
1051 +
1052 + #[serde(default)]
1053 + pub range: Option<SourceRange>,
1054 +}
1055 +
1056 +#[derive(Serialize, Deserialize, Debug)]
1057 +#[serde(tag = "type")]
1058 +pub enum Binding {
1059 + Local(BindingId),
1060 + Module(BindingId),
1061 + Global,
1062 +}
1063 +
1064 +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, Copy)]
1065 +#[serde(transparent)]
1066 +pub struct BindingId(NonZeroU32);
1067 +
1068 +impl BindingId {
1069 + pub fn new(id: NonZeroU32) -> Self {
1070 + Self(id)
1071 + }
1072 +}
1073 +
1074 +impl From<BindingId> for u32 {
1075 + fn from(value: BindingId) -> Self {
1076 + value.0.into()
1077 + }
1078 +}
1079 +
1080 +#[derive(Serialize, Deserialize, Debug)]
1081 +pub struct MemberExpression {
1082 + pub object: ExpressionLike,
1083 +
1084 + pub property: ExpressionLike, // ExpressionOrPrivateIdentifier
1085 +
1086 + #[serde(rename = "computed")]
1087 + #[serde(default)]
1088 + pub is_computed: bool,
1089 +
1090 + #[serde(rename = "optional")]
1091 + #[serde(default)]
1092 + pub is_optional: bool,
1093 +
1094 + pub loc: Option<SourceLocation>,
1095 + #[serde(default)]
1096 + pub range: Option<SourceRange>,
1097 +}
1098 +
1099 +#[derive(Serialize, Deserialize, Debug)]
1100 +pub struct Super {
1101 + pub loc: Option<SourceLocation>,
1102 + #[serde(default)]
1103 + pub range: Option<SourceRange>,
1104 +}
1105 +
1106 +#[derive(Serialize, Deserialize, Debug)]
1107 +pub struct PrivateIdentifier {
1108 + pub name: String,
1109 + pub loc: Option<SourceLocation>,
1110 + #[serde(default)]
1111 + pub range: Option<SourceRange>,
1112 +}
1113 +
1114 +#[derive(Serialize, Deserialize, Debug)]
1115 +pub struct ObjectPattern {
1116 + pub properties: Vec<ExpressionLike>,
1117 + pub loc: Option<SourceLocation>,
1118 + #[serde(default)]
1119 + pub range: Option<SourceRange>,
1120 +}
1121 +
1122 +#[derive(Serialize, Deserialize, Debug)]
1123 +pub struct Property {
1124 + pub key: ExpressionLike,
1125 +
1126 + pub value: PropertyValue,
1127 +
1128 + pub kind: PropertyKind,
1129 +
1130 + #[serde(rename = "method")]
1131 + #[serde(default)]
1132 + pub is_method: bool,
1133 +
1134 + #[serde(rename = "shorthand")]
1135 + #[serde(default)]
1136 + pub is_shorthand: bool,
1137 +
1138 + #[serde(rename = "computed")]
1139 + #[serde(default)]
1140 + pub is_computed: bool,
1141 +
1142 + pub loc: Option<SourceLocation>,
1143 + #[serde(default)]
1144 + pub range: Option<SourceRange>,
1145 +}
1146 +
1147 +#[derive(Serialize, Deserialize, Debug)]
1148 +#[serde(untagged)]
1149 +pub enum PropertyValue {
1150 + Expression(Box<ExpressionLike>),
1151 + Pattern(Box<Pattern>),
1152 +}
1153 +
1154 +#[derive(Serialize, Deserialize, Debug)]
1155 +pub enum PropertyKind {
1156 + #[serde(rename = "init")]
1157 + Init,
1158 + #[serde(rename = "get")]
1159 + Get,
1160 + #[serde(rename = "set")]
1161 + Set,
1162 +}
1163 +
1164 +impl Default for PropertyKind {
1165 + fn default() -> Self {
1166 + Self::Init
1167 + }
1168 +}
1169 +
1170 +#[derive(Serialize, Deserialize, Debug)]
1171 +pub struct RestElement {
1172 + pub argument: Pattern,
1173 + pub loc: Option<SourceLocation>,
1174 + #[serde(default)]
1175 + pub range: Option<SourceRange>,
1176 +}
1177 +
1178 +#[derive(Serialize, Deserialize, Debug)]
1179 +pub struct SpreadElement {
1180 + pub argument: ExpressionLike,
1181 + pub loc: Option<SourceLocation>,
1182 + #[serde(default)]
1183 + pub range: Option<SourceRange>,
1184 +}
1185 +
1186 +#[derive(Serialize, Deserialize, Debug)]
1187 +pub struct JSXElement {
1188 + #[serde(rename = "openingElement")]
1189 + pub opening_element: ExpressionLike,
1190 +
1191 + pub children: Vec<ExpressionLike>,
1192 +
1193 + #[serde(rename = "closingElement")]
1194 + pub closing_element: Option<ExpressionLike>,
1195 +
1196 + pub loc: Option<SourceLocation>,
1197 +
1198 + #[serde(default)]
1199 + pub range: Option<SourceRange>,
1200 +}
1201 +
1202 +#[derive(Serialize, Deserialize, Debug)]
1203 +pub struct JSXOpeningElement {
1204 + pub name: ExpressionLike,
1205 +
1206 + pub attributes: Vec<JSXAttribute>,
1207 +
1208 + #[serde(rename = "selfClosing")]
1209 + #[serde(default)]
1210 + pub self_closing: bool,
1211 +
1212 + pub loc: Option<SourceLocation>,
1213 +
1214 + #[serde(default)]
1215 + pub range: Option<SourceRange>,
1216 +}
1217 +
1218 +#[derive(Serialize, Deserialize, Debug)]
1219 +pub struct JSXClosingElement {
1220 + pub name: ExpressionLike,
1221 +
1222 + pub loc: Option<SourceLocation>,
1223 +
1224 + #[serde(default)]
1225 + pub range: Option<SourceRange>,
1226 +}
1227 +
1228 +#[derive(Serialize, Deserialize, Debug)]
1229 +pub struct JSXMemberExpression {
1230 + pub object: ExpressionLike,
1231 +
1232 + pub property: ExpressionLike,
1233 +
1234 + pub loc: Option<SourceLocation>,
1235 +
1236 + #[serde(default)]
1237 + pub range: Option<SourceRange>,
1238 +}
1239 +
1240 +#[derive(Serialize, Deserialize, Debug)]
1241 +pub struct JSXIdentifier {
1242 + pub name: String,
1243 +
1244 + pub loc: Option<SourceLocation>,
1245 +
1246 + #[serde(default)]
1247 + pub range: Option<SourceRange>,
1248 +}
1249 +
1250 +#[derive(Serialize, Deserialize, Debug)]
1251 +pub struct JSXNamedspacedName {
1252 + pub namespace: ExpressionLike,
1253 +
1254 + pub name: ExpressionLike,
1255 +
1256 + pub loc: Option<SourceLocation>,
1257 +
1258 + #[serde(default)]
1259 + pub range: Option<SourceRange>,
1260 +}
1261 +
1262 +#[derive(Serialize, Deserialize, Debug)]
1263 +pub struct JSXAttribute {
1264 + pub name: ExpressionLike,
1265 +
1266 + pub value: ExpressionLike,
1267 +
1268 + pub loc: Option<SourceLocation>,
1269 +
1270 + #[serde(default)]
1271 + pub range: Option<SourceRange>,
1272 +}
1273 +
1274 +#[derive(Serialize, Deserialize, Debug)]
1275 +pub struct JSXExpressionContainer {
1276 + expression: ExpressionLike,
1277 +
1278 + pub loc: Option<SourceLocation>,
1279 +
1280 + #[serde(default)]
1281 + pub range: Option<SourceRange>,
1282 +}
1283 +
1284 +#[derive(Serialize, Deserialize, Debug)]
1285 +pub struct JSXText {
1286 + value: String,
1287 + raw: String,
1288 +
1289 + pub loc: Option<SourceLocation>,
1290 +
1291 + #[serde(default)]
1292 + pub range: Option<SourceRange>,
1293 +}
1294 +
1295 +#[cfg(test)]
1296 +mod tests {
1297 + use super::*;
1298 + use insta::{assert_snapshot, glob};
1299 + use serde_json;
1300 +
1301 + #[test]
1302 + fn for_statement() {
1303 + let source = include_str!("for-statement.json");
1304 + let ast: Program = serde_json::from_str(&source).unwrap();
1305 + println!("deserialized:\n{:#?}", ast);
1306 + let serialized = serde_json::to_string_pretty(&ast).unwrap();
1307 + println!("serialized:\n{}", serialized);
1308 + }
1309 +
1310 + #[test]
1311 + fn simple() {
1312 + let source = include_str!("simple.json");
1313 + let ast: Program = serde_json::from_str(&source).unwrap();
1314 + println!("deserialized:\n{:#?}", ast);
1315 + let serialized = serde_json::to_string_pretty(&ast).unwrap();
1316 + println!("serialized:\n{}", serialized);
1317 + }
1318 +
1319 + /// TODO: enable once this deserializes
1320 + fn _kitchen_sink() {
1321 + let source = include_str!("kitchen-sink.json");
1322 + let ast: Program = match serde_json::from_str(&source) {
1323 + Ok(ast) => ast,
1324 + Err(err) => panic!("{:#?}", err),
1325 + };
1326 + println!("deserialized:\n{:#?}", ast);
1327 + let serialized = serde_json::to_string_pretty(&ast).unwrap();
1328 + println!("serialized:\n{}", serialized);
1329 + }
1330 +
1331 + #[test]
1332 + fn import() {
1333 + let source = include_str!("import.json");
1334 + let ast: Program = serde_json::from_str(&source).unwrap();
1335 + println!("deserialized:\n{:#?}", ast);
1336 + let serialized = serde_json::to_string_pretty(&ast).unwrap();
1337 + println!("serialized:\n{}", serialized);
1338 + }
1339 +
1340 + #[test]
1341 + fn test() {
1342 + let source = include_str!("test.json");
1343 + let ast: Program = serde_json::from_str(&source).unwrap();
1344 + println!("deserialized:\n{:#?}", ast);
1345 + let serialized = serde_json::to_string_pretty(&ast).unwrap();
1346 + println!("serialized:\n{}", serialized);
1347 + }
1348 +
1349 + #[test]
1350 + fn fixtures() {
1351 + glob!("fixtures/**.json", |path| {
1352 + let input = std::fs::read_to_string(path).unwrap();
1353 + let ast: Program = serde_json::from_str(&input).unwrap();
1354 + let serialized = serde_json::to_string_pretty(&ast).unwrap();
1355 + assert_snapshot!(format!("Input:\n{input}\n\nOutput:\n{serialized}"));
1356 + });
1357 + }
1358 +}
compiler/forget/crates/estree/src/range.rs new
+9
@@ -0,0 +1,9 @@
1 +use std::num::NonZeroU32;
2 +
3 +use serde::{Deserialize, Serialize};
4 +
5 +#[derive(Serialize, Deserialize, Clone, Debug)]
6 +pub struct SourceRange {
7 + pub start: u32,
8 + pub end: NonZeroU32,
9 +}
compiler/forget/crates/estree/src/simple.json deleted
-189
@@ -1,189 +0,0 @@
1 -{
2 - "type": "Program",
3 - "loc": {
4 - "source": null,
5 - "start": {
6 - "line": 1,
7 - "column": 0
8 - },
9 - "end": {
10 - "line": 3,
11 - "column": 1
12 - }
13 - },
14 - "range": [
15 - 0,
16 - 51
17 - ],
18 - "body": [
19 - {
20 - "type": "FunctionDeclaration",
21 - "loc": {
22 - "source": null,
23 - "start": {
24 - "line": 1,
25 - "column": 0
26 - },
27 - "end": {
28 - "line": 3,
29 - "column": 1
30 - }
31 - },
32 - "range": [
33 - 0,
34 - 51
35 - ],
36 - "id": {
37 - "type": "Identifier",
38 - "loc": {
39 - "source": null,
40 - "start": {
41 - "line": 1,
42 - "column": 9
43 - },
44 - "end": {
45 - "line": 1,
46 - "column": 18
47 - }
48 - },
49 - "range": [
50 - 9,
51 - 18
52 - ],
53 - "name": "Component",
54 - "typeAnnotation": null,
55 - "optional": false
56 - },
57 - "params": [
58 - {
59 - "type": "Identifier",
60 - "loc": {
61 - "source": null,
62 - "start": {
63 - "line": 1,
64 - "column": 19
65 - },
66 - "end": {
67 - "line": 1,
68 - "column": 24
69 - }
70 - },
71 - "range": [
72 - 19,
73 - 24
74 - ],
75 - "name": "props",
76 - "typeAnnotation": null,
77 - "optional": false
78 - }
79 - ],
80 - "body": {
81 - "type": "BlockStatement",
82 - "loc": {
83 - "source": null,
84 - "start": {
85 - "line": 1,
86 - "column": 26
87 - },
88 - "end": {
89 - "line": 3,
90 - "column": 1
91 - }
92 - },
93 - "range": [
94 - 26,
95 - 51
96 - ],
97 - "body": [
98 - {
99 - "type": "ReturnStatement",
100 - "loc": {
101 - "source": null,
102 - "start": {
103 - "line": 2,
104 - "column": 2
105 - },
106 - "end": {
107 - "line": 2,
108 - "column": 21
109 - }
110 - },
111 - "range": [
112 - 30,
113 - 49
114 - ],
115 - "argument": {
116 - "type": "MemberExpression",
117 - "loc": {
118 - "source": null,
119 - "start": {
120 - "line": 2,
121 - "column": 9
122 - },
123 - "end": {
124 - "line": 2,
125 - "column": 20
126 - }
127 - },
128 - "range": [
129 - 37,
130 - 48
131 - ],
132 - "object": {
133 - "type": "Identifier",
134 - "loc": {
135 - "source": null,
136 - "start": {
137 - "line": 2,
138 - "column": 9
139 - },
140 - "end": {
141 - "line": 2,
142 - "column": 14
143 - }
144 - },
145 - "range": [
146 - 37,
147 - 42
148 - ],
149 - "name": "props",
150 - "typeAnnotation": null,
151 - "optional": false
152 - },
153 - "property": {
154 - "type": "Identifier",
155 - "loc": {
156 - "source": null,
157 - "start": {
158 - "line": 2,
159 - "column": 15
160 - },
161 - "end": {
162 - "line": 2,
163 - "column": 20
164 - }
165 - },
166 - "range": [
167 - 43,
168 - 48
169 - ],
170 - "name": "value",
171 - "typeAnnotation": null,
172 - "optional": false
173 - },
174 - "computed": false
175 - }
176 - }
177 - ]
178 - },
179 - "async": false,
180 - "generator": false,
181 - "predicate": null,
182 - "expression": false,
183 - "returnType": null,
184 - "typeParameters": null
185 - }
186 - ],
187 - "comments": [],
188 - "errors": []
189 - }
\ No newline at end of file
compiler/forget/crates/estree/src/snapshots/estree__tests__fixtures@for-statement.json.snap
+15 -13
@@ -535,7 +535,6 @@ Input:
535
536 Output:
537 {
538 - "sourceType": "script",
538 "body": [
539 {
540 "type": "FunctionDeclaration",
@@ -580,13 +579,11 @@ Output:
579 }
580 }
581 ],
583 - "generator": false,
584 - "async": false,
582 "body": {
586 - "type": "BlockStatement",
583 "body": [
584 {
585 "type": "VariableDeclaration",
586 + "kind": "let",
587 "declarations": [
588 {
589 "id": {
@@ -611,8 +608,11 @@ Output:
608 },
609 "init": {
610 "type": "Literal",
614 - "value": 0,
611 + "value": {
612 + "Number": 0
613 + },
614 "raw": "0",
615 + "regex": null,
616 "loc": {
617 "source": null,
618 "start": {
@@ -646,7 +646,6 @@ Output:
646 }
647 }
648 ],
649 - "kind": "let",
649 "loc": {
650 "source": null,
651 "start": {
@@ -666,7 +665,7 @@ Output:
665 {
666 "type": "ForStatement",
667 "init": {
669 - "type": "VariableDeclaration",
668 + "kind": "let",
669 "declarations": [
670 {
671 "id": {
@@ -691,8 +690,11 @@ Output:
690 },
691 "init": {
692 "type": "Literal",
694 - "value": 0,
693 + "value": {
694 + "Number": 0
695 + },
696 "raw": "0",
697 + "regex": null,
698 "loc": {
699 "source": null,
700 "start": {
@@ -726,7 +728,6 @@ Output:
728 }
729 }
730 ],
729 - "kind": "let",
731 "loc": {
732 "source": null,
733 "start": {
@@ -745,7 +746,6 @@ Output:
746 },
747 "test": {
748 "type": "BinaryExpression",
748 - "operator": "<",
749 "left": {
750 "type": "Identifier",
751 "name": "i",
@@ -766,10 +766,14 @@ Output:
766 "end": 60
767 }
768 },
769 + "operator": "<",
770 "right": {
771 "type": "Literal",
771 - "value": 10,
772 + "value": {
773 + "Number": 10
774 + },
775 "raw": "10",
776 + "regex": null,
777 "loc": {
778 "source": null,
779 "start": {
@@ -906,7 +910,6 @@ Output:
910 "end": 84
911 }
912 },
909 - "directive": null,
913 "loc": {
914 "source": null,
915 "start": {
@@ -1028,7 +1031,6 @@ Output:
1031 }
1032 }
1033 ],
1031 - "comments": [],
1034 "loc": {
1035 "source": null,
1036 "start": {
compiler/forget/crates/estree/src/test.json deleted
-351
@@ -1,351 +0,0 @@
1 -{
2 - "type": "Program",
3 - "loc": {
4 - "source": null,
5 - "start": {
6 - "line": 2,
7 - "column": 0
8 - },
9 - "end": {
10 - "line": 4,
11 - "column": 1
12 - }
13 - },
14 - "body": [
15 - {
16 - "type": "FunctionDeclaration",
17 - "loc": {
18 - "source": null,
19 - "start": {
20 - "line": 2,
21 - "column": 0
22 - },
23 - "end": {
24 - "line": 4,
25 - "column": 1
26 - }
27 - },
28 - "id": {
29 - "type": "Identifier",
30 - "loc": {
31 - "source": null,
32 - "start": {
33 - "line": 2,
34 - "column": 9
35 - },
36 - "end": {
37 - "line": 2,
38 - "column": 12
39 - }
40 - },
41 - "name": "foo",
42 - "typeAnnotation": null,
43 - "optional": false,
44 - "range": [
45 - 10,
46 - 13
47 - ]
48 - },
49 - "params": [],
50 - "body": {
51 - "type": "BlockStatement",
52 - "loc": {
53 - "source": null,
54 - "start": {
55 - "line": 2,
56 - "column": 15
57 - },
58 - "end": {
59 - "line": 4,
60 - "column": 1
61 - }
62 - },
63 - "body": [
64 - {
65 - "type": "ReturnStatement",
66 - "loc": {
67 - "source": null,
68 - "start": {
69 - "line": 3,
70 - "column": 2
71 - },
72 - "end": {
73 - "line": 3,
74 - "column": 36
75 - }
76 - },
77 - "argument": {
78 - "type": "JSXElement",
79 - "loc": {
80 - "source": null,
81 - "start": {
82 - "line": 3,
83 - "column": 9
84 - },
85 - "end": {
86 - "line": 3,
87 - "column": 36
88 - }
89 - },
90 - "openingElement": {
91 - "type": "JSXOpeningElement",
92 - "loc": {
93 - "source": null,
94 - "start": {
95 - "line": 3,
96 - "column": 9
97 - },
98 - "end": {
99 - "line": 3,
100 - "column": 26
101 - }
102 - },
103 - "name": {
104 - "type": "JSXMemberExpression",
105 - "loc": {
106 - "source": null,
107 - "start": {
108 - "line": 3,
109 - "column": 10
110 - },
111 - "end": {
112 - "line": 3,
113 - "column": 17
114 - }
115 - },
116 - "object": {
117 - "type": "JSXIdentifier",
118 - "loc": {
119 - "source": null,
120 - "start": {
121 - "line": 3,
122 - "column": 10
123 - },
124 - "end": {
125 - "line": 3,
126 - "column": 13
127 - }
128 - },
129 - "name": "Foo",
130 - "range": [
131 - 28,
132 - 31
133 - ]
134 - },
135 - "property": {
136 - "type": "JSXIdentifier",
137 - "loc": {
138 - "source": null,
139 - "start": {
140 - "line": 3,
141 - "column": 14
142 - },
143 - "end": {
144 - "line": 3,
145 - "column": 17
146 - }
147 - },
148 - "name": "Bar",
149 - "range": [
150 - 32,
151 - 35
152 - ]
153 - },
154 - "range": [
155 - 28,
156 - 35
157 - ]
158 - },
159 - "attributes": [
160 - {
161 - "type": "JSXAttribute",
162 - "loc": {
163 - "source": null,
164 - "start": {
165 - "line": 3,
166 - "column": 18
167 - },
168 - "end": {
169 - "line": 3,
170 - "column": 24
171 - }
172 - },
173 - "name": {
174 - "type": "JSXIdentifier",
175 - "loc": {
176 - "source": null,
177 - "start": {
178 - "line": 3,
179 - "column": 18
180 - },
181 - "end": {
182 - "line": 3,
183 - "column": 19
184 - }
185 - },
186 - "name": "a",
187 - "range": [
188 - 36,
189 - 37
190 - ]
191 - },
192 - "value": {
193 - "type": "JSXExpressionContainer",
194 - "loc": {
195 - "source": null,
196 - "start": {
197 - "line": 3,
198 - "column": 20
199 - },
200 - "end": {
201 - "line": 3,
202 - "column": 24
203 - }
204 - },
205 - "expression": {
206 - "type": "Literal",
207 - "loc": {
208 - "source": null,
209 - "start": {
210 - "line": 3,
211 - "column": 21
212 - },
213 - "end": {
214 - "line": 3,
215 - "column": 23
216 - }
217 - },
218 - "value": 10,
219 - "range": [
220 - 39,
221 - 41
222 - ],
223 - "raw": "10"
224 - },
225 - "range": [
226 - 38,
227 - 42
228 - ]
229 - },
230 - "range": [
231 - 36,
232 - 42
233 - ]
234 - }
235 - ],
236 - "selfClosing": false,
237 - "range": [
238 - 27,
239 - 44
240 - ]
241 - },
242 - "children": [],
243 - "closingElement": {
244 - "type": "JSXClosingElement",
245 - "loc": {
246 - "source": null,
247 - "start": {
248 - "line": 3,
249 - "column": 26
250 - },
251 - "end": {
252 - "line": 3,
253 - "column": 36
254 - }
255 - },
256 - "name": {
257 - "type": "JSXMemberExpression",
258 - "loc": {
259 - "source": null,
260 - "start": {
261 - "line": 3,
262 - "column": 28
263 - },
264 - "end": {
265 - "line": 3,
266 - "column": 35
267 - }
268 - },
269 - "object": {
270 - "type": "JSXIdentifier",
271 - "loc": {
272 - "source": null,
273 - "start": {
274 - "line": 3,
275 - "column": 28
276 - },
277 - "end": {
278 - "line": 3,
279 - "column": 31
280 - }
281 - },
282 - "name": "Foo",
283 - "range": [
284 - 46,
285 - 49
286 - ]
287 - },
288 - "property": {
289 - "type": "JSXIdentifier",
290 - "loc": {
291 - "source": null,
292 - "start": {
293 - "line": 3,
294 - "column": 32
295 - },
296 - "end": {
297 - "line": 3,
298 - "column": 35
299 - }
300 - },
301 - "name": "Bar",
302 - "range": [
303 - 50,
304 - 53
305 - ]
306 - },
307 - "range": [
308 - 46,
309 - 53
310 - ]
311 - },
312 - "range": [
313 - 44,
314 - 54
315 - ]
316 - },
317 - "range": [
318 - 27,
319 - 54
320 - ]
321 - },
322 - "range": [
323 - 20,
324 - 54
325 - ]
326 - }
327 - ],
328 - "range": [
329 - 16,
330 - 56
331 - ]
332 - },
333 - "typeParameters": null,
334 - "returnType": null,
335 - "predicate": null,
336 - "generator": false,
337 - "async": false,
338 - "range": [
339 - 1,
340 - 56
341 - ]
342 - }
343 - ],
344 - "comments": [],
345 - "interpreter": null,
346 - "range": [
347 - 1,
348 - 56
349 - ],
350 - "sourceType": "script"
351 - }
\ No newline at end of file