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

Code Processor - Alloy: analyzed code results can be different from the expected ones

    Details

    • Type: Story
    • Status: Closed
    • Priority: Low
    • Resolution: Won't Fix
    • Affects Version/s: Release 3.1.1
    • Fix Version/s: None
    • Component/s: Code Processor
    • Environment:

      Appcelerator Studio 3.1.1.201305292130
      Titanium SDK 3.1.1.v20130529114554
      Alloy 1.1.3-alpha
      Titanium-Code-Processor 1.1.3-alpha3

      Description

      Problem description

      Code Processor results for Alloy projects are based an Analysis on the compiled code in the Resources folder.
      This could generate unexpected results and parity issues for the end user whose expectations are that the Code Processor is checking his code, as included in the Alloy project 'app' folder, even if the Code Processor is actually correctly analyzing the javascript code compiled by Alloy.

      Example:
      "ContextTest" sample project

      (https://github.com/appcelerator/titanium-code-processor/tree/master/test_projects/ContextTest or attached here in the Jira)

      In this case, the code to be analyzed is:

      (function foo() {
      	var x = 10;
      	setTimeout(function () {
      		console.log(x);
      	});
       
      	function bar() {
      		console.log(x);
      		x = 20;
      		require(x);
      	}
      	if (Date.now()) {
      		bar();
      	}
      })();
      console.log(x);
      

      and the result, as expected, is that:

      "x" is not defined | app.js | 16 
      

      By placing the same identical code in an Alloy project index.js controller file, the result is a bit different.

      Attached in the Jira there is the ContextTest sample for Alloy too.

      After being compiled, the Resources/alloy/controllers/index.js looks like this:

      function Controller() {
          require("alloy/controllers/BaseController").apply(this, Array.prototype.slice.call(arguments));
          arguments[0] ? arguments[0]["__parentSymbol"] : null;
          arguments[0] ? arguments[0]["$model"] : null;
          var $ = this;
          var exports = {};
          $.__views.index = Ti.UI.createWindow({
              backgroundColor: "blue",
              id: "index"
          });
          $.__views.index && $.addTopLevelView($.__views.index);
          exports.destroy = function() {};
          _.extend($, $.__views);
          (function() {
              function bar() {
                  console.log(x);
                  x = 20;
                  require(x);
              }
              var x = 10;
              setTimeout(function() {
                  console.log(x);
              });
              Date.now() && bar();
          })();
          console.log(x);
          $.index.open();
          _.extend($, exports);
      }
       
      var Alloy = require("alloy"), Backbone = Alloy.Backbone, _ = Alloy._;
       
      module.exports = Controller;
      

      so, lines 14 to 26 are the ones regarding the code put in the controller. The code is a bit different (for example the function "bar()" is declared before the 'var x = 10') and the Code Analyzer result is a bit different:

      The module "20" could not be found | app/controllers/index.js | 10
      "x" is not defined | app/controllers/index.js | 17
      

      In this case the Code Processor is likely behaving correctly, in fact putting the generated code from lines 14 to 26 in a Classic Titanium project, I'm getting the same as the Alloy one.

      The issue relates in the fact that from the end-user standpoint, the two results should be identical and the user could be easily confused by those results.

      Attached both the classic and the Alloy 'ContextTest' sample projects and the Code Analyzer Results for each.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                cbarber Chris Barber
                Reporter:
                fcasali Federico Casali
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

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

                    Git Integration