Skip to content

Commit 7fcde00

Browse files
author
Andy Hanson
committed
Use a union for FlowNode
1 parent 08d8e04 commit 7fcde00

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/compiler/binder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,20 +801,20 @@ namespace ts {
801801
return antecedent;
802802
}
803803
setFlowNodeReferenced(antecedent);
804-
return id<FlowCondition>({ flags, expression, antecedent });
804+
return { flags, expression, antecedent };
805805
}
806806

807807
function createFlowSwitchClause(antecedent: FlowNode, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number): FlowNode {
808808
if (!isNarrowingExpression(switchStatement.expression)) {
809809
return antecedent;
810810
}
811811
setFlowNodeReferenced(antecedent);
812-
return id<FlowSwitchClause>({ flags: FlowFlags.SwitchClause, switchStatement, clauseStart, clauseEnd, antecedent });
812+
return { flags: FlowFlags.SwitchClause, switchStatement, clauseStart, clauseEnd, antecedent };
813813
}
814814

815815
function createFlowAssignment(antecedent: FlowNode, node: Expression | VariableDeclaration | BindingElement): FlowNode {
816816
setFlowNodeReferenced(antecedent);
817-
return id<FlowAssignment>({ flags: FlowFlags.Assignment, antecedent, node });
817+
return { flags: FlowFlags.Assignment, antecedent, node };
818818
}
819819

820820
function createFlowArrayMutation(antecedent: FlowNode, node: CallExpression | BinaryExpression): FlowNode {

src/compiler/types.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,47 +2176,49 @@ namespace ts {
21762176
locked?: boolean;
21772177
}
21782178

2179-
export interface AfterFinallyFlow extends FlowNode, FlowLock {
2179+
export interface AfterFinallyFlow extends FlowNodeBase, FlowLock {
21802180
antecedent: FlowNode;
21812181
}
21822182

2183-
export interface PreFinallyFlow extends FlowNode {
2183+
export interface PreFinallyFlow extends FlowNodeBase {
21842184
antecedent: FlowNode;
21852185
lock: FlowLock;
21862186
}
21872187

2188-
export interface FlowNode {
2188+
export type FlowNode =
2189+
| AfterFinallyFlow | PreFinallyFlow | FlowStart | FlowLabel | FlowAssignment | FlowCondition | FlowSwitchClause | FlowArrayMutation;
2190+
export interface FlowNodeBase {
21892191
flags: FlowFlags;
21902192
id?: number; // Node id used by flow type cache in checker
21912193
}
21922194

21932195
// FlowStart represents the start of a control flow. For a function expression or arrow
21942196
// function, the container property references the function (which in turn has a flowNode
21952197
// property for the containing control flow).
2196-
export interface FlowStart extends FlowNode {
2198+
export interface FlowStart extends FlowNodeBase {
21972199
container?: FunctionExpression | ArrowFunction | MethodDeclaration;
21982200
}
21992201

22002202
// FlowLabel represents a junction with multiple possible preceding control flows.
2201-
export interface FlowLabel extends FlowNode {
2203+
export interface FlowLabel extends FlowNodeBase {
22022204
antecedents: FlowNode[];
22032205
}
22042206

22052207
// FlowAssignment represents a node that assigns a value to a narrowable reference,
22062208
// i.e. an identifier or a dotted name that starts with an identifier or 'this'.
2207-
export interface FlowAssignment extends FlowNode {
2209+
export interface FlowAssignment extends FlowNodeBase {
22082210
node: Expression | VariableDeclaration | BindingElement;
22092211
antecedent: FlowNode;
22102212
}
22112213

22122214
// FlowCondition represents a condition that is known to be true or false at the
22132215
// node's location in the control flow.
2214-
export interface FlowCondition extends FlowNode {
2216+
export interface FlowCondition extends FlowNodeBase {
22152217
expression: Expression;
22162218
antecedent: FlowNode;
22172219
}
22182220

2219-
export interface FlowSwitchClause extends FlowNode {
2221+
export interface FlowSwitchClause extends FlowNodeBase {
22202222
switchStatement: SwitchStatement;
22212223
clauseStart: number; // Start index of case/default clause range
22222224
clauseEnd: number; // End index of case/default clause range
@@ -2225,7 +2227,7 @@ namespace ts {
22252227

22262228
// FlowArrayMutation represents a node potentially mutates an array, i.e. an
22272229
// operation of the form 'x.push(value)', 'x.unshift(value)' or 'x[n] = value'.
2228-
export interface FlowArrayMutation extends FlowNode {
2230+
export interface FlowArrayMutation extends FlowNodeBase {
22292231
node: CallExpression | BinaryExpression;
22302232
antecedent: FlowNode;
22312233
}

0 commit comments

Comments
 (0)