Support transforming params of arrow functions in class fields (#13941)

This commit is contained in:
Nicolò Ribaudo
2021-11-09 12:12:23 +01:00
committed by GitHub
parent a6a526968d
commit 43f989941b
17 changed files with 167 additions and 20 deletions

View File

@@ -0,0 +1 @@
let f = (x = 0) => x + 1;

View File

@@ -0,0 +1,7 @@
var _this = this;
let f = function f() {
let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
babelHelpers.newArrowCheck(this, _this);
return x + 1;
}.bind(this);

View File

@@ -0,0 +1,6 @@
{
"plugins": ["transform-parameters"],
"assumptions": {
"noNewArrows": false
}
}

View File

@@ -0,0 +1,8 @@
class A extends B {
handle = ((x = 0) => {
console.log(x, this, new.target, super.y);
})(() => {
let y = 0;
return (x = y) => x + this;
})((x = 1) => {})(this);
}

View File

@@ -0,0 +1,5 @@
{
"plugins": [
"transform-parameters"
]
}

View File

@@ -0,0 +1,22 @@
class A extends B {
handle = (() => {
var _newtarget = new.target,
_superprop_getY = () => super.y,
_this = this;
return function () {
let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
console.log(x, _this, _newtarget, _superprop_getY());
};
})()(() => {
var _this2 = this;
let y = 0;
return function () {
let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : y;
return x + _this2;
};
})((() => function () {
let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
})())(this);
}

View File

@@ -0,0 +1,8 @@
class A extends B {
#handle = ((x = 0) => {
console.log(x, this, new.target, super.y);
})(() => {
let y = 0;
return (x = y) => x + this;
})((x = 1) => {})(this);
}

View File

@@ -0,0 +1,5 @@
{
"plugins": [
"transform-parameters"
]
}

View File

@@ -0,0 +1,22 @@
class A extends B {
#handle = (() => {
var _newtarget = new.target,
_superprop_getY = () => super.y,
_this = this;
return function () {
let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
console.log(x, _this, _newtarget, _superprop_getY());
};
})()(() => {
var _this2 = this;
let y = 0;
return function () {
let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : y;
return x + _this2;
};
})((() => function () {
let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
})())(this);
}

View File

@@ -0,0 +1,5 @@
class A {
#handle = (x = 0) => {
console.log(x);
};
}

View File

@@ -0,0 +1,5 @@
{
"plugins": [
"transform-parameters"
]
}

View File

@@ -0,0 +1,6 @@
class A {
#handle = (() => function () {
let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
console.log(x);
})();
}

View File

@@ -0,0 +1,5 @@
class A {
handle = (x = 0) => {
console.log(x);
};
}

View File

@@ -0,0 +1,5 @@
{
"plugins": [
"transform-parameters"
]
}

View File

@@ -0,0 +1,6 @@
class A {
handle = (() => function () {
let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
console.log(x);
})();
}