Skip to content

Suppress args for getters on super calls #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/ruby2js/converter/super.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,29 @@ class Converter
end

if es2015
add_args = true

if @class_method
parse @class_parent
put '.'
put method.children[0]
add_args = method.is_method?
elsif method.children[0] == :constructor
put 'super'
else
put 'super.'
put method.children[0]
add_args = method.is_method?
end

put '('
cleaned_args = args.map do |arg| # FIX: #212
arg.type == :optarg ? s(:arg, arg.children[0]) : arg
if add_args
put '('
cleaned_args = args.map do |arg| # FIX: #212
arg.type == :optarg ? s(:arg, arg.children[0]) : arg
end
parse s(:args, *cleaned_args)
put ')'
end
parse s(:args, *cleaned_args)
put ')'
else
parse @class_parent

Expand Down
5 changes: 5 additions & 0 deletions spec/es2015_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ def to_js_fn(string)
must_equal 'class A {}; class B extends A {_render(force=false, options={}) {super._render(force, options)}}'
end

it "should handle super getter" do
to_js('class A; end; class B < A; def self.foo; super; end; end').
must_equal 'class A {}; class B extends A {static get foo() {return A.foo}}'
end

it "should handle class super" do
to_js('class A; end; class B < A; def self.foo(x); super; end; end').
must_equal 'class A {}; class B extends A {static foo(x) {A.foo(x)}}'
Expand Down
5 changes: 5 additions & 0 deletions spec/es2018_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def to_js_fn(string)
end
end

it "should handle super getter merge" do
to_js_fn('class A; end; class B < A; def self.foo; super.merge(o: 1); end; end').
must_equal 'class A {}; class B extends A {static get foo() {return {...A.foo, o: 1}}}'
end

describe 'keyword arguments' do
it 'should handle rest arguments with keyword arguments in methods' do
skip if RUBY_VERSION =~ /^(1\.9|2\.0)/
Expand Down
Loading