Copy link to clipboard
Copied
I am trying to minify a bunch of components for a new program i'm rolling out, and several of the components are failing during my #include statements because a semi colon is expected somewhere?
I've run the components code through js validators and everything comes back valid. But for some reason estk doesn't like them..? Have any of you run into this issue? and how did you handle it?
Here's one of the minified components. maybe one of you could replicate the issue and figure out what the cause is. Thanks in advance.
function checkStyleNum(b,a,d){var c=!0;log.h("Beginning of checkStyleNum function for "+d+"."+a+"::Style number is "+b.styleNo);b.styleNo?0==b.styleNo.indexOf("B")?(a=b.styleNo,log.l("Updating styleNo. styleNo was "+a),a=a.substring(a.indexOf("B")+2,a.length),log.l("Changed styleNo to "+a),b.styleNo=a):log.l("No need to update style number. "):(c=!1,log.e("Failed to find a style number for "+b.garment),errorList.push("Sorry. Failed to find the style number for "+a));return c};
This error is relative to the chained "? :" statement:
Condition1 ? Condition2 ? a : b : c
You will have to add () to aviod it, like this:
Condition1 ? (Condition2 ? a : b) : c
This will work.
...function checkStyleNum(b,a,d){var c=!0;log.h("Beginning of checkStyleNum function for "+d+"."+a+"::Style number is "+b.styleNo);b.styleNo?(0==b.styleNo.indexOf("B")?(a=b.styleNo,log.l("Updating styleNo. styleNo was "+a),a=a.substring(a.indexOf("B")+2,a.length),log.l("Changed styleNo to "+a),b.styleNo=a):log.l
Copy link to clipboard
Copied
Yea, the old ES3 javascript doesn't like some things about minified code. When I had a problem like that I was able to find the spot to stick in a semicolon, I think. I was of course trying to put in the JSON object. It may turn out that minifying is just not friendly to extendscript.
Copy link to clipboard
Copied
This error is relative to the chained "? :" statement:
Condition1 ? Condition2 ? a : b : c
You will have to add () to aviod it, like this:
Condition1 ? (Condition2 ? a : b) : c
This will work.
function checkStyleNum(b,a,d){var c=!0;log.h("Beginning of checkStyleNum function for "+d+"."+a+"::Style number is "+b.styleNo);b.styleNo?(0==b.styleNo.indexOf("B")?(a=b.styleNo,log.l("Updating styleNo. styleNo was "+a),a=a.substring(a.indexOf("B")+2,a.length),log.l("Changed styleNo to "+a),b.styleNo=a):log.l("No need to update style number. ")):(c=!1,log.e("Failed to find a style number for "+b.garment),errorList.push("Sorry. Failed to find the style number for "+a));return c};
Copy link to clipboard
Copied
Interesting. I did attempt to add semicolons and colons in the right places (annoying because you can only find the issues one at a time) and i was eventually able to get rid of all of the error messages, but then some conditions were returning incorrect values, so I'm sure i put something out of place..
I ended up just releasing the code as it was, so i may be busy with bug reports, but as soon as I get some time I'll have a look at adding parentheses like you've shown here moluapple.
The only issue i have with that is that if I have to go back and manually ad those every time i update a component, that will be quite a drag.. I'll let you guys know how it goes.
Thanks a lot!
Copy link to clipboard
Copied
A regex search and replace will do the job most of the time, like i've done in above post.
Copy link to clipboard
Copied
Would you mind sharing the regex you used to find that?
Copy link to clipboard
Copied
Well, say "most of the time" I mean right the form of the example code, I should have said "some times" .
Code : true ? true ? 1 : 2 : 3;
Search : (?<=\?)[^:]*:[^:]*
Replace : ($0)
It's more better to modify the source code of tool that used to minify your code.
Copy link to clipboard
Copied
If you are using UglifyJS, http://lisperator.net/uglifyjs/#demo , there is a option for not optimize conditionals and IF-s, so the final code will be friendly to extendscript.
Copy link to clipboard
Copied
This still didn't solve the problem completely, but it got me way way closer than before. Most files came out alright, and on a couple of them i had to manually add a semicolon. I haven't verified it to be universally true, but it appears that the issue often happens when one block of code is immediately succeeded by an if statement. In the minified code it looks like this:
...return 0}if(someCondition){doSomeFunction()}...
it seems that having
}if
right next to each other causes the error.
I'll have to keep looking at the errors and see whether that's always true. But for now, I've gotten everything working by adding a semicolon between the closing brackets and subsequent if statements.
Thanks so much for your help, Moluapple.