Titanium JIRA Archive
Appcelerator Community (AC)

[AC-4704] Strange issue when using "const" and conditional code

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionCannot Reproduce
Resolution Date2017-01-10T18:25:36.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterJérémy Tonneau
AssigneeShak Hossain
Created2017-01-02T21:27:59.000+0000
Updated2017-01-10T18:25:36.000+0000

Description

Hello, When I do something like that on an Android (note that this code shouldn't exists at all in "builded code") :
if(OS_IOS){
	const test = 'my string';
}
I have this error:
[ERROR] :  TiExceptionHandler: (main) [128,128] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [1,129] - In /app.js:60,10
[ERROR] :  TiExceptionHandler: (main) [0,129] - Message: Uncaught SyntaxError: Missing initializer in const declaration
[ERROR] :  TiExceptionHandler: (main) [0,129] - Source: const test;
[ERROR] :  V8Exception: Exception occurred at /app.js:60: Uncaught SyntaxError: Missing initializer in const declaration
And when I go the the "builded" file I have something like that :
const test;
Which is not good because "const" need to been initialized ... And also not good because const is block scoped !

Comments

  1. Sharif AbuDarda 2017-01-03

    Hello, I can't reproduce the issue with the below code. In Android I don't run into any error.
       var win = Ti.UI.createWindow({
       
           backgroundColor : 'white'
       
       });
       var osname = Ti.Platform.osname;
       
       var OS_IOS = (osname == 'iOS') ? true : false;
       
       if (OS_IOS) {
       
           const test = 'my string';
       
       }
       
       win.open(); 
       
    Can you provide a full sample code to reproduce. I am testing on SDK 6.0.1.GA. Thanks.

JSON Source