Skip to content

Commit

Permalink
pure new option
Browse files Browse the repository at this point in the history
  • Loading branch information
ahorek committed Jan 22, 2024
1 parent 80ed2a3 commit acefa29
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/terser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions spec/terser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit acefa29

Please sign in to comment.