lautis / uglifier Goto Github PK
View Code? Open in Web Editor NEWRuby wrapper for UglifyJS JavaScript compressor.
Home Page: http://www.rubydoc.info/gems/uglifier
License: MIT License
Ruby wrapper for UglifyJS JavaScript compressor.
Home Page: http://www.rubydoc.info/gems/uglifier
License: MIT License
I am stack with issue that the same js code returns different result with and without uglification.
It's jade template library:
The source code I use: https://gist.github.com/1213558
Test code:
js = File.read("jade.js")
string = "#{js}; var jade = require('jade'); jade.compile('');"
ExecJS.exec(string)
ExecJS.exec(Uglifier.new.compile(string))
After investigation I figured out the issue scope in how the following peace of code is minified:
var Block = module.exports = function Block(node){
this.nodes = [];
if (node) this.push(node);
};
Author of the library does very tricky thing by parsing function name here:
visitNode: function(node){
var name = node.constructor.name
|| node.constructor.toString().match(/function ([^(\s]+)()/)[1];
return this['visit' + name](node);
},
node.constructor
equal Block
. And in minified version node.constructor.toString()
returns:
function (a){this.nodes=[],a&&this.push(a)}
The Regexp /fuction .../
can not parse function name from it. But in non minified version it is possible because
node.constructor.toString
returns:
function Block(node){
this.nodes = [];
if (node) this.push(node);
}
I can not localize issue with minimum amount of code now. So dumping all my investigation as is. Because want to receive a feedback from You.
I am running into an issue where when deploying the application to 20 nodes, the asset digests for some JS files seem to be different. Now as the page is loaded from node1 and assets from node2 for example, then node1 will have a different MD5 digest in its manifest file, which node2 does not have and this results in a 404 asset request.
I am using Uglifier for JS compressions, I have verified that sprockets, uglifier and execjs versions are the same on all nodes. Also the system packages are all up to date (which should include any native depeendencies).
I also compared the files with different hash digests. There clearly are differences and mostly in external library code that gets compressed. And the differences seem to be caused by compression as its mostly small things like variable names being different.
# node1
if (qt.test(t))return ut.filter(t, e, n);
# node2
if (Bt.test(t))return ut.filter(t, e, n);
And the hashes are not completely random across nodes, there is a certain consistency there. Like node1 will always result in one MD5 digest for application.js, while node2 will always end up with a different MD5 digest. This leads me to believe that it could be somehow related to the underlying libraries or dependencies, but so far I have had no luck in pinpointing what they could be.
Also when I precompile the same assets locally, I get a third MD5 digest value. When diffing the contents for all 3 files I can see that node1 and node2 have 8 differences while node1 and local have just 1 difference, leading me to believe that somehow node1 is much closer to my local environment.
I would gladly explore this further if I would have any more suggestions or ideas where to look. But as of now, this is breaking production functionality unless manually handled and fixed.
The ability to drop the console commands is missing. (drop_console -- default false. Pass true to discard calls to console.* functions.)
in 2.1.1 I get a regression error for self invoking anonymous functions that have use the new keyword.
new (function(){
// do stuff
})();
gets converted to
new!function(){
// do stuff
}();
the new!function generates and error.
based on this question in StackOverflow ( http://stackoverflow.com/questions/5827290/javascript-function-leading-bang-syntax ) I think I understand what the minimizer is doing, but if the self invoking function has other context with it, like the new keyword, it generates an error.
Were are using the new keyword with this functions to set the 'this' pointer.
We did not get this error in 2.0.1
I deploy my production env. But error report in IE6.
I spend 2 days to test and found it is minfing error with uglifier 2.2.
However it works well in 2.1.x
http://stackoverflow.com/questions/8692666/rails-3-1-possible-bug-in-asset-pipeline-and-uglifier
I ran into a problem deploying on Heroku do to a failure in the rake task
rake assets:precompile
At the bottom is the error I get if I integrate
Rails 3.1
Jquery calendar: https://github.com/themouette/jquery-week-calendar
Twitter bootstrap
The error happens from uglifier.
I suspect that problem could be related to the inclusion of many localizations for the calendar.
I worked around the error by setting:
config.assets.compress = false
I was not able to examine the files as the temporary files are cleaned up. I also could not get the debugger in RubyMine to stop at a breakpoint.
Any ideas if this is a bug? Any way to get the temporary files to not get deleted? Any way to make the RubyMine debugger work on the rake task (yes, tried the obvious, using EAP 112-291.
rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets rake aborted! Unexpected character '' (line: 21454, col: 0, pos: 641761)
Error at new JS_Parse_Error (/tmp/execjs20111231-15374-1fve7h4.js:497:22) at js_error (/tmp/execjs20111231-15374-1fve7h4.js:505:15) at parse_error (/tmp/execjs20111231-15374-1fve7h4.js:596:17) at Object.next_token as input at next (/tmp/execjs20111231-15374-1fve7h4.js:943:37) at Object.semicolon as 1 at prog1 (/tmp/execjs20111231-15374-1fve7h4.js:1527:28) at simple_statement (/tmp/execjs20111231-15374-1fve7h4.js:1123:35) at /tmp/execjs20111231-15374-1fve7h4.js:1031:35 at /tmp/execjs20111231-15374-1fve7h4.js:1510:32
if you compress ivaynberg/select2 code, it will generate invalid code for IE8(even leaving :screw_ie8 = false
- the default)
https://github.com/ivaynberg/select2/blob/master/select2.js#L101
Here is the piece of javascript code.
$(function(){
var modalElement = '<div id="confirm-logout-modal" class="modal hide fade">' +
'<div class="modal-header">' +
'<h3 class="modal-title">Logout</h3>' +
'</div>' +
'<div class="modal-body">' +
'<p>' +
'<span class="modal-main-message">You have been logged</span>' +
'</p>' +
'</div>' +
'<div class="modal-footer">' +
'<button id="btn-confirm" class="btn btn-success">Okay</button>' +
'</div>' +
'</div>';
$("body").append(modalElement);
$('#btn-open').click(function(){
$('#confirm-logout-modal').modal('show');
});
$('#btn-close').click(function(){
$('#confirm-logout-modal').modal('hide');
});
});
I minified it using
Uglifier.compile(File.read("source.js"))
Its output is
004 > Uglifier.compile(File.read("source.js"))
=> "$(function(){var o='<div id=\"confirm-logout-modal\" class=\"modal hide fade\"><div class=\"modal-header\"><h3 class=\"modal-title\">Logout</h3></div><div class=\"modal-body\"><p><span class=\"modal-main-message\">You have been logged</span></p></div><div class=\"modal-footer\"><button id=\"btn-confirm\" class=\"btn btn-success\">Okay</button></div></div>';$(\"body\").append(o),$(\"#btn-open\").click(function(){$(\"#confirm-logout-modal\").modal(\"show\")}),$(\"#btn-close\").click(function(){$(\"#confirm-logout-modal\").modal(\"hide\")})});"
It is wrong javascript code
Here is the issue that I created on the uglifier js repo. See the owner's comment
mishoo/UglifyJS#645 (comment)
Attempting to minify mozilla/pdf.js brakes js. ( see mozilla/pdf.js#2479)
Using the file I get this error:
SyntaxError: octal literals and octal escape sequences are deprecated
[Break On This Error]
...-b);var w=n.yMax||y,E=-n.yMin||-b;return"\0$ô\0\0\0�»\0\0\0��»\0\0ß\01...
Compression is made on rails asset pipeline.
Not sure what happened here. I've updated to the latest gem and the errors still get displayed, but now without the line number, making it much harder to debug. Is this an option I can turn back on? I've tried to use :preserve_line => true
but that tells me it's an invalid option. Futzing with this to get it to say it's no longer an invalid option doesn't produce any result.
I am using webpack to generate the source map before running the files through the Uglifier. I understand the default behavior is to always remove the comments at the end of a file, even when they match the pattern in comments: Regexp
option. Is there a way around this?
Guys,
Please take a look at this post http://forum.dhtmlx.com/viewtopic.php?f=2&t=24298 and let me know if there is a way to work around the problem. Thanks a lot.
Uglifyjs is stripping the last semicolon of the file, which generates a very hard to find bug when concatenating files together.
Looks like it was fixed but the latest ruby gem hasn't pulled it in.
I've found another situation where quoting is needed. if you have a key, like this
{ÿ:"3"}
IE8+(9, 10 and 11, also) will fail, so I think that the right behavior is to make :quote_keys => true
the default.
related #58
For reference: rails/rails#12720
When minifying assets with accented characters (e.g. russian in Sugar.JS), when environment settings are in a certain way (see below), uglifier will replace those characters with question marks. Only tested through rails assets:precompile.
Important: I am just assuming it's the locale settings, I have no way of knowing. It is something that started being forwarded in net-ssh as of this change: https://github.com/net-ssh/net-ssh/blob/master/CHANGES.txt#L6
Failing machine locale:
LANG="sl_SI.UTF-8"
LC_COLLATE="sl_SI.UTF-8"
LC_CTYPE="sl_SI.UTF-8"
LC_MESSAGES="sl_SI.UTF-8"
LC_MONETARY="sl_SI.UTF-8"
LC_NUMERIC="sl_SI.UTF-8"
LC_TIME="sl_SI.UTF-8"
LC_ALL=
Another failing machine locale:
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
OK machine locale:
LANG=
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
The only thing I can deduce from this is that both failing machines have some variation of UTF-8 for LC_CTYPE.
Uglifier 2.3.0.
PS: Neither yui-compressor or closure-compiler experience this problem, on identical setup.
Uglifier should not remove Internet Explorer conditional comments from JavaScript.
/@cc_on this is a conditional comment and only IE ( < 10 ) will read that @/
This source code couses exception
var allocate = function(allocation) {
if (allocation.multiple) {
for (var id = kind; allocations[++id];);
}
}
.../gems/execjs-1.2.0/lib/execjs/external_runtime.rb:59:in `extract_result': Unexpected token: punc (}) (line: 0, col: 72, pos: 72) (ExecJS::ProgramError)
then I change for loop to this - it works
for (var id = kind; allocations[++id];) console.log(id);
Hey all,
I wanted to share a recent bug / fix we encountered yesterday. There was nothing anywhere using Google to try and research the bug, but updating the uglifier gem in our rails app fixed it.
Including Bootstrap.js from Bootstrap 3 resulted in the following error when precompiling assets:
% RAILS_ENV=production rake assets:precompile
/Users/mmoen/.rbenv/versions/1.9.3-p484/bin/ruby bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
TypeError: Cannot call method 'active' of undefined
(in /Users/mmoen/code/dojo4/gnerdl/app/assets/javascripts/application.js)
/Users/mmoen/code/dojo4/gnerdl/vendor/bundle/ruby/1.9.1/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:34:in `rescue in block in eval'
/Users/mmoen/code/dojo4/gnerdl/vendor/bundle/ruby/1.9.1/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:28:in `block in eval'
/Users/mmoen/code/dojo4/gnerdl/vendor/bundle/ruby/1.9.1/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:80:in `block in lock'
/Users/mmoen/code/dojo4/gnerdl/vendor/bundle/ruby/1.9.1/gems/therubyracer-0.10.1/lib/v8/c/locker.rb:13:in `Locker'
When we substituted bootstrap3 with bootstrap 2.3.2's js, compilation & minification worked.
We upgraded uglifier from 1.2.6 to 2.4.0 and minifying with bootstrap 3 worked.
I was wondering if anyone had any insight into this, knows what fix in uglifier fixed this, or had seen this before? I'd like to know more about why it was blowing up.
Heya,
The uglifier converts if(){debugger} statements like so -
Uglifier.new.compile('if (value) debugger') #=> "value&&debugger"
which (at least in Chrome & Firefox) raises a syntax error (Unexpected token debugger).
It could perhaps be argued that the debugger statement shouldn't be in minified production code, but it caught me by surprise & took quite a while to track down the syntax error in the minified js. Any thoughts?
after change from version 2.1.2 to 2.2.0 we have error in Rails compressed JS asset files - only on IE 8
I reproduced this issue with 1.3.0.
The following javascript:
// unminified + works
WHERE.changes = {
'run_show_action_for_type' : function(type) {
((WHERE[type + 's'] || {})['init'] || function() {})();
((WHERE[type + 's'] || {})['show'] || function() {})();
}
}
Gets minified to:
// minified + broken. sad face.
WHERE.changes={run_show_action_for_type:function(a){(WHERE[a+"s"]||{}).init||function(){}(),(WHERE[a+"s"]||{}).show||function(){}()}}
The stripping of parens causes the meaning of the function to change.
A subpart of the broken minfied looks like this:
// minified broken section. broken
(WHERE[a+"s"]||{}).show||function(){}();
But wrapping the outer section in parens, like the unminfied version fixes it:
// fixed minified broken section by adding parens. works.
((WHERE[a+"s"]||{}).show||function(){})();
I'm using Rails 2.3, pow.cx, barista, jammit, and uglifier. Restarting pow.cx takes care of the problem, but it's happening about once in three requests and it's problematic to have to go back to the console for touch tmp/restart.txt
every time.
The same error doesn't seem to happen with script/server
.
Referencing this Stackoverflow question, I tried commenting uglifier out of my Gemfile and that seemed to take care of the problem.
Full trace:
[Barista] Compiling all scripts for barista
[Barista] Compiling all coffeescripts
[Barista] Compiling admin.coffee from framework 'default'
/!\ FAILSAFE /!\ Thu Jun 16 14:02:42 -0400 2011
Status: 500 Internal Server Error
HandleScope::HandleScope: Entering the V8 API without proper locking in place
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/therubyracer-0.8.1/lib/v8/context.rb:74:in IsEntered' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/therubyracer-0.8.1/lib/v8/context.rb:74:in
enter'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/therubyracer-0.8.1/lib/v8/portal.rb:74:in open' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/therubyracer-0.8.1/lib/v8/object.rb:11:in
[]'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/coffee-script-2.1.3/lib/coffee_script.rb:124:in compile' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/coffee-script-2.1.3/lib/coffee_script.rb:169:in
compile'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/barista-1.0.0/lib/barista/compiler.rb:104:in compile' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/barista-1.0.0/lib/barista/compiler.rb:92:in
compile!'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/barista-1.0.0/lib/barista/compiler.rb:98:in to_js' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/barista-1.0.0/lib/barista/compiler.rb:54:in
autocompile_file'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/barista-1.0.0/lib/barista.rb:178:in compile_all!' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/barista-1.0.0/lib/barista.rb:177:in
each'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/barista-1.0.0/lib/barista.rb:177:in compile_all!' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/barista-1.0.0/lib/barista/filter.rb:14:in
_call'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/barista-1.0.0/lib/barista/filter.rb:9:in call' /Users/adam/Projects/tixato/app/middleware/no_www.rb:15:in
call'
/Users/adam/Projects/tixato/app/middleware/subdomain_files.rb:24:in call' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/actionpack-2.3.12/lib/action_controller/string_coercion.rb:25:in
call'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/rack-1.1.2/lib/rack/head.rb:9:in call' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/rack-1.1.2/lib/rack/methodoverride.rb:24:in
call'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/actionpack-2.3.12/lib/action_controller/params_parser.rb:15:in call' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/actionpack-2.3.12/lib/action_controller/session/cookie_store.rb:99:in
call'
/Users/adam/Projects/tixato/app/middleware/flash_session_cookie_middleware.rb:20:in call' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/activesupport-2.3.12/lib/active_support/cache/strategy/local_cache.rb:25:in
call'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/hoptoad_notifier-2.4.9/lib/hoptoad_notifier/rack.rb:27:in call' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/actionpack-2.3.12/lib/action_controller/failsafe.rb:26:in
call'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/hoptoad_notifier-2.4.9/lib/hoptoad_notifier/user_informer.rb:12:in call' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/rack-1.1.2/lib/rack/lock.rb:11:in
call'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/rack-1.1.2/lib/rack/lock.rb:11:in synchronize' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/rack-1.1.2/lib/rack/lock.rb:11:in
call'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/actionpack-2.3.12/lib/action_controller/dispatcher.rb:114:in call' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/actionpack-2.3.12/lib/action_controller/reloader.rb:34:in
run'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/actionpack-2.3.12/lib/action_controller/dispatcher.rb:108:in call' ./app/middleware/virtual_subdomain.rb:21:in
call'
/Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/rails-2.3.12/lib/rails/rack/static.rb:31:in call' /Users/adam/.rvm/gems/ree-1.8.7-2011.03@tixato/gems/rails-2.3.12/lib/rails/rack/log_tailer.rb:17:in
call'
/Users/adam/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:146:in handle' /Users/adam/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:99:in
start'
/Users/adam/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:86:in each' /Users/adam/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:86:in
start'
/Users/adam/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:66:in loop' /Users/adam/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:66:in
start'
/Users/adam/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:13:in `run'
/Users/adam/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/bin/nack_worker:4
Rails 3.2.9
#Gemfile
group :assets do
gem 'therubyracer', require: 'v8'
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.3.0'
gem 'yui-compressor'
gem 'bootstrap-sass', '~> 2.2.1.1'
gem "bourbon"
end
gem 'jquery-rails'
#the env.rb
config.assets.js_compressor = Uglifier.new :copyright => false,
:mangle => true,
:quote_keys => true,
:ascii_only => false,
:squeeze => true,
:toplevel => true,
:except => ["$super"]
So here are two js files.
https://gist.github.com/gists/4162900/edit
The first one is the mangeled one (mangle => true)
And it doesn't work
Second is the working UNmangeled one (mangle => false)
Hello,
I need to pass the mangle: false
option to compress my rails js, on my local machine bundle exec rake assets:precompile RAILS_ENV=production
renders the expected files, but not on my staging server ... The mangle: false
option seems to have been ignored.
I'm really lost here could you advice me were to start digging ?
PS: for what it worth i use gem 'therubyracer' , platforms: :ruby
for js execution
Thanks in advance for help / advising
I was wondering if you had any plans for uglifyjs2 support?
Can you please extend list of predefined identifier names with names do, for, in, if, etc.
Hey,
I wanted to use the define option to replace a debug variable but it didn't work. After I tried around a bit I got it working after I put the :define => { "DEBUG" => false }
into the :compress
hash it worked. So apparently this option has to be defined in that hash instead of the top level (of all options) so the listed options aren't quite correct, I guess (https://github.com/lautis/uglifier -> Usage)
uglifier-1.2.1 can't compile the following JavaScript code:
var str = "\u201E";
My environment:
ruby_1_9_3-r34209
multi_json-1.0.4
execjs-1.2.13
uglifier-1.2.1
The complete session log (paths in backtrace trimmed):
$ cat pr1.js
var str = "\u201E";
$ irb
irb(main):001:0> require 'uglifier'
=> true
irb(main):002:0> Uglifier.new.compile(File.read("pr1.js"))
MultiJson::DecodeError: 387: unexpected token at '"var str=\"\""]
'
from /opt/ruby_1_9_3-r34209/lib/ruby/1.9.1/json/common.rb:148:in `parse'
from /opt/ruby_1_9_3-r34209/lib/ruby/1.9.1/json/common.rb:148:in `parse'
from /[...]/gems/multi_json-1.0.4/lib/multi_json/engines/json_common.rb:9:in `decode'
from /[...]/gems/multi_json-1.0.4/lib/multi_json.rb:76:in `decode'
from /[...]/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:61:in `extract_result'
from /[...]/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:27:in `block in exec'
from /[...]/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:40:in `compile_to_tempfile'
from /[...]/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:26:in `exec'
from /[...]/gems/uglifier-1.2.1/lib/uglifier.rb:101:in `compile'
from (irb):2
from /opt/ruby_1_9_3-r34209/bin/irb:12:in `<main>'
irb(main):003:0>
The problematic Unicode character is a "low double comma quotation mark" (http://www.unicode.org/charts/PDF/U2000.pdf). I stumbled upon this by uglifiing a tiny_mce.js from https://github.com/spohlenz/tinymce-rails/blob/master/assets/vendor/tinymce/tiny_mce.js#L1238 (TinyMCE 3.4.7) - see code block starting at line 1238, "asciiMap" variable).
I'm using "\00" as a way to have an empty string that can be used to create a text node with no content. An empty string doesn't work, but setting a null character in there makes it behave without inserting any real content.
empty = document.createTextNode('\00');
element.appendChild(empty);
You'll notice that this is not the same behavior as using an empty string (eg. "").
After running it through uglifier, the result is already escaped as "0", and after playing quite a bit, I'm unable to get "\00". The closest I can get is "\00".
I highlighted the issue in more detail over at stackoverflow, but in a nutshell, turning compression on and using uglifer is causing an illegal character to be inserted in my combined and compressed code. Turning off compression and only using a combined file causes the error to go away.
Hi,
I am using uglifier as part of Rails 3.1 asset pipeline.
I am also using open_flash_chart which includes a version of swfobject.js
https://github.com/pullmonkey/open_flash_chart/blob/e1c826351ab5c1c1370507d8d0b83789807c65a3/assets/javascripts/swfobject.js
After uglfying, the script does not function correctly in IE, although it does in Firefox and Chrome. The problem relates to the function swfobject.embedSWF
Unfortunately, I am not familiar with the inner workings of swfobject.js - so can't give much insight into what is going wrong. Please let me know if I can provide more information.
I'm looking into an interesting site with exceptionhub - but the line numbers in their traces aren't useful since they've been minized. Any way to keep the line numbers the same as my source?
Bundler updated my uglifier from version 1.3.0 to 2.0.1 this weekend. When precompiling my asset pipeline now I get an error. Switching the gem back to version 1.3 resolves the issue. I'm running Windows 7. Full trace is below:
rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
C:/RailsInstaller/Ruby1.9.3/bin/ruby.exe C:\RailsInstaller\Ruby1.9.3\bin\rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
TypeError: Object doesn't support this property or method
(in C:/RailsSites/UglifierTest/app/assets/javascripts/application.js)
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:68:in extract_result' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:28:in
block in exec'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:41:in compile_to_tempfile' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:27:in
exec'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/uglifier-2.1.0/lib/uglifier.rb:173:in really_compile' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/uglifier-2.1.0/lib/uglifier.rb:97:in
compile'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/sprockets/compressors.rb:74:in compress' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/processing.rb:265:in
block in js_compressor='
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/processor.rb:29:in call' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/processor.rb:29:in
evaluate'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/tilt-1.4.1/lib/tilt/template.rb:103:in render' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:193:in
block in evaluate'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in each' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in
evaluate'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/bundled_asset.rb:26:in initialize' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:252:in
new'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:252:in build_asset' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in
block in build_asset'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in cache_asset' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in
build_asset'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in find_asset' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:60:in
find_asset'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/sprockets/static_compiler.rb:19:in block in compile' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:219:in
block in each_logical_path'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:206:in block (2 levels) in each_file' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in
each'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in each_entry' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:204:in
block in each_file'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in each' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in
each_file'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:217:in each_logical_path' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/sprockets/static_compiler.rb:18:in
compile'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:56:in internal_precompile' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:70:in
block (3 levels) in <top (required)>'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in call' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in
block in execute'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in each' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in
execute'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in block in invoke_with_call_chain' C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/monitor.rb:211:in
mon_synchronize'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in invoke_with_call_chain' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in
invoke'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:60:in block (3 levels) in <top (required)>' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in
call'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in block in execute' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in
each'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in execute' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in
block in invoke_with_call_chain'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in
invoke_with_call_chain'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in invoke' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:143:in
invoke_task'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in block (2 levels) in top_level' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in
each'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in block in top_level' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:110:in
run_with_threads'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:95:in top_level' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:73:in
block in run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in standard_exception_handling' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in
run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in <top (required)>' C:/RailsInstaller/Ruby1.9.3/bin/rake:19:in
load'
C:/RailsInstaller/Ruby1.9.3/bin/rake:19:in <main>' Tasks: TOP => assets:precompile:primary rake aborted! Command failed with status (1): [C:/RailsInstaller/Ruby1.9.3/bin/ruby.exe C...] C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils.rb:53:in
block in create_shell_runner'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in call' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in
sh'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils_ext.rb:37:in sh' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils.rb:80:in
ruby'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils_ext.rb:37:in ruby' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:12:in
ruby_rake_task'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:21:in invoke_or_reboot_rake_task' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:29:in
block (2 levels) in <top (required)>'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in call' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in
block in execute'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in each' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in
execute'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in block in invoke_with_call_chain' C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/monitor.rb:211:in
mon_synchronize'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in invoke_with_call_chain' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in
invoke'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:143:in invoke_task' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in
block (2 levels) in top_level'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in each' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in
block in top_level'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:110:in run_with_threads' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:95:in
top_level'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:73:in block in run' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in
standard_exception_handling'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in run' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in
<top (required)>'
C:/RailsInstaller/Ruby1.9.3/bin/rake:19:in load' C:/RailsInstaller/Ruby1.9.3/bin/rake:19:in
<top (required)>'
-e:1:in load' -e:1:in
After upgrading to Ruby 2.0.0, Uglifier has been producing invalid output when attempting to minify the paper.js source. The offending line of code looks like this after minification:
new!function(){
I've tried configuring a lot of the options, and the only way I can get it to produce valid code is by setting beautify: true, which isn't ideal of course. This is happening within a Rails application.
It is fixed in master, but new version is not yet released. When the new version is released, please upgrade the dependency.
Original Code:
$( 'body' ).css('background','red');
$( 'div' ).css('background','blue');
Uglified Code:
$(\"body\").css(\"background\",\"red\"),$(\"div\").css(\"background\",\"blue\");
Notice the comma added before $(\"div\")
When trying to use Uglify to minify JS files that are currently open in Visual Studio 10, I get the error:
Unexpected character '∩' (line: 1, col: 1, pos: 1)
This is regardless of whether or not there is actually any content inside the file. When trying to save the exact same file from Sublime Text 2 or Notepad, I do not receive this error.
:(
It would be nice if I could disable the line
js << "ast = UglifyJS.uglify.ast_mangle(ast, #{json_encode(mangle_options)});"
with configuration (with the default to be today's behavior). Angularjs has a lot of problems if variable names get compressed.
/usr/lib/ruby/gems/1.8/gems/execjs-1.2.4/lib/execjs/ruby_racer_runtime.rb:32:in eval': Unexpected character ' ' (ExecJS::ProgramError) from /usr/lib/ruby/gems/1.8/gems/execjs-1.2.4/lib/execjs/ruby_racer_runtime.rb:78:in
lock'
from /usr/lib/ruby/gems/1.8/gems/therubyracer-0.9.4/lib/v8/c/locker.rb:13:in Locker' from /usr/lib/ruby/gems/1.8/gems/execjs-1.2.4/lib/execjs/ruby_racer_runtime.rb:76:in
lock'
from /usr/lib/ruby/gems/1.8/gems/execjs-1.2.4/lib/execjs/ruby_racer_runtime.rb:25:in eval' from /usr/lib/ruby/gems/1.8/gems/execjs-1.2.4/lib/execjs/ruby_racer_runtime.rb:17:in
exec'
from /usr/lib/ruby/gems/1.8/gems/uglifier-1.0.1/lib/uglifier.rb:95:in `compress'
Hello.
I was using uglifier 2.5.3, nested_form 0.3.2, rails 4.0.10, ruby 2.1.1 and ExecJS 2.2.1
After assets compilation on production, nested_form behaved like included twice. A special method link_to_add
was adding two subforms instead of one.
That behavior was not reproduced in development environment, where assets are not precompiled.
So I switched to another compressor for production with config.assets.js_compressor
. And it behaves like it should now.
My JS skill doesn't allow me to find out which of two gems contains the issue, so I'm sorry for not submitting PR.
I am using uglifier gem version-2.2.1. I want to understand how can I turn on sourceMaps in my development.rb
Docs are a bit unclear.
Please see: sstephenson/sprockets#71
Disabling uglifier resolved the issue.
In my case it takes 60 seconds to process around 20 js files (angular with common modules).
Here is profiler log http://pastebin.com/uNWPSzCw
The reason is explained here: http://stackoverflow.com/questions/9573818/rubyracer-v8-binding-for-ruby-performs-really-slow
SO answer above claims this can be fixed by passing strings by reference.
Hello, is there any way to pass --lift-vars
option to UglifyJS to make it lift variables?
The gem therubyracer
currently doesn't compile on Heroku. There's a gem therubyracer-heroku
that is precompiled for Heroku's platform.
Can the gemspec dependency on therubyracer
be removed? It can be replaced with a README note instead.
Also see https://github.com/josh/ruby-coffee-script/blob/master/lib/coffee_script.rb for an example of supporting multiple possible JavaScript runtimes, including V8 via TheRubyRacer, a preinstalled Node.js, and JavaScriptCore on Macs, and using whichever is detected first.
When using uglifier via execjs using jscript on Windows, the exported functions don't seem to work. It fails on the line:
ast = UglifyJS.uglify.ast_squeeze(ast, {"make_seqs":true,"dead_code":true,"keep_comps":true});
with the error:
TypeError: Object doesn't support this property or method
I am trying to use this to pre-compile assets using rails 3.1.1.
Regards,
Jeff
UglifyJS2 adds new configuration options and removes some old. Additionally, preserving comments is now more powerful. As UglifyJS2 already necessitates breaking changes, this is a good time to make the options more sensible with regards to UglifyJS2 functionality.
I noticed in the minified JS file under Rails 3.1.3, which uses:
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
the resulting minified code sometimes has a comma after "use strict":
[lots of code]"use strict",[lots of code]
and occasionally has a semicolon after "use strict":
[lots of code]"use strict";[lots of code]
(The right form is with the semicolon. All our code uses a semicolon.)
In some cases (I guess if the minified content is large enough), the application.js file contents gets broken out over multiple lines.
Now even if the line gets broken after "use strict" but before the comma there was not an issue in any browser... until we upgraded Firefox to v16.0.1.
Here's an example JS file that causes a syntax error in FF 16 only:
(function(a){"use strict"
,a=10;});
I'm not sure why lines are broken after the comma/semicolon, but in this case, if there was a semicolon instead of a comma, the syntax error does not occur.
Not sure if it's a Firefox bug or not, but since the minification process could solve the issue, creating a ticket for you here.
Here's a sample file you can load in Chrome and FF 15 w/o error. But in FF 16 you'll see the error.
<html>
<body>
JS error with FF 16
<script>
(function(a){"use strict"
,a=10;});
</script>
</body>
</html>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.