Skip to content

Commit

Permalink
fix(es/parser): Revert #4067 (#4540)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamtetlow authored May 6, 2022
1 parent c797de4 commit 2831059
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 353 deletions.
2 changes: 0 additions & 2 deletions crates/swc_ecma_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,6 @@ pub struct Context {

in_function: bool,

in_arrow_function: bool,
is_direct_child_of_braceless_arrow_function: bool,
/// This indicates current scope or the scope out of arrow function is
/// function declaration or function expression or not.
inside_non_arrow_function_scope: bool,
Expand Down
18 changes: 2 additions & 16 deletions crates/swc_ecma_parser/src/parser/class_and_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,6 @@ impl<'a, I: Tokens> Parser<I> {
let ctx = Context {
in_async: is_async,
in_generator: is_generator,
in_arrow_function: is_arrow_function,
inside_non_arrow_function_scope: if is_arrow_function {
self.ctx().inside_non_arrow_function_scope
} else {
Expand Down Expand Up @@ -1523,13 +1522,7 @@ fn has_use_strict(block: &BlockStmt) -> Option<Span> {
impl<I: Tokens> FnBodyParser<BlockStmtOrExpr> for Parser<I> {
fn parse_fn_body_inner(&mut self, is_simple_parameter_list: bool) -> PResult<BlockStmtOrExpr> {
if is!(self, '{') {
let cur_ctx = self.ctx();
let ctx = Context {
is_direct_child_of_braceless_arrow_function: false,
..cur_ctx
};
let result = self.with_ctx(ctx).parse_block(false);
result.map(|block_stmt| {
self.parse_block(false).map(|block_stmt| {
if !is_simple_parameter_list {
if let Some(span) = has_use_strict(&block_stmt) {
self.emit_err(span, SyntaxError::IllegalLanguageModeDirective);
Expand All @@ -1538,14 +1531,7 @@ impl<I: Tokens> FnBodyParser<BlockStmtOrExpr> for Parser<I> {
BlockStmtOrExpr::BlockStmt(block_stmt)
})
} else {
let cur_ctx = self.ctx();
let ctx = Context {
is_direct_child_of_braceless_arrow_function: cur_ctx.in_arrow_function,
..cur_ctx
};
self.with_ctx(ctx)
.parse_assignment_expr()
.map(BlockStmtOrExpr::Expr)
self.parse_assignment_expr().map(BlockStmtOrExpr::Expr)
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions crates/swc_ecma_parser/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,11 +732,7 @@ impl<'a, I: Tokens> Parser<I> {

let is_direct_child_of_cond = self.ctx().is_direct_child_of_cond;
// This is slow path. We handle arrow in conditional expression.
if self.syntax().typescript()
&& self.ctx().in_cond_expr
&& !self.ctx().is_direct_child_of_braceless_arrow_function
&& is!(self, ':')
{
if self.syntax().typescript() && self.ctx().in_cond_expr && is!(self, ':') {
// TODO: Remove clone
let items_ref = &paren_items;
if let Some(expr) = self.try_parse_ts(|p| {
Expand Down

This file was deleted.

160 changes: 0 additions & 160 deletions crates/swc_ecma_parser/tests/typescript/issue-2174/case1/input.ts.json

This file was deleted.

This file was deleted.

This file was deleted.

1 comment on commit 2831059

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 2831059 Previous: a4a815b Ratio
es/full/minify/libraries/antd 1709274125 ns/iter (± 55929894) 1865406985 ns/iter (± 85384681) 0.92
es/full/minify/libraries/d3 453547192 ns/iter (± 23338945) 443130881 ns/iter (± 14918673) 1.02
es/full/minify/libraries/echarts 1871827547 ns/iter (± 6498021) 2238499780 ns/iter (± 66090735) 0.84
es/full/minify/libraries/jquery 89623877 ns/iter (± 393633) 113990672 ns/iter (± 7147200) 0.79
es/full/minify/libraries/lodash 117494379 ns/iter (± 926467) 127121326 ns/iter (± 11660885) 0.92
es/full/minify/libraries/moment 51563579 ns/iter (± 2184002) 56310795 ns/iter (± 772304) 0.92
es/full/minify/libraries/react 16177171 ns/iter (± 105273) 19036769 ns/iter (± 404854) 0.85
es/full/minify/libraries/terser 611645135 ns/iter (± 2890070) 672576445 ns/iter (± 29975880) 0.91
es/full/minify/libraries/three 629961884 ns/iter (± 3146641) 720536213 ns/iter (± 7616749) 0.87
es/full/minify/libraries/typescript 3774213257 ns/iter (± 119076254) 4339145566 ns/iter (± 58613476) 0.87
es/full/minify/libraries/victory 715718494 ns/iter (± 8053829) 918656588 ns/iter (± 14636854) 0.78
es/full/minify/libraries/vue 124312507 ns/iter (± 1664961) 161618918 ns/iter (± 3267805) 0.77
es/full/codegen/es3 29576 ns/iter (± 125) 29666 ns/iter (± 166) 1.00
es/full/codegen/es5 29560 ns/iter (± 1426) 29690 ns/iter (± 221) 1.00
es/full/codegen/es2015 26114 ns/iter (± 100) 29636 ns/iter (± 159) 0.88
es/full/codegen/es2016 26104 ns/iter (± 123) 29623 ns/iter (± 133) 0.88
es/full/codegen/es2017 26085 ns/iter (± 286) 29675 ns/iter (± 151) 0.88
es/full/codegen/es2018 26066 ns/iter (± 255) 29628 ns/iter (± 116) 0.88
es/full/codegen/es2019 26052 ns/iter (± 187) 29627 ns/iter (± 156) 0.88
es/full/codegen/es2020 26080 ns/iter (± 161) 29641 ns/iter (± 127) 0.88
es/full/all/es3 182119410 ns/iter (± 6119527) 184078989 ns/iter (± 3082122) 0.99
es/full/all/es5 155809451 ns/iter (± 5263129) 172121977 ns/iter (± 3972193) 0.91
es/full/all/es2015 115100549 ns/iter (± 400925) 137872885 ns/iter (± 20998531) 0.83
es/full/all/es2016 136706515 ns/iter (± 5253652) 136794279 ns/iter (± 17088084) 1.00
es/full/all/es2017 136794562 ns/iter (± 961099) 135449872 ns/iter (± 14279716) 1.01
es/full/all/es2018 135715348 ns/iter (± 1970091) 136795634 ns/iter (± 6352507) 0.99
es/full/all/es2019 133257019 ns/iter (± 793951) 135325877 ns/iter (± 3440216) 0.98
es/full/all/es2020 118677544 ns/iter (± 692029) 124485754 ns/iter (± 1434435) 0.95
es/full/parser 581315 ns/iter (± 21204) 593938 ns/iter (± 18671) 0.98
es/full/base/fixer 22208 ns/iter (± 187) 22218 ns/iter (± 204) 1.00
es/full/base/resolver_and_hygiene 93516 ns/iter (± 1399) 95391 ns/iter (± 1446) 0.98
serialization of ast node 136 ns/iter (± 0) 136 ns/iter (± 0) 1
serialization of serde 137 ns/iter (± 0) 137 ns/iter (± 0) 1
es/codegen/colors 67791 ns/iter (± 485) 68870 ns/iter (± 505) 0.98
es/codegen/large 346754 ns/iter (± 2588) 344430 ns/iter (± 2701) 1.01
es/codegen/with-parser/colors 53987 ns/iter (± 505) 53880 ns/iter (± 418) 1.00
es/codegen/with-parser/large 575477 ns/iter (± 12804) 573149 ns/iter (± 5663) 1.00
es/minify/libraries/antd 1641727513 ns/iter (± 40034512) 1890650353 ns/iter (± 44026496) 0.87
es/minify/libraries/d3 430116510 ns/iter (± 12124569) 456652451 ns/iter (± 31049562) 0.94
es/minify/libraries/echarts 1963013358 ns/iter (± 11849620) 2185834635 ns/iter (± 34764558) 0.90
es/minify/libraries/jquery 94158592 ns/iter (± 724177) 95824649 ns/iter (± 3454350) 0.98
es/minify/libraries/lodash 111016805 ns/iter (± 244008) 124600169 ns/iter (± 4840031) 0.89
es/minify/libraries/moment 53521759 ns/iter (± 155468) 57165443 ns/iter (± 2387261) 0.94
es/minify/libraries/react 16471473 ns/iter (± 65848) 17547863 ns/iter (± 663788) 0.94
es/minify/libraries/terser 566387456 ns/iter (± 4345610) 586056720 ns/iter (± 19895795) 0.97
es/minify/libraries/three 551629557 ns/iter (± 10890954) 615130806 ns/iter (± 39884883) 0.90
es/minify/libraries/typescript 3681612944 ns/iter (± 19817818) 4163935872 ns/iter (± 87766234) 0.88
es/minify/libraries/victory 713916623 ns/iter (± 17534925) 815801830 ns/iter (± 36724190) 0.88
es/minify/libraries/vue 132859018 ns/iter (± 1023641) 151360255 ns/iter (± 10287821) 0.88
es/visitor/compare/clone 2459715 ns/iter (± 44175) 2304364 ns/iter (± 14342) 1.07
es/visitor/compare/visit_mut_span 3049281 ns/iter (± 76930) 2973384 ns/iter (± 231896) 1.03
es/visitor/compare/visit_mut_span_panic 3049455 ns/iter (± 79074) 3124999 ns/iter (± 253526) 0.98
es/visitor/compare/fold_span 4127827 ns/iter (± 63433) 3910570 ns/iter (± 424878) 1.06
es/visitor/compare/fold_span_panic 4364579 ns/iter (± 145872) 4819901 ns/iter (± 583958) 0.91
es/lexer/colors 21780 ns/iter (± 93) 20590 ns/iter (± 52) 1.06
es/lexer/angular 10604762 ns/iter (± 8668) 10051832 ns/iter (± 26345) 1.06
es/lexer/backbone 1434423 ns/iter (± 2185) 1347788 ns/iter (± 25615) 1.06
es/lexer/jquery 7704537 ns/iter (± 40280) 7228367 ns/iter (± 6013) 1.07
es/lexer/jquery mobile 12485404 ns/iter (± 43664) 11728219 ns/iter (± 8531) 1.06
es/lexer/mootools 5961740 ns/iter (± 4274) 5565849 ns/iter (± 4074) 1.07
es/lexer/underscore 1199312 ns/iter (± 1224) 1125223 ns/iter (± 8364) 1.07
es/lexer/three 35474545 ns/iter (± 26170) 33328798 ns/iter (± 46288) 1.06
es/lexer/yui 6493340 ns/iter (± 6863) 6142073 ns/iter (± 7000) 1.06
es/parser/colors 35273 ns/iter (± 255) 35578 ns/iter (± 299) 0.99
es/parser/angular 18706092 ns/iter (± 186039) 18361938 ns/iter (± 569470) 1.02
es/parser/backbone 2560419 ns/iter (± 16649) 2596029 ns/iter (± 16067) 0.99
es/parser/jquery 14168659 ns/iter (± 198852) 14056565 ns/iter (± 251133) 1.01
es/parser/jquery mobile 23065195 ns/iter (± 328199) 24265866 ns/iter (± 697745) 0.95
es/parser/mootools 11137290 ns/iter (± 113691) 11112408 ns/iter (± 1049028) 1.00
es/parser/underscore 2203447 ns/iter (± 9033) 2243357 ns/iter (± 25084) 0.98
es/parser/three 67258485 ns/iter (± 255552) 71340348 ns/iter (± 551506) 0.94
es/parser/yui 11076782 ns/iter (± 86214) 11246826 ns/iter (± 104427) 0.98
es/preset-env/usage/builtin_type 124178 ns/iter (± 4673) 128218 ns/iter (± 5983) 0.97
es/preset-env/usage/property 29719 ns/iter (± 473) 29376 ns/iter (± 340) 1.01
es/transforms/base/resolver 137919 ns/iter (± 1020) 138299 ns/iter (± 2369) 1.00
es/transforms/base/fixer 128738 ns/iter (± 957) 128381 ns/iter (± 902) 1.00
es/transforms/base/hygiene 325972 ns/iter (± 1163) 324546 ns/iter (± 1478) 1.00
es/transforms/base/resolver_with_hygiene 384075 ns/iter (± 2333) 383297 ns/iter (± 2919) 1.00
es/visitor/base-perf/module_clone 96256 ns/iter (± 2158) 95358 ns/iter (± 2237) 1.01
es/visitor/base-perf/fold_empty 107449 ns/iter (± 1977) 107433 ns/iter (± 2034) 1.00
es/visitor/base-perf/fold_noop_impl_all 107418 ns/iter (± 2356) 108305 ns/iter (± 1969) 0.99
es/visitor/base-perf/fold_noop_impl_vec 107542 ns/iter (± 2193) 108636 ns/iter (± 1863) 0.99
es/visitor/base-perf/boxing_boxed_clone 69 ns/iter (± 0) 68 ns/iter (± 0) 1.01
es/visitor/base-perf/boxing_unboxed_clone 106 ns/iter (± 0) 106 ns/iter (± 0) 1
es/visitor/base-perf/boxing_boxed 132 ns/iter (± 0) 132 ns/iter (± 0) 1
es/visitor/base-perf/boxing_unboxed 162 ns/iter (± 1) 166 ns/iter (± 0) 0.98
es/visitor/base-perf/visit_contains_this 3584 ns/iter (± 95) 3707 ns/iter (± 90) 0.97
misc/visitors/time-complexity/time 5 98 ns/iter (± 0) 98 ns/iter (± 0) 1
misc/visitors/time-complexity/time 10 301 ns/iter (± 0) 311 ns/iter (± 9) 0.97
misc/visitors/time-complexity/time 15 566 ns/iter (± 9) 632 ns/iter (± 5) 0.90
misc/visitors/time-complexity/time 20 1098 ns/iter (± 12) 1231 ns/iter (± 18) 0.89
misc/visitors/time-complexity/time 40 5874 ns/iter (± 11) 6717 ns/iter (± 33) 0.87
misc/visitors/time-complexity/time 60 15431 ns/iter (± 279) 17184 ns/iter (± 13) 0.90
es/full-target/es2016 221643 ns/iter (± 1077) 252497 ns/iter (± 1122) 0.88
es/full-target/es2017 209063 ns/iter (± 1056) 238201 ns/iter (± 1068) 0.88
es/full-target/es2018 199540 ns/iter (± 1142) 226702 ns/iter (± 1100) 0.88
es2020_nullish_coalescing 103880 ns/iter (± 820) 116971 ns/iter (± 1156) 0.89
es2020_optional_chaining 129945 ns/iter (± 1135) 146313 ns/iter (± 842) 0.89
es2022_class_properties 129702 ns/iter (± 737) 147505 ns/iter (± 935) 0.88
es2018_object_rest_spread 94835 ns/iter (± 1476) 106561 ns/iter (± 2019) 0.89
es2019_optional_catch_binding 83738 ns/iter (± 1458) 94252 ns/iter (± 1941) 0.89
es2017_async_to_generator 83765 ns/iter (± 1539) 93996 ns/iter (± 2086) 0.89
es2016_exponentiation 102716 ns/iter (± 1231) 115452 ns/iter (± 514) 0.89
es2015_arrow 118387 ns/iter (± 590) 118155 ns/iter (± 655) 1.00
es2015_block_scoped_fn 103816 ns/iter (± 467) 117836 ns/iter (± 632) 0.88
es2015_block_scoping 174349 ns/iter (± 786) 198160 ns/iter (± 881) 0.88
es2015_classes 147987 ns/iter (± 921) 167192 ns/iter (± 1352) 0.89
es2015_computed_props 84933 ns/iter (± 1820) 96516 ns/iter (± 1790) 0.88
es2015_destructuring 155418 ns/iter (± 664) 176830 ns/iter (± 8229) 0.88
es2015_duplicate_keys 87134 ns/iter (± 1656) 98858 ns/iter (± 2163) 0.88
es2015_parameters 110843 ns/iter (± 587) 124595 ns/iter (± 945) 0.89
es2015_fn_name 87679 ns/iter (± 1816) 98606 ns/iter (± 2331) 0.89
es2015_for_of 101575 ns/iter (± 758) 114232 ns/iter (± 514) 0.89
es2015_instanceof 94029 ns/iter (± 658) 106307 ns/iter (± 674) 0.88
es2015_shorthand_property 84606 ns/iter (± 1594) 95488 ns/iter (± 1886) 0.89
es2015_spread 84640 ns/iter (± 1662) 96042 ns/iter (± 1920) 0.88
es2015_sticky_regex 85751 ns/iter (± 1648) 96790 ns/iter (± 1857) 0.89
es2015_typeof_symbol 85609 ns/iter (± 1694) 96754 ns/iter (± 2189) 0.88
es/transform/baseline/base 74006 ns/iter (± 1897) 83158 ns/iter (± 2024) 0.89
es/transform/baseline/common_reserved_word 86887 ns/iter (± 1660) 97325 ns/iter (± 2213) 0.89
es/transform/baseline/common_typescript 184493 ns/iter (± 743) 206438 ns/iter (± 1310) 0.89
es/target/es3 225658 ns/iter (± 993) 257391 ns/iter (± 1057) 0.88
es/target/es2015 659275 ns/iter (± 2988) 749791 ns/iter (± 1244) 0.88
es/target/es2016 102925 ns/iter (± 681) 116593 ns/iter (± 801) 0.88
es/target/es2017 84285 ns/iter (± 1458) 96297 ns/iter (± 1883) 0.88
es/target/es2018 106788 ns/iter (± 1684) 120250 ns/iter (± 2230) 0.89
es/target/es2020 160550 ns/iter (± 947) 181497 ns/iter (± 1689) 0.88
babelify-only 693163 ns/iter (± 31987) 703711 ns/iter (± 3631) 0.99
parse_and_babelify_angular 64522580 ns/iter (± 1886623) 70867639 ns/iter (± 1152281) 0.91
parse_and_babelify_backbone 6540735 ns/iter (± 215763) 8333603 ns/iter (± 619718) 0.78
parse_and_babelify_jquery 44897092 ns/iter (± 1098713) 54360985 ns/iter (± 853245) 0.83
parse_and_babelify_jquery_mobile 78645049 ns/iter (± 1316211) 93931036 ns/iter (± 1797603) 0.84
parse_and_babelify_mootools 35438953 ns/iter (± 778737) 41934663 ns/iter (± 5452554) 0.85
parse_and_babelify_underscore 5521627 ns/iter (± 238303) 6506054 ns/iter (± 714386) 0.85
parse_and_babelify_yui 34364740 ns/iter (± 1300020) 39845638 ns/iter (± 3645154) 0.86

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.