[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.
This commit is contained in:
Joe Savona
2023-07-08 23:00:00 +09:00
parent 3983e882b8
commit 1abea6c49d
6 changed files with 174 additions and 232 deletions
@@ -3,6 +3,7 @@ use std::collections::HashSet;
use indexmap::IndexMap;
use quote::{__private::TokenStream, format_ident, quote};
use serde::{Deserialize, Serialize};
use syn::Type;
/// Returns prettyplease-formatted Rust source for estree
pub fn estree() -> String {
@@ -15,6 +16,7 @@ pub fn estree() -> String {
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Grammar {
pub objects: IndexMap<String, Object>,
pub nodes: IndexMap<String, Node>,
@@ -70,6 +72,7 @@ impl Grammar {
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Object {
#[serde(default)]
pub fields: IndexMap<String, Field>,
@@ -94,6 +97,7 @@ impl Object {
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Node {
#[serde(default)]
pub fields: IndexMap<String, Field>,
@@ -124,89 +128,65 @@ impl Node {
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Field {
#[serde(rename = "type")]
pub type_: String,
#[serde(default)]
pub nullable: bool,
#[serde(default)]
pub optional: bool,
#[serde(default)]
pub plural: bool,
#[serde(default)]
pub nullable_item: bool,
#[serde(default)]
pub flatten: bool,
#[serde(default)]
pub rename: Option<String>,
#[serde(default)]
pub skip: bool,
}
impl Field {
pub fn codegen(&self, name: &str) -> TokenStream {
let name = format_ident!("{}", name);
let type_name = format_ident!("{}", &self.type_);
let mut type_ = quote!(#type_name);
if self.plural {
if self.nullable_item {
type_ = quote!(Option<#type_>);
}
type_ = quote! { Vec<#type_> };
} else {
assert_eq!(
self.nullable_item, false,
"Can only set nullable_item if plural"
)
}
if self.nullable {
type_ = quote!(Option<#type_>);
}
let mut field = quote!(#name: #type_);
let type_name: Type = syn::parse_str(&self.type_)
.unwrap_or_else(|_| panic!("Expected a type name, got `{}`", &self.type_));
let type_ = quote!(#type_name);
let mut field = quote!(pub #name: #type_);
if self.optional {
field = quote! {
#[serde(default)]
#field
}
}
if self.flatten {
field = quote! {
#[serde(flatten)]
#field
}
}
if self.skip {
field = quote! {
#[serde(skip)]
#field
}
}
if let Some(rename) = &self.rename {
field = quote! {
#[serde(rename = #rename)]
#field
}
}
if self.flatten {
field = quote! {
#[serde(flatten)]
#field
}
}
field
}
pub fn codegen_node(&self, name: &str) -> TokenStream {
let name = format_ident!("{}", name);
let type_name = format_ident!("{}", &self.type_);
let mut type_ = quote!(#type_name);
if self.plural {
if self.nullable_item {
type_ = quote!(Option<#type_>);
}
type_ = quote! { Vec<#type_> };
} else {
assert_eq!(
self.nullable_item, false,
"Can only set nullable_item if plural"
)
}
if self.nullable {
type_ = quote!(Option<#type_>);
}
let mut field = quote!(#name: #type_);
let type_name: Type = syn::parse_str(&self.type_)
.unwrap_or_else(|_| panic!("Expected a type name, got `{}`", &self.type_));
let type_ = quote!(#type_name);
let mut field = quote!(pub #name: #type_);
if self.optional {
field = quote! {
#[serde(default)]
@@ -219,6 +199,12 @@ impl Field {
#field
}
}
if self.skip {
field = quote! {
#[serde(skip)]
#field
}
}
if let Some(rename) = &self.rename {
field = quote! {
#[serde(rename = #rename)]
@@ -231,6 +217,7 @@ impl Field {
#[derive(Serialize, Deserialize, Debug)]
#[serde(transparent)]
#[serde(deny_unknown_fields)]
pub struct Enum {
pub variants: Vec<String>,
}
@@ -280,6 +267,7 @@ impl Enum {
#[derive(Serialize, Deserialize, Debug)]
#[serde(transparent)]
#[serde(deny_unknown_fields)]
pub struct Operator {
pub variants: IndexMap<String, String>,
}
@@ -3,8 +3,7 @@
"SourceLocation": {
"fields": {
"source": {
"type": "String",
"nullable": true
"type": "Option<String>"
},
"start": {
"type": "Position"
@@ -27,16 +26,13 @@
"Function": {
"fields": {
"id": {
"type": "Identifier",
"nullable": true
"type": "Option<Identifier>"
},
"params": {
"type": "Pattern",
"plural": true
"type": "Vec<Pattern>"
},
"body": {
"type": "FunctionBody",
"nullable": true
"type": "Option<FunctionBody>"
},
"is_generator": {
"type": "bool",
@@ -68,8 +64,7 @@
"type": "String"
},
"binding": {
"type": "Binding",
"nullable": true,
"type": "Option<Binding>",
"optional": true,
"skip": true
}
@@ -81,13 +76,11 @@
"type": "JsValue"
},
"raw": {
"type": "String",
"nullable": true,
"type": "Option<String>",
"optional": true
},
"regex": {
"type": "RegExpValue",
"nullable": true,
"type": "Option<RegExpValue>",
"optional": true
}
}
@@ -95,12 +88,10 @@
"Program": {
"fields": {
"body": {
"type": "ModuleItem",
"plural": true
"type": "Vec<ModuleItem>"
},
"source_type": {
"type": "SourceType",
"nullable": true,
"type": "Option<SourceType>",
"rename": "sourceType"
}
}
@@ -111,8 +102,7 @@
"type": "Expression"
},
"directive": {
"type": "String",
"nullable": true,
"type": "Option<String>",
"optional": true
}
}
@@ -120,8 +110,7 @@
"BlockStatement": {
"fields": {
"body": {
"type": "Statement",
"plural": true
"type": "Vec<Statement>"
}
}
},
@@ -140,8 +129,7 @@
"ReturnStatement": {
"fields": {
"argument": {
"type": "Expression",
"nullable": true
"type": "Option<Expression>"
}
}
},
@@ -158,16 +146,14 @@
"BreakStatement": {
"fields": {
"label": {
"type": "Identifier",
"nullable": true
"type": "Option<Identifier>"
}
}
},
"ContinueStatement": {
"fields": {
"label": {
"type": "Identifier",
"nullable": true
"type": "Option<Identifier>"
}
}
},
@@ -180,8 +166,7 @@
"type": "Statement"
},
"alternate": {
"type": "Statement",
"nullable": true
"type": "Option<Statement>"
}
}
},
@@ -191,20 +176,17 @@
"type": "Expression"
},
"cases": {
"type": "SwitchCase",
"plural": true
"type": "Vec<SwitchCase>"
}
}
},
"SwitchCase": {
"fields": {
"test": {
"type": "Expression",
"nullable": true
"type": "Option<Expression>"
},
"consequent": {
"type": "Statement",
"plural": true
"type": "Vec<Statement>"
}
}
},
@@ -221,12 +203,10 @@
"type": "BlockStatement"
},
"handler": {
"type": "CatchClause",
"nullable": true
"type": "Option<CatchClause>"
},
"finalizer": {
"type": "BlockStatement",
"nullable": true
"type": "Option<BlockStatement>"
}
}
},
@@ -263,16 +243,13 @@
"ForStatement": {
"fields": {
"init": {
"type": "ForInit",
"nullable": true
"type": "Option<ForInit>"
},
"test": {
"type": "Expression",
"nullable": true
"type": "Option<Expression>"
},
"update": {
"type": "Expression",
"nullable": true
"type": "Option<Expression>"
},
"body": {
"type": "Statement"
@@ -319,8 +296,7 @@
"type": "VariableDeclarationKind"
},
"declarations": {
"type": "VariableDeclarator",
"plural": true
"type": "Vec<VariableDeclarator>"
}
}
},
@@ -330,8 +306,7 @@
"type": "Pattern"
},
"init": {
"type": "Expression",
"nullable": true
"type": "Option<Expression>"
}
}
},
@@ -339,17 +314,14 @@
"ArrayExpression": {
"fields": {
"elements": {
"type": "ExpressionOrSpread",
"plural": true,
"nullable_item": true
"type": "Vec<Option<ExpressionOrSpread>>"
}
}
},
"ObjectExpression": {
"fields": {
"properties": {
"type": "Property",
"plural": true
"type": "Vec<Property>"
}
}
},
@@ -483,8 +455,7 @@
"type": "ExpressionOrSuper"
},
"arguments": {
"type": "ExpressionOrSpread",
"plural": true
"type": "Vec<ExpressionOrSpread>"
}
}
},
@@ -494,16 +465,14 @@
"type": "Expression"
},
"arguments": {
"type": "ExpressionOrSpread",
"plural": true
"type": "Vec<ExpressionOrSpread>"
}
}
},
"SequenceExpression": {
"fields": {
"expressions": {
"type": "Expression",
"plural": true
"type": "Vec<Expression>"
}
}
},
@@ -518,8 +487,7 @@
"YieldExpression": {
"fields": {
"argument": {
"type": "Expression",
"nullable": true,
"type": "Option<Expression>",
"optional": true
},
"is_delegate": {
@@ -531,8 +499,7 @@
"ImportDeclaration": {
"fields": {
"specifiers": {
"type": "ImportDeclarationSpecifier",
"plural": true
"type": "Vec<ImportDeclarationSpecifier>"
},
"source": {
"type": "Literal"
+105 -104
View File
@@ -3,37 +3,38 @@ use serde::{Serialize, Deserialize};
use crate::{JsValue, Binding, SourceRange};
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SourceLocation {
source: Option<String>,
start: Position,
end: Position,
pub source: Option<String>,
pub start: Position,
pub end: Position,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Position {
line: NonZeroU32,
column: u32,
pub line: NonZeroU32,
pub column: u32,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Function {
id: Option<Identifier>,
params: Vec<Pattern>,
body: Option<FunctionBody>,
pub id: Option<Identifier>,
pub params: Vec<Pattern>,
pub body: Option<FunctionBody>,
#[serde(rename = "generator")]
#[serde(default)]
is_generator: bool,
pub is_generator: bool,
#[serde(rename = "async")]
#[serde(default)]
is_async: bool,
pub is_async: bool,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct RegExpValue {
pattern: String,
flags: String,
pub pattern: String,
pub flags: String,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Identifier {
name: String,
pub name: String,
#[serde(skip)]
#[serde(default)]
binding: Option<Binding>,
pub binding: Option<Binding>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -41,11 +42,11 @@ pub struct Identifier {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Literal {
value: JsValue,
pub value: JsValue,
#[serde(default)]
raw: Option<String>,
pub raw: Option<String>,
#[serde(default)]
regex: Option<RegExpValue>,
pub regex: Option<RegExpValue>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -53,9 +54,9 @@ pub struct Literal {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Program {
body: Vec<ModuleItem>,
pub body: Vec<ModuleItem>,
#[serde(rename = "sourceType")]
source_type: Option<SourceType>,
pub source_type: Option<SourceType>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -63,9 +64,9 @@ pub struct Program {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ExpressionStatement {
expression: Expression,
pub expression: Expression,
#[serde(default)]
directive: Option<String>,
pub directive: Option<String>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -73,7 +74,7 @@ pub struct ExpressionStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct BlockStatement {
body: Vec<Statement>,
pub body: Vec<Statement>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -95,8 +96,8 @@ pub struct DebuggerStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct WithStatement {
object: Expression,
body: Statement,
pub object: Expression,
pub body: Statement,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -104,7 +105,7 @@ pub struct WithStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ReturnStatement {
argument: Option<Expression>,
pub argument: Option<Expression>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -112,8 +113,8 @@ pub struct ReturnStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct LabeledStatement {
label: Identifier,
body: Statement,
pub label: Identifier,
pub body: Statement,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -121,7 +122,7 @@ pub struct LabeledStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct BreakStatement {
label: Option<Identifier>,
pub label: Option<Identifier>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -129,7 +130,7 @@ pub struct BreakStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ContinueStatement {
label: Option<Identifier>,
pub label: Option<Identifier>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -137,9 +138,9 @@ pub struct ContinueStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct IfStatement {
test: Expression,
consequent: Statement,
alternate: Option<Statement>,
pub test: Expression,
pub consequent: Statement,
pub alternate: Option<Statement>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -147,8 +148,8 @@ pub struct IfStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SwitchStatement {
discriminant: Expression,
cases: Vec<SwitchCase>,
pub discriminant: Expression,
pub cases: Vec<SwitchCase>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -156,8 +157,8 @@ pub struct SwitchStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SwitchCase {
test: Option<Expression>,
consequent: Vec<Statement>,
pub test: Option<Expression>,
pub consequent: Vec<Statement>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -165,7 +166,7 @@ pub struct SwitchCase {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ThrowStatement {
argument: Expression,
pub argument: Expression,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -173,9 +174,9 @@ pub struct ThrowStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct TryStatement {
block: BlockStatement,
handler: Option<CatchClause>,
finalizer: Option<BlockStatement>,
pub block: BlockStatement,
pub handler: Option<CatchClause>,
pub finalizer: Option<BlockStatement>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -183,8 +184,8 @@ pub struct TryStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct CatchClause {
param: Pattern,
body: BlockStatement,
pub param: Pattern,
pub body: BlockStatement,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -192,8 +193,8 @@ pub struct CatchClause {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct WhileStatement {
test: Expression,
body: Statement,
pub test: Expression,
pub body: Statement,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -201,8 +202,8 @@ pub struct WhileStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct DoWhileStatement {
body: Statement,
test: Expression,
pub body: Statement,
pub test: Expression,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -210,10 +211,10 @@ pub struct DoWhileStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ForStatement {
init: Option<ForInit>,
test: Option<Expression>,
update: Option<Expression>,
body: Statement,
pub init: Option<ForInit>,
pub test: Option<Expression>,
pub update: Option<Expression>,
pub body: Statement,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -221,9 +222,9 @@ pub struct ForStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ForInStatement {
left: ForInInit,
right: Expression,
body: Statement,
pub left: ForInInit,
pub right: Expression,
pub body: Statement,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -231,9 +232,9 @@ pub struct ForInStatement {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ForOfStatement {
left: ForInInit,
right: Expression,
body: Statement,
pub left: ForInInit,
pub right: Expression,
pub body: Statement,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -242,7 +243,7 @@ pub struct ForOfStatement {
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct FunctionDeclaration {
#[serde(flatten)]
function: Function,
pub function: Function,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -250,8 +251,8 @@ pub struct FunctionDeclaration {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct VariableDeclaration {
kind: VariableDeclarationKind,
declarations: Vec<VariableDeclarator>,
pub kind: VariableDeclarationKind,
pub declarations: Vec<VariableDeclarator>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -259,8 +260,8 @@ pub struct VariableDeclaration {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct VariableDeclarator {
id: Pattern,
init: Option<Expression>,
pub id: Pattern,
pub init: Option<Expression>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -275,7 +276,7 @@ pub struct ThisExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ArrayExpression {
elements: Vec<Option<ExpressionOrSpread>>,
pub elements: Vec<Option<ExpressionOrSpread>>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -283,7 +284,7 @@ pub struct ArrayExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ObjectExpression {
properties: Vec<Property>,
pub properties: Vec<Property>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -291,9 +292,9 @@ pub struct ObjectExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Property {
key: PropertyKey,
value: Expression,
kind: PropertyKind,
pub key: PropertyKey,
pub value: Expression,
pub kind: PropertyKind,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -302,7 +303,7 @@ pub struct Property {
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct FunctionExpression {
#[serde(flatten)]
function: Function,
pub function: Function,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -311,9 +312,9 @@ pub struct FunctionExpression {
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ArrowFunctionExpression {
#[serde(flatten)]
function: Function,
pub function: Function,
#[serde(rename = "expression")]
is_expression: bool,
pub is_expression: bool,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -321,9 +322,9 @@ pub struct ArrowFunctionExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct UnaryExpression {
operator: UnaryOperator,
prefix: bool,
argument: Expression,
pub operator: UnaryOperator,
pub prefix: bool,
pub argument: Expression,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -331,9 +332,9 @@ pub struct UnaryExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct UpdateExpression {
operator: UpdateOperator,
argument: Expression,
prefix: bool,
pub operator: UpdateOperator,
pub argument: Expression,
pub prefix: bool,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -341,9 +342,9 @@ pub struct UpdateExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct BinaryExpression {
left: Expression,
operator: BinaryOperator,
right: Expression,
pub left: Expression,
pub operator: BinaryOperator,
pub right: Expression,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -351,9 +352,9 @@ pub struct BinaryExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AssignmentExpression {
operator: AssignmentOperator,
left: AssignmentTarget,
right: Expression,
pub operator: AssignmentOperator,
pub left: AssignmentTarget,
pub right: Expression,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -361,9 +362,9 @@ pub struct AssignmentExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct LogicalExpression {
operator: LogicalOperator,
left: Expression,
right: Expression,
pub operator: LogicalOperator,
pub left: Expression,
pub right: Expression,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -371,9 +372,9 @@ pub struct LogicalExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct MemberExpression {
object: ExpressionOrSuper,
property: Expression,
computed: bool,
pub object: ExpressionOrSuper,
pub property: Expression,
pub computed: bool,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -381,9 +382,9 @@ pub struct MemberExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ConditionalExpression {
test: Expression,
alternate: Expression,
consequent: Expression,
pub test: Expression,
pub alternate: Expression,
pub consequent: Expression,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -391,8 +392,8 @@ pub struct ConditionalExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct CallExpression {
callee: ExpressionOrSuper,
arguments: Vec<ExpressionOrSpread>,
pub callee: ExpressionOrSuper,
pub arguments: Vec<ExpressionOrSpread>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -400,8 +401,8 @@ pub struct CallExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct NewExpression {
callee: Expression,
arguments: Vec<ExpressionOrSpread>,
pub callee: Expression,
pub arguments: Vec<ExpressionOrSpread>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -409,7 +410,7 @@ pub struct NewExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SequenceExpression {
expressions: Vec<Expression>,
pub expressions: Vec<Expression>,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -424,7 +425,7 @@ pub struct Super {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SpreadElement {
argument: Expression,
pub argument: Expression,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -433,9 +434,9 @@ pub struct SpreadElement {
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct YieldExpression {
#[serde(default)]
argument: Option<Expression>,
pub argument: Option<Expression>,
#[serde(rename = "delegate")]
is_delegate: bool,
pub is_delegate: bool,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -443,8 +444,8 @@ pub struct YieldExpression {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ImportDeclaration {
specifiers: Vec<ImportDeclarationSpecifier>,
source: Literal,
pub specifiers: Vec<ImportDeclarationSpecifier>,
pub source: Literal,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -452,8 +453,8 @@ pub struct ImportDeclaration {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ImportSpecifier {
imported: Identifier,
local: Identifier,
pub imported: Identifier,
pub local: Identifier,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -461,7 +462,7 @@ pub struct ImportSpecifier {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ImportDefaultSpecifier {
local: Identifier,
pub local: Identifier,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -469,7 +470,7 @@ pub struct ImportDefaultSpecifier {
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ImportNamespaceSpecifier {
local: Identifier,
pub local: Identifier,
#[serde(default)]
pub loc: Option<SourceLocation>,
#[serde(default)]
@@ -540,7 +540,6 @@ Output:
"type": "FunctionDeclaration",
"id": {
"name": "Component",
"binding": null,
"loc": {
"source": null,
"start": {
@@ -561,7 +560,6 @@ Output:
{
"type": "Identifier",
"name": "props",
"binding": null,
"loc": {
"source": null,
"start": {
@@ -589,7 +587,6 @@ Output:
"id": {
"type": "Identifier",
"name": "x",
"binding": null,
"loc": {
"source": null,
"start": {
@@ -671,7 +668,6 @@ Output:
"id": {
"type": "Identifier",
"name": "i",
"binding": null,
"loc": {
"source": null,
"start": {
@@ -749,7 +745,6 @@ Output:
"left": {
"type": "Identifier",
"name": "i",
"binding": null,
"loc": {
"source": null,
"start": {
@@ -812,7 +807,6 @@ Output:
"argument": {
"type": "Identifier",
"name": "i",
"binding": null,
"loc": {
"source": null,
"start": {
@@ -857,7 +851,6 @@ Output:
"left": {
"type": "Identifier",
"name": "x",
"binding": null,
"loc": {
"source": null,
"start": {
@@ -877,7 +870,6 @@ Output:
"right": {
"type": "Identifier",
"name": "i",
"binding": null,
"loc": {
"source": null,
"start": {
@@ -965,7 +957,6 @@ Output:
"argument": {
"type": "Identifier",
"name": "x",
"binding": null,
"loc": {
"source": null,
"start": {
@@ -119,7 +119,6 @@ Output:
"type": "ImportDefaultSpecifier",
"local": {
"name": "React",
"binding": null,
"loc": {
"source": null,
"start": {
@@ -201,7 +201,6 @@ Output:
"type": "FunctionDeclaration",
"id": {
"name": "Component",
"binding": null,
"loc": {
"source": null,
"start": {
@@ -222,7 +221,6 @@ Output:
{
"type": "Identifier",
"name": "props",
"binding": null,
"loc": {
"source": null,
"start": {
@@ -249,7 +247,6 @@ Output:
"object": {
"type": "Identifier",
"name": "props",
"binding": null,
"loc": {
"source": null,
"start": {
@@ -269,7 +266,6 @@ Output:
"property": {
"type": "Identifier",
"name": "value",
"binding": null,
"loc": {
"source": null,
"start": {