mirror of
https://github.com/swc-project/swc.git
synced 2024-12-21 12:41:54 +03:00
Optional try catch binding (#422)
swc_ecma_parser: - Add test for optional try catch binding swc_ecma_transforms: - Implement optional catch binding (#411)
This commit is contained in:
parent
febe34e280
commit
d7d22c2d5e
47
README.md
47
README.md
@ -25,8 +25,6 @@
|
|||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h2 align="center">Supporting swc</h2>
|
<h2 align="center">Supporting swc</h2>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
@ -38,7 +36,6 @@
|
|||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
swc is a community-driven project, and is maintained by a group of [volunteers](https://opencollective.com/swc#team). If you'd like to help support the future of the project, please consider:
|
swc is a community-driven project, and is maintained by a group of [volunteers](https://opencollective.com/swc#team). If you'd like to help support the future of the project, please consider:
|
||||||
|
|
||||||
- Giving developer time on the project. (Message us on [Slack](https://swc-org.slack.com/) for guidance!)
|
- Giving developer time on the project. (Message us on [Slack](https://swc-org.slack.com/) for guidance!)
|
||||||
@ -69,7 +66,6 @@ Become a sponsor and get your logo on our README on Github with a link to your s
|
|||||||
<a href="https://opencollective.com/swc/backer/8/website?requireActive=false" target="_blank"><img src="https://opencollective.com/swc/backer/8/avatar.svg?requireActive=false"></a>
|
<a href="https://opencollective.com/swc/backer/8/website?requireActive=false" target="_blank"><img src="https://opencollective.com/swc/backer/8/avatar.svg?requireActive=false"></a>
|
||||||
<a href="https://opencollective.com/swc/backer/9/website?requireActive=false" target="_blank"><img src="https://opencollective.com/swc/backer/9/avatar.svg?requireActive=false"></a>
|
<a href="https://opencollective.com/swc/backer/9/website?requireActive=false" target="_blank"><img src="https://opencollective.com/swc/backer/9/avatar.svg?requireActive=false"></a>
|
||||||
|
|
||||||
|
|
||||||
# Documentation
|
# Documentation
|
||||||
|
|
||||||
Check out the documentation [in the website](https://swc-project.github.io/docs/installation).
|
Check out the documentation [in the website](https://swc-project.github.io/docs/installation).
|
||||||
@ -77,22 +73,27 @@ Check out the documentation [in the website](https://swc-project.github.io/docs/
|
|||||||
# Features
|
# Features
|
||||||
|
|
||||||
## Parsers
|
## Parsers
|
||||||
- [x] es2019
|
|
||||||
- [x] jsx
|
- [x] es2019
|
||||||
- [x] typescript
|
- [x] jsx
|
||||||
|
- [x] typescript
|
||||||
|
|
||||||
## Transforms
|
## Transforms
|
||||||
|
|
||||||
New generation javascript to old-days javascript.
|
New generation javascript to old-days javascript.
|
||||||
|
|
||||||
- es3
|
- es3
|
||||||
|
|
||||||
- [x] member-expression-literals
|
- [x] member-expression-literals
|
||||||
- [x] property-literals
|
- [x] property-literals
|
||||||
- [x] reserved-words
|
- [x] reserved-words
|
||||||
|
|
||||||
- es5
|
- es5
|
||||||
|
|
||||||
- [ ] property-mutators
|
- [ ] property-mutators
|
||||||
|
|
||||||
- es2015
|
- es2015
|
||||||
|
|
||||||
- [x] arrow-functions
|
- [x] arrow-functions
|
||||||
- [x] block-scoped-functions
|
- [x] block-scoped-functions
|
||||||
- [x] block-scoping
|
- [x] block-scoping
|
||||||
@ -115,21 +116,24 @@ New generation javascript to old-days javascript.
|
|||||||
- [x] typeof-symbol
|
- [x] typeof-symbol
|
||||||
- [ ] unicode-regex
|
- [ ] unicode-regex
|
||||||
|
|
||||||
- es2016
|
- es2016
|
||||||
|
|
||||||
- [x] exponentiation-operator
|
- [x] exponentiation-operator
|
||||||
|
|
||||||
- es2017
|
- es2017
|
||||||
|
|
||||||
- [x] async-to-generator
|
- [x] async-to-generator
|
||||||
|
|
||||||
- es2018
|
- es2018
|
||||||
|
|
||||||
- [ ] async-generator-functions
|
- [ ] async-generator-functions
|
||||||
- [ ] dotall-regex
|
- [ ] dotall-regex
|
||||||
- [x] object-rest-spread
|
- [x] object-rest-spread
|
||||||
- [ ] Using symbol as a key
|
- [ ] Using symbol as a key
|
||||||
- [ ] optional-catch-binding
|
- [x] optional-catch-binding
|
||||||
- [ ] unicode-property-regex
|
- [ ] unicode-property-regex
|
||||||
|
|
||||||
- react
|
- react
|
||||||
- [x] jsx
|
- [x] jsx
|
||||||
|
|
||||||
# Performance
|
# Performance
|
||||||
@ -137,16 +141,15 @@ New generation javascript to old-days javascript.
|
|||||||
The lower bound of the speedup compared to babel is **16**. The benchmarks were run on Macbook pro, dual core, 2.3GHz Intel Core i5, 16 GB ram
|
The lower bound of the speedup compared to babel is **16**. The benchmarks were run on Macbook pro, dual core, 2.3GHz Intel Core i5, 16 GB ram
|
||||||
|
|
||||||
| | performance |
|
| | performance |
|
||||||
| ------------------------ |:--------------------------------------:|
|
| ------------------ | :-------------------------------------: |
|
||||||
| swc (es3) | 610 ops/sec ±1.76% (82 runs sampled) |
|
| swc (es3) | 610 ops/sec ±1.76% (82 runs sampled) |
|
||||||
| swc (es2015) | 682 ops/sec ±0.63% (88 runs sampled) |
|
| swc (es2015) | 682 ops/sec ±0.63% (88 runs sampled) |
|
||||||
| swc (es2016) | 1,659 ops/sec ±4.32% (79 runs sampled) |
|
| swc (es2016) | 1,659 ops/sec ±4.32% (79 runs sampled) |
|
||||||
| swc (es2017) | 1,384 ops/sec ±7.24% (82 runs sampled) |
|
| swc (es2017) | 1,384 ops/sec ±7.24% (82 runs sampled) |
|
||||||
| swc (es2018) | 1,765 ops/sec ±11.78% (82 runs sampled)|
|
| swc (es2018) | 1,765 ops/sec ±11.78% (82 runs sampled) |
|
||||||
| swc-optimize (es3) | 535 ops/sec ±1.01% (83 runs sampled) |
|
| swc-optimize (es3) | 535 ops/sec ±1.01% (83 runs sampled) |
|
||||||
| babel | 42.12 ops/sec ±6.27% (55 runs sampled) |
|
| babel | 42.12 ops/sec ±6.27% (55 runs sampled) |
|
||||||
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
See [CONTRIBUTING.md](CONTRIBUTING.md). You may also find the architecture
|
See [CONTRIBUTING.md](CONTRIBUTING.md). You may also find the architecture
|
||||||
@ -159,8 +162,6 @@ and the Apache License (Version 2.0).
|
|||||||
|
|
||||||
See LICENSE-APACHE and LICENSE-MIT for details.
|
See LICENSE-APACHE and LICENSE-MIT for details.
|
||||||
|
|
||||||
|
[babel]: https://github.com/babel/babel
|
||||||
|
[closure compiler]: https://github.com/google/closure-compiler
|
||||||
[babel]:https://github.com/babel/babel
|
[rust]: https://www.rust-lang.org
|
||||||
[closure compiler]:https://github.com/google/closure-compiler
|
|
||||||
[rust]:https://www.rust-lang.org
|
|
||||||
|
@ -1347,4 +1347,20 @@ export default function waitUntil(callback, options = {}) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn issue_411() {
|
||||||
|
test_parser(
|
||||||
|
"try {
|
||||||
|
} catch {}",
|
||||||
|
Syntax::Es(EsConfig {
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
|p| {
|
||||||
|
p.parse_module().map_err(|mut e| {
|
||||||
|
e.emit();
|
||||||
|
()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
pub use self::object_rest_spread::object_rest_spread;
|
pub use self::{
|
||||||
|
object_rest_spread::object_rest_spread, optional_catch_binding::optional_catch_binding,
|
||||||
|
};
|
||||||
use crate::pass::Pass;
|
use crate::pass::Pass;
|
||||||
|
use ast::Module;
|
||||||
|
|
||||||
mod object_rest_spread;
|
mod object_rest_spread;
|
||||||
|
mod optional_catch_binding;
|
||||||
|
|
||||||
pub fn es2018() -> impl Pass {
|
pub fn es2018() -> impl Pass {
|
||||||
object_rest_spread()
|
chain_at!(Module, object_rest_spread(), optional_catch_binding())
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
use crate::pass::Pass;
|
||||||
|
use ast::*;
|
||||||
|
use swc_common::Fold;
|
||||||
|
|
||||||
|
struct OptionalCatchBinding;
|
||||||
|
|
||||||
|
pub fn optional_catch_binding() -> impl Pass {
|
||||||
|
OptionalCatchBinding
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Fold<CatchClause> for OptionalCatchBinding {
|
||||||
|
fn fold(&mut self, cc: CatchClause) -> CatchClause {
|
||||||
|
if cc.param.is_some() {
|
||||||
|
return cc;
|
||||||
|
}
|
||||||
|
|
||||||
|
CatchClause {
|
||||||
|
param: Some(private_ident!("e").into()),
|
||||||
|
..cc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::optional_catch_binding as tr;
|
||||||
|
|
||||||
|
test!(
|
||||||
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|
|_| tr(),
|
||||||
|
issue_411,
|
||||||
|
"try {} catch {}",
|
||||||
|
"try {} catch(e) {}"
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user