Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1296] LiveView: functions in Alloy.js crash fail to build

GitHub Issuen/a
TypeBug
PriorityHigh
StatusResolved
ResolutionFixed
Resolution Date2015-08-25T03:17:06.000+0000
Affected Version/sAlloy 1.6.2
Fix Version/sAlloy 1.7.1
Componentsn/a
LabelsTCSupport, liveview
ReporterMauro Parra-Miranda
AssigneeFeon Sua Xin Miao
Created2014-07-15T21:09:34.000+0000
Updated2015-08-25T03:17:06.000+0000

Description

Problem Description

When you create a new alloy project and define a function inside alloy.js, If you are using LiveView the application will crash

Sample Code

alloy.js
 
function sum(a,b){
	return a+ b ;
};
index.xml
<Alloy>
	<Window class="container">
		<Label id="label" onClick="doClick">Appcelerator Titanium</Label>
	</Window>
</Alloy>
index.tss
".container": {
	backgroundColor:"white"
},
"Label": {
	width: Ti.UI.SIZE,
	height: Ti.UI.SIZE,
	color: "#000"
}
index.js
function doClick(e) {
    alert($.label.text);
}
$.index.open();

Steps to reproduce

- Create a simple alloy project. - Update alloy.js, index.xml, index.tss and index.js file with test code - Enable LiveView in Appcelerator Studio - Run on iOS simulator - Project crash and produce errors.

Actual Results

[ERROR] :  SyntaxError: Parse error
[ERROR] :  File: app
[ERROR] :  Line: 1
[ERROR] :  SourceId: 316582208
[ERROR] :  Backtrace:
[ERROR] :   #0 () at file:///Users/rmitro/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/F7F894E3-3A78-4E1D-9E4E-A54A4DDE7746/QnA_Alloy.app/app.js:502
[ERROR] :  #1 () at file:///Users/rmitro/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/F7F894E3-3A78-4E1D-9E4E-A54A4DDE7746/QnA_Alloy.app/app.js:469
[ERROR] :  #2 () at file:///Users/rmitro/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/F7F894E3-3A78-4E1D-9E4E-A54A4DDE7746/QnA_Alloy.app/app.js:403
[ERROR] :  #3 () at file:///Users/rmitro/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/F7F894E3-3A78-4E1D-9E4E-A54A4DDE7746/QnA_Alloy.app/app.js:676

Extra info

This is the error shown:
[INFO] :   alloyJSHatesFunctions/1.0 (3.2.3.GA.b958a70)
[LiveView] Client connected
[INFO] :   [LiveView] Error Evaluating app @ Line: 1
[ERROR] :  SyntaxError: Parse error
[ERROR] :  File: app
[ERROR] :  Line: 1
[ERROR] :  SourceId: 350635136
[ERROR] :  Backtrace:
[ERROR] :   #0 () at file:///Users/andrewmcelroy/Library/Application%20Support/iphone%20simulator/7.1-64/Applications/4A49D81E-DEF2-43ED-A74C-437076DE3B4E/alloyJSHatesFunctions.app/app.js:502
[ERROR] :  #1 () at file:///Users/andrewmcelroy/Library/Application%20Support/iphone%20simulator/7.1-64/Applications/4A49D81E-DEF2-43ED-A74C-437076DE3B4E/alloyJSHatesFunctions.app/app.js:469
[ERROR] :  #2 () at file:///Users/andrewmcelroy/Library/Application%20Support/iphone%20simulator/7.1-64/Applications/4A49D81E-DEF2-43ED-A74C-437076DE3B4E/alloyJSHatesFunctions.app/app.js:403
[ERROR] :  #3 () at file:///Users/andrewmcelroy/Library/Application%20Support/iphone%20simulator/7.1-64/Applications/4A49D81E-DEF2-43ED-A74C-437076DE3B4E/alloyJSHatesFunctions.app/app.js:676
[LiveView] Client disconnected

Attachments

