Skip to content

Commit

Permalink
avoid shouldCaptureInTempVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingwl committed May 6, 2020
1 parent e02591d commit b62c8c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/compiler/transformers/es2020.ts
Expand Up @@ -73,7 +73,7 @@ namespace ts {

let thisArg: Expression | undefined;
if (captureThisArg) {
if (shouldCaptureInTempVariable(expression)) {
if (!isSimpleCopiableExpression(expression)) {
thisArg = createTempVariable(hoistVariableDeclaration);
expression = createAssignment(thisArg, expression);
// if (inParameterInitializer) tempVariableInParameter = true;
Expand Down Expand Up @@ -113,7 +113,7 @@ namespace ts {
const leftThisArg = isSyntheticReference(left) ? left.thisArg : undefined;
let leftExpression = isSyntheticReference(left) ? left.expression : left;
let capturedLeft: Expression = leftExpression;
if (shouldCaptureInTempVariable(leftExpression)) {
if (!isSimpleCopiableExpression(leftExpression)) {
capturedLeft = createTempVariable(hoistVariableDeclaration);
leftExpression = createAssignment(capturedLeft, leftExpression);
// if (inParameterInitializer) tempVariableInParameter = true;
Expand All @@ -126,7 +126,7 @@ namespace ts {
case SyntaxKind.PropertyAccessExpression:
case SyntaxKind.ElementAccessExpression:
if (i === chain.length - 1 && captureThisArg) {
if (shouldCaptureInTempVariable(rightExpression)) {
if (!isSimpleCopiableExpression(rightExpression)) {
thisArg = createTempVariable(hoistVariableDeclaration);
rightExpression = createAssignment(thisArg, rightExpression);
// if (inParameterInitializer) tempVariableInParameter = true;
Expand Down Expand Up @@ -184,7 +184,7 @@ namespace ts {
function transformNullishCoalescingExpression(node: BinaryExpression) {
let left = visitNode(node.left, visitor, isExpression);
let right = left;
if (shouldCaptureInTempVariable(left)) {
if (!isSimpleCopiableExpression(left)) {
right = createTempVariable(hoistVariableDeclaration);
left = createAssignment(right, left);
// if (inParameterInitializer) tempVariableInParameter = true;
Expand Down
8 changes: 0 additions & 8 deletions src/compiler/transformers/utilities.ts
Expand Up @@ -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.
*
Expand Down

0 comments on commit b62c8c8

Please sign in to comment.