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

LiveView: Breaks when app.js contains named self execution function

    Details

    • Type: Bug
    • Status: Closed
    • Priority: None
    • Resolution: Fixed
    • Affects Version/s: Release 4.1.0
    • Fix Version/s: None
    • Component/s: LiveView
    • Labels:
      None
    • Environment:

      LiveView 1.1.0.1433362383

      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's fileserver.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();
      })();
      

      Solution

      As the comment in the LiveView code says there IS a better way to do this. An example could be how I did this for ti-proxy, the client-side transformer that appc-liveviewer-app uses.

      We should consider using ti-proxy for LiveViewer as well, it already has more features then LiveViewer does, like serving new/changed assets, cleaning up events etc.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              fokkezb Fokke Zandbergen
            • Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-20092
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Integration