Skip to content

Commit 041d045

Browse files
committed
Revise return control flow graph construction logic
1 parent 190f99e commit 041d045

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

src/compiler/binder.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -506,16 +506,14 @@ namespace ts {
506506
const isIIFE = containerFlags & ContainerFlags.IsFunctionExpression && !hasModifier(node, ModifierFlags.Async) && !!getImmediatelyInvokedFunctionExpression(node);
507507
// A non-async IIFE is considered part of the containing control flow. Return statements behave
508508
// similarly to break statements that exit to a label just past the statement body.
509-
if (isIIFE) {
510-
currentReturnTarget = createBranchLabel();
511-
}
512-
else {
509+
if (!isIIFE) {
513510
currentFlow = { flags: FlowFlags.Start };
514511
if (containerFlags & (ContainerFlags.IsFunctionExpression | ContainerFlags.IsObjectLiteralOrClassExpressionMethod)) {
515512
(<FlowStart>currentFlow).container = <FunctionExpression | ArrowFunction | MethodDeclaration>node;
516513
}
517-
currentReturnTarget = node.kind === SyntaxKind.Constructor ? createBranchLabel() : undefined;
518514
}
515+
// We create a return control flow graph for IIFEs and constructors. For constructors
516+
// we use the return control flow graph in strict property intialization checks.
519517
currentReturnTarget = isIIFE || node.kind === SyntaxKind.Constructor ? createBranchLabel() : undefined;
520518
currentBreakTarget = undefined;
521519
currentContinueTarget = undefined;
@@ -531,15 +529,14 @@ namespace ts {
531529
if (node.kind === SyntaxKind.SourceFile) {
532530
node.flags |= emitFlags;
533531
}
534-
if (isIIFE) {
532+
if (currentReturnTarget) {
535533
addAntecedent(currentReturnTarget, currentFlow);
536534
currentFlow = finishFlowLabel(currentReturnTarget);
537-
}
538-
else {
539535
if (node.kind === SyntaxKind.Constructor) {
540-
addAntecedent(currentReturnTarget, currentFlow);
541536
(<ConstructorDeclaration>node).returnFlowNode = currentFlow;
542537
}
538+
}
539+
if (!isIIFE) {
543540
currentFlow = saveCurrentFlow;
544541
}
545542
currentBreakTarget = saveBreakTarget;

0 commit comments

Comments
 (0)