[TIMOB-25573] CLI: iOS compiler breaks and compiles incorrectly when building to device - 6.3.0
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-12-08T18:31:56.000+0000 |
Affected Version/s | Release 6.3.0 |
Fix Version/s | Release 7.0.1 |
Components | iOS |
Labels | cli, ios, merge-7.0.1, sdk |
Reporter | David van de Meer |
Assignee | Feon Sua Xin Miao |
Created | 2017-11-30T11:55:34.000+0000 |
Updated | 2019-06-19T12:54:43.000+0000 |
Description
Hi, I am having some issues with the compiler for iOS on Titanium 6.3.0 - when it compiles to the simulator it works fine but Device compiler breaks things.
I have gotten the error down to standalone code on blank appcelerator classic app it build to ios device:
Add this code to the app.js and build
var virtualScroller = {
getView: function(i) {
var web_view = Ti.UI.createWebView({
});
web_view.addEventListener('click', function(){
});
return web_view;
},
start: 1,
infinite: false,
itemCount: 12,
};
check the build version of app_js
var virtualScroller={getView:function(){var a=Ti.UI.createWebView({});return a.addEventListener('click',function(){}),a},start:1,infinite:!1,itemCount:12};
notice that the ``return
` is before the eventlisteners and other values, this causes the code to return out and not function as it should
May be a duplicate of TIMOB-25328, although the return statement looks correctly. It adds the event-listener on return to save one line, but it still adds it.
As a workaround, try to replace the file located i
~/Library/Application Support/Titanium/mobilesdk/osx/6.3.0.GA/node_modules/node-titanium-sdk/lib/jsanalyze.js
with [this file](https://raw.githubusercontent.com/feons/node-titanium-sdk/92a02476596bbda5257d624b1ea9a29b39a5174e/lib/jsanalyze.js).With the jsanalyze.js replace this is the compiled file
I apologize if I am wrong but I dont think this is valid code, but I might be wrong
The new jsanalyze.js does seem to allow the code to work now but js miniy has now cause another issue with one of the modules, when I disable js minification all my code works fine...ill try to track it down
Here is what is happening now My code:
not minified result:
minified result
Tons of missing code.....for example where is
I have found more instances where code gets stripped out even though it should not, it seems like its happening when the OS_IOS tag is used - this is really super frustrating as how are we supposed to be able to build and distribute apps if the cli is so bug ridden....I am not sure how I can be the only one finding these bugs, do most appcelerator users not actually have much code? This code
gets minified:
notice the void void
[~dieskim] As this occurs with all SDK versions since you upgraded could you try downgrading the appc cli using
appc use 6.2.4
and rebuilding to see if the issue still occurs?CLI ad 6.2.4:
I also just did a search on all my build code for "void" tons and tons of them scattered throughout my codebase, will take many many hours to fix all of them with adding a log in front of each!
so one way we have found to fix this is to actually just log out the var In the example below adding
Ti.API.info(convertedBookName);
allows the value to not minify as "void"this compiles as
Looks like babel minify removes all
function declarations
inif statements
. But I'm not able to reproduce thevoid 0
case yet.Here is a complete test example to recreate the void 0 errors Build the following in new blank alloy app - simply add this function only to the alloy.js - this code does seem to compile correctly on classic app. I believe its an issues with babel minify not understanding some alloy tags / code
Builds as:
removing the OS_ANDROID part
allows the void 0 mistakes to disappear, but thats not really a solution - just shows the cause of the problem is related to OS_ANDROID and OS_IOS Simply adding logs
and
fixes the with both void 0 errors
I also had alot of issues with minification removing function declarations in if statements, along with other wierd bugs due to minification. I found that assigning the function declaration to a var would solve issues with functions being removed. Additionally variables randomly become null or wierd values, logging them just before using htem worked. Sometimes functions declared normally, outisde if statements, also bugged in diffrent ways. When this happend i found that declaring a new function as an identical copy with a new name, just below the bugged function, solved the problem. The code becomes very ugly when making these workarounds, so i really hope this is fixed soon.
PR: https://github.com/appcelerator/node-titanium-sdk/pull/19
Thanks for the PR! So basically just turn off more and more minification? Did you guys recently switch to a different minification tool or why are things breaking now?
[~dieskim], Yes, we replaced UglifyJS with Babili so that we can support ES2015 and newer in the tooling. It's minification and dead code removal seems pretty aggressive, there are also some known issues (i.e https://github.com/babel/minify/issues/404).
Yes I did notice those issues on the repo, does not seem like they are being handled... turning off minification functions is not ideal as it almost defies the whole point, but I guess at this stage its the best we can do?
For best practice, use function expressions for conditional creation instead.
Verified Fix in SDK version
7.0.1.v20171218104141
and7.1.0.v20171220095337
with test case mentioned in the description; device compiler no longer broke. *Test Environment* Appcelerator Command-Line Interface, version 7.0.0 iphone 5s (11.0.3) Operating System Name: Mac OS High Sierra Operating System Version: 10.13 Node.js Version: 8.9.1 Xcode: 9.0.1 Appcelerator Studio: 5.0.0.201711280737