Code Monkey home page Code Monkey logo

uglifier's Introduction

Uglifier

Ruby wrapper for UglifyJS JavaScript compressor.

UglifyJS only works with ES5. If you need to compress ES6, ruby-terser is a better option.

Rails

When used in Rails, replace

config.assets.js_compressor = :uglifier

with

config.assets.js_compressor = Uglifier.new(harmony: true)

in config/environments/production.rb.

Installation

Uglifier is available as a ruby gem.

$ gem install uglifier

Ensure that your environment has a JavaScript interpreter supported by ExecJS. Using therubyracer gem is a safe choice if a runtime isn't already present. Note that while JScript built-in Windows 7 and older works, it is extremely slow.

Usage

require 'uglifier'

Uglifier.new.compile(File.read("source.js"))
# => js file minified

# Or alternatively
Uglifier.compile(File.read("source.js"))

Uglifier also supports generating source maps:

uglified, source_map = Uglifier.new.compile_with_map(source)

When initializing UglifyJS, you can tune the behavior of UglifyJS by passing options. For example, if you want disable variable name mangling:

Uglifier.new(:mangle => false).compile(source)

# Or
Uglifier.compile(source, :mangle => false)

Available options and their defaults are

{
  :output => {
    :ascii_only => true,        # Escape non-ASCII characters
    :comments => :copyright,    # Preserve comments (:all, :jsdoc, :copyright, :none, Regexp (see below))
    :inline_script => false,    # Escape occurrences of </script in strings
    :quote_keys => false,       # Quote keys in object literals
    :max_line_len => 32 * 1024, # Maximum line length in minified code
    :bracketize => false,       # Bracketize if, for, do, while or with statements, even if their body is a single statement
    :semicolons => true,        # Separate statements with semicolons
    :preserve_line => false,    # Preserve line numbers in outputs
    :beautify => false,         # Beautify output
    :indent_level => 4,         # Indent level in spaces
    :indent_start => 0,         # Starting indent level
    :width => 80,               # Specify line width when beautifier is used (only with beautifier)
    :preamble => nil,           # Preamble for the generated JS file. Can be used to insert any code or comment.
    :wrap_iife => false,        # Wrap IIFEs in parenthesis. Note: this disables the negate_iife compression option.
    :shebang => true,           # Preserve shebang (#!) in preamble (shell scripts)
    :quote_style => 0,          # Quote style, possible values :auto (default), :single, :double, :original
    :keep_quoted_props => false # Keep quotes property names
  },
  :mangle => {
    :eval => false,             # Mangle names when eval of when is used in scope
    :reserved => ["$super"],    # Argument names to be excluded from mangling
    :sort => false,             # Assign shorter names to most frequently used variables. Often results in bigger output after gzip.
    :toplevel => false,         # Mangle names declared in the toplevel scope
    :properties => false,       # Mangle property names
    :keep_fnames => false       # Do not modify function names
  },                            # Mangle variable and function names, set to false to skip mangling
  :mangle_properties => {
    :regex => nil,              # A regular expression to filter property names to be mangled
    :ignore_quoted => false,    # Only mangle unquoted property names
    :debug => false,            # Mangle names with the original name still present
  },                            # Mangle property names, disabled by default
  :compress => {
    :sequences => true,         # Allow statements to be joined by commas
    :properties => true,        # Rewrite property access using the dot notation
    :dead_code => true,         # Remove unreachable code
    :drop_debugger => true,     # Remove debugger; statements
    :unsafe => false,           # Apply "unsafe" transformations
    :unsafe_comps => false,     # Reverse < and <= to > and >= to allow improved compression. This might be unsafe when an at least one of two operands is an object with computed values due the use of methods like get, or valueOf. This could cause change in execution order after operands in the comparison are switching. Compression only works if both comparisons and unsafe_comps are both set to true.
    :unsafe_math => false,      # Optimize numerical expressions like 2 * x * 3 into 6 * x, which may give imprecise floating point results.
    :unsafe_proto => false,     # Optimize expressions like Array.prototype.slice.call(a) into [].slice.call(a)
    :conditionals => true,      # Optimize for if-s and conditional expressions
    :comparisons => true,       # Apply binary node optimizations for comparisons
    :evaluate => true,          # Attempt to evaluate constant expressions
    :booleans => true,          # Various optimizations to boolean contexts
    :loops => true,             # Optimize loops when condition can be statically determined
    :unused => true,            # Drop unreferenced functions and variables
    :toplevel => false,         # Drop unreferenced top-level functions and variables
    :top_retain => [],          # prevent specific toplevel functions and variables from `unused` removal
    :hoist_funs => true,        # Hoist function declarations
    :hoist_vars => false,       # Hoist var declarations
    :if_return => true,         # Optimizations for if/return and if/continue
    :join_vars => true,         # Join consecutive var statements
    :collapse_vars => false,    # Collapse single-use var and const definitions when possible.
    :reduce_funcs => false,     # Inline single-use functions as function expressions. Depends on reduce_vars.
    :reduce_vars => false,      # Collapse variables assigned with and used as constant values.
    :negate_iife => true,       # Negate immediately invoked function expressions to avoid extra parens
    :pure_getters => false,     # Assume that object property access does not have any side-effects
    :pure_funcs => nil,         # List of functions without side-effects. Can safely discard function calls when the result value is not used
    :drop_console => false,     # Drop calls to console.* functions
    :keep_fargs => false,       # Preserve unused function arguments
    :keep_fnames => false,      # Do not drop names in function definitions
    :passes => 1,               # Number of times to run compress. Raising the number of passes will increase compress time, but can produce slightly smaller code.
    :keep_infinity => false,    # Prevent compression of Infinity to 1/0
    :side_effects => true,      # Pass false to disable potentially dropping functions marked as "pure" using pure comment annotation. See UglifyJS documentation for details.
    :switches => true,          # de-duplicate and remove unreachable switch branches
  },                            # Apply transformations to code, set to false to skip
  :parse => {
    :bare_returns => false,     # Allow top-level return statements.
    :expression => false,       # Parse a single expression, rather than a program (for parsing JSON).
    :html5_comments => true,    # Ignore HTML5 comments in input
    :shebang => true,           # support #!command as the first line
    :strict => false
  },
  :define => {},                # Define values for symbol replacement
  :enclose => false,            # Enclose in output function wrapper, define replacements as key-value pairs
  :keep_fnames => false,        # Generate code safe for the poor souls relying on Function.prototype.name at run-time. Sets both compress and mangle keep_fanems to true.
  :source_map => {
    :map_url => false,          # Url for source mapping to be appended in minified source
    :url => false,              # Url for original source to be appended in minified source
    :sources_content => false,  # Include original source content in map
    :filename => nil,           # The filename of the input file
    :root => nil,               # The URL of the directory which contains :filename
    :output_filename => nil,    # The filename or URL where the minified output can be found
    :input_source_map => nil    # The contents of the source map describing the input
  },
  :error_context_lines => 8,    # How many context lines surrounding the error line. Env var ERROR_CONTEXT_LINES overrides this option
  :harmony => false             # Enable ES6/Harmony mode (experimental). Disabling mangling and compressing is recommended with Harmony mode.
}

