lib/uglifier.rb in uglifier-3.1.13 vs lib/uglifier.rb in uglifier-3.2.0

- old
+ new

@@ -10,10 +10,12 @@ # Error class for compilation errors. Error = ExecJS::Error # UglifyJS source path SourcePath = File.expand_path("../uglify.js", __FILE__) + # UglifyJS with Harmony source path + HarmonySourcePath = File.expand_path("../uglify-harmony.js", __FILE__) # Source Map path SourceMapPath = File.expand_path("../source-map.js", __FILE__) # ES5 shims source path ES5FallbackPath = File.expand_path("../es5.js", __FILE__) # String.split shim source path @@ -84,11 +86,12 @@ }, # 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 :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. :screw_ie8 => false, # Don't bother to generate safe code for IE8 - :source_map => false # Generate source map + :source_map => false, # Generate source map + :harmony => false # Enable ES6/Harmony mode (experimental). Disabling mangling and compressing is recommended with Harmony mode. } LEGACY_OPTIONS = [:comments, :squeeze, :copyright, :mangle] MANGLE_PROPERTIES_DEFAULTS = { @@ -133,11 +136,13 @@ def initialize(options = {}) (options.keys - DEFAULTS.keys - LEGACY_OPTIONS)[0..1].each do |missing| raise ArgumentError, "Invalid option: #{missing}" end @options = options - @context = ExecJS.compile(uglifyjs_source) + + source = @options[:harmony] ? source_with(HarmonySourcePath) : source_with(SourcePath) + @context = ExecJS.compile(source) end # Minifies JavaScript code # # @param source [IO, String] valid JS source code. @@ -162,11 +167,11 @@ run_uglifyjs(source, true) end private - def uglifyjs_source - [ES5FallbackPath, SplitFallbackPath, SourceMapPath, SourcePath, + def source_with(path) + [ES5FallbackPath, SplitFallbackPath, SourceMapPath, path, UglifyJSWrapperPath].map do |file| File.open(file, "r:UTF-8", &:read) end.join("\n") end