[TIMOB-19155] LiveView: Breaks when app.js contains named self execution function
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | None |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2020-05-19T15:18:43.000+0000 |
Affected Version/s | Release 4.1.0 |
Fix Version/s | n/a |
Components | LiveView |
Labels | n/a |
Reporter | Fokke Zandbergen |
Assignee | Unknown |
Created | 2015-07-03T06:44:09.000+0000 |
Updated | 2020-05-19T15:18:43.000+0000 |
Description
When the (compiled)
app.js
contains a named self executing function (e.g. to protect global scope) LiveView will break.
Example
(function hello() {
Ti.UI.createWindow({
backgroundColor: 'green'
}).open();
})();
Error
[INFO] [LiveView] Error Evaluating app @ Line: 1
[ERROR] SyntaxError: Unexpected identifier 'hello'
[ERROR] File: app
[ERROR] Line: 1
[ERROR] SourceId: <null>
[ERROR] Backtrace:
[ERROR] undefined
Cause
I tracked this back to LiveView'sfileserver.js
where it bind all global variables in app.js
to Global._globalCtx
:
https://github.com/appcelerator/liveview/blob/master/lib/fserver.js#L298-L312
Before this part everything is OK, but after the code will end up as:
nction hello() {
Ti.UI.createWindow({
backgroundColor: 'green'
}).open();
})();
I can no longer reproduce this on SDK 9.0.1.GA, we removed the munging of code we use to do via a regex in favour of operating on the AST via babel so I imagine that this got fixed with that