When passing a regular expression to the output => comments option, be sure to pass a valid Ruby Regexp. The beginning and ending of comments are removed and cannot be matched (/*, */, //). For example: When matching

/*!
 * comment
 */

use Uglifier.new(output: {comments: /^!/}).

Development

Tests are run using

bundle exec rake

See CONTRIBUTING for details about working on and contributing to Uglifier.

Copyright

© Ville Lautanala. Released under MIT license, see LICENSE for details.

uglifier's People

Contributors

a6b8 avatar ahorek avatar amatsuda avatar conradirwin avatar diclophis avatar egust avatar gmarik avatar hexgnu avatar inukshuk avatar josh avatar jraspass avatar junaruga avatar justinledwards avatar lautis avatar lencioni avatar nilbus avatar oliverklee avatar randoum avatar reedloden avatar roryhardy avatar ryankshaw avatar salimane avatar sanemat avatar seanlinsley avatar sferik avatar tbranyen avatar terceiro avatar vfrride avatar zachbeta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uglifier's Issues

define option incorrectly documented

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)

rake assets:precompile problem on Windows: Object doesn't support this property or method

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:inblock 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:inexec'
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:incompile'
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:inblock 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:inevaluate'
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:inblock 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:inevaluate'
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:innew'
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:inblock 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:inbuild_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:infind_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:inblock 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:ineach'
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:inblock 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:ineach_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:incompile'
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:inblock (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:inblock 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:inexecute'
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:inmon_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:ininvoke'
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:incall'
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:ineach'
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:inblock 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:ininvoke_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:ininvoke_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:ineach'
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:inrun_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:inblock 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:inrun'
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:inload'
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:inblock 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:insh'
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:inruby'
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:inruby_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:inblock (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:inblock 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:inexecute'
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:inmon_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:ininvoke'
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:inblock (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:inblock 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:intop_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:instandard_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

'
Tasks: TOP => assets:precompile

Used to show line number of broken JS, doesn't anymore

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.

Compiller foult

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);

IE8 + utf-8 problem, part 2

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

UglifyJS2 configuration options

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.

Broken JS minifing pdf.js

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.

[Bug] JS code fragment have uglification problems

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.

Uglifier.new(mangle: false) working locally but not on my remote env

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

bootstrap 3 bug?

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.

Drop console option is missing

The ability to drop the console commands is missing. (drop_console -- default false. Pass true to discard calls to console.* functions.)

invalid minified js

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)

any way to preserve newlines?

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?

Provide Option to disable mangling of variable names

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.

'\00' is being escaped improperly?

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".

Invalid JS output

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.

  • Uglifier version: 2.1.1
  • ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin13.0.0]
  • MultiJSON version: 1.7.7
  • ExecJS version: 1.4.0