FileDateSize
alloyJSHatesFunctions.zip2014-07-15T21:09:34.000+00005920253
truncated.txt2014-08-15T19:33:43.000+0000107390

Comments

  1. Mauro Parra-Miranda 2014-07-30

    Hello! I tested this in 3.3.0 without problem. My testcase: 1. Create a new mobile project with alloy default app. 2. Run it in the iOS simulator. 3. Modify the alloy.js with this:
       
       function sum(a,b){
       	return a+ b ;
       };
       
    4. The app didn't crash. After that, I re-run the app with the modified alloy.js without any issues. Can you please update and retest with the latest Ti Studio and Mobile SDK? Thanks!
  2. Andrew McElroy 2014-08-02

    You did not do all the required steps to reproduce this error. 1. Create a new mobile project with Alloy default app 2. ***** Enable LiveView in AppceleratorStudio ***** 3. Modify the alloy.js file with this:
       function sum(a,b){
           return a+ b ;
       };
       
    4. Run the Simulator 5. Watch it crash and produce this error:
       [INFO] :   [LiveView] Error Evaluating app @ Line: 1
       [ERROR] :  SyntaxError: Parse error
       [ERROR] :  File: app
       [ERROR] :  Line: 1
       [ERROR] :  SourceId: 332969088
       [ERROR] :  Backtrace:
       [ERROR] :   #0 () at file:///Users/andrewmcelroy/Library/Application%20Support/iphone%20simulator/7.1-64/Applications/04BCA961-3CC0-4746-B1A9-9BDAA7BB8E73/lol.app/app.js:502
       [ERROR] :  #1 () at file:///Users/andrewmcelroy/Library/Application%20Support/iphone%20simulator/7.1-64/Applications/04BCA961-3CC0-4746-B1A9-9BDAA7BB8E73/lol.app/app.js:469
       [ERROR] :  #2 () at file:///Users/andrewmcelroy/Library/Application%20Support/iphone%20simulator/7.1-64/Applications/04BCA961-3CC0-4746-B1A9-9BDAA7BB8E73/lol.app/app.js:403
       [ERROR] :  #3 () at file:///Users/andrewmcelroy/Library/Application%20Support/iphone%20simulator/7.1-64/Applications/04BCA961-3CC0-4746-B1A9-9BDAA7BB8E73/lol.app/app.js:676
       
  3. Andrew McElroy 2014-08-15

    any progress or information i need provide?
  4. Andrew McElroy 2014-08-15

    to make this ticket more readable. I dumped the environment info and npm info and sdk info in this file.
  5. Tim Poulsen 2014-09-02

    One of our other Titans independently discovered this bug recently. In his investigations, it was due to a hoisting issue. He found a workaround is to use the function statement form rather than function declaration. So, in alloy.js:
       var sum = function(a,b){
           return a+ b ;
       };
       
  6. Jason Kneen 2014-09-02

    Yep, that was me and the statement method solved it as Tim said.
  7. Jason Kneen 2014-10-14

    Problem with this solution If you do
       var sum = function(a,b){
           return a+ b ;
       };
       
    you end up creating a global variable/function.
  8. Andrew Natoli 2015-04-20

    Jason, alloy.js houses global variables and functions. The problem with the solution is that doing a normal function declaration still doesn't work. Having this issue with SDK 3.5.1. I did however rewrite my alloy.js to use "var eggo = function()" instead of "function eggo()" and it resolved the issue.
  9. Jason Kneen 2015-04-20

    Isn't that what I said? rewrite function foo() to var foo = function() and it works.
  10. Andrew Natoli 2015-04-20

    You did. I was just confirming that it worked as I added that line in after I posted my original comment.
  11. Jason Kneen 2015-04-20

    cool. Credit to Tim for the solution ;)
  12. Feon Sua Xin Miao 2015-08-24

    PR: https://github.com/appcelerator/liveview/pull/89
  13. Chee Kiat Ng 2015-08-25

    Approved. PR merged.

JSON Source