开发者

YUI compressor not behaving as expected

开发者 https://www.devze.com 2022-12-15 00:48 出处:网络
I tried compressing a JavaScript file of mine using YUI compressor, but somehow it did not do what was expected.

I tried compressing a JavaScript file of mine using YUI compressor, but somehow it did not do what was expected.

The JavaScript file is here.

The compressed output looked like this:

    !window.$j&&(function($){$.jswaf={};$j=$.jswaf;var resources={},modules={},depends={},events={},eventfired={},modulepath={},themepath={}; [...]

and so on.

What I expected was that variables like "resources", "modules", "depends" etc would be reduced to small 1, 2 or 3 letter identifiers.

Is this what is supposed to happen? Or is something wrong with my source file?

BTW:

  1. The compressor puked this output (I used -v option):

    [WARNING] Try to use a single 'var' statement per scope. ={},themepath={}; ---> var <--- _nullf=function(){};var WAIT_TIME_RECHECK_FETCHED

    [WARNING] Try to use a single 'var' statement per scope. var _nullf=function(){}; ---> var <--- WAIT_TIME_RECHECK_FETCHED=300;var WAIT_TIME_LOAD_CALLBACK=20;var

    [WARNING] Try to use a single 'var' statement per scope. ){};var WAIT_TIME_RECHECK_FETCHED=300; ---> var <--- WAIT_TIME_LOAD_CALLBACK=20;var WAIT_TIME_UNLOAD_CALLBACK=20;var

    [WARNING] Try to use a single 'var' statement per scope. WAIT_TIME_RECHECK_FETCHED=300;var WAIT_TIME_LOAD_CALLBACK=20; ---> var <--- WAIT_TIME_UNLOAD_CALLBACK=20;var WAIT_TIME_EVENT_FIRE=20;var

    [WARNING] Try to use a single 'var' statement per scope. WAIT_TIME_LOAD_CALLBACK=20;var WAIT_TIME_UNLOAD_CALLBACK=20; ---> var <--- WAIT_TIME_EVENT_FIRE=20;var WAIT_TIME_ADD_REPO_CALLBACK=20;$j

    [WARNING] Try to use a single 'var' statement per scope. WAIT_TIME_UNLOAD_CALLBACK=20;var WAIT_TIME_EVENT_FIRE=20; ---> var <--- WAIT_TIME_ADD_REPO_CALLBACK=20;$j.resources=resources;

    开发者_开发百科

    [WARNING] Try to use a single 'var' statement per scope. ;}var modpath=path+"modules/module-list.js"; ---> var <--- thpath=path+"themes/theme-list.js";functionfinish(val

    [WARNING] Try to use a single 'var' statement per scope. +module+"/";}}for( ---> var <--- theme in thlist){theme=thlist[theme

    [WARNING] Try to use a single 'var' statement per scope. false){returnfalse;}for( ---> var <--- res in obj.prod){if(resources

    [WARNING] Try to use a single 'var' statement per scope. (var req in module.req){ ---> var <--- found=false;var dependents=depends[resources

    [WARNING] Try to use a single 'var' statement per scope. .req){var found=false; ---> var <--- dependents=depends[resources[req].id

    [WARNING] Try to use a single 'var' statement per scope. [req].id];for( ---> var <--- moduleIdIndex in dependents){if(moduleIdIndex==module

    [WARNING] Try to use a single 'var' statement per scope. ,arg3){var id=""; ---> var <--- conf={};var callback=_nullf;

    [WARNING] Try to use a single 'var' statement per scope. ="";var conf={}; ---> var <--- callback=_nullf;if(typeofarg1=="string"

    [WARNING] Try to use a single 'var' statement per scope. return;}path=path+"module.js"; ---> var <--- done=false;functionfetchDoneCallback(){done

    [WARNING] Try to use a single 'var' statement per scope. {return;}var callback=null; ---> var <--- recursive=null;if(typeofarg1=="function"

    [WARNING] Try to use a single 'var' statement per scope. [dep];}}}for( ---> var <--- prod in modules[modId].prod){

    [WARNING] Try to use a single 'var' statement per scope. (true);return;}else{ ---> var <--- dependents=depends[moduleId];for(var

    [WARNING] Try to use a single 'var' statement per scope. dependents=depends[moduleId];for( ---> var <--- index in dependents){$.jswaf.unloadModule

    [WARNING] Using 'eval' is not recommended. Moreover, using 'eval' reduces the level of compression! ,function(data){var conf= ---> eval <--- (data);var css=conf.css

    [WARNING] Try to use a single 'var' statement per scope. {var conf=eval(data); ---> var <--- css=conf.css;for(i in

    [WARNING] Found an undeclared symbol: $j ){$.jswaf={}; ---> $j <--- =$.jswaf;var resources={}

    [WARNING] Found an undeclared symbol: ind evtListeners=getListeners(evt);for( ---> ind <--- in evtListeners){setTimeout(evtListeners[ind]

    [WARNING] Found an undeclared symbol: i WAIT_TIME_EVENT_FIRE);}}else{for( ---> i <--- =eventfired[evt];i>0;

    [WARNING] Found an undeclared symbol: mod ;delete depends[modId];for( ---> mod <--- in depends){var deps=depends[mod

    [WARNING] Found an undeclared symbol: dep deps=depends[mod];for( ---> dep <--- in deps){if(dep==modId)

  2. Do I need to install Rhino separately for YUI compressor to work? Or is it packaged along with YUI compressor?

Thanks, jrh


Looks to me as if it would be happier if you added declarations for all of your Javascript variables.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号