avoid shouldCaptureInTempVariable
This commit is contained in:
parent
9681c1611c
commit
11bed4456b
2 changed files with 4 additions and 12 deletions
|
@ -73,7 +73,7 @@ namespace ts {
|
||||||
|
|
||||||
let thisArg: Expression | undefined;
|
let thisArg: Expression | undefined;
|
||||||
if (captureThisArg) {
|
if (captureThisArg) {
|
||||||
if (shouldCaptureInTempVariable(expression)) {
|
if (!isSimpleCopiableExpression(expression)) {
|
||||||
thisArg = createTempVariable(hoistVariableDeclaration);
|
thisArg = createTempVariable(hoistVariableDeclaration);
|
||||||
expression = createAssignment(thisArg, expression);
|
expression = createAssignment(thisArg, expression);
|
||||||
// if (inParameterInitializer) tempVariableInParameter = true;
|
// if (inParameterInitializer) tempVariableInParameter = true;
|
||||||
|
@ -113,7 +113,7 @@ namespace ts {
|
||||||
const leftThisArg = isSyntheticReference(left) ? left.thisArg : undefined;
|
const leftThisArg = isSyntheticReference(left) ? left.thisArg : undefined;
|
||||||
let leftExpression = isSyntheticReference(left) ? left.expression : left;
|
let leftExpression = isSyntheticReference(left) ? left.expression : left;
|
||||||
let capturedLeft: Expression = leftExpression;
|
let capturedLeft: Expression = leftExpression;
|
||||||
if (shouldCaptureInTempVariable(leftExpression)) {
|
if (!isSimpleCopiableExpression(leftExpression)) {
|
||||||
capturedLeft = createTempVariable(hoistVariableDeclaration);
|
capturedLeft = createTempVariable(hoistVariableDeclaration);
|
||||||
leftExpression = createAssignment(capturedLeft, leftExpression);
|
leftExpression = createAssignment(capturedLeft, leftExpression);
|
||||||
// if (inParameterInitializer) tempVariableInParameter = true;
|
// if (inParameterInitializer) tempVariableInParameter = true;
|
||||||
|
@ -126,7 +126,7 @@ namespace ts {
|
||||||
case SyntaxKind.PropertyAccessExpression:
|
case SyntaxKind.PropertyAccessExpression:
|
||||||
case SyntaxKind.ElementAccessExpression:
|
case SyntaxKind.ElementAccessExpression:
|
||||||
if (i === chain.length - 1 && captureThisArg) {
|
if (i === chain.length - 1 && captureThisArg) {
|
||||||
if (shouldCaptureInTempVariable(rightExpression)) {
|
if (!isSimpleCopiableExpression(rightExpression)) {
|
||||||
thisArg = createTempVariable(hoistVariableDeclaration);
|
thisArg = createTempVariable(hoistVariableDeclaration);
|
||||||
rightExpression = createAssignment(thisArg, rightExpression);
|
rightExpression = createAssignment(thisArg, rightExpression);
|
||||||
// if (inParameterInitializer) tempVariableInParameter = true;
|
// if (inParameterInitializer) tempVariableInParameter = true;
|
||||||
|
@ -184,7 +184,7 @@ namespace ts {
|
||||||
function transformNullishCoalescingExpression(node: BinaryExpression) {
|
function transformNullishCoalescingExpression(node: BinaryExpression) {
|
||||||
let left = visitNode(node.left, visitor, isExpression);
|
let left = visitNode(node.left, visitor, isExpression);
|
||||||
let right = left;
|
let right = left;
|
||||||
if (shouldCaptureInTempVariable(left)) {
|
if (!isSimpleCopiableExpression(left)) {
|
||||||
right = createTempVariable(hoistVariableDeclaration);
|
right = createTempVariable(hoistVariableDeclaration);
|
||||||
left = createAssignment(right, left);
|
left = createAssignment(right, left);
|
||||||
// if (inParameterInitializer) tempVariableInParameter = true;
|
// if (inParameterInitializer) tempVariableInParameter = true;
|
||||||
|
|
|
@ -280,14 +280,6 @@ namespace ts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function shouldCaptureInTempVariable(expression: Expression): boolean {
|
|
||||||
// don't capture identifiers and `this` in a temporary variable
|
|
||||||
// `super` cannot be captured as it's not a real variable
|
|
||||||
return !isIdentifier(expression) &&
|
|
||||||
expression.kind !== SyntaxKind.ThisKeyword &&
|
|
||||||
expression.kind !== SyntaxKind.SuperKeyword;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds super call and preceding prologue directives into the list of statements.
|
* Adds super call and preceding prologue directives into the list of statements.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue