uglifier-2.7.2/0000755000004100000410000000000012567417234013373 5ustar www-datawww-datauglifier-2.7.2/Rakefile0000644000004100000410000000247512567417234015050 0ustar www-datawww-data# encoding: utf-8 require 'rubygems' require 'bundler' require 'bundler/gem_tasks' begin Bundler.setup(:default, :development) rescue Bundler::BundlerError => e $stderr.puts e.message $stderr.puts "Run `bundle install` to install missing gems" exit e.status_code end require 'rake' require 'rspec/core' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |spec| spec.pattern = FileList['spec/**/*_spec.rb'] end require 'rdoc/task' Rake::RDocTask.new do |rdoc| version = File.exist?('VERSION') ? File.read('VERSION') : "" rdoc.rdoc_dir = 'rdoc' rdoc.title = "uglifier #{version}" rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') end desc "Rebuild lib/uglify.js" task :js do cd 'vendor/source-map/' do `npm install` `node Makefile.dryice.js` end cd 'vendor/uglifyjs/' do # required to run ./uglifyjs2 --self; not bundled. `npm install` end source = "" source << "window = this;" source << File.read("vendor/source-map/dist/source-map.js") source << "MOZ_SourceMap = sourceMap;" source << `./vendor/uglifyjs/bin/uglifyjs --self --comments /Copyright/` File.write("lib/uglify.js", source) end begin require 'rubocop/rake_task' RuboCop::RakeTask.new(:rubocop) task :default => [:spec] rescue LoadError task :default => [:spec] end uglifier-2.7.2/Gemfile0000644000004100000410000000023412567417234014665 0ustar www-datawww-datasource "https://rubygems.org" gemspec if RUBY_VERSION >= '1.9' gem 'rubocop', '~> 0.28.0', :group => [:development] else gem 'execjs', '~> 2.0.2' end uglifier-2.7.2/.rspec0000644000004100000410000000001012567417234014477 0ustar www-datawww-data--color uglifier-2.7.2/LICENSE.txt0000644000004100000410000000204312567417234015215 0ustar www-datawww-dataCopyright (c) 2011 Ville Lautanala Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. uglifier-2.7.2/spec/0000755000004100000410000000000012567417234014325 5ustar www-datawww-datauglifier-2.7.2/spec/uglifier_spec.rb0000644000004100000410000002210112567417234017466 0ustar www-datawww-data# encoding: UTF-8 require 'stringio' require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe "Uglifier" do it "minifies JS" do source = File.open("lib/uglify.js", "r:UTF-8").read minified = Uglifier.new.compile(source) expect(minified.length).to be < source.length expect { Uglifier.new.compile(minified) }.not_to raise_error end it "throws an exception when compilation fails" do expect { Uglifier.new.compile(")(") }.to raise_error(Uglifier::Error) end it "throws an exception on invalid option" do expect { Uglifier.new(:foo => true) }.to raise_error(ArgumentError) end it "doesn't omit null character in strings" do expect(Uglifier.new.compile('var foo="\0bar"')).to include("\\x00bar") end it "adds trailing semicolon to minified source" do source = "(function id(i) {return i;}());" expect(Uglifier.new.compile(source)[-1]).to eql(";"[0]) end describe "argument name mangling" do it "doesn't try to mangle $super by default to avoid breaking PrototypeJS" do expect(Uglifier.compile('function foo($super) {return $super}')).to include("$super") end it "allows variables to be excluded from mangling" do code = "function bar(foo) {return foo + 'bar'};" expect(Uglifier.compile(code, :mangle => { :except => ["foo"] })).to include("(foo)") end it "skips mangling when set to false" do code = "function bar(foo) {return foo + 'bar'};" expect(Uglifier.compile(code, :mangle => false)).to include("(foo)") end it "mangles argumen names by default" do code = "function bar(foo) {return foo + 'bar'};" expect(Uglifier.compile(code, :mangle => true)).not_to include("(foo)") end it "mangles top-level names when explicitly instructed" do code = "function bar(foo) {return foo + 'bar'};" expect(Uglifier.compile(code, :mangle => { :toplevel => false })).to include("bar(") expect(Uglifier.compile(code, :mangle => { :toplevel => true })).not_to include("bar(") end end describe "comment preservation" do let(:source) do <<-EOS /* @preserve Copyright Notice */ /* (c) 2011 */ // INCLUDED //! BANG function identity(p) { return p; } /* Another Copyright */ /*! Another Bang */ // A comment! function add(a, b) { return a + b; } EOS end it "handles copyright option" do compiled = Uglifier.compile(source, :copyright => false) expect(compiled).not_to match(/Copyright/) end describe ":copyright" do subject { Uglifier.compile(source, :comments => :copyright) } it "preserves comments with string Copyright" do expect(subject).to match(/Copyright Notice/) expect(subject).to match(/Another Copyright/) end it "preserves comments that start with a bang (!)" do expect(subject).to match(/! BANG/) expect(subject).to match(/! Another Bang/) end it "ignores other comments" do expect(subject).not_to match(/INCLUDED/) expect(subject).not_to match(/A comment!/) end end describe ":jsdoc" do subject { Uglifier.compile(source, :output => { :comments => :jsdoc }) } it "preserves jsdoc license/preserve blocks" do expect(subject).to match(/Copyright Notice/) end it "ignores other comments" do expect(subject).not_to match(/Another Copyright/) end end describe ":all" do subject { Uglifier.compile(source, :comments => :all) } it "preserves all comments" do expect(subject).to match(/INCLUDED/) expect(subject).to match(/2011/) end end describe ":none" do subject { Uglifier.compile(source, :comments => :none) } it "omits all comments" do expect(subject).not_to match %r{//} expect(subject).not_to match(/\/\*/) end end describe "regular expression" do subject { Uglifier.compile(source, :comments => /included/i) } it "matches comment blocks with regex" do expect(subject).to match(/INCLUDED/) end it "omits other blocks" do expect(subject).not_to match(/2011/) end end end it "squeezes code only if squeeze is set to true" do code = "function a(a){if(a) { return 0; } else { return 1; }}" minified = Uglifier.compile(code, :squeeze => false) squeezed = Uglifier.compile(code, :squeeze => true) expect(minified.length).to be > squeezed.length end it "honors max line length" do code = "var foo = 123;function bar() { return foo; }" uglifier = Uglifier.new(:output => { :max_line_len => 20 }, :compress => false) expect(uglifier.compile(code).split("\n").map(&:length)).to all(be < 28) end it "hoists vars to top of the scope" do code = "function something() { var a = 1; a = 2; var b = 3; return a + b;}" minified = Uglifier.compile(code, :compress => { :hoist_vars => true }) expect(minified).to match(/var \w,\w/) end it "forwards screw_ie8 option to UglifyJS" do code = "function something() { return g['switch']; }" expect(Uglifier.compile(code, :mangle => false, :screw_ie8 => true)).to match(/g\.switch/) expect(Uglifier.compile(code, :compress => false, :screw_ie8 => true)).to match(/g\.switch/) end it "can be configured to output only ASCII" do code = "function emoji() { return '\\ud83c\\ude01'; }" minified = Uglifier.compile(code, :output => { :ascii_only => true }) expect(minified).to include("\\ud83c\\ude01") end it "escapes { :inline_script => true }) expect(minified).not_to include("") end it "quotes keys" do code = "var a = {foo: 1}" minified = Uglifier.compile(code, :output => { :quote_keys => true }) expect(minified).to include('"foo"') end it "quotes unsafe keys by default" do code = 'var code = {"class": "", "\u200c":"A"}' expect(Uglifier.compile(code)).to include('"class"') expect(Uglifier.compile(code)).to include('"\u200c"') uglifier = Uglifier.new(:output => { :ascii_only => false, :quote_keys => false }) expect(uglifier.compile(code)).to include(["200c".to_i(16)].pack("U*")) end it "handles constant definitions" do code = "if (BOOL) { var a = STR; var b = NULL; var c = NUM; }" defines = { "NUM" => 1234, "BOOL" => true, "NULL" => nil, "STR" => "str" } processed = Uglifier.compile(code, :define => defines) expect(processed).to include("a=\"str\"") expect(processed).not_to include("if") expect(processed).to include("b=null") expect(processed).to include("c=1234") end it "can disable IIFE negation" do code = "(function() { console.log('test')})();" disabled_negation = Uglifier.compile(code, :compress => { :negate_iife => false }) expect(disabled_negation).not_to include("!") negation = Uglifier.compile(code, :compress => { :negate_iife => true }) expect(negation).to include("!") end it "can drop console logging" do code = "(function() { console.log('test')})();" compiled = Uglifier.compile(code, :compress => { :drop_console => true }) expect(compiled).not_to include("console") end it "processes @ngInject annotations" do code = <<-EOF /** * @ngInject */ var f = function(foo, bar) { return foo + bar}; EOF with_angular = Uglifier.compile(code, :compress => { :angular => true }) without_angular = Uglifier.compile(code, :compress => { :angular => false }) expect(with_angular).to include("f.$inject") expect(without_angular).not_to include("f.$inject") end it "keeps unused function arguments when keep_fargs option is set" do code = <<-EOF function plus(a, b, c) { return a + b}; plus(1, 2); EOF options = lambda do |keep_fargs| { :mangle => false, :compress => { :keep_fargs => keep_fargs, :unsafe => true } } end expect(Uglifier.compile(code, options.call(false))).not_to include("c)") expect(Uglifier.compile(code, options.call(true))).to include("c)") end describe "Input Formats" do let(:code) { "function hello() { return 'hello world'; }" } it "handles strings" do expect(Uglifier.new.compile(code)).not_to be_empty end it "handles IO objects" do expect(Uglifier.new.compile(StringIO.new(code))).not_to be_empty end end describe "enclose" do let(:code) { "$.foo()" } it "encloses code with given arguments" do minified = Uglifier.compile(code, :enclose => { 'window.jQuery' => '$' }) expect(minified).to match(/window.jQuery/) end it "handles multiple definitions" do definitions = [%w(lol lulz), %w(foo bar)] minified = Uglifier.compile(code, :enclose => definitions) expect(minified).to match(/lol,foo/) expect(minified).to match(/lulz,bar/) end it "wraps with function when given empty object" do minified = Uglifier.compile(code, :enclose => {}) expect(minified).to match(/function\(/) end end end uglifier-2.7.2/spec/spec_helper.rb0000644000004100000410000000102112567417234017135 0ustar www-datawww-data# encoding: UTF-8 require 'uglifier' require 'rspec' require 'source_map' # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } if ENV["ALASKA"] require 'alaska' require 'tempfile' ExecJS.runtime = Alaska::Runtime.new end RSpec.configure do |config| config.mock_with :rspec do |mock| mock.syntax = :expect end config.expect_with :rspec do |expect| expect.syntax = :expect end end uglifier-2.7.2/spec/source_map_spec.rb0000644000004100000410000000627112567417234020027 0ustar www-datawww-data# encoding: UTF-8 require 'stringio' require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe "Uglifier" do let(:source) do <<-JS function hello () { function world () { return 2; }; return world() + world(); }; JS end it "generates source maps" do source = File.open("lib/uglify.js", "r:UTF-8").read minified, map = Uglifier.new.compile_with_map(source) expect(minified.length).to be < source.length expect(map.length).to be > 0 expect { JSON.parse(map) }.not_to raise_error end it "generates source maps with the correct meta-data" do _, map = Uglifier.compile_with_map(source, :source_filename => "ahoy.js", :output_filename => "ahoy.min.js", :source_root => "http://localhost/") map = SourceMap.from_s(map) expect(map.file).to eq("ahoy.min.js") expect(map.sources).to eq(["ahoy.js"]) expect(map.names).to eq(%w(hello world)) expect(map.source_root).to eq("http://localhost/") expect(map.mappings.first[:generated_line]).to eq(1) end it "should skip copyright lines in source maps" do source = <<-JS /* @copyright Conrad Irwin */ function hello () { function world () { return 2; }; return world() + world(); }; JS _, map = Uglifier.compile_with_map(source, :source_filename => "ahoy.js", :source_root => "http://localhost/") map = SourceMap.from_s(map) expect(map.mappings.first[:generated_line]).to eq(2) end it "should be able to handle an input source map" do source = <<-JS function hello () { function world () { return 2; }; return world() + world(); }; JS minified1, map1 = Uglifier.compile_with_map( source, :source_filename => "ahoy.js", :source_root => "http://localhost/", :mangle => false ) _, map2 = Uglifier.compile_with_map(source, :input_source_map => map1, :mangle => true) expect(minified1.lines.to_a.length).to eq(1) map = SourceMap.from_s(map2) expect(map.sources).to eq(["ahoy.js", "http://localhost/ahoy.js"]) expect(map.mappings.first[:source_line]).to eq(1) expect(map.mappings.last[:source_line]).to eq(6) end it "appens source map url" do minified, _ = Uglifier.compile_with_map( source, :source_filename => "ahoy.js", :output_filename => "ahoy.min.js", :source_root => "http://localhost/", :source_map_url => "http://example.com/map" ) expect(minified).to include("\n//# sourceMappingURL=http://example.com/map") end it "appens source url" do minified, _ = Uglifier.compile_with_map( source, :source_filename => "ahoy.js", :output_filename => "ahoy.min.js", :source_root => "http://localhost/", :source_url => "http://example.com/source" ) expect(minified).to include("\n//# sourceURL=http://example.com/source") end end uglifier-2.7.2/.travis.yml0000644000004100000410000000076012567417234015507 0ustar www-datawww-datasudo: false language: ruby cache: bundler rvm: - 1.8.7 - 1.9.3 - 2.0.0 - 2.1.5 - 2.2.0 - jruby - rbx-2 git: submodules: false gemfile: - Gemfile matrix: include: - rvm: 2.2.0 gemfile: gemfiles/rubyracer - rvm: 2.1.5 gemfile: gemfiles/rubyracer - rvm: jruby-19mode gemfile: gemfiles/rubyrhino - rvm: 2.2.0 gemfile: gemfiles/alaska env: ALASKA=1 allow_failures: - rvm: 2.2.0 gemfile: gemfiles/alaska env: ALASKA=1 uglifier-2.7.2/lib/0000755000004100000410000000000012567417234014141 5ustar www-datawww-datauglifier-2.7.2/lib/split.js0000644000004100000410000001122312567417234015631 0ustar www-datawww-data/*! * Cross-Browser Split 1.1.1 * Copyright 2007-2012 Steven Levithan * Available under the MIT License * ECMAScript compliant, uniform cross-browser split method */ /** * Splits a string into an array of strings using a regex or string separator. Matches of the * separator are not included in the result array. However, if `separator` is a regex that contains * capturing groups, backreferences are spliced into the result each time `separator` is matched. * Fixes browser bugs compared to the native `String.prototype.split` and can be used reliably * cross-browser. * @param {String} str String to split. * @param {RegExp|String} separator Regex or string to use for separating the string. * @param {Number} [limit] Maximum number of items to include in the result array. * @returns {Array} Array of substrings. * @example * * // Basic use * split('a b c d', ' '); * // -> ['a', 'b', 'c', 'd'] * * // With limit * split('a b c d', ' ', 2); * // -> ['a', 'b'] * * // Backreferences in result array * split('..word1 word2..', /([a-z]+)(\d+)/i); * // -> ['..', 'word', '1', ' ', 'word', '2', '..'] */ var split; // Avoid running twice; that would break the `nativeSplit` reference split = split || function (undef) { var nativeSplit = String.prototype.split, compliantExecNpcg = /()??/.exec("")[1] === undef, // NPCG: nonparticipating capturing group self; self = function (str, separator, limit) { // If `separator` is not a regex, use `nativeSplit` if (Object.prototype.toString.call(separator) !== "[object RegExp]") { return nativeSplit.call(str, separator, limit); } var output = [], flags = (separator.ignoreCase ? "i" : "") + (separator.multiline ? "m" : "") + (separator.extended ? "x" : "") + // Proposed for ES6 (separator.sticky ? "y" : ""), // Firefox 3+ lastLastIndex = 0, // Make `global` and avoid `lastIndex` issues by working with a copy separator = new RegExp(separator.source, flags + "g"), separator2, match, lastIndex, lastLength; str += ""; // Type-convert if (!compliantExecNpcg) { // Doesn't need flags gy, but they don't hurt separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags); } /* Values for `limit`, per the spec: * If undefined: 4294967295 // Math.pow(2, 32) - 1 * If 0, Infinity, or NaN: 0 * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296; * If negative number: 4294967296 - Math.floor(Math.abs(limit)) * If other: Type-convert, then use the above rules */ limit = limit === undef ? -1 >>> 0 : // Math.pow(2, 32) - 1 limit >>> 0; // ToUint32(limit) while (match = separator.exec(str)) { // `separator.lastIndex` is not reliable cross-browser lastIndex = match.index + match[0].length; if (lastIndex > lastLastIndex) { output.push(str.slice(lastLastIndex, match.index)); // Fix browsers whose `exec` methods don't consistently return `undefined` for // nonparticipating capturing groups if (!compliantExecNpcg && match.length > 1) { match[0].replace(separator2, function () { for (var i = 1; i < arguments.length - 2; i++) { if (arguments[i] === undef) { match[i] = undef; } } }); } if (match.length > 1 && match.index < str.length) { Array.prototype.push.apply(output, match.slice(1)); } lastLength = match[0].length; lastLastIndex = lastIndex; if (output.length >= limit) { break; } } if (separator.lastIndex === match.index) { separator.lastIndex++; // Avoid an infinite loop } } if (lastLastIndex === str.length) { if (lastLength || !separator.test("")) { output.push(""); } } else { output.push(str.slice(lastLastIndex)); } return output.length > limit ? output.slice(0, limit) : output; }; if ("\n".split(/\n/).length == 0) { String.prototype.split = function (separator, limit) { return self(this, separator, limit); }; } return self; }(); uglifier-2.7.2/lib/uglifier.rb0000644000004100000410000002477112567417234016307 0ustar www-datawww-data# encoding: UTF-8 require "execjs" require "json" require "uglifier/version" # A wrapper around the UglifyJS interface class Uglifier # Error class for compilation errors. Error = ExecJS::Error # JavaScript code to call UglifyJS JS = <<-JS (function(options) { function comments(option) { if (Object.prototype.toString.call(option) === '[object Array]') { return new RegExp(option[0], option[1]); } else if (option == "jsdoc") { return function(node, comment) { if (comment.type == "comment2") { return /@preserve|@license|@cc_on/i.test(comment.value); } else { return false; } } } else { return option; } } var source = options.source; var ast = UglifyJS.parse(source, options.parse_options); ast.figure_out_scope(); if (options.compress) { var compressor = UglifyJS.Compressor(options.compress); ast = ast.transform(compressor); ast.figure_out_scope(); } if (options.mangle) { ast.compute_char_frequency(); ast.mangle_names(options.mangle); } if (options.enclose) { ast = ast.wrap_enclose(options.enclose); } var gen_code_options = options.output; gen_code_options.comments = comments(options.output.comments); if (options.generate_map) { var source_map = UglifyJS.SourceMap(options.source_map_options); gen_code_options.source_map = source_map; } var stream = UglifyJS.OutputStream(gen_code_options); ast.print(stream); if (options.source_map_options.map_url) { stream += "\\n//# sourceMappingURL=" + options.source_map_options.map_url; } if (options.source_map_options.url) { stream += "\\n//# sourceURL=" + options.source_map_options.url; } if (options.generate_map) { return [stream.toString(), source_map.toString()]; } else { return stream.toString(); } }) JS # UglifyJS source path SourcePath = File.expand_path("../uglify.js", __FILE__) # ES5 shims source path ES5FallbackPath = File.expand_path("../es5.js", __FILE__) # String.split shim source path SplitFallbackPath = File.expand_path("../split.js", __FILE__) # Default options for compilation DEFAULTS = { # rubocop:disable LineLength :output => { :ascii_only => true, # Escape non-ASCII characterss :comments => :copyright, # Preserve comments (:all, :jsdoc, :copyright, :none) :inline_script => false, # Escape occurrences of 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 :space_colon => false, # Insert space before colons (only with beautifier) :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. }, :mangle => { :eval => false, # Mangle names when eval of when is used in scope :except => ["$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 }, # Mangle variable and function names, set to false to skip mangling :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 :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 :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 :cascade => true, # Cascade sequences :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 :angular => false, # Process @ngInject annotations :keep_fargs => false # Preserve unused function arguments }, # Apply transformations to code, set to false to skip :define => {}, # Define values for symbol replacement :enclose => false, # Enclose in output function wrapper, define replacements as key-value pairs :source_filename => nil, # The filename of the input file :source_root => nil, # The URL of the directory which contains :source_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 :screw_ie8 => false, # Don't bother to generate safe code for IE8 :source_map_url => false, # Url for source mapping to be appended in minified source :source_url => false # Url for original source to be appended in minified source } # rubocop:enable LineLength # Minifies JavaScript code using implicit context. # # @param source [IO, String] valid JS source code. # @param options [Hash] optional overrides to +Uglifier::DEFAULTS+ # @return [String] minified code. def self.compile(source, options = {}) new(options).compile(source) end # Minifies JavaScript code and generates a source map using implicit context. # # @param source [IO, String] valid JS source code. # @param options [Hash] optional overrides to +Uglifier::DEFAULTS+ # @return [Array(String, String)] minified code and source map. def self.compile_with_map(source, options = {}) new(options).compile_with_map(source) end # Initialize new context for Uglifier with given options # # @param options [Hash] optional overrides to +Uglifier::DEFAULTS+ def initialize(options = {}) (options.keys - DEFAULTS.keys - [:comments, :squeeze, :copyright])[0..1].each do |missing| raise ArgumentError, "Invalid option: #{missing}" end @options = options @context = ExecJS.compile(uglifyjs_source) end # Minifies JavaScript code # # @param source [IO, String] valid JS source code. # @return [String] minified code. def compile(source) run_uglifyjs(source, false) end alias_method :compress, :compile # Minifies JavaScript code and generates a source map # # @param source [IO, String] valid JS source code. # @return [Array(String, String)] minified code and source map. def compile_with_map(source) run_uglifyjs(source, true) end private def uglifyjs_source [ES5FallbackPath, SplitFallbackPath, SourcePath].map do |file| File.open(file, "r:UTF-8") { |f| f.read } end.join("\n") end # Run UglifyJS for given source code def run_uglifyjs(source, generate_map) options = { :source => read_source(source), :output => output_options, :compress => compressor_options, :mangle => mangle_options, :parse_options => parse_options, :source_map_options => source_map_options, :generate_map => generate_map, :enclose => enclose_options } @context.call(Uglifier::JS, options) end def read_source(source) if source.respond_to?(:read) source.read else source.to_s end end def mangle_options conditional_option(@options[:mangle], DEFAULTS[:mangle]) end def compressor_options defaults = conditional_option( DEFAULTS[:compress], :global_defs => @options[:define] || {}, :screw_ie8 => @options[:screw_ie8] || DEFAULTS[:screw_ie8] ) conditional_option(@options[:compress] || @options[:squeeze], defaults) end def comment_options case comment_setting when :all, true true when :jsdoc "jsdoc" when :copyright encode_regexp(/(^!)|Copyright/i) when Regexp encode_regexp(comment_setting) else false end end def comment_setting if @options.has_key?(:output) && @options[:output].has_key?(:comments) @options[:output][:comments] elsif @options.has_key?(:comments) @options[:comments] elsif @options[:copyright] == false :none else DEFAULTS[:output][:comments] end end def output_options DEFAULTS[:output].merge(@options[:output] || {}).merge( :comments => comment_options, :screw_ie8 => screw_ie8? ).reject { |key, _| key == :ie_proof } end def screw_ie8? if (@options[:output] || {}).has_key?(:ie_proof) false else @options[:screw_ie8] || DEFAULTS[:screw_ie8] end end def source_map_options { :file => @options[:output_filename], :root => @options[:source_root], :orig => @options[:input_source_map], :map_url => @options[:source_map_url], :url => @options[:source_url] } end def parse_options { :filename => @options[:source_filename] } end def enclose_options if @options[:enclose] @options[:enclose].map do |pair| pair.first + ':' + pair.last end else false end end def encode_regexp(regexp) modifiers = if regexp.casefold? "i" else "" end [regexp.source, modifiers] end def conditional_option(value, defaults) if value == true || value.nil? defaults elsif value defaults.merge(value) else false end end end uglifier-2.7.2/lib/es5.js0000644000004100000410000002135212567417234015176 0ustar www-datawww-data// https://developer.mozilla.org/en/JavaScript/Reference/global_objects/array/foreach if (!Array.prototype.forEach) { Array.prototype.forEach = function(fun /*, thisp */) { "use strict"; if (this === void 0 || this === null) throw new TypeError(); var t = Object(this); var len = t.length >>> 0; if (typeof fun !== "function") throw new TypeError(); var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in t) fun.call(thisp, t[i], i, t); } }; } // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map // Production steps of ECMA-262, Edition 5, 15.4.4.19 // Reference: http://es5.github.com/#x15.4.4.19 if (!Array.prototype.map) { Array.prototype.map = function(callback, thisArg) { var T, A, k; if (this == null) { throw new TypeError(" this is null or not defined"); } // 1. Let O be the result of calling ToObject passing the |this| value as the argument. var O = Object(this); // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length". // 3. Let len be ToUint32(lenValue). var len = O.length >>> 0; // 4. If IsCallable(callback) is false, throw a TypeError exception. // See: http://es5.github.com/#x9.11 if ({}.toString.call(callback) != "[object Function]") { throw new TypeError(callback + " is not a function"); } // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. if (thisArg) { T = thisArg; } // 6. Let A be a new array created as if by the expression new Array(len) where Array is // the standard built-in constructor with that name and len is the value of len. A = new Array(len); // 7. Let k be 0 k = 0; // 8. Repeat, while k < len while(k < len) { var kValue, mappedValue; // a. Let Pk be ToString(k). // This is implicit for LHS operands of the in operator // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk. // This step can be combined with c // c. If kPresent is true, then if (k in O) { // i. Let kValue be the result of calling the Get internal method of O with argument Pk. kValue = O[ k ]; // ii. Let mappedValue be the result of calling the Call internal method of callback // with T as the this value and argument list containing kValue, k, and O. mappedValue = callback.call(T, kValue, k, O); // iii. Call the DefineOwnProperty internal method of A with arguments // Pk, Property Descriptor {Value: mappedValue, Writable: true, Enumerable: true, Configurable: true}, // and false. // In browsers that support Object.defineProperty, use the following: // Object.defineProperty(A, Pk, { value: mappedValue, writable: true, enumerable: true, configurable: true }); // For best browser support, use the following: A[ k ] = mappedValue; } // d. Increase k by 1. k++; } // 9. return A return A; }; } // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/Reduce if (!Array.prototype.reduce) { Array.prototype.reduce = function(fun /*, initialValue */) { "use strict"; if (this === void 0 || this === null) throw new TypeError(); var t = Object(this); var len = t.length >>> 0; if (typeof fun !== "function") throw new TypeError(); // no value to return if no initial value and an empty array if (len == 0 && arguments.length == 1) throw new TypeError(); var k = 0; var accumulator; if (arguments.length >= 2) { accumulator = arguments[1]; } else { do { if (k in t) { accumulator = t[k++]; break; } // if array contains no values, no initial value to return if (++k >= len) throw new TypeError(); } while (true); } while (k < len) { if (k in t) accumulator = fun.call(undefined, accumulator, t[k], k, t); k++; } return accumulator; }; } // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { "use strict"; if (this === void 0 || this === null) { throw new TypeError(); } var t = Object(this); var len = t.length >>> 0; if (len === 0) { return -1; } var n = 0; if (arguments.length > 0) { n = Number(arguments[1]); if (n !== n) { // shortcut for verifying if it's NaN n = 0; } else if (n !== 0 && n !== Infinity && n !== -Infinity) { n = (n > 0 || -1) * Math.floor(Math.abs(n)); } } if (n >= len) { return -1; } var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); for (; k < len; k++) { if (k in t && t[k] === searchElement) { return k; } } return -1; } } // https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/Object/keys if (!Object.keys) { Object.keys = (function () { var hasOwnProperty = Object.prototype.hasOwnProperty, hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'), dontEnums = [ 'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'constructor' ], dontEnumsLength = dontEnums.length; return function (obj) { if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object'); var result = []; for (var prop in obj) { if (hasOwnProperty.call(obj, prop)) result.push(prop); } if (hasDontEnumBug) { for (var i=0; i < dontEnumsLength; i++) { if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]); } } return result; } })() }; // https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/Object/create if (!Object.create) { Object.create = function (o) { if (arguments.length > 1) { throw new Error('Object.create implementation only accepts the first parameter.'); } function F() {} F.prototype = o; return new F(); }; } // https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/Array/filter if (!Array.prototype.filter) { Array.prototype.filter = function(fun /*, thisp*/) { "use strict"; if (this == null) throw new TypeError(); var t = Object(this); var len = t.length >>> 0; if (typeof fun != "function") throw new TypeError(); var res = []; var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in t) { var val = t[i]; // in case fun mutates this if (fun.call(thisp, val, i, t)) res.push(val); } } return res; }; } // https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/Function/bind if (!Function.prototype.bind) { Function.prototype.bind = function (oThis) { if (typeof this !== "function") { // closest thing possible to the ECMAScript 5 internal IsCallable function throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); } var aArgs = Array.prototype.slice.call(arguments, 1), fToBind = this, fNOP = function () {}, fBound = function () { return fToBind.apply(this instanceof fNOP && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments))); }; fNOP.prototype = this.prototype; fBound.prototype = new fNOP(); return fBound; }; } // https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/Array/isArray if(!Array.isArray) { Array.isArray = function (vArg) { return Object.prototype.toString.call(vArg) === "[object Array]"; }; } // https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/String/trim if(!String.prototype.trim) { String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g,''); }; } function definePropertyWorks() { try { Object.defineProperty({}, "property", {}); return true; } catch (exception) { return false; } } if (!definePropertyWorks()) { Object.defineProperty = function defineProperty(object) { // fail silently return object; } } uglifier-2.7.2/lib/uglifier/0000755000004100000410000000000012567417234015747 5ustar www-datawww-datauglifier-2.7.2/lib/uglifier/version.rb0000644000004100000410000000011012567417234017751 0ustar www-datawww-dataclass Uglifier # Current version of Uglifier. VERSION = "2.7.2" end uglifier-2.7.2/gemfiles/0000755000004100000410000000000012567417234015166 5ustar www-datawww-datauglifier-2.7.2/gemfiles/rubyracer0000644000004100000410000000011012567417234017077 0ustar www-datawww-datasource "https://rubygems.org" gemspec :path=> "../" gem 'therubyracer' uglifier-2.7.2/gemfiles/rubyrhino0000644000004100000410000000011112567417234017123 0ustar www-datawww-datasource "https://rubygems.org" gemspec :path => "../" gem 'therubyrhino' uglifier-2.7.2/gemfiles/alaska0000644000004100000410000000013612567417234016345 0ustar www-datawww-datasource "https://rubygems.org" gemspec :path=> "../" gem "alaska", github: "mavenlink/alaska" uglifier-2.7.2/.rubocop.yml0000644000004100000410000000062312567417234015646 0ustar www-datawww-dataAllCops: Exclude: - uglifier.gemspec - lib/uglifier/version.rb - "vendor/**/*" - "gemfiles/vendor/**/*" Metrics/ClassLength: Enabled: false Metrics/LineLength: Max: 100 Metrics/MethodLength: Max: 20 Style/DeprecatedHashMethods: Enabled: false Style/HashSyntax: EnforcedStyle: hash_rockets Style/SignalException: Enabled: false Style/StringLiterals: Enabled: false uglifier-2.7.2/metadata.yml0000644000004100000410000000772412567417234015710 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: uglifier version: !ruby/object:Gem::Version version: 2.7.2 platform: ruby authors: - Ville Lautanala autorequire: bindir: bin cert_chain: [] date: 2015-08-26 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: execjs requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 0.3.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 0.3.0 - !ruby/object:Gem::Dependency name: json requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 1.8.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 1.8.0 - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '3.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '3.0' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '10.4' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '10.4' - !ruby/object:Gem::Dependency name: bundler requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.3' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.3' - !ruby/object:Gem::Dependency name: rdoc requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '3.11' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '3.11' - !ruby/object:Gem::Dependency name: source_map requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' description: Uglifier minifies JavaScript files by wrapping UglifyJS to be accessible in Ruby email: - lautis@gmail.com executables: [] extensions: [] extra_rdoc_files: - LICENSE.txt - README.md - CHANGELOG.md - CONTRIBUTING.md files: - ".document" - ".gitignore" - ".gitmodules" - ".rspec" - ".rubocop.yml" - ".travis.yml" - CHANGELOG.md - CONTRIBUTING.md - Gemfile - LICENSE.txt - README.md - Rakefile - gemfiles/alaska - gemfiles/rubyracer - gemfiles/rubyrhino - lib/es5.js - lib/split.js - lib/uglifier.rb - lib/uglifier/version.rb - lib/uglify.js - spec/source_map_spec.rb - spec/spec_helper.rb - spec/uglifier_spec.rb - uglifier.gemspec homepage: http://github.com/lautis/uglifier licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 1.8.7 required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.4.5.1 signing_key: specification_version: 4 summary: Ruby wrapper for UglifyJS JavaScript compressor test_files: - spec/source_map_spec.rb - spec/spec_helper.rb - spec/uglifier_spec.rb uglifier-2.7.2/.gitignore0000644000004100000410000000142612567417234015366 0ustar www-datawww-data# rcov generated coverage # rdoc generated rdoc # yard generated doc .yardoc # bundler .bundle Gemfile.lock gemfiles/*.lock # jeweler generated pkg # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore: # # * Create a file at ~/.gitignore # * Include files you want ignored # * Run: git config --global core.excludesfile ~/.gitignore # # After doing this, these files will be ignored in all your git projects, # saving you from having to 'pollute' every project you touch with them # # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line) # # For MacOS: # #.DS_Store # # For TextMate #*.tmproj #tmtags # # For emacs: #*~ #\#* #.\#* # # For vim: #*.swp uglifier-2.7.2/CONTRIBUTING.md0000644000004100000410000000401112567417234015620 0ustar www-datawww-data# Contributing to Uglifier Any contributions to Uglifier are welcome, whether they are feedback, bug reports, or - even better - pull requests. ## Development To start working on Uglifier, fork the repo to your own account. [Ruby](https://www.ruby-lang.org), [bundler](http://bundler.io) and [Node.js](http://nodejs.org) are required as dependencies. Ensure that your local copy is up-to-date before you start working on a feature or a bug fix. You should write any new code in a topic branch. ### Tests Try to write a test case that reproduces the problem you're trying to fix or describes a feature that you want to build. Tests are located in `spec/` directory. Tests as a pull request are appreciated even without a fix to highlight or reproduce a problem. To run tests, first install all project dependencies: bundle install Then run tests using rake: bundle exec rake ### Updating UglifyJS and source-map [UglifyJS](https://github.com/mishoo/UglifyJS2) and [source-map](https://github.com/mozilla/source-map/) are included in the project as Git submodules. To install submodules, run in your terminal git submodule update --init After that, UglifyJS and source-map are checked out under `vendor/uglifyjs` and `vendor/source-map`. Use Git commands (e.g. git checkout master) to change the included version. You can even write custom code to yourself. After changing the dependencies, compile new version of the bundled JS file using rake js After this, the new JS is used in your development version. ## Reporting issues Uglifier uses the [GitHub issue tracker](https://github.com/lautis/uglifier/issues) to track bugs and features. Before submitting a bug report or feature request, check to make sure it hasn't already been submitted. When submitting a bug report, please include a Gist that includes a stack trace and any details that may be necessary to reproduce the bug, including your gem version, Ruby version, and **ExecJS runtime**. Ideally, a bug report should include a pull request with failing specs. uglifier-2.7.2/uglifier.gemspec0000644000004100000410000000226012567417234016546 0ustar www-datawww-data# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'uglifier/version' Gem::Specification.new do |spec| spec.name = "uglifier" spec.version = Uglifier::VERSION spec.authors = ["Ville Lautanala"] spec.email = ["lautis@gmail.com"] spec.homepage = "http://github.com/lautis/uglifier" spec.summary = "Ruby wrapper for UglifyJS JavaScript compressor" spec.description = "Uglifier minifies JavaScript files by wrapping UglifyJS to be accessible in Ruby" spec.license = "MIT" spec.required_ruby_version = '>= 1.8.7' spec.extra_rdoc_files = [ "LICENSE.txt", "README.md", "CHANGELOG.md", "CONTRIBUTING.md" ] spec.files = `git ls-files`.split($/) spec.test_files = spec.files.grep(%r{^spec/}) spec.require_paths = ["lib"] spec.add_runtime_dependency "execjs", ">= 0.3.0" spec.add_runtime_dependency "json", ">= 1.8.0" spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "rake", "~> 10.4" spec.add_development_dependency "bundler", "~> 1.3" spec.add_development_dependency "rdoc", ">= 3.11" spec.add_development_dependency "source_map", ">= 0" end uglifier-2.7.2/CHANGELOG.md0000644000004100000410000000363712567417234015215 0ustar www-datawww-data## 2.7.2 (26 August 2015) - update UglifyJS to 2.4.24 ## 2.7.1 (27 February 2015) - fix compatibility with experimental Alaska ExecJS runtime ## 2.7.0 (8 January 2015) - copyright comment preservation also includes comments starting with a bang (!) ## 2.6.1 (1 January 2015) - update UglifyJS to 2.4.16 ## 2.6.0 (8 December 2014) - allow metadata to be appended to minified code ## 2.5.3 (18 July 2014) - no changes ## 2.5.2 (18 July 2014) - update UglifyJS to 2.4.15 ## 2.5.1 (13 June 2014) - update UglifyJS to 2.4.14 ## 2.5.0 (15 March 2014) - update UglifyJS to 2.4.13 - process Angular @ngInject annotations - add keep_fargs option - change `ascii_only` default to true ## 2.4.0 (19 December 2013) - update UglifyJS to 2.4.8 - add drop_console compress option ## 2.3.3 (12 December 2013) - update UglifyJS to 2.4.7 ## 2.3.2 (1 December 2013) - update UglifyJS to 2.4.6 - document missing mangler and output options ## 2.3.1 (8 November 2013) - update UglifyJS to 2.4.3 ## 2.3.0 (26 October 2013) - use JSON gem instead of multi_json - update UglifyJS to 2.4.1 - fix issues with some Unicode JS identifiers (#47, #58) ## 2.2.1 (28 August 2013) - fix IE8 compatibility ## 2.2.0 (25 August 2013) - update UglifyJS to 2.4.0 - add `negate_iife` compressor option - escape null characters as \x00, so that null followed by number isn't interpreted as octal (#47) ## 2.1.2 (7 July 2013) - update UglifyJS to 2.3.6 ## 2.1.1 (18 May 2013) - fix JScript compatibility - update UglifyJS to 2.3.4 ## 2.1.0 (8 May 2013) - update to UglifyJS 2.3.0 - add enclose and screw_ie8 options ## 2.0.1 (6 April 2013) - fix compatibility with Sprockets 2.9.0 ## 2.0.0 (6 April 2013) This release is backwards incompatible for JS compressor options. - update UglifyJS to 2.2.5 - change compressor arguments to align with UglifyJS2 - `compile_with_map`: generate source maps for minified code uglifier-2.7.2/README.md0000644000004100000410000001372512567417234014662 0ustar www-datawww-data# Uglifier [![Build Status](https://travis-ci.org/lautis/uglifier.svg?branch=master)](https://travis-ci.org/lautis/uglifier) [![Dependency Status](https://gemnasium.com/lautis/uglifier.svg)](https://gemnasium.com/lautis/uglifier) Ruby wrapper for [UglifyJS](https://github.com/mishoo/UglifyJS2) JavaScript compressor. ## Installation Uglifier is available as a ruby gem. $ gem install uglifier Ensure that your environment has a JavaScript interpreter supported by [ExecJS](https://github.com/sstephenson/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 ```ruby 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: ```ruby 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: ```ruby Uglifier.new(:mangle => false).compile(source) # Or Uglifier.compile(source, :mangle => false) ``` Available options and their defaults are ```ruby { :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 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 :space_colon => false, # Insert space before colons (only with beautifier) :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. }, :mangle => { :eval => false, # Mangle names when eval of when is used in scope :except => ["$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 }, # Mangle variable and function names, set to false to skip mangling :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 :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 :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 :cascade => true, # Cascade sequences :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 :angular => false # Process @ngInject annotations :keep_fargs => false # Preserve unused function arguments }, # Apply transformations to code, set to false to skip :define => {}, # Define values for symbol replacement :enclose => false, # Enclose in output function wrapper, define replacements as key-value pairs :source_filename => nil, # The filename of the input file :source_root => nil, # The URL of the directory which contains :source_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 :screw_ie8 => false, # Don't bother to generate safe code for IE8 :source_map_url => false, # Url for source mapping to be appended in minified source :source_url => false # Url to original source to be appended in minified source } ``` 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](https://github.com/lautis/uglifier/blob/master/CONTRIBUTING.md) for details about working on and contributing to Uglifier. ## Copyright © Ville Lautanala. Released under MIT license, see [LICENSE](https://github.com/lautis/uglifier/blob/master/LICENSE.txt) for details. uglifier-2.7.2/.document0000644000004100000410000000006712567417234015215 0ustar www-datawww-datalib/**/*.rb bin/* - features/**/*.feature LICENSE.txt uglifier-2.7.2/.gitmodules0000644000004100000410000000032012567417234015543 0ustar www-datawww-data[submodule "vendor/uglifyjs"] path = vendor/uglifyjs url = https://github.com/mishoo/UglifyJS2.git [submodule "vendor/source-map"] path = vendor/source-map url = https://github.com/mozilla/source-map.git