-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Control flow analysis for element access with variable constant-like index in for statements #60715
base: main
Are you sure you want to change the base?
Conversation
…index in for statements
function isSymbolAssignedInForStatementBody(symbol: Symbol) { | ||
const forStatement = getRootDeclaration(symbol.valueDeclaration!).parent.parent; | ||
Debug.assert(isForStatement(forStatement)); | ||
return !isPastLastAssignment(symbol, forStatement.statement); | ||
} | ||
|
||
function isUsedInForStatementBody(symbol: Symbol, location: Node) { | ||
const forStatement = getRootDeclaration(symbol.valueDeclaration!).parent.parent; | ||
Debug.assert(isForStatement(forStatement)); | ||
return location.pos >= forStatement.statement.pos && location.end <= forStatement.statement.end; | ||
} |
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.
I'd love to combine those 2 but I've failed so far to figure out an elegant function name for a function that would do both 😅
@typescript-bot test it |
@jakebailey Here are the results of running the user tests with tsc comparing Everything looks good! |
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@jakebailey Here are the results of running the top 400 repos with tsc comparing Something interesting changed - please have a look. Details
|
The snabbdom break isn't harmful. It boils down to a code like this: declare function isPrimitive(s: any): s is string | number;
export function test() {
let c: any;
for (let i = 0; i < c.length; ++i) {
if (isPrimitive(c[i])) {
const target: string | undefined = c[i];
}
}
} The problem is that declare function isPrimitive(s: any): s is string | number;
declare const foo: any;
if (isPrimitive(foo)) {
foo; // string | number
} Since now this constant-like |
This is a small extension of #57847
closes #58803
let
variables in for loops are special, despite them being mutable and "shared" for the loop - each iteration gets its own unique copy of that variable. A mutation in the incrementor has no effect on the loop's body so, to the best of my understanding, it can safely be ignored.