Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c95daab
Add support for Optional Chaining
rbuckton Sep 6, 2019
c2f53fc
Add grammar error for invalid tagged template, more tests
rbuckton Sep 7, 2019
0f5d5d6
Prototype
andrewbranch Sep 23, 2019
24de747
Merge branch 'master' into optionalChainingStage3
rbuckton Sep 23, 2019
7be47ab
PR feedback
rbuckton Sep 24, 2019
e073c05
Add errors for invalid assignments and a trailing '?.'
rbuckton Sep 24, 2019
72f44d9
Add additional signature help test, fix lint warnings
rbuckton Sep 24, 2019
488c9e6
Merge branch 'master' into optionalChainingStage3
rbuckton Sep 24, 2019
2ffd8e1
Merge branch 'enhancement/auto-insert-question-dot' of github.com:and…
rbuckton Sep 24, 2019
096bb49
Fix to insert text for completions
rbuckton Sep 24, 2019
1bf2d56
Add initial control-flow analysis for optional chains
rbuckton Sep 25, 2019
1d7446f
PR Feedback and more tests
rbuckton Sep 26, 2019
b282b62
Update to control flow
rbuckton Sep 26, 2019
be3e21f
Merge branch 'master' into optionalChainingStage3
rbuckton Sep 26, 2019
fd8c0d4
Remove mangled smart quotes in comments
rbuckton Sep 26, 2019
7c9ef50
Fix lint, PR feedback
rbuckton Sep 27, 2019
ad7c33c
Updates to control flow
rbuckton Sep 28, 2019
6b49a03
Switch to FlowCondition for CFA of optional chains
rbuckton Sep 29, 2019
aaa30f4
Fix ?. insertion for completions on type variables
rbuckton Sep 29, 2019
5ea7cb5
Accept API baseline change
rbuckton Sep 29, 2019
7463860
Clean up types
rbuckton Sep 29, 2019
0828674
improve control-flow debug output
rbuckton Sep 30, 2019
d408e81
Merge branch 'master' into optionalChainingStage3
rbuckton Sep 30, 2019
c2070be
Revert Debug.formatControlFlowGraph helper
rbuckton Sep 30, 2019
dfc798f
Merge branch 'master' into optionalChainingStage3
rbuckton Sep 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert Debug.formatControlFlowGraph helper
  • Loading branch information
rbuckton committed Sep 30, 2019
commit c2070bead0dd306e92b1bfb663c316bdbbf45589
69 changes: 14 additions & 55 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,10 @@ namespace ts {
let symbolCount = 0;

let Symbol: new (flags: SymbolFlags, name: __String) => Symbol;
let FlowNode: new (flags: FlowFlags) => FlowNodeBase;
let classifiableNames: UnderscoreEscapedMap<true>;

let unreachableFlow: FlowNode;
let reportedUnreachableFlow: FlowNode;
const unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
const reportedUnreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };

// state used to aggregate transform flags during bind.
let subtreeTransformFlags: TransformFlags = TransformFlags.None;
Expand All @@ -228,17 +227,6 @@ namespace ts {
return createDiagnosticForNodeInSourceFile(getSourceFileOfNode(node) || file, node, message, arg0, arg1, arg2);
}

function initializeBinder() {
const symbolConstructor = objectAllocator.getSymbolConstructor();
const flowNodeConstructor = objectAllocator.getFlowNodeConstructor();
if (Symbol !== symbolConstructor || FlowNode !== flowNodeConstructor) {
Symbol = symbolConstructor;
FlowNode = flowNodeConstructor;
unreachableFlow = new FlowNode(FlowFlags.Unreachable);
reportedUnreachableFlow = new FlowNode(FlowFlags.Unreachable);
}
}

