mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 09:38:16 +03:00
fix(es/compat): Hoist env in function params (#4210)
This commit is contained in:
parent
809c87e8b7
commit
6a27a0ce88
@ -0,0 +1,24 @@
|
||||
{
|
||||
"jsc": {
|
||||
"externalHelpers": true,
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"decorators": true,
|
||||
"tsx": true
|
||||
},
|
||||
"transform": {
|
||||
"legacyDecorator": true,
|
||||
"decoratorMetadata": false
|
||||
},
|
||||
"target": "es5",
|
||||
"loose": false,
|
||||
"minify": {
|
||||
"compress": false,
|
||||
"mangle": false
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "es6"
|
||||
},
|
||||
"minify": false
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
export class CompanyBgStore {
|
||||
public corpName = 123;
|
||||
|
||||
public getBusinessInfo = async (corpName = this.corpName) => {
|
||||
console.log(corpName);
|
||||
};
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
import * as swcHelpers from "@swc/helpers";
|
||||
import regeneratorRuntime from "regenerator-runtime";
|
||||
export var CompanyBgStore = function CompanyBgStore() {
|
||||
"use strict";
|
||||
swcHelpers.classCallCheck(this, CompanyBgStore);
|
||||
this.corpName = 123;
|
||||
var _this = this;
|
||||
this.getBusinessInfo = swcHelpers.asyncToGenerator(regeneratorRuntime.mark(function _callee() {
|
||||
var corpName, _args = arguments;
|
||||
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
||||
while(1)switch(_ctx.prev = _ctx.next){
|
||||
case 0:
|
||||
corpName = _args.length > 0 && _args[0] !== void 0 ? _args[0] : _this.corpName;
|
||||
console.log(corpName);
|
||||
case 2:
|
||||
case "end":
|
||||
return _ctx.stop();
|
||||
}
|
||||
}, _callee);
|
||||
}));
|
||||
};
|
@ -309,7 +309,7 @@ impl Actual {
|
||||
Expr::Arrow(arrow_expr @ ArrowExpr { is_async: true, .. }) => {
|
||||
let mut state = FnEnvHoister::default();
|
||||
|
||||
arrow_expr.body.visit_mut_with(&mut state);
|
||||
arrow_expr.visit_mut_with(&mut state);
|
||||
|
||||
self.hoist_stmts.extend(state.to_stmt());
|
||||
|
||||
|
@ -3557,6 +3557,32 @@ const p = Z((f)=>_asyncToGenerator(function*(n = 0) {
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
Syntax::default(),
|
||||
|_| async_to_generator(Default::default()),
|
||||
issue_4208,
|
||||
"
|
||||
function foo() {
|
||||
const bar = async (baz = this.baz) => {
|
||||
console.log(this);
|
||||
}
|
||||
}
|
||||
",
|
||||
"
|
||||
function foo() {
|
||||
var _this = this;
|
||||
const bar = function() {
|
||||
var _ref = _asyncToGenerator(function*(baz = _this.baz) {
|
||||
console.log(_this);
|
||||
});
|
||||
return function bar() {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
}();
|
||||
}
|
||||
"
|
||||
);
|
||||
|
||||
#[testing::fixture("tests/async-to-generator/**/exec.js")]
|
||||
fn exec(input: PathBuf) {
|
||||
let input = read_to_string(&input).unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user