Skip to content

Commit 2484e28

Browse files
committed
fix
1 parent b8bfeed commit 2484e28

File tree

4 files changed

+7
-104
lines changed

4 files changed

+7
-104
lines changed

crates/swc_ecma_fast_parser/src/parser/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! This module contains methods for parsing JavaScript expressions.
44
5-
use swc_common::Span;
5+
use swc_common::{Span, Spanned};
66
use swc_ecma_ast::{
77
ArrayLit, AwaitExpr, BinExpr, BinaryOp, Bool, Expr, ExprOrSpread, Lit, Null, ObjectLit,
88
ParenExpr, PropOrSpread, SpreadElement, ThisExpr, UnaryExpr, UnaryOp, UpdateExpr, UpdateOp,
@@ -11,7 +11,7 @@ use swc_ecma_ast::{
1111

1212
use crate::{
1313
error::{Error, ErrorKind, Result},
14-
parser::{util, util::GetSpan, Parser},
14+
parser::{util, Parser},
1515
token::{TokenType, TokenValue},
1616
};
1717

crates/swc_ecma_fast_parser/src/parser/pat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
//! This module contains methods for parsing JavaScript patterns (destructuring,
44
//! etc.).
55
6-
use swc_common::Span;
6+
use swc_common::{Span, Spanned};
77
use swc_ecma_ast::{
88
ArrayPat, AssignPat, AssignPatProp, BindingIdent, ComputedPropName, IdentName, KeyValuePatProp,
99
ObjectPat, ObjectPatProp, Pat, PropName, RestPat,
1010
};
1111

1212
use crate::{
1313
error::{Error, ErrorKind, Result},
14-
parser::{util, util::GetSpan, Parser},
14+
parser::{util, Parser},
1515
token::TokenType,
1616
};
1717

crates/swc_ecma_fast_parser/src/parser/stmt.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
//!
33
//! This module contains methods for parsing JavaScript statements.
44
5-
use swc_common::{Span, SyntaxContext};
5+
use swc_common::{Span, Spanned, SyntaxContext};
66
use swc_ecma_ast::{BlockStmt, ExprStmt, ReturnStmt, Stmt, VarDecl, VarDeclKind, VarDeclarator};
77

8-
use crate::{
9-
error::Result,
10-
parser::{util::GetSpan, Parser},
11-
token::TokenType,
12-
};
8+
use crate::{error::Result, parser::Parser, token::TokenType};
139

1410
impl Parser<'_> {
1511
/// Parse a statement

crates/swc_ecma_fast_parser/src/parser/util.rs

+1-94
Original file line numberDiff line numberDiff line change
@@ -2,106 +2,13 @@
22
33
use swc_atoms::Atom;
44
use swc_common::{Span, SyntaxContext};
5-
use swc_ecma_ast::{BindingIdent, Expr, Ident, Number, Pat, Str};
5+
use swc_ecma_ast::{BindingIdent, Ident, Number, Str};
66

77
use crate::{
88
error::{Error, ErrorKind},
99
token::{Token, TokenType, TokenValue},
1010
};
1111

12-
/// Trait for getting spans from AST nodes
13-
pub trait GetSpan {
14-
fn span(&self) -> Span;
15-
}
16-
17-
// Implement GetSpan for Box<Expr>
18-
impl GetSpan for Box<Expr> {
19-
fn span(&self) -> Span {
20-
match &**self {
21-
Expr::Array(e) => e.span,
22-
Expr::Arrow(e) => e.span,
23-
Expr::Assign(e) => e.span,
24-
Expr::Await(e) => e.span,
25-
Expr::Bin(e) => e.span,
26-
Expr::Call(e) => e.span,
27-
Expr::Class(e) => {
28-
if let Some(ident) = &e.ident {
29-
ident.span
30-
} else {
31-
e.class.span
32-
}
33-
}
34-
Expr::Cond(e) => e.span,
35-
Expr::Fn(e) => {
36-
if let Some(ident) = &e.ident {
37-
ident.span
38-
} else {
39-
e.function.span
40-
}
41-
}
42-
Expr::Ident(e) => e.span,
43-
Expr::Lit(e) => match e {
44-
swc_ecma_ast::Lit::Str(s) => s.span,
45-
swc_ecma_ast::Lit::Bool(b) => b.span,
46-
swc_ecma_ast::Lit::Null(n) => n.span,
47-
swc_ecma_ast::Lit::Num(n) => n.span,
48-
swc_ecma_ast::Lit::BigInt(b) => b.span,
49-
swc_ecma_ast::Lit::Regex(r) => r.span,
50-
swc_ecma_ast::Lit::JSXText(j) => j.span,
51-
},
52-
Expr::Member(e) => e.span,
53-
Expr::MetaProp(e) => e.span,
54-
Expr::New(e) => e.span,
55-
Expr::Object(e) => e.span,
56-
Expr::OptChain(e) => e.span,
57-
Expr::Paren(e) => e.span,
58-
Expr::PrivateName(e) => e.span,
59-
Expr::Seq(e) => e.span,
60-
Expr::SuperProp(e) => e.span,
61-
Expr::TaggedTpl(e) => e.span,
62-
Expr::This(e) => e.span,
63-
Expr::Tpl(e) => e.span,
64-
Expr::Unary(e) => e.span,
65-
Expr::Update(e) => e.span,
66-
Expr::Yield(e) => e.span,
67-
Expr::JSXMember(e) => e.span,
68-
Expr::JSXNamespacedName(e) => e.span,
69-
Expr::JSXEmpty(e) => e.span,
70-
Expr::JSXElement(e) => e.span,
71-
Expr::JSXFragment(e) => e.span,
72-
Expr::TsTypeAssertion(e) => e.span,
73-
Expr::TsConstAssertion(e) => e.span,
74-
Expr::TsNonNull(e) => e.span,
75-
Expr::TsAs(e) => e.span,
76-
Expr::TsInstantiation(e) => e.span,
77-
Expr::TsSatisfies(e) => e.span,
78-
Expr::Invalid(e) => e.span,
79-
}
80-
}
81-
}
82-
83-
// Implement GetSpan for Pat
84-
impl GetSpan for Pat {
85-
fn span(&self) -> Span {
86-
match self {
87-
Pat::Ident(i) => i.id.span,
88-
Pat::Array(a) => a.span,
89-
Pat::Rest(r) => r.span,
90-
Pat::Object(o) => o.span,
91-
Pat::Assign(a) => a.span,
92-
Pat::Invalid(i) => i.span,
93-
Pat::Expr(e) => e.span(),
94-
}
95-
}
96-
}
97-
98-
// Implement GetSpan for BindingIdent
99-
impl GetSpan for BindingIdent {
100-
fn span(&self) -> Span {
101-
self.id.span
102-
}
103-
}
104-
10512
/// Convert a token value to an identifier
10613
pub fn token_value_to_ident(token: &Token, span: Span) -> Ident {
10714
if let TokenValue::Str { value, .. } = &token.value {

0 commit comments

Comments
 (0)