diff --git a/README.md b/README.md index fd35c2f9778..29138c052cb 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,6 @@

- -

Supporting swc

@@ -38,7 +36,6 @@

- 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!) @@ -69,7 +66,6 @@ Become a sponsor and get your logo on our README on Github with a link to your s - # Documentation Check out the documentation [in the website](https://swc-project.github.io/docs/installation). @@ -77,75 +73,82 @@ Check out the documentation [in the website](https://swc-project.github.io/docs/ # Features ## Parsers - - [x] es2019 - - [x] jsx - - [x] typescript + +- [x] es2019 +- [x] jsx +- [x] typescript ## Transforms + New generation javascript to old-days javascript. - - es3 - - [x] member-expression-literals - - [x] property-literals - - [x] reserved-words +- es3 - - es5 - - [ ] property-mutators + - [x] member-expression-literals + - [x] property-literals + - [x] reserved-words - - es2015 - - [x] arrow-functions - - [x] block-scoped-functions - - [x] block-scoping - - [x] classes - - [x] computed-properties - - [x] destructuring - - [x] duplicate-keys - - [x] for-of - - [x] function-name - - [x] instanceof - - [x] literals - - [x] new-target - - [ ] object-super - - [x] parameters - - [x] shorthand-properties - - [x] spread - - [x] sticky regex (`y` flag) - - [x] template-literals - - [ ] invalid escape sequences inside tagged template literals. (aka es2018) - - [x] typeof-symbol - - [ ] unicode-regex +- es5 - - es2016 - - [x] exponentiation-operator + - [ ] property-mutators - - es2017 - - [x] async-to-generator +- es2015 - - es2018 - - [ ] async-generator-functions - - [ ] dotall-regex - - [x] object-rest-spread - - [ ] Using symbol as a key - - [ ] optional-catch-binding - - [ ] unicode-property-regex - - - react - - [x] jsx + - [x] arrow-functions + - [x] block-scoped-functions + - [x] block-scoping + - [x] classes + - [x] computed-properties + - [x] destructuring + - [x] duplicate-keys + - [x] for-of + - [x] function-name + - [x] instanceof + - [x] literals + - [x] new-target + - [ ] object-super + - [x] parameters + - [x] shorthand-properties + - [x] spread + - [x] sticky regex (`y` flag) + - [x] template-literals + - [ ] invalid escape sequences inside tagged template literals. (aka es2018) + - [x] typeof-symbol + - [ ] unicode-regex + +- es2016 + + - [x] exponentiation-operator + +- es2017 + + - [x] async-to-generator + +- es2018 + + - [ ] async-generator-functions + - [ ] dotall-regex + - [x] object-rest-spread + - [ ] Using symbol as a key + - [x] optional-catch-binding + - [ ] unicode-property-regex + +- react + - [x] jsx # Performance 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 | -| ------------------------ |:--------------------------------------:| -| swc (es3) | 610 ops/sec ±1.76% (82 runs sampled) | -| swc (es2015) | 682 ops/sec ±0.63% (88 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 (es2018) | 1,765 ops/sec ±11.78% (82 runs sampled)| -| swc-optimize (es3) | 535 ops/sec ±1.01% (83 runs sampled) | -| babel | 42.12 ops/sec ±6.27% (55 runs sampled) | - +| | performance | +| ------------------ | :-------------------------------------: | +| swc (es3) | 610 ops/sec ±1.76% (82 runs sampled) | +| swc (es2015) | 682 ops/sec ±0.63% (88 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 (es2018) | 1,765 ops/sec ±11.78% (82 runs sampled) | +| swc-optimize (es3) | 535 ops/sec ±1.01% (83 runs sampled) | +| babel | 42.12 ops/sec ±6.27% (55 runs sampled) | ## Contributing @@ -159,8 +162,6 @@ and the Apache License (Version 2.0). See LICENSE-APACHE and LICENSE-MIT for details. - - -[babel]:https://github.com/babel/babel -[closure compiler]:https://github.com/google/closure-compiler -[rust]:https://www.rust-lang.org +[babel]: https://github.com/babel/babel +[closure compiler]: https://github.com/google/closure-compiler +[rust]: https://www.rust-lang.org diff --git a/ecmascript/parser/src/parser/stmt/mod.rs b/ecmascript/parser/src/parser/stmt/mod.rs index f20877dbde0..a6ac9807f30 100644 --- a/ecmascript/parser/src/parser/stmt/mod.rs +++ b/ecmascript/parser/src/parser/stmt/mod.rs @@ -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(); + () + }) + }, + ); + } } diff --git a/ecmascript/transforms/src/compat/es2018/mod.rs b/ecmascript/transforms/src/compat/es2018/mod.rs index 9090cb4a87c..7cf2d6dd0c7 100644 --- a/ecmascript/transforms/src/compat/es2018/mod.rs +++ b/ecmascript/transforms/src/compat/es2018/mod.rs @@ -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 ast::Module; mod object_rest_spread; +mod optional_catch_binding; pub fn es2018() -> impl Pass { - object_rest_spread() + chain_at!(Module, object_rest_spread(), optional_catch_binding()) } diff --git a/ecmascript/transforms/src/compat/es2018/optional_catch_binding.rs b/ecmascript/transforms/src/compat/es2018/optional_catch_binding.rs new file mode 100644 index 00000000000..66d48de16a3 --- /dev/null +++ b/ecmascript/transforms/src/compat/es2018/optional_catch_binding.rs @@ -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 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) {}" + ); +}