Skip to content

Commit 0559239

Browse files
committed
Fix filters list which filters examine
1 parent caa10f9 commit 0559239

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

lib/ruby2js.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ def self.convert(source, options={})
263263
filters = Filter.require_filters(options[:filters] || Filter::DEFAULTS)
264264

265265
unless filters.empty?
266+
filter_options = options.merge({ filters: filters })
266267
filters.dup.each do |filter|
267268
filters = filter.reorder(filters) if filter.respond_to? :reorder
268269
end
@@ -273,7 +274,7 @@ def self.convert(source, options={})
273274
end
274275
filter = filter.new(comments)
275276

276-
filter.options = options
277+
filter.options = filter_options
277278
filter.namespace = namespace
278279
ast = filter.process(ast)
279280

spec/config/test_ruby2js.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
preset
22

33
filter :camelCase
4+
filter :lit
45

56
eslevel 2022
67

spec/configuration_dsl_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@ def to_js( string)
1414
to_js( 'class C; def self.f_n(x_y); FooBar.(x_y); end; def inst; self.class.f_n(); end; end' ).
1515
must_equal '"use strict"; import FooBar from "@org/package/foobar.js"; class C {static fN(xY) {return FooBar(xY)}; get inst() {return this.constructor.fN()}}'
1616
end
17+
18+
it "should support Lit" do
19+
to_js( 'class FooElement < LitElement; customElement "foo-bar"; end' ).
20+
must_equal '"use strict"; import { LitElement, css, html } from "lit"; class FooElement extends LitElement {}; customElements.define("foo-bar", FooElement)'
21+
end
1722
end
1823
end

spec/lit_spec.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ def to_js22(string)
1515
end
1616

1717
def to_js_esm(string)
18-
_(Ruby2JS.convert(string, eslevel: 2021,
19-
filters: [Ruby2JS::Filter::Lit, Ruby2JS::Filter::ESM]).to_s)
18+
_(Ruby2JS.convert(string, eslevel: 2021, filters: [:lit, :esm]).to_s)
2019
end
2120

2221
describe "properties <= 2021" do

0 commit comments

Comments
 (0)