Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27301] CLI: Block scoped variables in for loops are attempted to be added to the global scope

GitHub Issuen/a
TypeBug
PriorityMedium
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 8.0.2, Release 8.1.0, Release 8.2.0
Fix Version/sn/a
ComponentsCLI
Labelsn/a
ReporterEwan Harris
AssigneeEric Merriman
Created2019-07-31T14:02:22.000+0000
Updated2019-07-31T15:29:16.000+0000

Description

Description

When using a for loop in the top level scope (i.e. not in a function) of an app.js or alloy.js file if the variable declaration used is a block scoped variable (const/let) the below error will be thrown. This is because we try to use add the level to the global scope, but as it is block scope we can't reference it outside of the for loop. *workaround*: Use var to declare the variable, or move the code into a function and call that. *Note*: I believe by default this will only be seen on Android as babel will convert const/let to var on iOS
ERROR] TiExceptionHandler: (main) [218,218] /app.js:29
[ERROR] TiExceptionHandler: }global.col = col;
[ERROR] TiExceptionHandler:               ^
[ERROR] TiExceptionHandler: ReferenceError: col is not defined

Steps to reproduce

1. Add the below code to your app.js
for (const number of [ 1, 2,3 ]) {
    console.log(number);
}
2. Build to android

Actual

App will crash with above error

Expected

App should not crash

Comments

No comments

JSON Source