Fixes setter paratemer default value (#8479)
* Fixes setter paratemer default value * Not changes doesn't mutate loose variable
This commit is contained in:
parent
3989213e37
commit
5043ec78bc
@ -60,7 +60,8 @@ export default function convertFunctionParams(path, loose) {
|
|||||||
for (let i = 0; i < params.length; i++) {
|
for (let i = 0; i < params.length; i++) {
|
||||||
const param = params[i];
|
const param = params[i];
|
||||||
|
|
||||||
if (param.isAssignmentPattern() && loose) {
|
const paramIsAssignmentPattern = param.isAssignmentPattern();
|
||||||
|
if (paramIsAssignmentPattern && (loose || node.kind === "set")) {
|
||||||
const left = param.get("left");
|
const left = param.get("left");
|
||||||
const right = param.get("right");
|
const right = param.get("right");
|
||||||
|
|
||||||
@ -87,13 +88,12 @@ export default function convertFunctionParams(path, loose) {
|
|||||||
);
|
);
|
||||||
param.replaceWith(paramName);
|
param.replaceWith(paramName);
|
||||||
}
|
}
|
||||||
} else if (param.isAssignmentPattern()) {
|
} else if (paramIsAssignmentPattern) {
|
||||||
if (firstOptionalIndex === null) firstOptionalIndex = i;
|
if (firstOptionalIndex === null) firstOptionalIndex = i;
|
||||||
|
|
||||||
const left = param.get("left");
|
const left = param.get("left");
|
||||||
const right = param.get("right");
|
const right = param.get("right");
|
||||||
|
|
||||||
//
|
|
||||||
if (!state.iife) {
|
if (!state.iife) {
|
||||||
if (right.isIdentifier() && !isSafeBinding(scope, right.node)) {
|
if (right.isIdentifier() && !isSafeBinding(scope, right.node)) {
|
||||||
// the right hand side references a parameter
|
// the right hand side references a parameter
|
||||||
|
|||||||
9
packages/babel-plugin-transform-parameters/test/fixtures/parameters/default-setter/exec.js
vendored
Normal file
9
packages/babel-plugin-transform-parameters/test/fixtures/parameters/default-setter/exec.js
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
const defaultValue = 1;
|
||||||
|
const obj = {
|
||||||
|
set field(num = defaultValue) {
|
||||||
|
this.num = num;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
obj.field = void 0;
|
||||||
|
|
||||||
|
expect(obj.num).toBe(defaultValue);
|
||||||
5
packages/babel-plugin-transform-parameters/test/fixtures/parameters/default-setter/input.js
vendored
Normal file
5
packages/babel-plugin-transform-parameters/test/fixtures/parameters/default-setter/input.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
const obj = {
|
||||||
|
set field(num = 1) {
|
||||||
|
this.num = num;
|
||||||
|
}
|
||||||
|
};
|
||||||
10
packages/babel-plugin-transform-parameters/test/fixtures/parameters/default-setter/output.js
vendored
Normal file
10
packages/babel-plugin-transform-parameters/test/fixtures/parameters/default-setter/output.js
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
var obj = {
|
||||||
|
set field(num) {
|
||||||
|
if (num === void 0) {
|
||||||
|
num = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.num = num;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user