Skip to content

Commit

Permalink
fix(es/compat): Revert wrong fix of arrow (#4093)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Mar 19, 2022
1 parent b4ad33a commit 0d6bd81
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as swcHelpers from "@swc/helpers";
var _superprop_get_b = function() {
return super.b;
}, _superprop_get_a = function() {
return super.a;
};
var _superprop_get_b = ()=>super.b
, _superprop_get_a = ()=>super.a
;
// @target: esnext, es2022, es2015, es5
var B = function B() {
"use strict";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as swcHelpers from "@swc/helpers";
var _this = this, _superprop_get_w = function() {
return super.w;
};
var _this = this, _superprop_get_w = ()=>super.w
;
// @target: es5, es2015, es2021, es2022, esnext
// @noTypesAndSymbols: true
// @filename: external.ts
Expand Down Expand Up @@ -774,9 +773,8 @@ _$_Reflect = function Reflect() {
}, _$__ = {
writable: true,
value: function() {
var _this1 = _this, _superprop_get_w1 = function() {
return super.w;
};
var _this1 = _this, _superprop_get_w1 = ()=>_superprop_get_w()
;
var _$_Reflect, _$__;
var C = /*#__PURE__*/ function(B) {
"use strict";
Expand Down Expand Up @@ -840,9 +838,8 @@ var _$__21 = {
C._ = swcHelpers.get(swcHelpers.getPrototypeOf(C), "w", C).call(C);
});
(function Reflect() {
var _this2 = this, _superprop_get_w2 = function() {
return super.w;
};
var _this2 = this, _superprop_get_w2 = ()=>super.w
;
var C = /*#__PURE__*/ function(B) {
"use strict";
swcHelpers.inherits(C, B);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as swcHelpers from "@swc/helpers";
var _this = this, _superprop_get_w = function() {
return super.w;
};
var _this = this, _superprop_get_w = ()=>super.w
;
export var Reflect = function() {
"use strict";
swcHelpers.classCallCheck(this, Reflect);
Expand Down Expand Up @@ -484,7 +483,7 @@ _superprop_get_w().call(_this), _$_Reflect = function Reflect3() {
}
return C;
}(B);
super.w.call(_this);
_superprop_get_w().call(_this);
}()
};
var C = function(B) {
Expand Down
31 changes: 5 additions & 26 deletions crates/swc_ecma_transforms_compat/src/es2015/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub fn arrow() -> impl Fold + VisitMut + InjectVars {
#[derive(Default)]
struct Arrow {
in_subclass: bool,
disable_fn_env_hoister: bool,
hoister: FnEnvHoister,
}

Expand Down Expand Up @@ -120,9 +119,7 @@ impl VisitMut for Arrow {
..
}) => {
params.visit_mut_with(self);
if !self.disable_fn_env_hoister {
params.visit_mut_with(&mut self.hoister);
}
params.visit_mut_with(&mut self.hoister);

let params: Vec<Param> = params
.take()
Expand All @@ -136,9 +133,7 @@ impl VisitMut for Arrow {

body.visit_mut_with(self);

if !self.disable_fn_env_hoister {
body.visit_mut_with(&mut self.hoister);
}
body.visit_mut_with(&mut self.hoister);

let fn_expr = Expr::Fn(FnExpr {
ident: None,
Expand Down Expand Up @@ -183,15 +178,8 @@ impl VisitMut for Arrow {

let decl = self.hoister.take().to_stmt();

if let Some(mut stmt) = decl {
let old_disable = self.disable_fn_env_hoister;
self.disable_fn_env_hoister = true;

stmt.visit_mut_with(self);

if let Some(stmt) = decl {
prepend(stmts, ModuleItem::Stmt(stmt));

self.disable_fn_env_hoister = old_disable;
}
}

Expand All @@ -200,20 +188,11 @@ impl VisitMut for Arrow {

stmts.visit_mut_children_with(self);

let decl = self.hoister.take().to_stmt();

if let Some(mut stmt) = decl {
let old_disable = self.disable_fn_env_hoister;
self.disable_fn_env_hoister = true;

stmt.visit_mut_with(self);
let decl = mem::replace(&mut self.hoister, old_rep).to_stmt();

if let Some(stmt) = decl {
prepend(stmts, stmt);

self.disable_fn_env_hoister = old_disable;
}

self.hoister = old_rep;
}
}

Expand Down

This file was deleted.

This file was deleted.

20 changes: 1 addition & 19 deletions crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use std::path::PathBuf;

use swc_ecma_parser::EsConfig;
use swc_ecma_transforms_compat::es2015::arrow;
use swc_ecma_transforms_testing::{compare_stdout, test, test_fixture};
use swc_ecma_transforms_testing::{compare_stdout, test};

test!(
::swc_ecma_parser::Syntax::default(),
Expand Down Expand Up @@ -526,18 +523,3 @@ test!(
};
}"
);

#[testing::fixture("tests/arrows/**/input.js")]
fn fixture(input: PathBuf) {
let output = input.with_file_name("output.js");

test_fixture(
swc_ecma_parser::Syntax::Es(EsConfig {
allow_super_outside_method: true,
..Default::default()
}),
&|_| arrow(),
&input,
&output,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fs::read_to_string, path::PathBuf};

use swc_common::{chain, Mark, Spanned};
use swc_ecma_ast::*;
use swc_ecma_parser::{EsConfig, Syntax};
use swc_ecma_parser::Syntax;
use swc_ecma_transforms_base::{fixer::fixer, resolver::resolver};
use swc_ecma_transforms_compat::{
es2015,
Expand Down Expand Up @@ -35,10 +35,7 @@ impl Fold for ParenRemover {
}

fn syntax() -> Syntax {
Syntax::Es(EsConfig {
allow_super_outside_method: true,
..Default::default()
})
Syntax::default()
}

fn tr() -> impl Fold {
Expand Down Expand Up @@ -426,14 +423,12 @@ test!(
class Foo extends class{
}{
method() {
var _this = this, _superprop_get_method1 = ()=>super.method;
var _this = this, _superprop_get_method = ()=>super.method;
return _asyncToGenerator(function*() {
var _this1 = _this, _superprop_get_method = function _superprop_get_method() {
return super.method;
};
_superprop_get_method1().call(_this);
var _this1 = _this, _superprop_get_method1 = ()=>_superprop_get_method();
_superprop_get_method().call(_this);
var arrow = function arrow() {
return _superprop_get_method().call(_this1);
return _superprop_get_method1().call(_this1);
};
})();
}
Expand Down

1 comment on commit 0d6bd81

@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: 0d6bd81 Previous: 533f756 Ratio
base_tr_fixer 27941 ns/iter (± 5577) 33204 ns/iter (± 4317) 0.84
base_tr_resolver_and_hygiene 119754 ns/iter (± 46917) 146697 ns/iter (± 27799) 0.82
codegen_es2015 36948 ns/iter (± 9968) 40763 ns/iter (± 10741) 0.91
codegen_es2016 37993 ns/iter (± 8241) 40634 ns/iter (± 5917) 0.94
codegen_es2017 37297 ns/iter (± 7282) 40893 ns/iter (± 6157) 0.91
codegen_es2018 36779 ns/iter (± 9679) 40678 ns/iter (± 6199) 0.90
codegen_es2019 36448 ns/iter (± 7702) 39543 ns/iter (± 5183) 0.92
codegen_es2020 36556 ns/iter (± 8980) 41319 ns/iter (± 6172) 0.88
codegen_es3 37398 ns/iter (± 6963) 39993 ns/iter (± 5487) 0.94
codegen_es5 38009 ns/iter (± 7987) 40919 ns/iter (± 7738) 0.93
full_es2015 155937711 ns/iter (± 25060915) 175324054 ns/iter (± 10244510) 0.89
full_es2016 152847261 ns/iter (± 16151231) 173864162 ns/iter (± 16313940) 0.88
full_es2017 150934421 ns/iter (± 16493562) 174684268 ns/iter (± 18030576) 0.86
full_es2018 149739670 ns/iter (± 15318819) 175850625 ns/iter (± 21245531) 0.85
full_es2019 148152851 ns/iter (± 16615397) 175909577 ns/iter (± 12319509) 0.84
full_es2020 143700905 ns/iter (± 17200999) 166143411 ns/iter (± 9115910) 0.86
full_es3 200525164 ns/iter (± 23362735) 236306750 ns/iter (± 22896586) 0.85
full_es5 190364570 ns/iter (± 24072601) 222177432 ns/iter (± 14953460) 0.86
parser 652989 ns/iter (± 215529) 785004 ns/iter (± 159950) 0.83
ser_ast_node 158 ns/iter (± 35) 201 ns/iter (± 41) 0.79
ser_serde 148 ns/iter (± 43) 189 ns/iter (± 33) 0.78
emit_colors 9373700 ns/iter (± 7602261) 5578371 ns/iter (± 4219004) 1.68
emit_large 50476676 ns/iter (± 72956303) 62553440 ns/iter (± 87503112) 0.81
base_clone 2490822 ns/iter (± 776848) 3114574 ns/iter (± 799303) 0.80
fold_span 4769814 ns/iter (± 1300567) 5420000 ns/iter (± 1199289) 0.88
fold_span_panic 4864885 ns/iter (± 1378974) 6133515 ns/iter (± 1919147) 0.79
visit_mut_span 3030941 ns/iter (± 440964) 3705131 ns/iter (± 970356) 0.82
visit_mut_span_panic 3115990 ns/iter (± 4032199) 3700101 ns/iter (± 868085) 0.84
usage_builtin_type 18013118 ns/iter (± 14319793) 20553924 ns/iter (± 12171138) 0.88
usage_property 433388 ns/iter (± 94118) 503074 ns/iter (± 100151) 0.86
boxing_boxed 130 ns/iter (± 55) 199 ns/iter (± 41) 0.65
boxing_boxed_clone 80 ns/iter (± 16) 87 ns/iter (± 12) 0.92
boxing_unboxed 128 ns/iter (± 51) 169 ns/iter (± 17) 0.76
boxing_unboxed_clone 63 ns/iter (± 9) 84 ns/iter (± 12) 0.75
time_10 304 ns/iter (± 81) 382 ns/iter (± 43) 0.80
time_15 690 ns/iter (± 158) 885 ns/iter (± 151) 0.78
time_20 1207 ns/iter (± 350) 1557 ns/iter (± 254) 0.78
time_40 4465 ns/iter (± 949) 5477 ns/iter (± 880) 0.82
time_5 98 ns/iter (± 22) 124 ns/iter (± 22) 0.79
time_60 10156 ns/iter (± 2352) 11837 ns/iter (± 2790) 0.86
total 0 ns/iter (± 0) 0 ns/iter (± 0) NaN

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

Please sign in to comment.