Skip to content

Commit 11bed44

Browse files
committed
avoid shouldCaptureInTempVariable
1 parent 9681c16 commit 11bed44

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

src/compiler/transformers/es2020.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace ts {
7373

7474
let thisArg: Expression | undefined;
7575
if (captureThisArg) {
76-
if (shouldCaptureInTempVariable(expression)) {
76+
if (!isSimpleCopiableExpression(expression)) {
7777
thisArg = createTempVariable(hoistVariableDeclaration);
7878
expression = createAssignment(thisArg, expression);
7979
// if (inParameterInitializer) tempVariableInParameter = true;
@@ -113,7 +113,7 @@ namespace ts {
113113
const leftThisArg = isSyntheticReference(left) ? left.thisArg : undefined;
114114
let leftExpression = isSyntheticReference(left) ? left.expression : left;
115115
let capturedLeft: Expression = leftExpression;
116-
if (shouldCaptureInTempVariable(leftExpression)) {
116+
if (!isSimpleCopiableExpression(leftExpression)) {
117117
capturedLeft = createTempVariable(hoistVariableDeclaration);
118118
leftExpression = createAssignment(capturedLeft, leftExpression);
119119
// if (inParameterInitializer) tempVariableInParameter = true;
@@ -126,7 +126,7 @@ namespace ts {
126126
case SyntaxKind.PropertyAccessExpression:
127127
case SyntaxKind.ElementAccessExpression:
128128
if (i === chain.length - 1 && captureThisArg) {
129-
if (shouldCaptureInTempVariable(rightExpression)) {
129+
if (!isSimpleCopiableExpression(rightExpression)) {
130130
thisArg = createTempVariable(hoistVariableDeclaration);
131131
rightExpression = createAssignment(thisArg, rightExpression);
132132
// if (inParameterInitializer) tempVariableInParameter = true;
@@ -184,7 +184,7 @@ namespace ts {
184184
function transformNullishCoalescingExpression(node: BinaryExpression) {
185185
let left = visitNode(node.left, visitor, isExpression);
186186
let right = left;
187-
if (shouldCaptureInTempVariable(left)) {
187+
if (!isSimpleCopiableExpression(left)) {
188188
right = createTempVariable(hoistVariableDeclaration);
189189
left = createAssignment(right, left);
190190
// if (inParameterInitializer) tempVariableInParameter = true;

src/compiler/transformers/utilities.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,6 @@ namespace ts {
280280
}
281281
}
282282

283-
export function shouldCaptureInTempVariable(expression: Expression): boolean {
284-
// don't capture identifiers and `this` in a temporary variable
285-
// `super` cannot be captured as it's not a real variable
286-
return !isIdentifier(expression) &&
287-
expression.kind !== SyntaxKind.ThisKeyword &&
288-
expression.kind !== SyntaxKind.SuperKeyword;
289-
}
290-
291283
/**
292284
* Adds super call and preceding prologue directives into the list of statements.
293285
*

0 commit comments

Comments
 (0)