Fix reused nodes - part 1 (#7149)

This commit is contained in:
Mateusz Burzyński
2018-01-11 19:31:48 +01:00
committed by Nicolò Ribaudo
parent 63ae923987
commit 912bcc186d
30 changed files with 202 additions and 117 deletions

View File

@@ -69,7 +69,7 @@ export default function convertFunctionParams(path, loose) {
if (left.isIdentifier()) {
body.push(
buildLooseDefaultParam({
ASSIGNMENT_IDENTIFIER: left.node,
ASSIGNMENT_IDENTIFIER: t.cloneNode(left.node),
DEFAULT_VALUE: right.node,
UNDEFINED: undefinedNode,
}),
@@ -81,7 +81,7 @@ export default function convertFunctionParams(path, loose) {
buildLooseDestructuredDefaultParam({
ASSIGNMENT_IDENTIFIER: left.node,
DEFAULT_VALUE: right.node,
PARAMETER_NAME: paramName,
PARAMETER_NAME: t.cloneNode(paramName),
UNDEFINED: undefinedNode,
}),
);
@@ -123,7 +123,7 @@ export default function convertFunctionParams(path, loose) {
]);
body.push(defNode);
param.replaceWith(uid);
param.replaceWith(t.cloneNode(uid));
}
if (!state.iife && !param.isIdentifier()) {

View File

@@ -168,7 +168,11 @@ function optimiseIndexGetter(path, argsId, offset) {
// Avoid unnecessary '+ 0'
index = path.parent.property;
} else {
index = t.binaryExpression("+", path.parent.property, offsetLiteral);
index = t.binaryExpression(
"+",
path.parent.property,
t.cloneNode(offsetLiteral),
);
}
const { scope } = path;
@@ -180,7 +184,7 @@ function optimiseIndexGetter(path, argsId, offset) {
ARGUMENTS: argsId,
OFFSET: offsetLiteral,
INDEX: index,
REF: temp,
REF: t.cloneNode(temp),
}),
);
} else {
@@ -262,15 +266,16 @@ export default function convertFunctionRest(path) {
// There are only "shorthand" references
if (!state.deopted && !state.references.length) {
for (const { path, cause } of (state.candidates: Array)) {
const clonedArgsId = t.cloneNode(argsId);
switch (cause) {
case "indexGetter":
optimiseIndexGetter(path, argsId, state.offset);
optimiseIndexGetter(path, clonedArgsId, state.offset);
break;
case "lengthGetter":
optimiseLengthGetter(path, argsId, state.offset);
optimiseLengthGetter(path, clonedArgsId, state.offset);
break;
default:
path.replaceWith(argsId);
path.replaceWith(clonedArgsId);
}
}
return true;
@@ -290,7 +295,7 @@ export default function convertFunctionRest(path) {
// this method has additional params, so we need to subtract
// the index of the current argument position from the
// position in the array that we want to populate
arrKey = t.binaryExpression("-", key, start);
arrKey = t.binaryExpression("-", t.cloneNode(key), t.cloneNode(start));
// we need to work out the size of the array that we're
// going to store all the rest parameters
@@ -299,8 +304,8 @@ export default function convertFunctionRest(path) {
// with <0 if there are less arguments than params as it'll
// cause an error
arrLen = t.conditionalExpression(
t.binaryExpression(">", len, start),
t.binaryExpression("-", len, start),
t.binaryExpression(">", t.cloneNode(len), t.cloneNode(start)),
t.binaryExpression("-", t.cloneNode(len), t.cloneNode(start)),
t.numericLiteral(0),
);
}