Skip to content

ArrayExprSyntax initializer that takes an array of ExprSyntax #1674

@grynspan

Description

@grynspan

Description

Constructing an ArrayExprSyntax from a Swift array of arbitrary ExprSyntax values is a bit of a pain. Right now, we do silly dances like:

let exprs: [ExprSyntax] = ...
let exprString = exprs.lazy
  .map(\.trimmedDescription)
  .joined(separator: ", ")
return ExprSyntax("[\(raw: exprString)]").as(ArrayExprSyntax.self)

Having a convenience initializer that inserts commas and necessary trailing trivia would make this much nicer.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions