Skip to content

Commit 7fb8f71

Browse files
committed
Allowing multiple externs to be passed in options
1 parent 70b2ab0 commit 7fb8f71

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

lib/closure/compiler.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ def compile(io)
5151

5252
# Serialize hash options to the command-line format.
5353
def serialize_options(options)
54-
options.map {|k, v| ["--#{k}", v.to_s] }.flatten
54+
options.map do |k, v|
55+
if (v.is_a?(Array))
56+
v.map {|v2| ["--#{k}", v2.to_s]}
57+
else
58+
["--#{k}", v.to_s]
59+
end
60+
end.flatten
5561
end
5662

5763
def command

test/unit/test_closure_compiler.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,13 @@ def test_permissions
6060
assert File.executable?(COMPILER_JAR)
6161
end
6262

63+
def test_serialize_options
64+
assert_equal ["--externs", "library1.js", "--compilation_level", "ADVANCED_OPTIMIZATIONS"], Closure::Compiler.new.send(:serialize_options, 'externs' => 'library1.js', "compilation_level" => "ADVANCED_OPTIMIZATIONS")
65+
end
66+
67+
def test_serialize_options_for_arrays
68+
compiler = Closure::Compiler.new('externs' => ['library1.js', "library2.js"])
69+
assert_equal ["--externs", "library1.js", "--externs", "library2.js"], compiler.send(:serialize_options, 'externs' => ['library1.js', "library2.js"])
70+
end
71+
6372
end

0 commit comments

Comments
 (0)