Fixes setter paratemer default value (#8479)

* Fixes setter paratemer default value

* Not changes doesn't mutate loose variable
This commit is contained in:
Nikolay Emrikh 2018-08-16 08:54:50 +03:00 committed by Justin Ridgewell
parent 3989213e37
commit 5043ec78bc
4 changed files with 27 additions and 3 deletions

View File

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

View 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);

View File

@ -0,0 +1,5 @@
const obj = {
set field(num = 1) {
this.num = num;
}
};

View File

@ -0,0 +1,10 @@
var obj = {
set field(num) {
if (num === void 0) {
num = 1;
}
this.num = num;
}
};