Class Uglifier
In: lib/uglifier/version.rb
lib/uglifier.rb
Parent: Object

A wrapper around the UglifyJS interface

Methods

Constants

VERSION = "2.7.2"   Current version of Uglifier.
Error = ExecJS::Error   Error class for compilation errors.
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   JavaScript code to call UglifyJS
SourcePath = File.expand_path("../uglify.js", __FILE__)   UglifyJS source path
ES5FallbackPath = File.expand_path("../es5.js", __FILE__)   ES5 shims source path
SplitFallbackPath = File.expand_path("../split.js", __FILE__)   String.split shim source path
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 </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 :space_colon => false, # Insert space before colons (only with beautifier) :width => 80, # Specify line width when beautifier is used (only with beautifier) :preamble => nil   Default options for compilation

Public Class methods

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.

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.

Initialize new context for Uglifier with given options

@param options [Hash] optional overrides to +Uglifier::DEFAULTS+

Public Instance methods

Minifies JavaScript code

@param source [IO, String] valid JS source code. @return [String] minified code.

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.

compress(source)

Alias for compile

[Validate]