Skip to content

Commit 8ad14cb

Browse files
committed
Split out array contents
1 parent cf507cb commit 8ad14cb

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

lib/syntax_tree.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -974,9 +974,8 @@ def to_json(*opts)
974974
end
975975

976976
# :call-seq:
977-
# on_array: (
978-
# (nil | Args | QSymbols | QWords | Symbols | Words) contents
979-
# ) -> ArrayLiteral
977+
# on_array: ((nil | Args) contents) ->
978+
# ArrayLiteral | QSymbols | QWords | Symbols | Words
980979
def on_array(contents)
981980
if !contents || contents.is_a?(Args)
982981
lbracket = find_token(LBracket)
@@ -988,13 +987,11 @@ def on_array(contents)
988987
)
989988
else
990989
tstring_end = find_token(TStringEnd)
991-
contents =
992-
contents.class.new(
993-
elements: contents.elements,
994-
location: contents.location.to(tstring_end.location)
995-
)
996990

997-
ArrayLiteral.new(contents: contents, location: contents.location)
991+
contents.class.new(
992+
elements: contents.elements,
993+
location: contents.location.to(tstring_end.location)
994+
)
998995
end
999996
end
1000997

test/syntax_tree_test.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ def test_array
144144
assert_node(ArrayLiteral, 'array', '[1]')
145145
end
146146

147-
def test_array_qwords
148-
assert_node(ArrayLiteral, 'array', '%w[1]')
149-
end
150-
151147
def test_aryptn
152148
source = <<~SOURCE
153149
case [1, 2, 3]
@@ -762,11 +758,11 @@ def test_program
762758
end
763759

764760
def test_qsymbols
765-
assert_node(QSymbols, 'qsymbols', '%i[one two three]', &:contents)
761+
assert_node(QSymbols, 'qsymbols', '%i[one two three]')
766762
end
767763

768764
def test_qwords
769-
assert_node(QWords, 'qwords', '%w[one two three]', &:contents)
765+
assert_node(QWords, 'qwords', '%w[one two three]')
770766
end
771767

772768
def test_rational
@@ -881,7 +877,7 @@ def test_symbol_literal
881877
end
882878

883879
def test_symbols
884-
assert_node(Symbols, 'symbols', '%I[one two three]', &:contents)
880+
assert_node(Symbols, 'symbols', '%I[one two three]')
885881
end
886882

887883
def test_top_const_field
@@ -980,12 +976,12 @@ def test_while_mod
980976
def test_word
981977
at = location(chars: 3..7)
982978
assert_node(Word, 'word', '%W[word]', at: at) do |node|
983-
node.contents.elements.first
979+
node.elements.first
984980
end
985981
end
986982

987983
def test_words
988-
assert_node(Words, 'words', '%W[one two three]', &:contents)
984+
assert_node(Words, 'words', '%W[one two three]')
989985
end
990986

991987
def test_xstring_literal

0 commit comments

Comments
 (0)