diff --git a/lib/terser.rb b/lib/terser.rb index 0498742..6f43ecc 100644 --- a/lib/terser.rb +++ b/lib/terser.rb @@ -79,6 +79,7 @@ class Error < StandardError; end :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 + :pure_new => false, # 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 :keep_fargs => false, # Preserve unused function arguments :keep_classnames => false, # Prevents discarding or mangling of class names. Pass a regular expression to only keep class names matching that regex. diff --git a/spec/terser_spec.rb b/spec/terser_spec.rb index 1274c67..d491180 100644 --- a/spec/terser_spec.rb +++ b/spec/terser_spec.rb @@ -313,6 +313,27 @@ end end + describe 'pure_new' do + let(:code) do + <<-JS + new function() {}; + (new function() { + this.pass = () => console.log("PASS"); + }).pass() + JS + end + + it "when compress option is set" do + minified = Terser.compile(code, :compress => { :pure_new => true }) + expect(minified).to match("(new function(){this.pass=()=>console.log(\"PASS\")}).pass();") + end + + it "when compress option is false" do + minified = Terser.compile(code, :compress => { :pure_new => false }) + expect(minified).to match("new function(){},(new function(){this.pass=()=>console.log(\"PASS\")}).pass();") + end + end + it "can be configured to output only ASCII" do code = "function emoji() { return '\\ud83c\\ude01'; }" minified = Terser.compile(code, :output => { :ascii_only => true })