-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Simple control flow analysis #1287
Conversation
@@ -4,6 +4,7 @@ | |||
/// <reference path="parser.ts"/> | |||
/// <reference path="binder.ts"/> | |||
/// <reference path="emitter.ts"/> | |||
/// <reference path="controlflow.ts"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider controlFlow.ts
, but I like this too.
return newLen - 1; | ||
} | ||
|
||
function setFinalStateAtLabel(mergedStates: ControlFlowState, outerState: ControlFlowState, name: Identifier): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a comment to explain that name
is optional for the case of implicit labels.
hasDefault = hasDefault || c.kind === SyntaxKind.DefaultClause; | ||
setState(startState); | ||
forEach(c.statements, check); | ||
if (c.statements.length && currentState === ControlFlowState.Reachable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider c.statements.length > 0
👍 Awesome job! |
We should put this back on the radar again. |
👍 |
IMO, it overlaps with TSLint. Regarding this, I'm concerned with the fact that I cannot use more mature JSHint or ESLint. Perhaps running them on the output (haven't tried that though). |
closed in favor of #4788 |
This PR adds a basic control flow analysis to typescript compiler. Now it can detect unreachable code, implicit returns of undefined in functions, unused labels, fall- through between cases in switch statements. Some of these checks can be used in #393 or #274.
Disclaimer: This PR is not intended to be checked in as-is. What I rather want is to use it as a starting point to discuss: