mirror of
https://github.com/swc-project/swc.git
synced 2024-12-01 09:52:57 +03:00
refactor(es/parser): Simplify parsing logic (#2405)
This commit is contained in:
parent
b5f832193a
commit
4ad25d2155
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -75,9 +75,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.7.4"
|
||||
version = "0.7.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98"
|
||||
checksum = "991984e3fd003e7ba02eb724f87a0f997b78677c46c0e91f8424ad7394c9886a"
|
||||
dependencies = [
|
||||
"const-random",
|
||||
"getrandom 0.2.3",
|
||||
@ -2411,7 +2411,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_bundler"
|
||||
version = "0.68.0"
|
||||
version = "0.68.1"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"anyhow",
|
||||
@ -2689,7 +2689,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_parser"
|
||||
version = "0.73.8"
|
||||
version = "0.73.9"
|
||||
dependencies = [
|
||||
"either",
|
||||
"enum_kind",
|
||||
@ -2974,7 +2974,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_utils"
|
||||
version = "0.47.0"
|
||||
version = "0.47.1"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"rayon",
|
||||
|
@ -9,7 +9,7 @@ include = ["Cargo.toml", "build.rs", "src/**/*.rs", "src/**/*.js"]
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_bundler"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.68.0"
|
||||
version = "0.68.1"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[features]
|
||||
|
@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "examples/**/*.rs"]
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_parser"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.73.8"
|
||||
version = "0.73.9"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
@ -1271,27 +1271,18 @@ impl<'a, I: Tokens> Parser<I> {
|
||||
|
||||
expect!(self, '(');
|
||||
|
||||
let mut first = true;
|
||||
let mut items = vec![];
|
||||
let mut rest_span = None;
|
||||
|
||||
// TODO(kdy1): optimize (once we parsed a pattern, we can parse everything else
|
||||
// as a pattern instead of reparsing)
|
||||
while !eof!(self) && !is!(self, ')') {
|
||||
let mut is_async = false;
|
||||
|
||||
if first {
|
||||
if is!(self, "async")
|
||||
&& matches!(
|
||||
peek!(self),
|
||||
Ok(tok!('(') | tok!("function") | Token::Word(..))
|
||||
)
|
||||
{
|
||||
// https://github.com/swc-project/swc/issues/410
|
||||
self.state.potential_arrow_start = Some(cur_pos!(self));
|
||||
is_async = true;
|
||||
}
|
||||
}
|
||||
// https://github.com/swc-project/swc/issues/410
|
||||
let is_async = is!(self, "async")
|
||||
&& matches!(
|
||||
peek!(self),
|
||||
Ok(tok!('(') | tok!("function") | Token::Word(..))
|
||||
);
|
||||
|
||||
let start = cur_pos!(self);
|
||||
self.state.potential_arrow_start = Some(start);
|
||||
@ -1495,7 +1486,7 @@ impl<'a, I: Tokens> Parser<I> {
|
||||
}
|
||||
|
||||
// https://github.com/swc-project/swc/issues/433
|
||||
if first && eat!(self, "=>") && {
|
||||
if eat!(self, "=>") && {
|
||||
debug_assert_eq!(items.len(), 1);
|
||||
match items[0] {
|
||||
PatOrExprOrSpread::ExprOrSpread(ExprOrSpread { ref expr, .. })
|
||||
@ -1532,8 +1523,6 @@ impl<'a, I: Tokens> Parser<I> {
|
||||
}));
|
||||
}
|
||||
|
||||
first = true;
|
||||
|
||||
if !is!(self, ')') {
|
||||
expect!(self, ',');
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_utils"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.47.0"
|
||||
version = "0.47.1"
|
||||
|
||||
[features]
|
||||
# Process in parallel.
|
||||
|
Loading…
Reference in New Issue
Block a user