diff --git a/lib/rbs/writer.rb b/lib/rbs/writer.rb index 4d2a1d0d2..89f4f9d6d 100644 --- a/lib/rbs/writer.rb +++ b/lib/rbs/writer.rb @@ -159,10 +159,12 @@ def write_decl(decl) puts "end" when AST::Declarations::Constant write_comment decl.comment + write_annotation decl.annotations puts "#{decl.name}: #{decl.type}" when AST::Declarations::Global write_comment decl.comment + write_annotation decl.annotations puts "#{decl.name}: #{decl.type}" when AST::Declarations::TypeAlias @@ -174,12 +176,14 @@ def write_decl(decl) when AST::Declarations::ClassAlias write_comment decl.comment + write_annotation decl.annotations write_loc_source(decl) { puts "class #{decl.new_name} = #{decl.old_name}" } when AST::Declarations::ModuleAlias write_comment decl.comment + write_annotation decl.annotations write_loc_source(decl) { puts "module #{decl.new_name} = #{decl.old_name}" } diff --git a/test/rbs/writer_test.rb b/test/rbs/writer_test.rb index 44b4c3570..225f1905c 100644 --- a/test/rbs/writer_test.rb +++ b/test/rbs/writer_test.rb @@ -41,6 +41,37 @@ module C = D SIG end + def test_annotated_decl + assert_writer <<-SIG +%a{deprecated} +FOO: Integer + +%a{deprecated} +$foo: Integer + +# Alias of B. +%a{deprecated} +class A = B + +# Alias of D. +%a{deprecated} +module C = D + +module Foo + %a{deprecated} + FOO: Integer + + # Alias of B. + %a{deprecated} + class A = B + + # Alias of D. + %a{deprecated} + module C = D +end + SIG + end + def test_class_decl assert_writer <<-SIG class Foo::Bar[X] < Array[String]