ahorek / terser-ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to set "keep_classnames: /Element$/", which available in terser.js?

le0pard opened this issue · comments

Hello. Thanks for your work.

I am trying to set "keep_classnames: /Element$/", which looks like available for terser, but no luck for terser-ruby:

irb(main):001:0> Terser.new(keep_classnames: /Element$/)
/Users/leo/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/terser-1.1.10/lib/terser.rb:148:in `initialize': Invalid option: keep_classnames (ArgumentError)
irb(main):002:0> Terser.new(mangle: {keep_classnames: /Element$/})
=> #<Terser:0x000000011432c818 @options={:mangle=>{:keep_classnames=>/Element$/}}>
irb(main):003:0> Terser.new(mangle: {keep_classnames: /Element$/}).compile('import{controller}from"@github/catalyst";controller(class ExampleComponentElement exten
ds HTMLElement{connectedCallback(){this.innerHTML="Hello World!"}});')
=> "import{controller}from\"@github/catalyst\";controller(class extends HTMLElement{connectedCallback(){this.innerHTML=\"Hello World!\"}});"

# classname "ExampleComponentElement" was removed

Is the are any way to set this option for terser-ruby ?

the option has to be exposed here https://github.com/ahorek/terser-ruby/blob/master/lib/terser.rb#L29 the list is a bit outdated.

I'll test it probably tomorrow to see if it works, thanks for the report!