@@ -795,16 +795,12 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
795
795
if let trailingComma = lastElement. trailingComma {
796
796
ignoredTokens. insert ( trailingComma)
797
797
}
798
- // The syntax library can't distinguish an array initializer (where the elements are types)
799
- // from an array literal (where the elements are the contents of the array). We never want to
800
- // add a trailing comma in the initializer case and there's always exactly 1 element, so we
801
- // never add a trailing comma to 1 element arrays.
802
- if let firstElement = node. first, firstElement != lastElement {
803
- before ( firstElement. firstToken, tokens: . commaDelimitedRegionStart)
804
- let endToken =
805
- Token . commaDelimitedRegionEnd ( hasTrailingComma: lastElement. trailingComma != nil )
806
- after ( lastElement. expression. lastToken, tokens: [ endToken] )
807
- }
798
+ before ( node. first? . firstToken, tokens: . commaDelimitedRegionStart)
799
+ let endToken =
800
+ Token . commaDelimitedRegionEnd (
801
+ hasTrailingComma: lastElement. trailingComma != nil ,
802
+ isSingleElement: node. first == lastElement)
803
+ after ( lastElement. expression. lastToken, tokens: [ endToken] )
808
804
}
809
805
return . visitChildren
810
806
}
@@ -842,16 +838,12 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
842
838
if let trailingComma = lastElement. trailingComma {
843
839
ignoredTokens. insert ( trailingComma)
844
840
}
845
- // The syntax library can't distinguish a dictionary initializer (where the elements are
846
- // types) from a dictionary literal (where the elements are the contents of the dictionary).
847
- // We never want to add a trailing comma in the initializer case and there's always exactly 1
848
- // element, so we never add a trailing comma to 1 element dictionaries.
849
- if let firstElement = node. first, let lastElement = node. last, firstElement != lastElement {
850
- before ( firstElement. firstToken, tokens: . commaDelimitedRegionStart)
851
- let endToken =
852
- Token . commaDelimitedRegionEnd ( hasTrailingComma: lastElement. trailingComma != nil )
853
- after ( lastElement. lastToken, tokens: endToken)
854
- }
841
+ before ( node. first? . firstToken, tokens: . commaDelimitedRegionStart)
842
+ let endToken =
843
+ Token . commaDelimitedRegionEnd (
844
+ hasTrailingComma: lastElement. trailingComma != nil ,
845
+ isSingleElement: node. first == node. last)
846
+ after ( lastElement. lastToken, tokens: endToken)
855
847
}
856
848
return . visitChildren
857
849
}
0 commit comments