Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 11bed44

Browse filesBrowse files
committed
avoid shouldCaptureInTempVariable
1 parent 9681c16 commit 11bed44
Copy full SHA for 11bed44

2 files changed

+4-12Lines changed: 4 additions & 12 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/transformers/es2020.ts‎

Copy file name to clipboardExpand all lines: src/compiler/transformers/es2020.ts
+4-4Lines 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;
Collapse file

‎src/compiler/transformers/utilities.ts‎

Copy file name to clipboardExpand all lines: src/compiler/transformers/utilities.ts
-8Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.