function bindSourceFile(f: SourceFile, opts: CompilerOptions) {
file = f;
options = opts;
Expand All @@ -248,7 +236,7 @@ namespace ts {
symbolCount = 0;
skipTransformFlagAggregation = file.isDeclarationFile;

initializeBinder();
Symbol = objectAllocator.getSymbolConstructor();

if (!file.locals) {
bind(file);
Expand Down Expand Up @@ -635,7 +623,7 @@ namespace ts {
// A non-async, non-generator IIFE is considered part of the containing control flow. Return statements behave
// similarly to break statements that exit to a label just past the statement body.
if (!isIIFE) {
currentFlow = createFlowStart();
currentFlow = { flags: FlowFlags.Start };
if (containerFlags & (ContainerFlags.IsFunctionExpression | ContainerFlags.IsObjectLiteralOrClassExpressionMethod)) {
currentFlow.node = <FunctionExpression | ArrowFunction | MethodDeclaration>node;
}
Expand Down Expand Up @@ -929,15 +917,11 @@ namespace ts {
}

function createBranchLabel(): FlowLabel {
const flow = new FlowNode(FlowFlags.BranchLabel) as FlowLabel;
flow.antecedents = undefined;
return flow;
return { flags: FlowFlags.BranchLabel, antecedents: undefined };
}

function createLoopLabel(): FlowLabel {
const flow = new FlowNode(FlowFlags.LoopLabel) as FlowLabel;
flow.antecedents = undefined;
return flow;
return { flags: FlowFlags.LoopLabel, antecedents: undefined };
}

function setFlowNodeReferenced(flow: FlowNode) {
Expand All @@ -952,10 +936,6 @@ namespace ts {
}
}

function createFlowStart(): FlowStart {
return new FlowNode(FlowFlags.Start) as FlowStart;
}

function createFlowCondition(flags: FlowFlags, antecedent: FlowNode, expression: Expression | undefined): FlowNode {
if (antecedent.flags & FlowFlags.Unreachable) {
return antecedent;
Expand All @@ -973,47 +953,30 @@ namespace ts {
return antecedent;
}
setFlowNodeReferenced(antecedent);
const flow = new FlowNode(flags) as FlowCondition;
flow.antecedent = antecedent;
flow.node = expression;
return flowNodeCreated(flow);
return flowNodeCreated({ flags, antecedent, node: expression });
}

function createFlowSwitchClause(antecedent: FlowNode, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number): FlowNode {
if (!isNarrowingExpression(switchStatement.expression)) {
return antecedent;
}
setFlowNodeReferenced(antecedent);
const flow = new FlowNode(FlowFlags.SwitchClause) as FlowSwitchClause;
flow.antecedent = antecedent;
flow.switchStatement = switchStatement;
flow.clauseStart = clauseStart;
flow.clauseEnd = clauseEnd;
return flowNodeCreated(flow);
return flowNodeCreated({ flags: FlowFlags.SwitchClause, antecedent, switchStatement, clauseStart, clauseEnd });
}

function createFlowAssignment(antecedent: FlowNode, node: Expression | VariableDeclaration | BindingElement): FlowNode {
setFlowNodeReferenced(antecedent);
const flow = new FlowNode(FlowFlags.Assignment) as FlowAssignment;
flow.antecedent = antecedent;
flow.node = node;
return flowNodeCreated(flow);
return flowNodeCreated({ flags: FlowFlags.Assignment, antecedent, node });
}

function createFlowCall(antecedent: FlowNode, node: CallExpression): FlowNode {
setFlowNodeReferenced(antecedent);
const flow = new FlowNode(FlowFlags.Call) as FlowCall;
flow.antecedent = antecedent;
flow.node = node;
return flowNodeCreated(flow);
return flowNodeCreated({ flags: FlowFlags.Call, antecedent, node });
}

function createFlowArrayMutation(antecedent: FlowNode, node: CallExpression | BinaryExpression): FlowNode {
setFlowNodeReferenced(antecedent);
const flow = new FlowNode(FlowFlags.ArrayMutation) as FlowArrayMutation;
flow.antecedent = antecedent;
flow.node = node;
return flowNodeCreated(flow);
return flowNodeCreated({ flags: FlowFlags.ArrayMutation, antecedent, node });
}

function finishFlowLabel(flow: FlowLabel): FlowNode {
Expand Down Expand Up @@ -1296,9 +1259,7 @@ namespace ts {
//
// extra edges that we inject allows to control this behavior
// 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.
const preFinallyFlow = new FlowNode(FlowFlags.PreFinally) as PreFinallyFlow;
preFinallyFlow.antecedent = preFinallyPrior;
preFinallyFlow.lock = {};
const preFinallyFlow: PreFinallyFlow = { flags: FlowFlags.PreFinally, antecedent: preFinallyPrior, lock: {} };
addAntecedent(preFinallyLabel, preFinallyFlow);

currentFlow = finishFlowLabel(preFinallyLabel);
Expand All @@ -1317,9 +1278,7 @@ namespace ts {
}
}
if (!(currentFlow.flags & FlowFlags.Unreachable)) {
const afterFinallyFlow = new FlowNode(FlowFlags.AfterFinally) as AfterFinallyFlow;
afterFinallyFlow.antecedent = currentFlow;
flowNodeCreated(afterFinallyFlow);
const afterFinallyFlow: AfterFinallyFlow = flowNodeCreated({ flags: FlowFlags.AfterFinally, antecedent: currentFlow });
preFinallyFlow.lock = afterFinallyFlow;
currentFlow = afterFinallyFlow;
}
Expand Down Expand Up @@ -2027,7 +1986,7 @@ namespace ts {
const host = getJSDocHost(typeAlias);
container = findAncestor(host.parent, n => !!(getContainerFlags(n) & ContainerFlags.IsContainer)) || file;
blockScopeContainer = getEnclosingBlockScopeContainer(host) || file;
currentFlow = createFlowStart();
currentFlow = { flags: FlowFlags.Start };
parent = typeAlias;
bind(typeAlias.typeExpression);
const declName = getNameOfDeclaration(typeAlias);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ namespace ts {
}
}

export function stableSortIndices<T>(array: readonly T[], indices: number[], comparer: Comparer<T>) {
function stableSortIndices<T>(array: readonly T[], indices: number[], comparer: Comparer<T>) {
// sort indices by value then position
indices.sort((x, y) => comparer(array[x], array[y]) || compareValues(x, y));
}
Expand Down
Loading