Skip to content

Commit

Permalink
to use the more idomatic ExecJS::Adapter#call method when running ugl…
Browse files Browse the repository at this point in the history
…ifyjs
  • Loading branch information
diclophis committed Feb 24, 2015
1 parent 7ff1a33 commit 0a8a1cc
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/uglifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Uglifier
Error = ExecJS::Error
# JavaScript code to call UglifyJS
JS = <<-JS
(function() {
(function(options) {
function comments(option) {
if (Object.prototype.toString.call(option) === '[object Array]') {
return new RegExp(option[0], option[1]);
Expand All @@ -27,7 +27,6 @@ class Uglifier
}
}
var options = %s;
var source = options.source;
var ast = UglifyJS.parse(source, options.parse_options);
ast.figure_out_scope();
Expand Down Expand Up @@ -72,7 +71,7 @@ class Uglifier
} else {
return stream.toString();
}
})()
})
JS

# UglifyJS source path
Expand Down Expand Up @@ -199,7 +198,7 @@ def uglifyjs_source

# Run UglifyJS for given source code
def run_uglifyjs(source, generate_map)
@context.exec(Uglifier::JS % json_encode(
options = {
:source => read_source(source),
:output => output_options,
:compress => compressor_options,
Expand All @@ -208,7 +207,9 @@ def run_uglifyjs(source, generate_map)
:source_map_options => source_map_options,
:generate_map => generate_map,
:enclose => enclose_options
))
}

@context.call(Uglifier::JS, options)
end

def read_source(source)
Expand Down Expand Up @@ -298,10 +299,6 @@ def enclose_options
end
end

def json_encode(obj)
JSON.dump(obj)
end

def encode_regexp(regexp)
modifiers = if regexp.casefold?
"i"
Expand Down

0 comments on commit 0a8a1cc

Please sign in to comment.