@samitouri / QOS-React-2 / commits / 1abea6c49d

[rust] allow complex types in estree codegen

Uses the `syn` crate, which can parse various Rust syntax forms, to parse the `type` field from json schema description. This allows us to describe complex types like `"type": "Vec<Option<ArrayElement>>"` directly, rather than requiring flags like nullable, plural, and nullable_item. The main flag that i'm keeping is "optional", which is used to indicate when the field itself (not the value) is optional.

Joe Savona committed Jul 8, 2023 at 23:00 UTC 1abea6c49de9deabdcad863d1ab67927fbdfa790
6 files changed +172 -230
compiler/forget/crates/estree-codegen/src/codegen.rs
+35 -47
@@ -3,6 +3,7 @@ use std::collections::HashSet;
3 use indexmap::IndexMap;
4 use quote::{__private::TokenStream, format_ident, quote};
5 use serde::{Deserialize, Serialize};
6 +use syn::Type;
7
8 /// Returns prettyplease-formatted Rust source for estree
9 pub fn estree() -> String {
@@ -15,6 +16,7 @@ pub fn estree() -> String {
16 }
17
18 #[derive(Serialize, Deserialize, Debug)]
19 +#[serde(deny_unknown_fields)]
20 pub struct Grammar {
21 pub objects: IndexMap<String, Object>,
22 pub nodes: IndexMap<String, Node>,
@@ -70,6 +72,7 @@ impl Grammar {
72 }
73
74 #[derive(Serialize, Deserialize, Debug)]
75 +#[serde(deny_unknown_fields)]
76 pub struct Object {
77 #[serde(default)]
78 pub fields: IndexMap<String, Field>,
@@ -94,6 +97,7 @@ impl Object {
97 }
98
99 #[derive(Serialize, Deserialize, Debug)]
100 +#[serde(deny_unknown_fields)]
101 pub struct Node {
102 #[serde(default)]
103 pub fields: IndexMap<String, Field>,
@@ -124,64 +128,53 @@ impl Node {
128 }
129
130 #[derive(Serialize, Deserialize, Debug)]
131 +#[serde(deny_unknown_fields)]
132 pub struct Field {
133 #[serde(rename = "type")]
134 pub type_: String,
135
131 - #[serde(default)]
132 - pub nullable: bool,
133 -
136 #[serde(default)]
137 pub optional: bool,
138
137 - #[serde(default)]
138 - pub plural: bool,
139 -
140 - #[serde(default)]
141 - pub nullable_item: bool,
142 -
139 #[serde(default)]
140 pub flatten: bool,
141
142 #[serde(default)]
143 pub rename: Option<String>,
144 +
145 + #[serde(default)]
146 + pub skip: bool,
147 }
148
149 impl Field {
150 pub fn codegen(&self, name: &str) -> TokenStream {
151 let name = format_ident!("{}", name);
153 - let type_name = format_ident!("{}", &self.type_);
154 - let mut type_ = quote!(#type_name);
155 - if self.plural {
156 - if self.nullable_item {
157 - type_ = quote!(Option<#type_>);
158 - }
159 - type_ = quote! { Vec<#type_> };
160 - } else {
161 - assert_eq!(
162 - self.nullable_item, false,
163 - "Can only set nullable_item if plural"
164 - )
165 - }
166 - if self.nullable {
167 - type_ = quote!(Option<#type_>);
168 - }
169 - let mut field = quote!(#name: #type_);
152 + let type_name: Type = syn::parse_str(&self.type_)
153 + .unwrap_or_else(|_| panic!("Expected a type name, got `{}`", &self.type_));
154 +
155 + let type_ = quote!(#type_name);
156 + let mut field = quote!(pub #name: #type_);
157 if self.optional {
158 field = quote! {
159 #[serde(default)]
160 #field
161 }
162 }
176 - if let Some(rename) = &self.rename {
163 + if self.flatten {
164 field = quote! {
178 - #[serde(rename = #rename)]
165 + #[serde(flatten)]
166 #field
167 }
168 }
182 - if self.flatten {
169 + if self.skip {
170 field = quote! {
184 - #[serde(flatten)]
171 + #[serde(skip)]
172 + #field
173 + }
174 + }
175 + if let Some(rename) = &self.rename {
176 + field = quote! {
177 + #[serde(rename = #rename)]
178 #field
179 }
180 }
@@ -190,23 +183,10 @@ impl Field {
183
184 pub fn codegen_node(&self, name: &str) -> TokenStream {
185 let name = format_ident!("{}", name);
193 - let type_name = format_ident!("{}", &self.type_);
194 - let mut type_ = quote!(#type_name);
195 - if self.plural {
196 - if self.nullable_item {
197 - type_ = quote!(Option<#type_>);
198 - }
199 - type_ = quote! { Vec<#type_> };
200 - } else {
201 - assert_eq!(
202 - self.nullable_item, false,
203 - "Can only set nullable_item if plural"
204 - )
205 - }
206 - if self.nullable {
207 - type_ = quote!(Option<#type_>);
208 - }
209 - let mut field = quote!(#name: #type_);
186 + let type_name: Type = syn::parse_str(&self.type_)
187 + .unwrap_or_else(|_| panic!("Expected a type name, got `{}`", &self.type_));
188 + let type_ = quote!(#type_name);
189 + let mut field = quote!(pub #name: #type_);
190 if self.optional {
191 field = quote! {
192 #[serde(default)]
@@ -219,6 +199,12 @@ impl Field {
199 #field
200 }
201 }
202 + if self.skip {
203 + field = quote! {
204 + #[serde(skip)]
205 + #field
206 + }
207 + }
208 if let Some(rename) = &self.rename {
209 field = quote! {
210 #[serde(rename = #rename)]
@@ -231,6 +217,7 @@ impl Field {
217
218 #[derive(Serialize, Deserialize, Debug)]
219 #[serde(transparent)]
220 +#[serde(deny_unknown_fields)]
221 pub struct Enum {
222 pub variants: Vec<String>,
223 }
@@ -280,6 +267,7 @@ impl Enum {
267
268 #[derive(Serialize, Deserialize, Debug)]
269 #[serde(transparent)]
270 +#[serde(deny_unknown_fields)]
271 pub struct Operator {
272 pub variants: IndexMap<String, String>,
273 }
compiler/forget/crates/estree-codegen/src/ecmascript.json
+32 -65
@@ -3,8 +3,7 @@
3 "SourceLocation": {
4 "fields": {
5 "source": {
6 - "type": "String",
7 - "nullable": true
6 + "type": "Option<String>"
7 },
8 "start": {
9 "type": "Position"
@@ -27,16 +26,13 @@
26 "Function": {
27 "fields": {
28 "id": {
30 - "type": "Identifier",
31 - "nullable": true
29 + "type": "Option<Identifier>"
30 },
31 "params": {
34 - "type": "Pattern",
35 - "plural": true
32 + "type": "Vec<Pattern>"
33 },
34 "body": {
38 - "type": "FunctionBody",
39 - "nullable": true
35 + "type": "Option<FunctionBody>"
36 },
37 "is_generator": {
38 "type": "bool",
@@ -68,8 +64,7 @@
64 "type": "String"
65 },
66 "binding": {
71 - "type": "Binding",
72 - "nullable": true,
67 + "type": "Option<Binding>",
68 "optional": true,
69 "skip": true
70 }
@@ -81,13 +76,11 @@
76 "type": "JsValue"
77 },
78 "raw": {
84 - "type": "String",
85 - "nullable": true,
79 + "type": "Option<String>",
80 "optional": true
81 },
82 "regex": {
89 - "type": "RegExpValue",
90 - "nullable": true,
83 + "type": "Option<RegExpValue>",
84 "optional": true
85 }
86 }
@@ -95,12 +88,10 @@
88 "Program": {
89 "fields": {
90 "body": {
98 - "type": "ModuleItem",
99 - "plural": true
91 + "type": "Vec<ModuleItem>"
92 },
93 "source_type": {
102 - "type": "SourceType",
103 - "nullable": true,
94 + "type": "Option<SourceType>",
95 "rename": "sourceType"
96 }
97 }
@@ -111,8 +102,7 @@
102 "type": "Expression"
103 },
104 "directive": {
114 - "type": "String",
115 - "nullable": true,
105 + "type": "Option<String>",
106 "optional": true
107 }
108 }
@@ -120,8 +110,7 @@
110 "BlockStatement": {
111 "fields": {
112 "body": {
123 - "type": "Statement",
124 - "plural": true
113 + "type": "Vec<Statement>"
114 }
115 }
116 },
@@ -140,8 +129,7 @@
129 "ReturnStatement": {
130 "fields": {
131 "argument": {
143 - "type": "Expression",
144 - "nullable": true
132 + "type": "Option<Expression>"
133 }
134 }
135 },
@@ -158,16 +146,14 @@
146 "BreakStatement": {
147 "fields": {
148 "label": {
161 - "type": "Identifier",
162 - "nullable": true
149 + "type": "Option<Identifier>"
150 }
151 }
152 },
153 "ContinueStatement": {
154 "fields": {
155 "label": {
169 - "type": "Identifier",
170 - "nullable": true
156 + "type": "Option<Identifier>"
157 }
158 }
159 },
@@ -180,8 +166,7 @@
166 "type": "Statement"
167 },
168 "alternate": {
183 - "type": "Statement",
184 - "nullable": true
169 + "type": "Option<Statement>"
170 }
171 }
172 },
@@ -191,20 +176,17 @@
176 "type": "Expression"
177 },
178 "cases": {
194 - "type": "SwitchCase",
195 - "plural": true
179 + "type": "Vec<SwitchCase>"
180 }
181 }
182 },
183 "SwitchCase": {
184 "fields": {
185 "test": {
202 - "type": "Expression",
203 - "nullable": true
186 + "type": "Option<Expression>"
187 },
188 "consequent": {
206 - "type": "Statement",
207 - "plural": true
189 + "type": "Vec<Statement>"
190 }
191 }
192 },
@@ -221,12 +203,10 @@
203 "type": "BlockStatement"
204 },
205 "handler": {
224 - "type": "CatchClause",
225 - "nullable": true
206 + "type": "Option<CatchClause>"
207 },
208 "finalizer": {
228 - "type": "BlockStatement",
229 - "nullable": true
209 + "type": "Option<BlockStatement>"
210 }
211 }
212 },
@@ -263,16 +243,13 @@
243 "ForStatement": {
244 "fields": {
245 "init": {
266 - "type": "ForInit",
267 - "nullable": true
246 + "type": "Option<ForInit>"
247 },
248 "test": {
270 - "type": "Expression",
271 - "nullable": true
249 + "type": "Option<Expression>"
250 },
251 "update": {
274 - "type": "Expression",
275 - "nullable": true
252 + "type": "Option<Expression>"
253 },
254 "body": {
255 "type": "Statement"
@@ -319,8 +296,7 @@
296 "type": "VariableDeclarationKind"
297 },
298 "declarations": {
322 - "type": "VariableDeclarator",
323 - "plural": true
299 + "type": "Vec<VariableDeclarator>"
300 }
301 }
302 },
@@ -330,8 +306,7 @@
306 "type": "Pattern"
307 },
308 "init": {
333 - "type": "Expression",
334 - "nullable": true
309 + "type": "Option<Expression>"
310 }
311 }
312 },
@@ -339,17 +314,14 @@
314 "ArrayExpression": {
315 "fields": {
316 "elements": {
342 - "type": "ExpressionOrSpread",
343 - "plural": true,
344 - "nullable_item": true
317 + "type": "Vec<Option<ExpressionOrSpread>>"
318 }
319 }
320 },
321 "ObjectExpression": {
322 "fields": {
323 "properties": {
351 - "type": "Property",
352 - "plural": true
324 + "type": "Vec<Property>"
325 }
326 }
327 },
@@ -483,8 +455,7 @@
455 "type": "ExpressionOrSuper"
456 },
457 "arguments": {
486 - "type": "ExpressionOrSpread",
487 - "plural": true
458 + "type": "Vec<ExpressionOrSpread>"
459 }
460 }
461 },
@@ -494,16 +465,14 @@
465 "type": "Expression"
466 },
467 "arguments": {
497 - "type": "ExpressionOrSpread",
498 - "plural": true
468 + "type": "Vec<ExpressionOrSpread>"
469 }
470 }
471 },
472 "SequenceExpression": {
473 "fields": {
474 "expressions": {
505 - "type": "Expression",
506 - "plural": true
475 + "type": "Vec<Expression>"
476 }
477 }
478 },
@@ -518,8 +487,7 @@
487 "YieldExpression": {
488 "fields": {
489 "argument": {
521 - "type": "Expression",
522 - "nullable": true,
490 + "type": "Option<Expression>",
491 "optional": true
492 },
493 "is_delegate": {
@@ -531,8 +499,7 @@
499 "ImportDeclaration": {
500 "fields": {
501 "specifiers": {
534 - "type": "ImportDeclarationSpecifier",
535 - "plural": true
502 + "type": "Vec<ImportDeclarationSpecifier>"
503 },
504 "source": {
505 "type": "Literal"
compiler/forget/crates/estree/src/generated.rs
+105 -104
@@ -3,37 +3,38 @@ 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,
6 + pub source: Option<String>,
7 + pub start: Position,
8 + pub end: Position,
9 }
10 #[derive(Serialize, Deserialize, Clone, Debug)]
11 pub struct Position {
12 - line: NonZeroU32,
13 - column: u32,
12 + pub line: NonZeroU32,
13 + pub column: u32,
14 }
15 #[derive(Serialize, Deserialize, Clone, Debug)]
16 pub struct Function {
17 - id: Option<Identifier>,
18 - params: Vec<Pattern>,
19 - body: Option<FunctionBody>,
17 + pub id: Option<Identifier>,
18 + pub params: Vec<Pattern>,
19 + pub body: Option<FunctionBody>,
20 #[serde(rename = "generator")]
21 #[serde(default)]
22 - is_generator: bool,
22 + pub is_generator: bool,
23 #[serde(rename = "async")]
24 #[serde(default)]
25 - is_async: bool,
25 + pub is_async: bool,
26 }
27 #[derive(Serialize, Deserialize, Clone, Debug)]
28 pub struct RegExpValue {
29 - pattern: String,
30 - flags: String,
29 + pub pattern: String,
30 + pub flags: String,
31 }
32 #[derive(Serialize, Deserialize, Clone, Debug)]
33 pub struct Identifier {
34 - name: String,
34 + pub name: String,
35 + #[serde(skip)]
36 #[serde(default)]
36 - binding: Option<Binding>,
37 + pub binding: Option<Binding>,
38 #[serde(default)]
39 pub loc: Option<SourceLocation>,
40 #[serde(default)]
@@ -41,11 +42,11 @@ pub struct Identifier {
42 }
43 #[derive(Serialize, Deserialize, Clone, Debug)]
44 pub struct Literal {
44 - value: JsValue,
45 + pub value: JsValue,
46 #[serde(default)]
46 - raw: Option<String>,
47 + pub raw: Option<String>,
48 #[serde(default)]
48 - regex: Option<RegExpValue>,
49 + pub regex: Option<RegExpValue>,
50 #[serde(default)]
51 pub loc: Option<SourceLocation>,
52 #[serde(default)]
@@ -53,9 +54,9 @@ pub struct Literal {
54 }
55 #[derive(Serialize, Deserialize, Clone, Debug)]
56 pub struct Program {
56 - body: Vec<ModuleItem>,
57 + pub body: Vec<ModuleItem>,
58 #[serde(rename = "sourceType")]
58 - source_type: Option<SourceType>,
59 + pub source_type: Option<SourceType>,
60 #[serde(default)]
61 pub loc: Option<SourceLocation>,
62 #[serde(default)]
@@ -63,9 +64,9 @@ pub struct Program {
64 }
65 #[derive(Serialize, Deserialize, Clone, Debug)]
66 pub struct ExpressionStatement {
66 - expression: Expression,
67 + pub expression: Expression,
68 #[serde(default)]
68 - directive: Option<String>,
69 + pub directive: Option<String>,
70 #[serde(default)]
71 pub loc: Option<SourceLocation>,
72 #[serde(default)]
@@ -73,7 +74,7 @@ pub struct ExpressionStatement {
74 }
75 #[derive(Serialize, Deserialize, Clone, Debug)]
76 pub struct BlockStatement {
76 - body: Vec<Statement>,
77 + pub body: Vec<Statement>,
78 #[serde(default)]
79 pub loc: Option<SourceLocation>,
80 #[serde(default)]
@@ -95,8 +96,8 @@ pub struct DebuggerStatement {
96 }
97 #[derive(Serialize, Deserialize, Clone, Debug)]
98 pub struct WithStatement {
98 - object: Expression,
99 - body: Statement,
99 + pub object: Expression,
100 + pub body: Statement,
101 #[serde(default)]
102 pub loc: Option<SourceLocation>,
103 #[serde(default)]
@@ -104,7 +105,7 @@ pub struct WithStatement {
105 }
106 #[derive(Serialize, Deserialize, Clone, Debug)]
107 pub struct ReturnStatement {
107 - argument: Option<Expression>,
108 + pub argument: Option<Expression>,
109 #[serde(default)]
110 pub loc: Option<SourceLocation>,
111 #[serde(default)]
@@ -112,8 +113,8 @@ pub struct ReturnStatement {
113 }
114 #[derive(Serialize, Deserialize, Clone, Debug)]
115 pub struct LabeledStatement {
115 - label: Identifier,
116 - body: Statement,
116 + pub label: Identifier,
117 + pub body: Statement,
118 #[serde(default)]
119 pub loc: Option<SourceLocation>,
120 #[serde(default)]
@@ -121,7 +122,7 @@ pub struct LabeledStatement {
122 }
123 #[derive(Serialize, Deserialize, Clone, Debug)]
124 pub struct BreakStatement {
124 - label: Option<Identifier>,
125 + pub label: Option<Identifier>,
126 #[serde(default)]
127 pub loc: Option<SourceLocation>,
128 #[serde(default)]
@@ -129,7 +130,7 @@ pub struct BreakStatement {
130 }
131 #[derive(Serialize, Deserialize, Clone, Debug)]
132 pub struct ContinueStatement {
132 - label: Option<Identifier>,
133 + pub label: Option<Identifier>,
134 #[serde(default)]
135 pub loc: Option<SourceLocation>,
136 #[serde(default)]
@@ -137,9 +138,9 @@ pub struct ContinueStatement {
138 }
139 #[derive(Serialize, Deserialize, Clone, Debug)]
140 pub struct IfStatement {
140 - test: Expression,
141 - consequent: Statement,
142 - alternate: Option<Statement>,
141 + pub test: Expression,
142 + pub consequent: Statement,
143 + pub alternate: Option<Statement>,
144 #[serde(default)]
145 pub loc: Option<SourceLocation>,
146 #[serde(default)]
@@ -147,8 +148,8 @@ pub struct IfStatement {
148 }
149 #[derive(Serialize, Deserialize, Clone, Debug)]
150 pub struct SwitchStatement {
150 - discriminant: Expression,
151 - cases: Vec<SwitchCase>,
151 + pub discriminant: Expression,
152 + pub cases: Vec<SwitchCase>,
153 #[serde(default)]
154 pub loc: Option<SourceLocation>,
155 #[serde(default)]
@@ -156,8 +157,8 @@ pub struct SwitchStatement {
157 }
158 #[derive(Serialize, Deserialize, Clone, Debug)]
159 pub struct SwitchCase {
159 - test: Option<Expression>,
160 - consequent: Vec<Statement>,
160 + pub test: Option<Expression>,
161 + pub consequent: Vec<Statement>,
162 #[serde(default)]
163 pub loc: Option<SourceLocation>,
164 #[serde(default)]
@@ -165,7 +166,7 @@ pub struct SwitchCase {
166 }
167 #[derive(Serialize, Deserialize, Clone, Debug)]
168 pub struct ThrowStatement {
168 - argument: Expression,
169 + pub argument: Expression,
170 #[serde(default)]
171 pub loc: Option<SourceLocation>,
172 #[serde(default)]
@@ -173,9 +174,9 @@ pub struct ThrowStatement {
174 }
175 #[derive(Serialize, Deserialize, Clone, Debug)]
176 pub struct TryStatement {
176 - block: BlockStatement,
177 - handler: Option<CatchClause>,
178 - finalizer: Option<BlockStatement>,
177 + pub block: BlockStatement,
178 + pub handler: Option<CatchClause>,
179 + pub finalizer: Option<BlockStatement>,
180 #[serde(default)]
181 pub loc: Option<SourceLocation>,
182 #[serde(default)]
@@ -183,8 +184,8 @@ pub struct TryStatement {
184 }
185 #[derive(Serialize, Deserialize, Clone, Debug)]
186 pub struct CatchClause {
186 - param: Pattern,
187 - body: BlockStatement,
187 + pub param: Pattern,
188 + pub body: BlockStatement,
189 #[serde(default)]
190 pub loc: Option<SourceLocation>,
191 #[serde(default)]
@@ -192,8 +193,8 @@ pub struct CatchClause {
193 }
194 #[derive(Serialize, Deserialize, Clone, Debug)]
195 pub struct WhileStatement {
195 - test: Expression,
196 - body: Statement,
196 + pub test: Expression,
197 + pub body: Statement,
198 #[serde(default)]
199 pub loc: Option<SourceLocation>,
200 #[serde(default)]
@@ -201,8 +202,8 @@ pub struct WhileStatement {
202 }
203 #[derive(Serialize, Deserialize, Clone, Debug)]
204 pub struct DoWhileStatement {
204 - body: Statement,
205 - test: Expression,
205 + pub body: Statement,
206 + pub test: Expression,
207 #[serde(default)]
208 pub loc: Option<SourceLocation>,
209 #[serde(default)]
@@ -210,10 +211,10 @@ pub struct DoWhileStatement {
211 }
212 #[derive(Serialize, Deserialize, Clone, Debug)]
213 pub struct ForStatement {
213 - init: Option<ForInit>,
214 - test: Option<Expression>,
215 - update: Option<Expression>,
216 - body: Statement,
214 + pub init: Option<ForInit>,
215 + pub test: Option<Expression>,
216 + pub update: Option<Expression>,
217 + pub body: Statement,
218 #[serde(default)]
219 pub loc: Option<SourceLocation>,
220 #[serde(default)]
@@ -221,9 +222,9 @@ pub struct ForStatement {
222 }
223 #[derive(Serialize, Deserialize, Clone, Debug)]
224 pub struct ForInStatement {
224 - left: ForInInit,
225 - right: Expression,
226 - body: Statement,
225 + pub left: ForInInit,
226 + pub right: Expression,
227 + pub body: Statement,
228 #[serde(default)]
229 pub loc: Option<SourceLocation>,
230 #[serde(default)]
@@ -231,9 +232,9 @@ pub struct ForInStatement {
232 }
233 #[derive(Serialize, Deserialize, Clone, Debug)]
234 pub struct ForOfStatement {
234 - left: ForInInit,
235 - right: Expression,
236 - body: Statement,
235 + pub left: ForInInit,
236 + pub right: Expression,
237 + pub body: Statement,
238 #[serde(default)]
239 pub loc: Option<SourceLocation>,
240 #[serde(default)]
@@ -242,7 +243,7 @@ pub struct ForOfStatement {
243 #[derive(Serialize, Deserialize, Clone, Debug)]
244 pub struct FunctionDeclaration {
245 #[serde(flatten)]
245 - function: Function,
246 + pub function: Function,
247 #[serde(default)]
248 pub loc: Option<SourceLocation>,
249 #[serde(default)]
@@ -250,8 +251,8 @@ pub struct FunctionDeclaration {
251 }
252 #[derive(Serialize, Deserialize, Clone, Debug)]
253 pub struct VariableDeclaration {
253 - kind: VariableDeclarationKind,
254 - declarations: Vec<VariableDeclarator>,
254 + pub kind: VariableDeclarationKind,
255 + pub declarations: Vec<VariableDeclarator>,
256 #[serde(default)]
257 pub loc: Option<SourceLocation>,
258 #[serde(default)]
@@ -259,8 +260,8 @@ pub struct VariableDeclaration {
260 }
261 #[derive(Serialize, Deserialize, Clone, Debug)]
262 pub struct VariableDeclarator {
262 - id: Pattern,
263 - init: Option<Expression>,
263 + pub id: Pattern,
264 + pub init: Option<Expression>,
265 #[serde(default)]
266 pub loc: Option<SourceLocation>,
267 #[serde(default)]
@@ -275,7 +276,7 @@ pub struct ThisExpression {
276 }
277 #[derive(Serialize, Deserialize, Clone, Debug)]
278 pub struct ArrayExpression {
278 - elements: Vec<Option<ExpressionOrSpread>>,
279 + pub elements: Vec<Option<ExpressionOrSpread>>,
280 #[serde(default)]
281 pub loc: Option<SourceLocation>,
282 #[serde(default)]
@@ -283,7 +284,7 @@ pub struct ArrayExpression {
284 }
285 #[derive(Serialize, Deserialize, Clone, Debug)]
286 pub struct ObjectExpression {
286 - properties: Vec<Property>,
287 + pub properties: Vec<Property>,
288 #[serde(default)]
289 pub loc: Option<SourceLocation>,
290 #[serde(default)]
@@ -291,9 +292,9 @@ pub struct ObjectExpression {
292 }
293 #[derive(Serialize, Deserialize, Clone, Debug)]
294 pub struct Property {
294 - key: PropertyKey,
295 - value: Expression,
296 - kind: PropertyKind,
295 + pub key: PropertyKey,
296 + pub value: Expression,
297 + pub kind: PropertyKind,
298 #[serde(default)]
299 pub loc: Option<SourceLocation>,
300 #[serde(default)]
@@ -302,7 +303,7 @@ pub struct Property {
303 #[derive(Serialize, Deserialize, Clone, Debug)]
304 pub struct FunctionExpression {
305 #[serde(flatten)]
305 - function: Function,
306 + pub function: Function,
307 #[serde(default)]
308 pub loc: Option<SourceLocation>,
309 #[serde(default)]
@@ -311,9 +312,9 @@ pub struct FunctionExpression {
312 #[derive(Serialize, Deserialize, Clone, Debug)]
313 pub struct ArrowFunctionExpression {
314 #[serde(flatten)]
314 - function: Function,
315 + pub function: Function,
316 #[serde(rename = "expression")]
316 - is_expression: bool,
317 + pub is_expression: bool,
318 #[serde(default)]
319 pub loc: Option<SourceLocation>,
320 #[serde(default)]
@@ -321,9 +322,9 @@ pub struct ArrowFunctionExpression {
322 }
323 #[derive(Serialize, Deserialize, Clone, Debug)]
324 pub struct UnaryExpression {
324 - operator: UnaryOperator,
325 - prefix: bool,
326 - argument: Expression,
325 + pub operator: UnaryOperator,
326 + pub prefix: bool,
327 + pub argument: Expression,
328 #[serde(default)]
329 pub loc: Option<SourceLocation>,
330 #[serde(default)]
@@ -331,9 +332,9 @@ pub struct UnaryExpression {
332 }
333 #[derive(Serialize, Deserialize, Clone, Debug)]
334 pub struct UpdateExpression {
334 - operator: UpdateOperator,
335 - argument: Expression,
336 - prefix: bool,
335 + pub operator: UpdateOperator,
336 + pub argument: Expression,
337 + pub prefix: bool,
338 #[serde(default)]
339 pub loc: Option<SourceLocation>,
340 #[serde(default)]
@@ -341,9 +342,9 @@ pub struct UpdateExpression {
342 }
343 #[derive(Serialize, Deserialize, Clone, Debug)]
344 pub struct BinaryExpression {
344 - left: Expression,
345 - operator: BinaryOperator,
346 - right: Expression,
345 + pub left: Expression,
346 + pub operator: BinaryOperator,
347 + pub right: Expression,
348 #[serde(default)]
349 pub loc: Option<SourceLocation>,
350 #[serde(default)]
@@ -351,9 +352,9 @@ pub struct BinaryExpression {
352 }
353 #[derive(Serialize, Deserialize, Clone, Debug)]
354 pub struct AssignmentExpression {
354 - operator: AssignmentOperator,
355 - left: AssignmentTarget,
356 - right: Expression,
355 + pub operator: AssignmentOperator,
356 + pub left: AssignmentTarget,
357 + pub right: Expression,
358 #[serde(default)]
359 pub loc: Option<SourceLocation>,
360 #[serde(default)]
@@ -361,9 +362,9 @@ pub struct AssignmentExpression {
362 }
363 #[derive(Serialize, Deserialize, Clone, Debug)]
364 pub struct LogicalExpression {
364 - operator: LogicalOperator,
365 - left: Expression,
366 - right: Expression,
365 + pub operator: LogicalOperator,
366 + pub left: Expression,
367 + pub right: Expression,
368 #[serde(default)]
369 pub loc: Option<SourceLocation>,
370 #[serde(default)]
@@ -371,9 +372,9 @@ pub struct LogicalExpression {
372 }
373 #[derive(Serialize, Deserialize, Clone, Debug)]
374 pub struct MemberExpression {
374 - object: ExpressionOrSuper,
375 - property: Expression,
376 - computed: bool,
375 + pub object: ExpressionOrSuper,
376 + pub property: Expression,
377 + pub computed: bool,
378 #[serde(default)]
379 pub loc: Option<SourceLocation>,
380 #[serde(default)]
@@ -381,9 +382,9 @@ pub struct MemberExpression {
382 }
383 #[derive(Serialize, Deserialize, Clone, Debug)]
384 pub struct ConditionalExpression {
384 - test: Expression,
385 - alternate: Expression,
386 - consequent: Expression,
385 + pub test: Expression,
386 + pub alternate: Expression,
387 + pub consequent: Expression,
388 #[serde(default)]
389 pub loc: Option<SourceLocation>,
390 #[serde(default)]
@@ -391,8 +392,8 @@ pub struct ConditionalExpression {
392 }
393 #[derive(Serialize, Deserialize, Clone, Debug)]
394 pub struct CallExpression {
394 - callee: ExpressionOrSuper,
395 - arguments: Vec<ExpressionOrSpread>,
395 + pub callee: ExpressionOrSuper,
396 + pub arguments: Vec<ExpressionOrSpread>,
397 #[serde(default)]
398 pub loc: Option<SourceLocation>,
399 #[serde(default)]
@@ -400,8 +401,8 @@ pub struct CallExpression {
401 }
402 #[derive(Serialize, Deserialize, Clone, Debug)]
403 pub struct NewExpression {
403 - callee: Expression,
404 - arguments: Vec<ExpressionOrSpread>,
404 + pub callee: Expression,
405 + pub arguments: Vec<ExpressionOrSpread>,
406 #[serde(default)]
407 pub loc: Option<SourceLocation>,
408 #[serde(default)]
@@ -409,7 +410,7 @@ pub struct NewExpression {
410 }
411 #[derive(Serialize, Deserialize, Clone, Debug)]
412 pub struct SequenceExpression {
412 - expressions: Vec<Expression>,
413 + pub expressions: Vec<Expression>,
414 #[serde(default)]
415 pub loc: Option<SourceLocation>,
416 #[serde(default)]
@@ -424,7 +425,7 @@ pub struct Super {
425 }
426 #[derive(Serialize, Deserialize, Clone, Debug)]
427 pub struct SpreadElement {
427 - argument: Expression,
428 + pub argument: Expression,
429 #[serde(default)]
430 pub loc: Option<SourceLocation>,
431 #[serde(default)]
@@ -433,9 +434,9 @@ pub struct SpreadElement {
434 #[derive(Serialize, Deserialize, Clone, Debug)]
435 pub struct YieldExpression {
436 #[serde(default)]
436 - argument: Option<Expression>,
437 + pub argument: Option<Expression>,
438 #[serde(rename = "delegate")]
438 - is_delegate: bool,
439 + pub is_delegate: bool,
440 #[serde(default)]
441 pub loc: Option<SourceLocation>,
442 #[serde(default)]
@@ -443,8 +444,8 @@ pub struct YieldExpression {
444 }
445 #[derive(Serialize, Deserialize, Clone, Debug)]
446 pub struct ImportDeclaration {
446 - specifiers: Vec<ImportDeclarationSpecifier>,
447 - source: Literal,
447 + pub specifiers: Vec<ImportDeclarationSpecifier>,
448 + pub source: Literal,
449 #[serde(default)]
450 pub loc: Option<SourceLocation>,
451 #[serde(default)]
@@ -452,8 +453,8 @@ pub struct ImportDeclaration {
453 }
454 #[derive(Serialize, Deserialize, Clone, Debug)]
455 pub struct ImportSpecifier {
455 - imported: Identifier,
456 - local: Identifier,
456 + pub imported: Identifier,
457 + pub local: Identifier,
458 #[serde(default)]
459 pub loc: Option<SourceLocation>,
460 #[serde(default)]
@@ -461,7 +462,7 @@ pub struct ImportSpecifier {
462 }
463 #[derive(Serialize, Deserialize, Clone, Debug)]
464 pub struct ImportDefaultSpecifier {
464 - local: Identifier,
465 + pub local: Identifier,
466 #[serde(default)]
467 pub loc: Option<SourceLocation>,
468 #[serde(default)]
@@ -469,7 +470,7 @@ pub struct ImportDefaultSpecifier {
470 }
471 #[derive(Serialize, Deserialize, Clone, Debug)]
472 pub struct ImportNamespaceSpecifier {
472 - local: Identifier,
473 + pub local: Identifier,
474 #[serde(default)]
475 pub loc: Option<SourceLocation>,
476 #[serde(default)]
compiler/forget/crates/estree/src/snapshots/estree__tests__fixtures@for-statement.json.snap
-9
@@ -540,7 +540,6 @@ Output:
540 "type": "FunctionDeclaration",
541 "id": {
542 "name": "Component",
543 - "binding": null,
543 "loc": {
544 "source": null,
545 "start": {
@@ -561,7 +560,6 @@ Output:
560 {
561 "type": "Identifier",
562 "name": "props",
564 - "binding": null,
563 "loc": {
564 "source": null,
565 "start": {
@@ -589,7 +587,6 @@ Output:
587 "id": {
588 "type": "Identifier",
589 "name": "x",
592 - "binding": null,
590 "loc": {
591 "source": null,
592 "start": {
@@ -671,7 +668,6 @@ Output:
668 "id": {
669 "type": "Identifier",
670 "name": "i",
674 - "binding": null,
671 "loc": {
672 "source": null,
673 "start": {
@@ -749,7 +745,6 @@ Output:
745 "left": {
746 "type": "Identifier",
747 "name": "i",
752 - "binding": null,
748 "loc": {
749 "source": null,
750 "start": {
@@ -812,7 +807,6 @@ Output:
807 "argument": {
808 "type": "Identifier",
809 "name": "i",
815 - "binding": null,
810 "loc": {
811 "source": null,
812 "start": {
@@ -857,7 +851,6 @@ Output:
851 "left": {
852 "type": "Identifier",
853 "name": "x",
860 - "binding": null,
854 "loc": {
855 "source": null,
856 "start": {
@@ -877,7 +870,6 @@ Output:
870 "right": {
871 "type": "Identifier",
872 "name": "i",
880 - "binding": null,
873 "loc": {
874 "source": null,
875 "start": {
@@ -965,7 +957,6 @@ Output:
957 "argument": {
958 "type": "Identifier",
959 "name": "x",
968 - "binding": null,
960 "loc": {
961 "source": null,
962 "start": {
compiler/forget/crates/estree/src/snapshots/estree__tests__fixtures@import.json.snap
-1
@@ -119,7 +119,6 @@ Output:
119 "type": "ImportDefaultSpecifier",
120 "local": {
121 "name": "React",
122 - "binding": null,
122 "loc": {
123 "source": null,
124 "start": {
compiler/forget/crates/estree/src/snapshots/estree__tests__fixtures@simple.json.snap
-4
@@ -201,7 +201,6 @@ Output:
201 "type": "FunctionDeclaration",
202 "id": {
203 "name": "Component",
204 - "binding": null,
204 "loc": {
205 "source": null,
206 "start": {
@@ -222,7 +221,6 @@ Output:
221 {
222 "type": "Identifier",
223 "name": "props",
225 - "binding": null,
224 "loc": {
225 "source": null,
226 "start": {
@@ -249,7 +247,6 @@ Output:
247 "object": {
248 "type": "Identifier",
249 "name": "props",
252 - "binding": null,
250 "loc": {
251 "source": null,
252 "start": {
@@ -269,7 +266,6 @@ Output:
266 "property": {
267 "type": "Identifier",
268 "name": "value",
272 - "binding": null,
269 "loc": {
270 "source": null,
271 "start": {