implement { Hash, Eq } for ast nodes (#684)

As NaN is`IIdent` not `Number`, we can use implement Hash and Eq for ast nodes.
This commit is contained in:
강동윤 2020-02-21 12:47:06 +09:00 committed by GitHub
parent e3ca8e5d13
commit cb43a69e02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 239 additions and 21 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "swc_ecma_ast" name = "swc_ecma_ast"
version = "0.17.0" version = "0.17.1"
authors = ["강동윤 <kdy1997.dev@gmail.com>"] authors = ["강동윤 <kdy1997.dev@gmail.com>"]
license = "Apache-2.0/MIT" license = "Apache-2.0/MIT"
repository = "https://github.com/swc-project/swc.git" repository = "https://github.com/swc-project/swc.git"

View File

@ -15,6 +15,7 @@ use swc_common::Fold;
use swc_common::{ast_node, Span}; use swc_common::{ast_node, Span};
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub struct Class { pub struct Class {
pub span: Span, pub span: Span,
@ -42,6 +43,7 @@ pub struct Class {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum ClassMember { pub enum ClassMember {
#[tag("Constructor")] #[tag("Constructor")]
Constructor(Constructor), Constructor(Constructor),
@ -62,6 +64,7 @@ pub enum ClassMember {
macro_rules! property { macro_rules! property {
($name:ident, $ty:literal, $KEY:ty) => { ($name:ident, $ty:literal, $KEY:ty) => {
#[ast_node($ty)] #[ast_node($ty)]
#[derive(Eq, Hash)]
pub struct $name { pub struct $name {
#[serde(default)] #[serde(default)]
pub span: Span, pub span: Span,
@ -109,6 +112,7 @@ property!(PrivateProp, "PrivateProperty", PrivateName);
macro_rules! method { macro_rules! method {
($name:ident, $ty:literal, $KEY:ty) => { ($name:ident, $ty:literal, $KEY:ty) => {
#[ast_node($ty)] #[ast_node($ty)]
#[derive(Eq, Hash)]
pub struct $name { pub struct $name {
#[serde(default)] #[serde(default)]
pub span: Span, pub span: Span,
@ -141,6 +145,7 @@ method!(ClassMethod, "ClassMethod", PropName);
method!(PrivateMethod, "PrivateMethod", PrivateName); method!(PrivateMethod, "PrivateMethod", PrivateName);
#[ast_node("Constructor")] #[ast_node("Constructor")]
#[derive(Eq, Hash)]
pub struct Constructor { pub struct Constructor {
pub span: Span, pub span: Span,
@ -159,6 +164,7 @@ pub struct Constructor {
} }
#[ast_node("Decorator")] #[ast_node("Decorator")]
#[derive(Eq, Hash)]
pub struct Decorator { pub struct Decorator {
pub span: Span, pub span: Span,

View File

@ -12,6 +12,7 @@ use swc_common::Fold;
use swc_common::{ast_node, Span}; use swc_common::{ast_node, Span};
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum Decl { pub enum Decl {
#[tag("ClassDeclaration")] #[tag("ClassDeclaration")]
Class(ClassDecl), Class(ClassDecl),
@ -30,6 +31,7 @@ pub enum Decl {
} }
#[ast_node("FunctionDeclaration")] #[ast_node("FunctionDeclaration")]
#[derive(Eq, Hash)]
pub struct FnDecl { pub struct FnDecl {
#[serde(rename = "identifier")] #[serde(rename = "identifier")]
pub ident: Ident, pub ident: Ident,
@ -43,6 +45,7 @@ pub struct FnDecl {
} }
#[ast_node("ClassDeclaration")] #[ast_node("ClassDeclaration")]
#[derive(Eq, Hash)]
pub struct ClassDecl { pub struct ClassDecl {
#[serde(rename = "identifier")] #[serde(rename = "identifier")]
pub ident: Ident, pub ident: Ident,
@ -56,6 +59,7 @@ pub struct ClassDecl {
} }
#[ast_node("VariableDeclaration")] #[ast_node("VariableDeclaration")]
#[derive(Eq, Hash)]
pub struct VarDecl { pub struct VarDecl {
pub span: Span, pub span: Span,
@ -80,6 +84,7 @@ pub enum VarDeclKind {
} }
#[ast_node("VariableDeclarator")] #[ast_node("VariableDeclarator")]
#[derive(Eq, Hash)]
pub struct VarDeclarator { pub struct VarDeclarator {
pub span: Span, pub span: Span,
#[serde(rename = "id")] #[serde(rename = "id")]

View File

@ -21,6 +21,7 @@ use swc_common::Fold;
use swc_common::{ast_node, Span, Spanned, DUMMY_SP}; use swc_common::{ast_node, Span, Spanned, DUMMY_SP};
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum Expr { pub enum Expr {
#[tag("ThisExpression")] #[tag("ThisExpression")]
This(ThisExpr), This(ThisExpr),
@ -152,13 +153,14 @@ pub enum Expr {
} }
#[ast_node("ThisExpression")] #[ast_node("ThisExpression")]
#[derive(Copy)] #[derive(Eq, Hash, Copy)]
pub struct ThisExpr { pub struct ThisExpr {
pub span: Span, pub span: Span,
} }
/// Array literal. /// Array literal.
#[ast_node("ArrayExpression")] #[ast_node("ArrayExpression")]
#[derive(Eq, Hash)]
pub struct ArrayLit { pub struct ArrayLit {
pub span: Span, pub span: Span,
@ -168,6 +170,7 @@ pub struct ArrayLit {
/// Object literal. /// Object literal.
#[ast_node("ObjectExpression")] #[ast_node("ObjectExpression")]
#[derive(Eq, Hash)]
pub struct ObjectLit { pub struct ObjectLit {
pub span: Span, pub span: Span,
@ -176,6 +179,7 @@ pub struct ObjectLit {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum PropOrSpread { pub enum PropOrSpread {
/// Spread properties, e.g., `{a: 1, ...obj, b: 2}`. /// Spread properties, e.g., `{a: 1, ...obj, b: 2}`.
#[tag("SpreadElement")] #[tag("SpreadElement")]
@ -186,6 +190,7 @@ pub enum PropOrSpread {
} }
#[ast_node("SpreadElement")] #[ast_node("SpreadElement")]
#[derive(Eq, Hash)]
pub struct SpreadElement { pub struct SpreadElement {
#[serde(rename = "spread")] #[serde(rename = "spread")]
#[span(lo)] #[span(lo)]
@ -197,6 +202,7 @@ pub struct SpreadElement {
} }
#[ast_node("UnaryExpression")] #[ast_node("UnaryExpression")]
#[derive(Eq, Hash)]
pub struct UnaryExpr { pub struct UnaryExpr {
pub span: Span, pub span: Span,
@ -208,6 +214,7 @@ pub struct UnaryExpr {
} }
#[ast_node("UpdateExpression")] #[ast_node("UpdateExpression")]
#[derive(Eq, Hash)]
pub struct UpdateExpr { pub struct UpdateExpr {
pub span: Span, pub span: Span,
@ -221,6 +228,7 @@ pub struct UpdateExpr {
} }
#[ast_node("BinaryExpression")] #[ast_node("BinaryExpression")]
#[derive(Eq, Hash)]
pub struct BinExpr { pub struct BinExpr {
pub span: Span, pub span: Span,
@ -234,6 +242,7 @@ pub struct BinExpr {
/// Function expression. /// Function expression.
#[ast_node("FunctionExpression")] #[ast_node("FunctionExpression")]
#[derive(Eq, Hash)]
pub struct FnExpr { pub struct FnExpr {
#[serde(default, rename = "identifier")] #[serde(default, rename = "identifier")]
pub ident: Option<Ident>, pub ident: Option<Ident>,
@ -245,6 +254,7 @@ pub struct FnExpr {
/// Class expression. /// Class expression.
#[ast_node("ClassExpression")] #[ast_node("ClassExpression")]
#[derive(Eq, Hash)]
pub struct ClassExpr { pub struct ClassExpr {
#[serde(default, rename = "identifier")] #[serde(default, rename = "identifier")]
pub ident: Option<Ident>, pub ident: Option<Ident>,
@ -255,6 +265,7 @@ pub struct ClassExpr {
} }
#[ast_node("AssignmentExpression")] #[ast_node("AssignmentExpression")]
#[derive(Eq, Hash)]
pub struct AssignExpr { pub struct AssignExpr {
pub span: Span, pub span: Span,
@ -267,6 +278,7 @@ pub struct AssignExpr {
} }
#[ast_node("MemberExpression")] #[ast_node("MemberExpression")]
#[derive(Eq, Hash)]
pub struct MemberExpr { pub struct MemberExpr {
pub span: Span, pub span: Span,
@ -280,6 +292,7 @@ pub struct MemberExpr {
} }
#[ast_node("ConditionalExpression")] #[ast_node("ConditionalExpression")]
#[derive(Eq, Hash)]
pub struct CondExpr { pub struct CondExpr {
pub span: Span, pub span: Span,
@ -293,6 +306,7 @@ pub struct CondExpr {
} }
#[ast_node("CallExpression")] #[ast_node("CallExpression")]
#[derive(Eq, Hash)]
pub struct CallExpr { pub struct CallExpr {
pub span: Span, pub span: Span,
@ -307,6 +321,7 @@ pub struct CallExpr {
} }
#[ast_node("NewExpression")] #[ast_node("NewExpression")]
#[derive(Eq, Hash)]
pub struct NewExpr { pub struct NewExpr {
pub span: Span, pub span: Span,
@ -321,6 +336,7 @@ pub struct NewExpr {
} }
#[ast_node("SequenceExpression")] #[ast_node("SequenceExpression")]
#[derive(Eq, Hash)]
pub struct SeqExpr { pub struct SeqExpr {
pub span: Span, pub span: Span,
@ -329,6 +345,7 @@ pub struct SeqExpr {
} }
#[ast_node("ArrowFunctionExpression")] #[ast_node("ArrowFunctionExpression")]
#[derive(Eq, Hash)]
pub struct ArrowExpr { pub struct ArrowExpr {
pub span: Span, pub span: Span,
@ -350,6 +367,7 @@ pub struct ArrowExpr {
} }
#[ast_node("YieldExpression")] #[ast_node("YieldExpression")]
#[derive(Eq, Hash)]
pub struct YieldExpr { pub struct YieldExpr {
pub span: Span, pub span: Span,
@ -361,6 +379,7 @@ pub struct YieldExpr {
} }
#[ast_node("MetaProperty")] #[ast_node("MetaProperty")]
#[derive(Eq, Hash)]
pub struct MetaPropExpr { pub struct MetaPropExpr {
#[span(lo)] #[span(lo)]
pub meta: Ident, pub meta: Ident,
@ -371,6 +390,7 @@ pub struct MetaPropExpr {
} }
#[ast_node("AwaitExpression")] #[ast_node("AwaitExpression")]
#[derive(Eq, Hash)]
pub struct AwaitExpr { pub struct AwaitExpr {
pub span: Span, pub span: Span,
@ -379,6 +399,7 @@ pub struct AwaitExpr {
} }
#[ast_node("TemplateLiteral")] #[ast_node("TemplateLiteral")]
#[derive(Eq, Hash)]
pub struct Tpl { pub struct Tpl {
pub span: Span, pub span: Span,
@ -389,6 +410,7 @@ pub struct Tpl {
} }
#[ast_node("TaggedTemplateExpression")] #[ast_node("TaggedTemplateExpression")]
#[derive(Eq, Hash)]
pub struct TaggedTpl { pub struct TaggedTpl {
pub span: Span, pub span: Span,
@ -403,6 +425,7 @@ pub struct TaggedTpl {
} }
#[ast_node("TemplateElement")] #[ast_node("TemplateElement")]
#[derive(Eq, Hash)]
pub struct TplElement { pub struct TplElement {
pub span: Span, pub span: Span,
pub tail: bool, pub tail: bool,
@ -411,6 +434,7 @@ pub struct TplElement {
} }
#[ast_node("ParenthesisExpression")] #[ast_node("ParenthesisExpression")]
#[derive(Eq, Hash)]
pub struct ParenExpr { pub struct ParenExpr {
pub span: Span, pub span: Span,
@ -420,6 +444,7 @@ pub struct ParenExpr {
#[ast_node] #[ast_node]
#[allow(variant_size_differences)] #[allow(variant_size_differences)]
#[derive(Eq, Hash)]
pub enum ExprOrSuper { pub enum ExprOrSuper {
#[tag("Super")] #[tag("Super")]
Super(Super), Super(Super),
@ -429,12 +454,12 @@ pub enum ExprOrSuper {
} }
#[ast_node("Super")] #[ast_node("Super")]
#[derive(Copy)] #[derive(Eq, Hash, Copy)]
pub struct Super { pub struct Super {
pub span: Span, pub span: Span,
} }
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
#[cfg_attr(feature = "fold", derive(Fold))] #[cfg_attr(feature = "fold", derive(Fold))]
pub struct ExprOrSpread { pub struct ExprOrSpread {
#[serde(default)] #[serde(default)]
@ -455,6 +480,7 @@ impl Spanned for ExprOrSpread {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
#[allow(variant_size_differences)] #[allow(variant_size_differences)]
pub enum BlockStmtOrExpr { pub enum BlockStmtOrExpr {
#[tag("BlockStatement")] #[tag("BlockStatement")]
@ -464,6 +490,7 @@ pub enum BlockStmtOrExpr {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum PatOrExpr { pub enum PatOrExpr {
#[tag("ThisExpression")] #[tag("ThisExpression")]
#[tag("ArrayExpression")] #[tag("ArrayExpression")]
@ -545,6 +572,7 @@ impl From<Str> for Expr {
} }
#[ast_node("OptionalChainingExpression")] #[ast_node("OptionalChainingExpression")]
#[derive(Eq, Hash)]
pub struct OptChainExpr { pub struct OptChainExpr {
pub span: Span, pub span: Span,
pub expr: Box<Expr>, pub expr: Box<Expr>,

View File

@ -8,6 +8,7 @@ use swc_common::{ast_node, Span};
/// Common parts of function and method. /// Common parts of function and method.
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub struct Function { pub struct Function {
pub params: Vec<Pat>, pub params: Vec<Pat>,
@ -35,6 +36,7 @@ pub struct Function {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum PatOrTsParamProp { pub enum PatOrTsParamProp {
#[tag("TsParameterProperty")] #[tag("TsParameterProperty")]
TsParamProp(TsParamProp), TsParamProp(TsParamProp),

View File

@ -4,6 +4,7 @@ use swc_common::{ast_node, Span};
/// Ident with span. /// Ident with span.
#[ast_node("Identifier")] #[ast_node("Identifier")]
#[derive(Eq, Hash)]
pub struct Ident { pub struct Ident {
pub span: Span, pub span: Span,
#[serde(rename = "value")] #[serde(rename = "value")]
@ -17,6 +18,7 @@ pub struct Ident {
} }
#[ast_node("PrivateName")] #[ast_node("PrivateName")]
#[derive(Eq, Hash)]
pub struct PrivateName { pub struct PrivateName {
pub span: Span, pub span: Span,
pub id: Ident, pub id: Ident,

View File

@ -9,6 +9,7 @@ use swc_common::{ast_node, Span};
/// Used for `obj` property of `JSXMemberExpr`. /// Used for `obj` property of `JSXMemberExpr`.
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
#[allow(variant_size_differences)] #[allow(variant_size_differences)]
pub enum JSXObject { pub enum JSXObject {
#[tag("JSXMemberExpression")] #[tag("JSXMemberExpression")]
@ -18,6 +19,7 @@ pub enum JSXObject {
} }
#[ast_node("JSXMemberExpression")] #[ast_node("JSXMemberExpression")]
#[derive(Eq, Hash)]
pub struct JSXMemberExpr { pub struct JSXMemberExpr {
#[serde(rename = "object")] #[serde(rename = "object")]
#[span(lo)] #[span(lo)]
@ -30,6 +32,7 @@ pub struct JSXMemberExpr {
/// XML-based namespace syntax: /// XML-based namespace syntax:
#[ast_node("JSXNamespacedName")] #[ast_node("JSXNamespacedName")]
#[derive(Eq, Hash)]
pub struct JSXNamespacedName { pub struct JSXNamespacedName {
#[serde(rename = "namespace")] #[serde(rename = "namespace")]
#[span(lo)] #[span(lo)]
@ -39,12 +42,13 @@ pub struct JSXNamespacedName {
} }
#[ast_node("JSXEmptyExpression")] #[ast_node("JSXEmptyExpression")]
#[derive(Copy)] #[derive(Eq, Hash, Copy)]
pub struct JSXEmptyExpr { pub struct JSXEmptyExpr {
pub span: Span, pub span: Span,
} }
#[ast_node("JSXExpressionContainer")] #[ast_node("JSXExpressionContainer")]
#[derive(Eq, Hash)]
pub struct JSXExprContainer { pub struct JSXExprContainer {
pub span: Span, pub span: Span,
#[serde(rename = "expression")] #[serde(rename = "expression")]
@ -52,6 +56,7 @@ pub struct JSXExprContainer {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
#[allow(variant_size_differences)] #[allow(variant_size_differences)]
pub enum JSXExpr { pub enum JSXExpr {
#[tag("JSXEmptyExpression")] #[tag("JSXEmptyExpression")]
@ -61,6 +66,7 @@ pub enum JSXExpr {
} }
#[ast_node("JSXSpreadChild")] #[ast_node("JSXSpreadChild")]
#[derive(Eq, Hash)]
pub struct JSXSpreadChild { pub struct JSXSpreadChild {
pub span: Span, pub span: Span,
#[serde(rename = "expression")] #[serde(rename = "expression")]
@ -68,6 +74,7 @@ pub struct JSXSpreadChild {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum JSXElementName { pub enum JSXElementName {
#[tag("Identifier")] #[tag("Identifier")]
Ident(Ident), Ident(Ident),
@ -78,6 +85,7 @@ pub enum JSXElementName {
} }
#[ast_node("JSXOpeningElement")] #[ast_node("JSXOpeningElement")]
#[derive(Eq, Hash)]
pub struct JSXOpeningElement { pub struct JSXOpeningElement {
pub name: JSXElementName, pub name: JSXElementName,
@ -96,6 +104,7 @@ pub struct JSXOpeningElement {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
#[allow(variant_size_differences)] #[allow(variant_size_differences)]
pub enum JSXAttrOrSpread { pub enum JSXAttrOrSpread {
#[tag("JSXAttribute")] #[tag("JSXAttribute")]
@ -105,12 +114,14 @@ pub enum JSXAttrOrSpread {
} }
#[ast_node("JSXClosingElement")] #[ast_node("JSXClosingElement")]
#[derive(Eq, Hash)]
pub struct JSXClosingElement { pub struct JSXClosingElement {
pub span: Span, pub span: Span,
pub name: JSXElementName, pub name: JSXElementName,
} }
#[ast_node("JSXAttribute")] #[ast_node("JSXAttribute")]
#[derive(Eq, Hash)]
pub struct JSXAttr { pub struct JSXAttr {
pub span: Span, pub span: Span,
pub name: JSXAttrName, pub name: JSXAttrName,
@ -119,6 +130,7 @@ pub struct JSXAttr {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum JSXAttrName { pub enum JSXAttrName {
#[tag("Identifier")] #[tag("Identifier")]
Ident(Ident), Ident(Ident),
@ -127,6 +139,7 @@ pub enum JSXAttrName {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum JSXAttrValue { pub enum JSXAttrValue {
#[tag("StringLiteral")] #[tag("StringLiteral")]
#[tag("BooleanLiteral")] #[tag("BooleanLiteral")]
@ -147,6 +160,7 @@ pub enum JSXAttrValue {
} }
#[ast_node("JSXText")] #[ast_node("JSXText")]
#[derive(Eq, Hash)]
pub struct JSXText { pub struct JSXText {
pub span: Span, pub span: Span,
pub value: JsWord, pub value: JsWord,
@ -154,6 +168,7 @@ pub struct JSXText {
} }
#[ast_node("JSXElement")] #[ast_node("JSXElement")]
#[derive(Eq, Hash)]
pub struct JSXElement { pub struct JSXElement {
pub span: Span, pub span: Span,
pub opening: JSXOpeningElement, pub opening: JSXOpeningElement,
@ -162,6 +177,7 @@ pub struct JSXElement {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum JSXElementChild { pub enum JSXElementChild {
#[tag("JSXText")] #[tag("JSXText")]
JSXText(JSXText), JSXText(JSXText),
@ -180,6 +196,7 @@ pub enum JSXElementChild {
} }
#[ast_node("JSXFragment")] #[ast_node("JSXFragment")]
#[derive(Eq, Hash)]
pub struct JSXFragment { pub struct JSXFragment {
pub span: Span, pub span: Span,
@ -192,13 +209,13 @@ pub struct JSXFragment {
} }
#[ast_node("JSXOpeningFragment")] #[ast_node("JSXOpeningFragment")]
#[derive(Copy)] #[derive(Eq, Hash, Copy)]
pub struct JSXOpeningFragment { pub struct JSXOpeningFragment {
pub span: Span, pub span: Span,
} }
#[ast_node("JSXClosingFragment")] #[ast_node("JSXClosingFragment")]
#[derive(Copy)] #[derive(Eq, Hash, Copy)]
pub struct JSXClosingFragment { pub struct JSXClosingFragment {
pub span: Span, pub span: Span,
} }

View File

@ -85,7 +85,7 @@ mod typescript;
/// Represents a invalid node. /// Represents a invalid node.
#[ast_node("Invalid")] #[ast_node("Invalid")]
#[derive(Copy)] #[derive(Eq, Hash, Copy)]
pub struct Invalid { pub struct Invalid {
pub span: Span, pub span: Span,
} }

View File

@ -1,10 +1,15 @@
use crate::jsx::JSXText; use crate::jsx::JSXText;
use num_bigint::BigInt as BigIntValue; use num_bigint::BigInt as BigIntValue;
use std::fmt::{self, Display, Formatter}; use std::{
fmt::{self, Display, Formatter},
hash::{Hash, Hasher},
mem,
};
use swc_atoms::JsWord; use swc_atoms::JsWord;
use swc_common::{ast_node, Span}; use swc_common::{ast_node, Span};
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum Lit { pub enum Lit {
#[tag("StringLiteral")] #[tag("StringLiteral")]
Str(Str), Str(Str),
@ -29,6 +34,7 @@ pub enum Lit {
} }
#[ast_node("BigIntLiteral")] #[ast_node("BigIntLiteral")]
#[derive(Eq, Hash)]
pub struct BigInt { pub struct BigInt {
pub span: Span, pub span: Span,
#[cfg_attr(feature = "fold", fold(ignore))] #[cfg_attr(feature = "fold", fold(ignore))]
@ -36,6 +42,7 @@ pub struct BigInt {
} }
#[ast_node("StringLiteral")] #[ast_node("StringLiteral")]
#[derive(Eq, Hash)]
pub struct Str { pub struct Str {
pub span: Span, pub span: Span,
@ -53,19 +60,20 @@ impl Str {
} }
#[ast_node("BooleanLiteral")] #[ast_node("BooleanLiteral")]
#[derive(Copy)] #[derive(Copy, Eq, Hash)]
pub struct Bool { pub struct Bool {
pub span: Span, pub span: Span,
pub value: bool, pub value: bool,
} }
#[ast_node("NullLiteral")] #[ast_node("NullLiteral")]
#[derive(Copy)] #[derive(Copy, Eq, Hash)]
pub struct Null { pub struct Null {
pub span: Span, pub span: Span,
} }
#[ast_node("RegExpLiteral")] #[ast_node("RegExpLiteral")]
#[derive(Eq, Hash)]
pub struct Regex { pub struct Regex {
pub span: Span, pub span: Span,
@ -80,9 +88,35 @@ pub struct Regex {
#[derive(Copy)] #[derive(Copy)]
pub struct Number { pub struct Number {
pub span: Span, pub span: Span,
/// **Note**: This should not be `NaN`. Use [crate::Ident] to represent NaN.
///
/// If you store `NaN` in this field, a hash map will behave strangely.
pub value: f64, pub value: f64,
} }
impl Eq for Number {}
impl Hash for Number {
fn hash<H: Hasher>(&self, state: &mut H) {
fn integer_decode(val: f64) -> (u64, i16, i8) {
let bits: u64 = unsafe { mem::transmute(val) };
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
let mantissa = if exponent == 0 {
(bits & 0xfffffffffffff) << 1
} else {
(bits & 0xfffffffffffff) | 0x10000000000000
};
exponent -= 1023 + 52;
(mantissa, exponent, sign)
}
self.span.hash(state);
integer_decode(self.value).hash(state);
}
}
impl Display for Number { impl Display for Number {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if self.value.is_infinite() { if self.value.is_infinite() {

View File

@ -3,6 +3,7 @@ use swc_atoms::JsWord;
use swc_common::{ast_node, Span}; use swc_common::{ast_node, Span};
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum Program { pub enum Program {
#[tag("Module")] #[tag("Module")]
Module(Module), Module(Module),
@ -11,6 +12,7 @@ pub enum Program {
} }
#[ast_node("Module")] #[ast_node("Module")]
#[derive(Eq, Hash)]
pub struct Module { pub struct Module {
pub span: Span, pub span: Span,
@ -21,6 +23,7 @@ pub struct Module {
} }
#[ast_node("Script")] #[ast_node("Script")]
#[derive(Eq, Hash)]
pub struct Script { pub struct Script {
pub span: Span, pub span: Span,
@ -31,6 +34,7 @@ pub struct Script {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum ModuleItem { pub enum ModuleItem {
#[tag("ImportDeclaration")] #[tag("ImportDeclaration")]
#[tag("ExportDeclaration")] #[tag("ExportDeclaration")]

View File

@ -8,6 +8,7 @@ use crate::{
use swc_common::{ast_node, Span}; use swc_common::{ast_node, Span};
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum ModuleDecl { pub enum ModuleDecl {
#[tag("ImportDeclaration")] #[tag("ImportDeclaration")]
Import(ImportDecl), Import(ImportDecl),
@ -38,6 +39,7 @@ pub enum ModuleDecl {
} }
#[ast_node("ExportDefaultExpression")] #[ast_node("ExportDefaultExpression")]
#[derive(Eq, Hash)]
pub struct ExportDefaultExpr { pub struct ExportDefaultExpr {
pub span: Span, pub span: Span,
@ -46,6 +48,7 @@ pub struct ExportDefaultExpr {
} }
#[ast_node("ExportDeclaration")] #[ast_node("ExportDeclaration")]
#[derive(Eq, Hash)]
pub struct ExportDecl { pub struct ExportDecl {
pub span: Span, pub span: Span,
@ -54,6 +57,7 @@ pub struct ExportDecl {
} }
#[ast_node("ImportDeclaration")] #[ast_node("ImportDeclaration")]
#[derive(Eq, Hash)]
pub struct ImportDecl { pub struct ImportDecl {
pub span: Span, pub span: Span,
@ -69,6 +73,7 @@ pub struct ImportDecl {
/// `export * from 'mod'` /// `export * from 'mod'`
#[ast_node("ExportAllDeclaration")] #[ast_node("ExportAllDeclaration")]
#[derive(Eq, Hash)]
pub struct ExportAll { pub struct ExportAll {
pub span: Span, pub span: Span,
@ -79,6 +84,7 @@ pub struct ExportAll {
/// `export { foo } from 'mod'` /// `export { foo } from 'mod'`
/// `export { foo as bar } from 'mod'` /// `export { foo as bar } from 'mod'`
#[ast_node("ExportNamedDeclaration")] #[ast_node("ExportNamedDeclaration")]
#[derive(Eq, Hash)]
pub struct NamedExport { pub struct NamedExport {
pub span: Span, pub span: Span,
@ -92,6 +98,7 @@ pub struct NamedExport {
} }
#[ast_node("ExportDefaultDeclaration")] #[ast_node("ExportDefaultDeclaration")]
#[derive(Eq, Hash)]
pub struct ExportDefaultDecl { pub struct ExportDefaultDecl {
pub span: Span, pub span: Span,
@ -99,6 +106,7 @@ pub struct ExportDefaultDecl {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum DefaultDecl { pub enum DefaultDecl {
#[tag("ClassExpression")] #[tag("ClassExpression")]
Class(ClassExpr), Class(ClassExpr),
@ -111,6 +119,7 @@ pub enum DefaultDecl {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum ImportSpecifier { pub enum ImportSpecifier {
#[tag("ImportSpecifier")] #[tag("ImportSpecifier")]
Specific(ImportSpecific), Specific(ImportSpecific),
@ -122,6 +131,7 @@ pub enum ImportSpecifier {
/// e.g. `import foo from 'mod.js'` /// e.g. `import foo from 'mod.js'`
#[ast_node("ImportDefaultSpecifier")] #[ast_node("ImportDefaultSpecifier")]
#[derive(Eq, Hash)]
pub struct ImportDefault { pub struct ImportDefault {
pub span: Span, pub span: Span,
@ -129,6 +139,7 @@ pub struct ImportDefault {
} }
/// e.g. `import * as foo from 'mod.js'`. /// e.g. `import * as foo from 'mod.js'`.
#[ast_node("ImportNamespaceSpecifier")] #[ast_node("ImportNamespaceSpecifier")]
#[derive(Eq, Hash)]
pub struct ImportStarAs { pub struct ImportStarAs {
pub span: Span, pub span: Span,
@ -138,6 +149,7 @@ pub struct ImportStarAs {
/// e.g. local = bar, imported = Some(foo) for `import { foo as bar } from /// e.g. local = bar, imported = Some(foo) for `import { foo as bar } from
/// 'mod.js'` /// 'mod.js'`
#[ast_node("ImportSpecifier")] #[ast_node("ImportSpecifier")]
#[derive(Eq, Hash)]
pub struct ImportSpecific { pub struct ImportSpecific {
pub span: Span, pub span: Span,
@ -148,8 +160,9 @@ pub struct ImportSpecific {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum ExportSpecifier { pub enum ExportSpecifier {
#[tag("ExportNamespaceSpecifer")] #[tag("ExportNamespaceSpecifier")]
Namespace(NamespaceExportSpecifier), Namespace(NamespaceExportSpecifier),
#[tag("ExportDefaultSpecifier")] #[tag("ExportDefaultSpecifier")]
@ -160,7 +173,8 @@ pub enum ExportSpecifier {
} }
/// `export * as foo from 'src';` /// `export * as foo from 'src';`
#[ast_node("ExportNamespaceSpecifer")] #[ast_node("ExportNamespaceSpecifier")]
#[derive(Eq, Hash)]
pub struct NamespaceExportSpecifier { pub struct NamespaceExportSpecifier {
pub span: Span, pub span: Span,
@ -168,12 +182,14 @@ pub struct NamespaceExportSpecifier {
} }
#[ast_node("ExportDefaultSpecifier")] #[ast_node("ExportDefaultSpecifier")]
#[derive(Eq, Hash)]
pub struct DefaultExportSpecifier { pub struct DefaultExportSpecifier {
#[span] #[span]
pub exported: Ident, pub exported: Ident,
} }
#[ast_node("ExportSpecifier")] #[ast_node("ExportSpecifier")]
#[derive(Eq, Hash)]
pub struct NamedExportSpecifier { pub struct NamedExportSpecifier {
pub span: Span, pub span: Span,
/// `foo` in `export { foo as bar }` /// `foo` in `export { foo as bar }`

View File

@ -2,6 +2,7 @@ use crate::{expr::Expr, ident::Ident, prop::PropName, typescript::TsTypeAnn, Inv
use swc_common::{ast_node, Span}; use swc_common::{ast_node, Span};
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum Pat { pub enum Pat {
#[tag("Identifier")] #[tag("Identifier")]
Ident(Ident), Ident(Ident),
@ -27,6 +28,7 @@ pub enum Pat {
} }
#[ast_node("ArrayPattern")] #[ast_node("ArrayPattern")]
#[derive(Eq, Hash)]
pub struct ArrayPat { pub struct ArrayPat {
pub span: Span, pub span: Span,
@ -38,6 +40,7 @@ pub struct ArrayPat {
} }
#[ast_node("ObjectPattern")] #[ast_node("ObjectPattern")]
#[derive(Eq, Hash)]
pub struct ObjectPat { pub struct ObjectPat {
pub span: Span, pub span: Span,
@ -49,6 +52,7 @@ pub struct ObjectPat {
} }
#[ast_node("AssignmentPattern")] #[ast_node("AssignmentPattern")]
#[derive(Eq, Hash)]
pub struct AssignPat { pub struct AssignPat {
pub span: Span, pub span: Span,
@ -62,6 +66,7 @@ pub struct AssignPat {
/// EsTree `RestElement` /// EsTree `RestElement`
#[ast_node("RestElement")] #[ast_node("RestElement")]
#[derive(Eq, Hash)]
pub struct RestPat { pub struct RestPat {
pub span: Span, pub span: Span,
@ -76,6 +81,7 @@ pub struct RestPat {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum ObjectPatProp { pub enum ObjectPatProp {
#[tag("KeyValuePatternProperty")] #[tag("KeyValuePatternProperty")]
KeyValue(KeyValuePatProp), KeyValue(KeyValuePatProp),
@ -89,6 +95,7 @@ pub enum ObjectPatProp {
/// `{key: value}` /// `{key: value}`
#[ast_node("KeyValuePatternProperty")] #[ast_node("KeyValuePatternProperty")]
#[derive(Eq, Hash)]
pub struct KeyValuePatProp { pub struct KeyValuePatProp {
#[span(lo)] #[span(lo)]
pub key: PropName, pub key: PropName,
@ -98,6 +105,7 @@ pub struct KeyValuePatProp {
} }
/// `{key}` or `{key = value}` /// `{key}` or `{key = value}`
#[ast_node("AssignmentPatternProperty")] #[ast_node("AssignmentPatternProperty")]
#[derive(Eq, Hash)]
pub struct AssignPatProp { pub struct AssignPatProp {
pub span: Span, pub span: Span,
pub key: Ident, pub key: Ident,

View File

@ -10,6 +10,7 @@ use crate::{
use swc_common::{ast_node, Span}; use swc_common::{ast_node, Span};
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum Prop { pub enum Prop {
/// `a` in `{ a, }` /// `a` in `{ a, }`
#[tag("Identifier")] #[tag("Identifier")]
@ -34,6 +35,7 @@ pub enum Prop {
} }
#[ast_node("KeyValueProperty")] #[ast_node("KeyValueProperty")]
#[derive(Eq, Hash)]
pub struct KeyValueProp { pub struct KeyValueProp {
#[span(lo)] #[span(lo)]
pub key: PropName, pub key: PropName,
@ -43,13 +45,16 @@ pub struct KeyValueProp {
} }
#[ast_node("AssignmentProperty")] #[ast_node("AssignmentProperty")]
#[derive(Eq, Hash)]
pub struct AssignProp { pub struct AssignProp {
#[span(lo)] #[span(lo)]
pub key: Ident, pub key: Ident,
#[span(hi)] #[span(hi)]
pub value: Box<Expr>, pub value: Box<Expr>,
} }
#[ast_node("GetterProperty")] #[ast_node("GetterProperty")]
#[derive(Eq, Hash)]
pub struct GetterProp { pub struct GetterProp {
pub span: Span, pub span: Span,
pub key: PropName, pub key: PropName,
@ -59,6 +64,7 @@ pub struct GetterProp {
pub body: Option<BlockStmt>, pub body: Option<BlockStmt>,
} }
#[ast_node("SetterProperty")] #[ast_node("SetterProperty")]
#[derive(Eq, Hash)]
pub struct SetterProp { pub struct SetterProp {
pub span: Span, pub span: Span,
pub key: PropName, pub key: PropName,
@ -67,6 +73,7 @@ pub struct SetterProp {
pub body: Option<BlockStmt>, pub body: Option<BlockStmt>,
} }
#[ast_node("MethodProperty")] #[ast_node("MethodProperty")]
#[derive(Eq, Hash)]
pub struct MethodProp { pub struct MethodProp {
#[span(lo)] #[span(lo)]
pub key: PropName, pub key: PropName,
@ -77,6 +84,7 @@ pub struct MethodProp {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum PropName { pub enum PropName {
#[tag("Identifier")] #[tag("Identifier")]
Ident(Ident), Ident(Ident),
@ -91,6 +99,7 @@ pub enum PropName {
} }
#[ast_node("Computed")] #[ast_node("Computed")]
#[derive(Eq, Hash)]
pub struct ComputedPropName { pub struct ComputedPropName {
/// Span including `[` and `]`. /// Span including `[` and `]`.
pub span: Span, pub span: Span,

View File

@ -8,6 +8,7 @@ use swc_common::{ast_node, Span};
/// Use when only block statements are allowed. /// Use when only block statements are allowed.
#[ast_node("BlockStatement")] #[ast_node("BlockStatement")]
#[derive(Eq, Hash)]
pub struct BlockStmt { pub struct BlockStmt {
/// Span including the braces. /// Span including the braces.
pub span: Span, pub span: Span,
@ -16,6 +17,7 @@ pub struct BlockStmt {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum Stmt { pub enum Stmt {
#[tag("BlockStatement")] #[tag("BlockStatement")]
Block(BlockStmt), Block(BlockStmt),
@ -83,6 +85,7 @@ pub enum Stmt {
} }
#[ast_node("ExpressionStatement")] #[ast_node("ExpressionStatement")]
#[derive(Eq, Hash)]
pub struct ExprStmt { pub struct ExprStmt {
pub span: Span, pub span: Span,
#[serde(rename = "expression")] #[serde(rename = "expression")]
@ -90,19 +93,20 @@ pub struct ExprStmt {
} }
#[ast_node("EmptyStatement")] #[ast_node("EmptyStatement")]
#[derive(Copy)] #[derive(Eq, Hash, Copy)]
pub struct EmptyStmt { pub struct EmptyStmt {
/// Span of semicolon. /// Span of semicolon.
pub span: Span, pub span: Span,
} }
#[ast_node("DebuggerStatement")] #[ast_node("DebuggerStatement")]
#[derive(Copy)] #[derive(Eq, Hash, Copy)]
pub struct DebuggerStmt { pub struct DebuggerStmt {
pub span: Span, pub span: Span,
} }
#[ast_node("WithStatement")] #[ast_node("WithStatement")]
#[derive(Eq, Hash)]
pub struct WithStmt { pub struct WithStmt {
pub span: Span, pub span: Span,
#[serde(rename = "object")] #[serde(rename = "object")]
@ -111,6 +115,7 @@ pub struct WithStmt {
} }
#[ast_node("ReturnStatement")] #[ast_node("ReturnStatement")]
#[derive(Eq, Hash)]
pub struct ReturnStmt { pub struct ReturnStmt {
pub span: Span, pub span: Span,
#[serde(default, rename = "argument")] #[serde(default, rename = "argument")]
@ -118,6 +123,7 @@ pub struct ReturnStmt {
} }
#[ast_node("LabeledStatement")] #[ast_node("LabeledStatement")]
#[derive(Eq, Hash)]
pub struct LabeledStmt { pub struct LabeledStmt {
pub span: Span, pub span: Span,
pub label: Ident, pub label: Ident,
@ -125,6 +131,7 @@ pub struct LabeledStmt {
} }
#[ast_node("BreakStatement")] #[ast_node("BreakStatement")]
#[derive(Eq, Hash)]
pub struct BreakStmt { pub struct BreakStmt {
pub span: Span, pub span: Span,
#[serde(default)] #[serde(default)]
@ -132,6 +139,7 @@ pub struct BreakStmt {
} }
#[ast_node("ContinueStatement")] #[ast_node("ContinueStatement")]
#[derive(Eq, Hash)]
pub struct ContinueStmt { pub struct ContinueStmt {
pub span: Span, pub span: Span,
#[serde(default)] #[serde(default)]
@ -139,6 +147,7 @@ pub struct ContinueStmt {
} }
#[ast_node("IfStatement")] #[ast_node("IfStatement")]
#[derive(Eq, Hash)]
pub struct IfStmt { pub struct IfStmt {
pub span: Span, pub span: Span,
pub test: Box<Expr>, pub test: Box<Expr>,
@ -151,6 +160,7 @@ pub struct IfStmt {
} }
#[ast_node("SwitchStatement")] #[ast_node("SwitchStatement")]
#[derive(Eq, Hash)]
pub struct SwitchStmt { pub struct SwitchStmt {
pub span: Span, pub span: Span,
pub discriminant: Box<Expr>, pub discriminant: Box<Expr>,
@ -158,6 +168,7 @@ pub struct SwitchStmt {
} }
#[ast_node("ThrowStatement")] #[ast_node("ThrowStatement")]
#[derive(Eq, Hash)]
pub struct ThrowStmt { pub struct ThrowStmt {
pub span: Span, pub span: Span,
#[serde(rename = "argument")] #[serde(rename = "argument")]
@ -165,6 +176,7 @@ pub struct ThrowStmt {
} }
#[ast_node("TryStatement")] #[ast_node("TryStatement")]
#[derive(Eq, Hash)]
pub struct TryStmt { pub struct TryStmt {
pub span: Span, pub span: Span,
@ -178,6 +190,7 @@ pub struct TryStmt {
} }
#[ast_node("WhileStatement")] #[ast_node("WhileStatement")]
#[derive(Eq, Hash)]
pub struct WhileStmt { pub struct WhileStmt {
pub span: Span, pub span: Span,
pub test: Box<Expr>, pub test: Box<Expr>,
@ -185,6 +198,7 @@ pub struct WhileStmt {
} }
#[ast_node("DoWhileStatement")] #[ast_node("DoWhileStatement")]
#[derive(Eq, Hash)]
pub struct DoWhileStmt { pub struct DoWhileStmt {
pub span: Span, pub span: Span,
pub test: Box<Expr>, pub test: Box<Expr>,
@ -192,6 +206,7 @@ pub struct DoWhileStmt {
} }
#[ast_node("ForStatement")] #[ast_node("ForStatement")]
#[derive(Eq, Hash)]
pub struct ForStmt { pub struct ForStmt {
pub span: Span, pub span: Span,
@ -208,6 +223,7 @@ pub struct ForStmt {
} }
#[ast_node("ForInStatement")] #[ast_node("ForInStatement")]
#[derive(Eq, Hash)]
pub struct ForInStmt { pub struct ForInStmt {
pub span: Span, pub span: Span,
pub left: VarDeclOrPat, pub left: VarDeclOrPat,
@ -216,6 +232,7 @@ pub struct ForInStmt {
} }
#[ast_node("ForOfStatement")] #[ast_node("ForOfStatement")]
#[derive(Eq, Hash)]
pub struct ForOfStmt { pub struct ForOfStmt {
pub span: Span, pub span: Span,
/// Span of the await token. /// Span of the await token.
@ -231,6 +248,7 @@ pub struct ForOfStmt {
} }
#[ast_node("SwitchCase")] #[ast_node("SwitchCase")]
#[derive(Eq, Hash)]
pub struct SwitchCase { pub struct SwitchCase {
pub span: Span, pub span: Span,
@ -243,6 +261,7 @@ pub struct SwitchCase {
} }
#[ast_node("CatchClause")] #[ast_node("CatchClause")]
#[derive(Eq, Hash)]
pub struct CatchClause { pub struct CatchClause {
pub span: Span, pub span: Span,
/// es2019 /// es2019
@ -256,6 +275,7 @@ pub struct CatchClause {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum VarDeclOrPat { pub enum VarDeclOrPat {
#[tag("VariableDeclaration")] #[tag("VariableDeclaration")]
VarDecl(VarDecl), VarDecl(VarDecl),
@ -265,6 +285,7 @@ pub enum VarDeclOrPat {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
#[allow(variant_size_differences)] #[allow(variant_size_differences)]
pub enum VarDeclOrExpr { pub enum VarDeclOrExpr {
#[tag("VariableDeclaration")] #[tag("VariableDeclaration")]

View File

@ -19,6 +19,7 @@ use swc_common::Fold;
use swc_common::{ast_node, Span}; use swc_common::{ast_node, Span};
#[ast_node("TsTypeAnnotation")] #[ast_node("TsTypeAnnotation")]
#[derive(Eq, Hash)]
pub struct TsTypeAnn { pub struct TsTypeAnn {
pub span: Span, pub span: Span,
#[serde(rename = "typeAnnotation")] #[serde(rename = "typeAnnotation")]
@ -26,6 +27,7 @@ pub struct TsTypeAnn {
} }
#[ast_node("TsTypeParameterDeclaration")] #[ast_node("TsTypeParameterDeclaration")]
#[derive(Eq, Hash)]
pub struct TsTypeParamDecl { pub struct TsTypeParamDecl {
pub span: Span, pub span: Span,
#[serde(rename = "parameters")] #[serde(rename = "parameters")]
@ -33,6 +35,7 @@ pub struct TsTypeParamDecl {
} }
#[ast_node("TsTypeParameter")] #[ast_node("TsTypeParameter")]
#[derive(Eq, Hash)]
pub struct TsTypeParam { pub struct TsTypeParam {
pub span: Span, pub span: Span,
pub name: Ident, pub name: Ident,
@ -45,12 +48,14 @@ pub struct TsTypeParam {
} }
#[ast_node("TsTypeParameterInstantiation")] #[ast_node("TsTypeParameterInstantiation")]
#[derive(Eq, Hash)]
pub struct TsTypeParamInstantiation { pub struct TsTypeParamInstantiation {
pub span: Span, pub span: Span,
pub params: Vec<Box<TsType>>, pub params: Vec<Box<TsType>>,
} }
#[ast_node("TsTypeCastExpression")] #[ast_node("TsTypeCastExpression")]
#[derive(Eq, Hash)]
pub struct TsTypeCastExpr { pub struct TsTypeCastExpr {
pub span: Span, pub span: Span,
#[serde(rename = "expression")] #[serde(rename = "expression")]
@ -60,6 +65,7 @@ pub struct TsTypeCastExpr {
} }
#[ast_node("TsParameterProperty")] #[ast_node("TsParameterProperty")]
#[derive(Eq, Hash)]
pub struct TsParamProp { pub struct TsParamProp {
pub span: Span, pub span: Span,
#[serde(default)] #[serde(default)]
@ -72,6 +78,7 @@ pub struct TsParamProp {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum TsParamPropParam { pub enum TsParamPropParam {
#[tag("Identifier")] #[tag("Identifier")]
Ident(Ident), Ident(Ident),
@ -81,6 +88,7 @@ pub enum TsParamPropParam {
} }
#[ast_node("TsQualifiedName")] #[ast_node("TsQualifiedName")]
#[derive(Eq, Hash)]
pub struct TsQualifiedName { pub struct TsQualifiedName {
#[span(lo)] #[span(lo)]
pub left: TsEntityName, pub left: TsEntityName,
@ -89,6 +97,7 @@ pub struct TsQualifiedName {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
#[allow(variant_size_differences)] #[allow(variant_size_differences)]
pub enum TsEntityName { pub enum TsEntityName {
#[tag("TsQualifiedName")] #[tag("TsQualifiedName")]
@ -99,6 +108,7 @@ pub enum TsEntityName {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum TsSignatureDecl { pub enum TsSignatureDecl {
#[tag("TsCallSignatureDeclaration")] #[tag("TsCallSignatureDeclaration")]
TsCallSignatureDecl(TsCallSignatureDecl), TsCallSignatureDecl(TsCallSignatureDecl),
@ -121,6 +131,7 @@ pub enum TsSignatureDecl {
// ================ // ================
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum TsTypeElement { pub enum TsTypeElement {
#[tag("TsCallSignatureDeclaration")] #[tag("TsCallSignatureDeclaration")]
TsCallSignatureDecl(TsCallSignatureDecl), TsCallSignatureDecl(TsCallSignatureDecl),
@ -139,6 +150,7 @@ pub enum TsTypeElement {
} }
#[ast_node("TsCallSignatureDeclaration")] #[ast_node("TsCallSignatureDeclaration")]
#[derive(Eq, Hash)]
pub struct TsCallSignatureDecl { pub struct TsCallSignatureDecl {
pub span: Span, pub span: Span,
pub params: Vec<TsFnParam>, pub params: Vec<TsFnParam>,
@ -149,6 +161,7 @@ pub struct TsCallSignatureDecl {
} }
#[ast_node("TsConstructSignatureDeclaration")] #[ast_node("TsConstructSignatureDeclaration")]
#[derive(Eq, Hash)]
pub struct TsConstructSignatureDecl { pub struct TsConstructSignatureDecl {
pub span: Span, pub span: Span,
pub params: Vec<TsFnParam>, pub params: Vec<TsFnParam>,
@ -159,6 +172,7 @@ pub struct TsConstructSignatureDecl {
} }
#[ast_node("TsPropertySignature")] #[ast_node("TsPropertySignature")]
#[derive(Eq, Hash)]
pub struct TsPropertySignature { pub struct TsPropertySignature {
pub span: Span, pub span: Span,
pub readonly: bool, pub readonly: bool,
@ -175,6 +189,7 @@ pub struct TsPropertySignature {
} }
#[ast_node("TsMethodSignature")] #[ast_node("TsMethodSignature")]
#[derive(Eq, Hash)]
pub struct TsMethodSignature { pub struct TsMethodSignature {
pub span: Span, pub span: Span,
pub readonly: bool, pub readonly: bool,
@ -189,6 +204,7 @@ pub struct TsMethodSignature {
} }
#[ast_node("TsIndexSignature")] #[ast_node("TsIndexSignature")]
#[derive(Eq, Hash)]
pub struct TsIndexSignature { pub struct TsIndexSignature {
pub params: Vec<TsFnParam>, pub params: Vec<TsFnParam>,
#[serde(default, rename = "typeAnnotation")] #[serde(default, rename = "typeAnnotation")]
@ -203,6 +219,7 @@ pub struct TsIndexSignature {
// ================ // ================
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum TsType { pub enum TsType {
#[tag("TsKeywordType")] #[tag("TsKeywordType")]
TsKeywordType(TsKeywordType), TsKeywordType(TsKeywordType),
@ -268,6 +285,7 @@ pub enum TsType {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum TsFnOrConstructorType { pub enum TsFnOrConstructorType {
#[tag("TsFunctionType")] #[tag("TsFunctionType")]
TsFnType(TsFnType), TsFnType(TsFnType),
@ -300,12 +318,13 @@ impl From<TsIntersectionType> for TsType {
} }
#[ast_node("TsKeywordType")] #[ast_node("TsKeywordType")]
#[derive(Eq, Hash)]
pub struct TsKeywordType { pub struct TsKeywordType {
pub span: Span, pub span: Span,
pub kind: TsKeywordTypeKind, pub kind: TsKeywordTypeKind,
} }
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "fold", derive(Fold))] #[cfg_attr(feature = "fold", derive(Fold))]
pub enum TsKeywordTypeKind { pub enum TsKeywordTypeKind {
#[serde(rename = "any")] #[serde(rename = "any")]
@ -346,11 +365,13 @@ pub enum TsKeywordTypeKind {
} }
#[ast_node("TsThisType")] #[ast_node("TsThisType")]
#[derive(Copy, Eq, Hash)]
pub struct TsThisType { pub struct TsThisType {
pub span: Span, pub span: Span,
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum TsFnParam { pub enum TsFnParam {
#[tag("Identifier")] #[tag("Identifier")]
Ident(Ident), Ident(Ident),
@ -366,6 +387,7 @@ pub enum TsFnParam {
} }
#[ast_node("TsFunctionType")] #[ast_node("TsFunctionType")]
#[derive(Eq, Hash)]
pub struct TsFnType { pub struct TsFnType {
pub span: Span, pub span: Span,
pub params: Vec<TsFnParam>, pub params: Vec<TsFnParam>,
@ -377,6 +399,7 @@ pub struct TsFnType {
} }
#[ast_node("TsConstructorType")] #[ast_node("TsConstructorType")]
#[derive(Eq, Hash)]
pub struct TsConstructorType { pub struct TsConstructorType {
pub span: Span, pub span: Span,
pub params: Vec<TsFnParam>, pub params: Vec<TsFnParam>,
@ -387,6 +410,7 @@ pub struct TsConstructorType {
} }
#[ast_node("TsTypeReference")] #[ast_node("TsTypeReference")]
#[derive(Eq, Hash)]
pub struct TsTypeRef { pub struct TsTypeRef {
pub span: Span, pub span: Span,
pub type_name: TsEntityName, pub type_name: TsEntityName,
@ -395,6 +419,7 @@ pub struct TsTypeRef {
} }
#[ast_node("TsTypePredicate")] #[ast_node("TsTypePredicate")]
#[derive(Eq, Hash)]
pub struct TsTypePredicate { pub struct TsTypePredicate {
pub span: Span, pub span: Span,
pub asserts: bool, pub asserts: bool,
@ -404,6 +429,7 @@ pub struct TsTypePredicate {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
#[allow(variant_size_differences)] #[allow(variant_size_differences)]
pub enum TsThisTypeOrIdent { pub enum TsThisTypeOrIdent {
#[tag("TsThisType")] #[tag("TsThisType")]
@ -415,12 +441,14 @@ pub enum TsThisTypeOrIdent {
/// `typeof` operator /// `typeof` operator
#[ast_node("TsTypeQuery")] #[ast_node("TsTypeQuery")]
#[derive(Eq, Hash)]
pub struct TsTypeQuery { pub struct TsTypeQuery {
pub span: Span, pub span: Span,
pub expr_name: TsTypeQueryExpr, pub expr_name: TsTypeQueryExpr,
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum TsTypeQueryExpr { pub enum TsTypeQueryExpr {
#[tag("TsQualifiedName")] #[tag("TsQualifiedName")]
#[tag("Identifier")] #[tag("Identifier")]
@ -430,6 +458,7 @@ pub enum TsTypeQueryExpr {
} }
#[ast_node("TsImportType")] #[ast_node("TsImportType")]
#[derive(Eq, Hash)]
pub struct TsImportType { pub struct TsImportType {
pub span: Span, pub span: Span,
#[serde(rename = "argument")] #[serde(rename = "argument")]
@ -440,24 +469,28 @@ pub struct TsImportType {
} }
#[ast_node("TsTypeLiteral")] #[ast_node("TsTypeLiteral")]
#[derive(Eq, Hash)]
pub struct TsTypeLit { pub struct TsTypeLit {
pub span: Span, pub span: Span,
pub members: Vec<TsTypeElement>, pub members: Vec<TsTypeElement>,
} }
#[ast_node("TsArrayType")] #[ast_node("TsArrayType")]
#[derive(Eq, Hash)]
pub struct TsArrayType { pub struct TsArrayType {
pub span: Span, pub span: Span,
pub elem_type: Box<TsType>, pub elem_type: Box<TsType>,
} }
#[ast_node("TsTupleType")] #[ast_node("TsTupleType")]
#[derive(Eq, Hash)]
pub struct TsTupleType { pub struct TsTupleType {
pub span: Span, pub span: Span,
pub elem_types: Vec<Box<TsType>>, pub elem_types: Vec<Box<TsType>>,
} }
#[ast_node("TsOptionalType")] #[ast_node("TsOptionalType")]
#[derive(Eq, Hash)]
pub struct TsOptionalType { pub struct TsOptionalType {
pub span: Span, pub span: Span,
#[serde(rename = "typeAnnotation")] #[serde(rename = "typeAnnotation")]
@ -465,6 +498,7 @@ pub struct TsOptionalType {
} }
#[ast_node("TsRestType")] #[ast_node("TsRestType")]
#[derive(Eq, Hash)]
pub struct TsRestType { pub struct TsRestType {
pub span: Span, pub span: Span,
#[serde(rename = "typeAnnotation")] #[serde(rename = "typeAnnotation")]
@ -472,6 +506,7 @@ pub struct TsRestType {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum TsUnionOrIntersectionType { pub enum TsUnionOrIntersectionType {
#[tag("TsUnionType")] #[tag("TsUnionType")]
TsUnionType(TsUnionType), TsUnionType(TsUnionType),
@ -481,18 +516,21 @@ pub enum TsUnionOrIntersectionType {
} }
#[ast_node("TsUnionType")] #[ast_node("TsUnionType")]
#[derive(Eq, Hash)]
pub struct TsUnionType { pub struct TsUnionType {
pub span: Span, pub span: Span,
pub types: Vec<Box<TsType>>, pub types: Vec<Box<TsType>>,
} }
#[ast_node("TsIntersectionType")] #[ast_node("TsIntersectionType")]
#[derive(Eq, Hash)]
pub struct TsIntersectionType { pub struct TsIntersectionType {
pub span: Span, pub span: Span,
pub types: Vec<Box<TsType>>, pub types: Vec<Box<TsType>>,
} }
#[ast_node("TsConditionalType")] #[ast_node("TsConditionalType")]
#[derive(Eq, Hash)]
pub struct TsConditionalType { pub struct TsConditionalType {
pub span: Span, pub span: Span,
pub check_type: Box<TsType>, pub check_type: Box<TsType>,
@ -502,12 +540,14 @@ pub struct TsConditionalType {
} }
#[ast_node("TsInferType")] #[ast_node("TsInferType")]
#[derive(Eq, Hash)]
pub struct TsInferType { pub struct TsInferType {
pub span: Span, pub span: Span,
pub type_param: TsTypeParam, pub type_param: TsTypeParam,
} }
#[ast_node("TsParenthesizedType")] #[ast_node("TsParenthesizedType")]
#[derive(Eq, Hash)]
pub struct TsParenthesizedType { pub struct TsParenthesizedType {
pub span: Span, pub span: Span,
#[serde(rename = "typeAnnotation")] #[serde(rename = "typeAnnotation")]
@ -515,6 +555,7 @@ pub struct TsParenthesizedType {
} }
#[ast_node("TsTypeOperator")] #[ast_node("TsTypeOperator")]
#[derive(Eq, Hash)]
pub struct TsTypeOperator { pub struct TsTypeOperator {
pub span: Span, pub span: Span,
pub op: TsTypeOperatorOp, pub op: TsTypeOperatorOp,
@ -522,7 +563,7 @@ pub struct TsTypeOperator {
pub type_ann: Box<TsType>, pub type_ann: Box<TsType>,
} }
#[derive(StringEnum, Clone, Copy, PartialEq, Eq)] #[derive(StringEnum, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "fold", derive(Fold))] #[cfg_attr(feature = "fold", derive(Fold))]
pub enum TsTypeOperatorOp { pub enum TsTypeOperatorOp {
/// `keyof` /// `keyof`
@ -534,6 +575,7 @@ pub enum TsTypeOperatorOp {
} }
#[ast_node("TsIndexedAccessType")] #[ast_node("TsIndexedAccessType")]
#[derive(Eq, Hash)]
pub struct TsIndexedAccessType { pub struct TsIndexedAccessType {
pub span: Span, pub span: Span,
pub readonly: bool, pub readonly: bool,
@ -542,7 +584,7 @@ pub struct TsIndexedAccessType {
pub index_type: Box<TsType>, pub index_type: Box<TsType>,
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "fold", derive(Fold))] #[cfg_attr(feature = "fold", derive(Fold))]
pub enum TruePlusMinus { pub enum TruePlusMinus {
True, True,
@ -605,6 +647,7 @@ impl<'de> Deserialize<'de> for TruePlusMinus {
} }
#[ast_node("TsMappedType")] #[ast_node("TsMappedType")]
#[derive(Eq, Hash)]
pub struct TsMappedType { pub struct TsMappedType {
pub span: Span, pub span: Span,
#[serde(default)] #[serde(default)]
@ -617,6 +660,7 @@ pub struct TsMappedType {
} }
#[ast_node("TsLiteralType")] #[ast_node("TsLiteralType")]
#[derive(Eq, Hash)]
pub struct TsLitType { pub struct TsLitType {
pub span: Span, pub span: Span,
#[serde(rename = "literal")] #[serde(rename = "literal")]
@ -624,6 +668,7 @@ pub struct TsLitType {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum TsLit { pub enum TsLit {
#[tag("NumericLiteral")] #[tag("NumericLiteral")]
Number(Number), Number(Number),
@ -640,6 +685,7 @@ pub enum TsLit {
// // ================ // // ================
#[ast_node("TsInterfaceDeclaration")] #[ast_node("TsInterfaceDeclaration")]
#[derive(Eq, Hash)]
pub struct TsInterfaceDecl { pub struct TsInterfaceDecl {
pub span: Span, pub span: Span,
pub id: Ident, pub id: Ident,
@ -651,12 +697,14 @@ pub struct TsInterfaceDecl {
} }
#[ast_node("TsInterfaceBody")] #[ast_node("TsInterfaceBody")]
#[derive(Eq, Hash)]
pub struct TsInterfaceBody { pub struct TsInterfaceBody {
pub span: Span, pub span: Span,
pub body: Vec<TsTypeElement>, pub body: Vec<TsTypeElement>,
} }
#[ast_node("TsExpressionWithTypeArguments")] #[ast_node("TsExpressionWithTypeArguments")]
#[derive(Eq, Hash)]
pub struct TsExprWithTypeArgs { pub struct TsExprWithTypeArgs {
pub span: Span, pub span: Span,
#[serde(rename = "expression")] #[serde(rename = "expression")]
@ -666,6 +714,7 @@ pub struct TsExprWithTypeArgs {
} }
#[ast_node("TsTypeAliasDeclaration")] #[ast_node("TsTypeAliasDeclaration")]
#[derive(Eq, Hash)]
pub struct TsTypeAliasDecl { pub struct TsTypeAliasDecl {
pub span: Span, pub span: Span,
pub declare: bool, pub declare: bool,
@ -677,6 +726,7 @@ pub struct TsTypeAliasDecl {
} }
#[ast_node("TsEnumDeclaration")] #[ast_node("TsEnumDeclaration")]
#[derive(Eq, Hash)]
pub struct TsEnumDecl { pub struct TsEnumDecl {
pub span: Span, pub span: Span,
pub declare: bool, pub declare: bool,
@ -686,6 +736,7 @@ pub struct TsEnumDecl {
} }
#[ast_node("TsEnumMember")] #[ast_node("TsEnumMember")]
#[derive(Eq, Hash)]
pub struct TsEnumMember { pub struct TsEnumMember {
pub span: Span, pub span: Span,
pub id: TsEnumMemberId, pub id: TsEnumMemberId,
@ -696,6 +747,7 @@ pub struct TsEnumMember {
/// ///
/// - Invalid: [Ident] with empty symbol. /// - Invalid: [Ident] with empty symbol.
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum TsEnumMemberId { pub enum TsEnumMemberId {
#[tag("Identifier")] #[tag("Identifier")]
Ident(Ident), Ident(Ident),
@ -705,6 +757,7 @@ pub enum TsEnumMemberId {
} }
#[ast_node("TsModuleDeclaration")] #[ast_node("TsModuleDeclaration")]
#[derive(Eq, Hash)]
pub struct TsModuleDecl { pub struct TsModuleDecl {
pub span: Span, pub span: Span,
pub declare: bool, pub declare: bool,
@ -718,6 +771,7 @@ pub struct TsModuleDecl {
/// `namespace A.B { }` is a namespace named `A` with another TsNamespaceDecl as /// `namespace A.B { }` is a namespace named `A` with another TsNamespaceDecl as
/// its body. /// its body.
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum TsNamespaceBody { pub enum TsNamespaceBody {
#[tag("TsModuleBlock")] #[tag("TsModuleBlock")]
TsModuleBlock(TsModuleBlock), TsModuleBlock(TsModuleBlock),
@ -727,12 +781,14 @@ pub enum TsNamespaceBody {
} }
#[ast_node("TsModuleBlock")] #[ast_node("TsModuleBlock")]
#[derive(Eq, Hash)]
pub struct TsModuleBlock { pub struct TsModuleBlock {
pub span: Span, pub span: Span,
pub body: Vec<ModuleItem>, pub body: Vec<ModuleItem>,
} }
#[ast_node("TsNamespaceDeclaration")] #[ast_node("TsNamespaceDeclaration")]
#[derive(Eq, Hash)]
pub struct TsNamespaceDecl { pub struct TsNamespaceDecl {
pub span: Span, pub span: Span,
pub declare: bool, pub declare: bool,
@ -743,6 +799,7 @@ pub struct TsNamespaceDecl {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum TsModuleName { pub enum TsModuleName {
#[tag("Identifier")] #[tag("Identifier")]
Ident(Ident), Ident(Ident),
@ -752,6 +809,7 @@ pub enum TsModuleName {
} }
#[ast_node("TsImportEqualsDeclaration")] #[ast_node("TsImportEqualsDeclaration")]
#[derive(Eq, Hash)]
pub struct TsImportEqualsDecl { pub struct TsImportEqualsDecl {
pub span: Span, pub span: Span,
pub declare: bool, pub declare: bool,
@ -761,6 +819,7 @@ pub struct TsImportEqualsDecl {
} }
#[ast_node] #[ast_node]
#[derive(Eq, Hash)]
pub enum TsModuleRef { pub enum TsModuleRef {
#[tag("TsQualifiedName")] #[tag("TsQualifiedName")]
#[tag("Identifier")] #[tag("Identifier")]
@ -771,6 +830,7 @@ pub enum TsModuleRef {
} }
#[ast_node("TsExternalModuleReference")] #[ast_node("TsExternalModuleReference")]
#[derive(Eq, Hash)]
pub struct TsExternalModuleRef { pub struct TsExternalModuleRef {
pub span: Span, pub span: Span,
#[serde(rename = "expression")] #[serde(rename = "expression")]
@ -781,6 +841,7 @@ pub struct TsExternalModuleRef {
/// `export =`. But for @babel/parser, `export default` is an ExportDefaultDecl, /// `export =`. But for @babel/parser, `export default` is an ExportDefaultDecl,
/// so a TsExportAssignment is always `export =`. /// so a TsExportAssignment is always `export =`.
#[ast_node("TsExportAssignment")] #[ast_node("TsExportAssignment")]
#[derive(Eq, Hash)]
pub struct TsExportAssignment { pub struct TsExportAssignment {
pub span: Span, pub span: Span,
#[serde(rename = "expression")] #[serde(rename = "expression")]
@ -788,6 +849,7 @@ pub struct TsExportAssignment {
} }
#[ast_node("TsNamespaceExportDeclaration")] #[ast_node("TsNamespaceExportDeclaration")]
#[derive(Eq, Hash)]
pub struct TsNamespaceExportDecl { pub struct TsNamespaceExportDecl {
pub span: Span, pub span: Span,
pub id: Ident, pub id: Ident,
@ -798,6 +860,7 @@ pub struct TsNamespaceExportDecl {
// // ================ // // ================
#[ast_node("TsAsExpression")] #[ast_node("TsAsExpression")]
#[derive(Eq, Hash)]
pub struct TsAsExpr { pub struct TsAsExpr {
pub span: Span, pub span: Span,
#[serde(rename = "expression")] #[serde(rename = "expression")]
@ -807,6 +870,7 @@ pub struct TsAsExpr {
} }
#[ast_node("TsTypeAssertion")] #[ast_node("TsTypeAssertion")]
#[derive(Eq, Hash)]
pub struct TsTypeAssertion { pub struct TsTypeAssertion {
pub span: Span, pub span: Span,
#[serde(rename = "expression")] #[serde(rename = "expression")]
@ -816,13 +880,14 @@ pub struct TsTypeAssertion {
} }
#[ast_node("TsNonNullExpression")] #[ast_node("TsNonNullExpression")]
#[derive(Eq, Hash)]
pub struct TsNonNullExpr { pub struct TsNonNullExpr {
pub span: Span, pub span: Span,
#[serde(rename = "expression")] #[serde(rename = "expression")]
pub expr: Box<Expr>, pub expr: Box<Expr>,
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Eq, Hash)]
#[cfg_attr(feature = "fold", derive(Fold))] #[cfg_attr(feature = "fold", derive(Fold))]
pub enum Accessibility { pub enum Accessibility {
#[serde(rename = "public")] #[serde(rename = "public")]
@ -834,6 +899,7 @@ pub enum Accessibility {
} }
#[ast_node("TsConstAssertion")] #[ast_node("TsConstAssertion")]
#[derive(Eq, Hash)]
pub struct TsConstAssertion { pub struct TsConstAssertion {
pub span: Span, pub span: Span,
pub expr: Box<Expr>, pub expr: Box<Expr>,

View File

@ -15,7 +15,7 @@
}, },
"specifiers": [ "specifiers": [
{ {
"type": "ExportNamespaceSpecifer", "type": "ExportNamespaceSpecifier",
"span": { "span": {
"start": 7, "start": 7,
"end": 14, "end": 14,

View File

@ -510,7 +510,7 @@ struct FunctionFinder {
noop_visit_type!(FunctionFinder); noop_visit_type!(FunctionFinder);
impl Visit<Function> for FunctionFinder { impl Visit<Function> for FunctionFinder {
fn visit(&mut self, node: &Function) { fn visit(&mut self, _: &Function) {
self.found = true self.found = true
} }
} }