Inconsistent asset digest values

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.

UglifyJS bug fix not included

mishoo/UglifyJS#126

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.

Possible bug in Uglifier call from Sprockets

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:

Compress JavaScripts and CSS

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

error while rendering in development: "HandleScope::HandleScope: Entering the V8 API without proper locking in place"

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:inenter'
/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:incompile'
/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:incompile!'
/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:inautocompile_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:ineach'
/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:incall'
/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:incall'
/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:incall'
/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:incall'
/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:incall'
/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:incall'
/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:incall'
/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:incall'
/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:inrun'
/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:incall'
/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:incall'
/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:instart'
/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:instart'
/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:instart'
/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

Making nested_form to load twice.

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.

Exports don't work with jscript

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

Uglified swfobject.js does not behave in same way as original

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.

Uglifier adding "Illegal Character" to JS

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.

code base messed up with Uglifier with mangle => true

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)

Don't depend on therubyracer

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.

encoding issues dependent on environment settings

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.

Execjs throws exception when source contains Unicode whitespace

/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:inlock'
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:inlock'
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:inexec'
from /usr/lib/ruby/gems/1.8/gems/uglifier-1.0.1/lib/uglifier.rb:95:in `compress'

Unable to minify JS files saved in Visual Studio

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.

:(

Lifting variables

Hello, is there any way to pass --lift-vars option to UglifyJS to make it lift variables?

self invoking anonymous functions generating errors

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

"if (v) debugger" doesn't uglify well

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?

Uglifier Minification breaks javascript

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(){})();

"use strict" followed by a comma could cause syntax error in Firefox 16.0.1

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>

Error compiling Unicode escape sequence

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).

How to keep the sourceMapUrl in the source file?

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.