fix(es/compat): Revert wrong fix of arrow (#4093)

This commit is contained in:
Donny/강동윤 2022-03-19 20:25:52 +09:00 committed by GitHub
parent b4ad33ae3d
commit 0d6bd813b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 107 deletions

View File

@ -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";

View File

@ -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
@ -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";
@ -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);

View File

@ -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);
@ -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) {

View File

@ -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,
}
@ -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()
@ -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,
@ -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;
}
}
@ -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;
}
}

View File

@ -1,15 +0,0 @@
function f0() {
}
f0.prototype = {
name: 'Nicholas',
age: 29,
job: 'Software Engineer',
sayName() {
v0[args](1, {
v9: v7 => super.v3(v27),
foo: a,
done: 'a'
});
}
};

View File

@ -1,18 +0,0 @@
function f0() {}
f0.prototype = {
name: "Nicholas",
age: 29,
job: "Software Engineer",
sayName () {
var _this = this, _superprop_get_v3 = function() {
return super.v3;
};
v0[args](1, {
v9: function(v7) {
return _superprop_get_v3().call(_this, v27);
},
foo: a,
done: "a"
});
}
};

View File

@ -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(),
@ -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,
);
}

View File

@ -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,
@ -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 {
@ -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);
};
})();
}