-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Python for loops create function-scoped variables, while transpiled JavaScript uses block-scoped let, causing reference errors when accessing loop variables post-loop.
Example:
def sum_range(n: int):
total = 0
for i in range(n):
total = total + i
return [total, i] # Validfunction sum_range(n) {
let total = 0;
for (let i of Array.from({length: n}, (_, i) => i)) {
total = (total + i);
}
return [total, i]; // ReferenceError
}Proposed Fix:
Use var for loop variables accessed outside their loop, or implement static analysis to detect such cases.
Metadata
Metadata
Assignees
Labels
No labels