@@ -1214,7 +1214,7 @@ def format(q)
12141214
12151215 q . group do
12161216 case lbracket
1217- when QSymbolsBeg , QWordsBeg
1217+ when QSymbolsBeg , QWordsBeg , WordsBeg
12181218 q . text ( lbracket . value )
12191219 else
12201220 q . format ( lbracket )
@@ -1228,6 +1228,10 @@ def format(q)
12281228 q . seplist ( contents . parts , BREAKABLE_SPACE_SEPARATOR ) do |part |
12291229 q . text ( part . value )
12301230 end
1231+ when WordsBeg
1232+ q . seplist ( contents . parts , BREAKABLE_SPACE_SEPARATOR ) do |part |
1233+ q . format ( part )
1234+ end
12311235 else
12321236 q . format ( contents )
12331237 q . if_break { q . text ( "," ) } if q . trailing_comma?
@@ -1238,7 +1242,7 @@ def format(q)
12381242 q . breakable_empty
12391243
12401244 case lbracket
1241- when QSymbolsBeg , QWordsBeg
1245+ when QSymbolsBeg , QWordsBeg , WordsBeg
12421246 q . text ( lbracket . value [ -1 ] == "{" ? "}" : "]" )
12431247 else
12441248 q . text ( "]" )
@@ -1416,7 +1420,7 @@ def ===(other)
14161420 module AssignFormatting
14171421 def self . skip_indent? ( value )
14181422 case value
1419- when ArrayLiteral , HashLiteral , Heredoc , Lambda , Symbols , Words
1423+ when ArrayLiteral , HashLiteral , Heredoc , Lambda , Symbols
14201424 true
14211425 when CallNode
14221426 skip_indent? ( value . receiver )
@@ -11825,7 +11829,8 @@ def modifier?
1182511829 #
1182611830 # %W[a#{b}c xyz]
1182711831 #
11828- # In the example above, there would be two Word nodes within a parent Words
11832+ # In the example above, there would be two Word nodes within a parent
11833+ # ArrayLiteral
1182911834 # node.
1183011835 class Word < Node
1183111836 # [Array[ StringEmbExpr | StringDVar | TStringContent ]] the parts of the
@@ -11879,82 +11884,6 @@ def ===(other)
1187911884 end
1188011885 end
1188111886
11882- # Words represents a string literal array with interpolation.
11883- #
11884- # %W[one two three]
11885- #
11886- class Words < Node
11887- # [WordsBeg] the token that opens this array literal
11888- attr_reader :beginning
11889-
11890- # [Array[ Word ]] the elements of this array
11891- attr_reader :elements
11892-
11893- # [Array[ Comment | EmbDoc ]] the comments attached to this node
11894- attr_reader :comments
11895-
11896- def initialize ( beginning :, elements :, location :)
11897- @beginning = beginning
11898- @elements = elements
11899- @location = location
11900- @comments = [ ]
11901- end
11902-
11903- def accept ( visitor )
11904- visitor . visit_words ( self )
11905- end
11906-
11907- def child_nodes
11908- [ ]
11909- end
11910-
11911- def copy ( beginning : nil , elements : nil , location : nil )
11912- Words . new (
11913- beginning : beginning || self . beginning ,
11914- elements : elements || self . elements ,
11915- location : location || self . location
11916- )
11917- end
11918-
11919- alias deconstruct child_nodes
11920-
11921- def deconstruct_keys ( _keys )
11922- {
11923- beginning : beginning ,
11924- elements : elements ,
11925- location : location ,
11926- comments : comments
11927- }
11928- end
11929-
11930- def format ( q )
11931- opening , closing = "%W[" , "]"
11932-
11933- if elements . any? { |element | element . match? ( /[\[ \] ]/ ) }
11934- opening = beginning . value
11935- closing = Quotes . matching ( opening [ 2 ] )
11936- end
11937-
11938- q . text ( opening )
11939- q . group do
11940- q . indent do
11941- q . breakable_empty
11942- q . seplist (
11943- elements ,
11944- ArrayLiteral ::BREAKABLE_SPACE_SEPARATOR
11945- ) { |element | q . format ( element ) }
11946- end
11947- q . breakable_empty
11948- end
11949- q . text ( closing )
11950- end
11951-
11952- def ===( other )
11953- other . is_a? ( Words ) && beginning === other . beginning &&
11954- ArrayMatch . call ( elements , other . elements )
11955- end
11956- end
11957-
1195811887 # WordsBeg represents the beginning of a string literal array with
1195911888 # interpolation.
1196011889 #
0 commit comments