diff --git a/Changelog.md b/Changelog.md index 7cdfab85..57254765 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,9 @@ +# v0.6.2 2022-02-05 + +[#297](https://github.com/mbj/unparser/pull/297) + +* Fix emit of of `match_pattern` vs `match_pattern_p` + # v0.6.3 2022-01-16 [#290](https://github.com/mbj/unparser/pull/290) diff --git a/config/mutant.yml b/config/mutant.yml index dc5750c5..b5e952ea 100644 --- a/config/mutant.yml +++ b/config/mutant.yml @@ -10,9 +10,9 @@ matcher: ignore: # API changed between ruby versions and each of them # have a different minimal form - - 'Unparser::Concord#define_readers' - 'Unparser::Builder#initialize' - 'Unparser::CLI*' + - 'Unparser::Concord#define_readers' - 'Unparser::Emitter#emit_comments' - 'Unparser::Emitter#emit_comments_before' - 'Unparser::Emitter#emit_eol_comments' @@ -28,6 +28,8 @@ matcher: - 'Unparser::Emitter::HashPattern#write_symbol_body' - 'Unparser::Emitter::LocalVariableRoot*' - 'Unparser::Emitter::LocalVariableRoot.included' + - 'Unparser::Emitter::MatchPattern#dispatch' # 2.7+ specific + - 'Unparser::Emitter::MatchPatternP#dispatch' # 3.0+ specific - 'Unparser::Emitter::Module#local_variable_scope' - 'Unparser::Emitter::Root#local_variable_scope' - 'Unparser::Emitter::Send#writer' diff --git a/lib/unparser.rb b/lib/unparser.rb index ba22cef6..b1cf847a 100644 --- a/lib/unparser.rb +++ b/lib/unparser.rb @@ -219,6 +219,7 @@ def self.buffer(source, identification = '(string)') require 'unparser/emitter/kwargs' require 'unparser/emitter/pair' require 'unparser/emitter/match_pattern' +require 'unparser/emitter/match_pattern_p' require 'unparser/writer' require 'unparser/writer/binary' require 'unparser/writer/dynamic_string' diff --git a/lib/unparser/emitter/match_pattern.rb b/lib/unparser/emitter/match_pattern.rb index 27c04ed2..c9e45dde 100644 --- a/lib/unparser/emitter/match_pattern.rb +++ b/lib/unparser/emitter/match_pattern.rb @@ -6,17 +6,25 @@ class Emitter class MatchPattern < self handle :match_pattern - handle :match_pattern_p children :target, :pattern + # Modern ast format emits `match_pattern` + # node on single line pre 3.0, but 3.0+ uses `match_pattern_p` + SYMBOL = + if RUBY_VERSION < '3.0' + ' in ' + else + ' => ' + end + private def dispatch visit(target) - write(' in ') + write(SYMBOL) visit(pattern) end - end # InPattern + end # MatchPattern end # Emitter end # Unparser diff --git a/lib/unparser/emitter/match_pattern_p.rb b/lib/unparser/emitter/match_pattern_p.rb new file mode 100644 index 00000000..90b62512 --- /dev/null +++ b/lib/unparser/emitter/match_pattern_p.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Unparser + class Emitter + class MatchPatternP < self + + handle :match_pattern_p + + children :target, :pattern + + private + + def dispatch + visit(target) + write(' in ') + visit(pattern) + end + end # MatchPatternP + end # Emitter +end # Unparser diff --git a/spec/unit/unparser_spec.rb b/spec/unit/unparser_spec.rb index d6eaaf1d..9ea50847 100644 --- a/spec/unit/unparser_spec.rb +++ b/spec/unit/unparser_spec.rb @@ -359,6 +359,14 @@ def noop let(:version_excludes) do excludes = [] + if RUBY_VERSION < '3.0.' + excludes.concat( + %w[ + test/corpus/literal/since/30.rb + ] + ) + end + if RUBY_VERSION < '2.7.' excludes.concat( %w[ diff --git a/test/corpus/literal/since/30.rb b/test/corpus/literal/since/30.rb new file mode 100644 index 00000000..7357de42 --- /dev/null +++ b/test/corpus/literal/since/30.rb @@ -0,0 +1,2 @@ +1 => [a] +1 => [*]