Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-27301

CLI: Block scoped variables in for loops are attempted to be added to the global scope

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Affects Version/s: Release 8.0.2, Release 8.1.0, Release 8.2.0
    • Fix Version/s: None
    • Component/s: CLI
    • Labels:
      None
    • Environment:

      SDK: 8.0.2.GA, 8.1.0.v20190726095146, 8.2.0.v20190725161133

      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

        Attachments

          Activity

            People

            • Assignee:
              emerriman Eric Merriman
              Reporter:
              eharris Ewan Harris
            • Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Source Code