@@ -148,8 +148,8 @@ namespace ts {
148
148
let Symbol : new ( flags : SymbolFlags , name : __String ) => Symbol ; // tslint:disable-line variable-name
149
149
let classifiableNames : UnderscoreEscapedMap < true > ;
150
150
151
- const unreachableFlow : FlowNode = { flags : FlowFlags . Unreachable } ;
152
- const reportedUnreachableFlow : FlowNode = { flags : FlowFlags . Unreachable } ;
151
+ const unreachableFlow = createFlowNode ( FlowFlags . Unreachable , /*antecedent*/ undefined , /*node*/ undefined ) ;
152
+ const reportedUnreachableFlow : FlowNode = createFlowNode ( FlowFlags . Unreachable , /*antecedent*/ undefined , /*node*/ undefined ) ;
153
153
154
154
// state used to aggregate transform flags during bind.
155
155
let subtreeTransformFlags : TransformFlags = TransformFlags . None ;
@@ -560,9 +560,9 @@ namespace ts {
560
560
// A non-async, non-generator IIFE is considered part of the containing control flow. Return statements behave
561
561
// similarly to break statements that exit to a label just past the statement body.
562
562
if ( ! isIIFE ) {
563
- currentFlow = { flags : FlowFlags . Start } ;
563
+ currentFlow = createFlowNode ( FlowFlags . Start , /*antecedent*/ undefined , /*node*/ undefined ) as FlowStart ;
564
564
if ( containerFlags & ( ContainerFlags . IsFunctionExpression | ContainerFlags . IsObjectLiteralOrClassExpressionMethod ) ) {
565
- currentFlow . container = < FunctionExpression | ArrowFunction | MethodDeclaration > node ;
565
+ currentFlow . node = < FunctionExpression | ArrowFunction | MethodDeclaration > node ;
566
566
}
567
567
}
568
568
// We create a return control flow graph for IIFEs and constructors. For constructors
@@ -842,18 +842,22 @@ namespace ts {
842
842
return isNarrowableReference ( expr ) ;
843
843
}
844
844
845
- function createBranchLabel ( ) : FlowLabel {
845
+ function createFlowNode ( flags : FlowFlags , antecedent : FlowNode | undefined , node : Node | undefined ) {
846
846
return {
847
- flags : FlowFlags . BranchLabel ,
848
- antecedents : undefined
849
- } ;
847
+ flags,
848
+ antecedent,
849
+ node,
850
+ id : undefined ,
851
+ antecedents : undefined ,
852
+ } as FlowNode ;
853
+ }
854
+
855
+ function createBranchLabel ( ) : FlowLabel {
856
+ return createFlowNode ( FlowFlags . BranchLabel , /*antecedent*/ undefined , /*node*/ undefined ) as FlowLabel ;
850
857
}
851
858
852
859
function createLoopLabel ( ) : FlowLabel {
853
- return {
854
- flags : FlowFlags . LoopLabel ,
855
- antecedents : undefined
856
- } ;
860
+ return createFlowNode ( FlowFlags . LoopLabel , /*antecedent*/ undefined , /*node*/ undefined ) as FlowLabel ;
857
861
}
858
862
859
863
function setFlowNodeReferenced ( flow : FlowNode ) {
@@ -883,31 +887,34 @@ namespace ts {
883
887
return antecedent ;
884
888
}
885
889
setFlowNodeReferenced ( antecedent ) ;
886
- return flowNodeCreated ( { flags, expression , antecedent } ) ;
890
+ return flowNodeCreated ( createFlowNode ( flags , antecedent , expression ) ) ;
887
891
}
888
892
889
893
function createFlowSwitchClause ( antecedent : FlowNode , switchStatement : SwitchStatement , clauseStart : number , clauseEnd : number ) : FlowNode {
890
894
if ( ! isNarrowingExpression ( switchStatement . expression ) ) {
891
895
return antecedent ;
892
896
}
893
897
setFlowNodeReferenced ( antecedent ) ;
894
- return flowNodeCreated ( { flags : FlowFlags . SwitchClause , switchStatement, clauseStart, clauseEnd, antecedent } ) ;
898
+ const result = createFlowNode ( FlowFlags . SwitchClause , antecedent , /*node*/ undefined ) as FlowSwitchClause ;
899
+ result . switchStatement = switchStatement ;
900
+ result . clauseStart = clauseStart ;
901
+ result . clauseEnd = clauseEnd ;
902
+ return flowNodeCreated ( result ) ;
895
903
}
896
904
897
905
function createFlowAssignment ( antecedent : FlowNode , node : Expression | VariableDeclaration | BindingElement ) : FlowNode {
898
906
setFlowNodeReferenced ( antecedent ) ;
899
- return flowNodeCreated ( { flags : FlowFlags . Assignment , antecedent, node } ) ;
907
+ return flowNodeCreated ( createFlowNode ( FlowFlags . Assignment , antecedent , node ) ) ;
900
908
}
901
909
902
910
function createFlowCall ( antecedent : FlowNode , node : CallExpression ) : FlowNode {
903
911
setFlowNodeReferenced ( antecedent ) ;
904
- return flowNodeCreated ( { flags : FlowFlags . Call , antecedent, node } ) ;
912
+ return flowNodeCreated ( createFlowNode ( FlowFlags . Call , antecedent , node ) ) ;
905
913
}
906
914
907
915
function createFlowArrayMutation ( antecedent : FlowNode , node : CallExpression | BinaryExpression ) : FlowNode {
908
916
setFlowNodeReferenced ( antecedent ) ;
909
- const res : FlowArrayMutation = flowNodeCreated ( { flags : FlowFlags . ArrayMutation , antecedent, node } ) ;
910
- return res ;
917
+ return flowNodeCreated ( createFlowNode ( FlowFlags . ArrayMutation , antecedent , node ) ) ;
911
918
}
912
919
913
920
function finishFlowLabel ( flow : FlowLabel ) : FlowNode {
@@ -1185,7 +1192,8 @@ namespace ts {
1185
1192
//
1186
1193
// extra edges that we inject allows to control this behavior
1187
1194
// if when walking the flow we step on post-finally edge - we can mark matching pre-finally edge as locked so it will be skipped.
1188
- const preFinallyFlow : PreFinallyFlow = { flags : FlowFlags . PreFinally , antecedent : preFinallyPrior , lock : { } } ;
1195
+ const preFinallyFlow = createFlowNode ( FlowFlags . PreFinally , preFinallyPrior , /*node*/ undefined ) as PreFinallyFlow ;
1196
+ preFinallyFlow . lock = { } ;
1189
1197
addAntecedent ( preFinallyLabel , preFinallyFlow ) ;
1190
1198
1191
1199
currentFlow = finishFlowLabel ( preFinallyLabel ) ;
@@ -1204,7 +1212,7 @@ namespace ts {
1204
1212
}
1205
1213
}
1206
1214
if ( ! ( currentFlow . flags & FlowFlags . Unreachable ) ) {
1207
- const afterFinallyFlow : AfterFinallyFlow = flowNodeCreated ( { flags : FlowFlags . AfterFinally , antecedent : currentFlow } ) ;
1215
+ const afterFinallyFlow = flowNodeCreated ( createFlowNode ( FlowFlags . AfterFinally , currentFlow , /*node*/ undefined ) as AfterFinallyFlow ) ;
1208
1216
preFinallyFlow . lock = afterFinallyFlow ;
1209
1217
currentFlow = afterFinallyFlow ;
1210
1218
}
@@ -1828,7 +1836,7 @@ namespace ts {
1828
1836
const host = getJSDocHost ( typeAlias ) ;
1829
1837
container = findAncestor ( host . parent , n => ! ! ( getContainerFlags ( n ) & ContainerFlags . IsContainer ) ) || file ;
1830
1838
blockScopeContainer = getEnclosingBlockScopeContainer ( host ) || file ;
1831
- currentFlow = { flags : FlowFlags . Start } ;
1839
+ currentFlow = createFlowNode ( FlowFlags . Start , /*antecedent*/ undefined , /*node*/ undefined ) ;
1832
1840
parent = typeAlias ;
1833
1841
bind ( typeAlias . typeExpression ) ;
1834
1842
if ( isJSDocEnumTag ( typeAlias ) || ! typeAlias . fullName || typeAlias . fullName . kind === SyntaxKind . Identifier ) {
0 commit comments