From 03027798abb4e238aa31e942f05d82dd60a31df2 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Tue, 23 Aug 2022 17:05:46 -0400 Subject: [PATCH] Support Ruby 2.7.0 --- .github/workflows/main.yml | 2 +- lib/syntax_tree/node.rb | 12 ++++++------ syntax_tree.gemspec | 2 +- test/fixtures/args_forward.rb | 2 +- test/fixtures/hshptn.rb | 9 ++++++++- test/fixtures/params.rb | 2 +- test/test_helper.rb | 2 +- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ed3c51fd..d707f33c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: fail-fast: false matrix: ruby: - - '2.7' + - '2.7.0' - '3.0' - '3.1' - head diff --git a/lib/syntax_tree/node.rb b/lib/syntax_tree/node.rb index d7b6d6cf..0b9ea958 100644 --- a/lib/syntax_tree/node.rb +++ b/lib/syntax_tree/node.rb @@ -2132,8 +2132,7 @@ def format(q) in [ Paren[ contents: { - body: [ArrayLiteral[contents: { parts: [_, _, *] }] => array] - } + body: [ArrayLiteral[contents: { parts: [_, _, *] }] => array] } ] ] # Here we have a single argument that is a set of parentheses wrapping @@ -5116,8 +5115,10 @@ def format(q) q.breakable contents.call end - q.breakable - q.text("}") + + # Doing this because Ruby 2.7 before 2.7.3 did not support a newline + # character before the closing brace. + q.text(" }") end end end @@ -5204,8 +5205,7 @@ def call(q, node) false in { statements: { body: [truthy] }, - consequent: Else[statements: { body: [falsy] }] - } + consequent: Else[statements: { body: [falsy] }] } ternaryable?(truthy) && ternaryable?(falsy) else false diff --git a/syntax_tree.gemspec b/syntax_tree.gemspec index 820a61a0..2b461dfd 100644 --- a/syntax_tree.gemspec +++ b/syntax_tree.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| .reject { |f| f.match(%r{^(test|spec|features)/}) } end - spec.required_ruby_version = ">= 2.7.3" + spec.required_ruby_version = ">= 2.7.0" spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } diff --git a/test/fixtures/args_forward.rb b/test/fixtures/args_forward.rb index 5ba618a8..cc538f44 100644 --- a/test/fixtures/args_forward.rb +++ b/test/fixtures/args_forward.rb @@ -1,4 +1,4 @@ -% +% # >= 2.7.3 def foo(...) bar(:baz, ...) end diff --git a/test/fixtures/hshptn.rb b/test/fixtures/hshptn.rb index 505336b8..d7aefdb2 100644 --- a/test/fixtures/hshptn.rb +++ b/test/fixtures/hshptn.rb @@ -30,7 +30,7 @@ case foo in **bar end -% +% # >= 2.7.3 case foo in { foo:, # comment1 @@ -38,6 +38,13 @@ } baz end +- +case foo +in { + foo:, # comment1 + bar: } # comment2 + baz +end % case foo in Foo[bar:] diff --git a/test/fixtures/params.rb b/test/fixtures/params.rb index 67b6ec90..551aa9a5 100644 --- a/test/fixtures/params.rb +++ b/test/fixtures/params.rb @@ -16,7 +16,7 @@ def foo(*) % def foo(*rest) end -% +% # >= 2.7.3 def foo(...) end % diff --git a/test/test_helper.rb b/test/test_helper.rb index 895fbc82..80e514f0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -26,7 +26,7 @@ def initialize @called = nil end - def method_missing(called, ...) + def method_missing(called, *, **) @called = called end end