krzysztofzablocki / Sourcery

Meta-programming for Swift, stop writing boilerplate code.
http://merowing.info
MIT License
7.58k stars 605 forks source link

Enable Quotes when parsing arguments in property wrapper parameters #1316

Closed art-divin closed 3 months ago

art-divin commented 3 months ago

Resolves #1043

Context

The logic at fault is, when Attribute is parsed from AttributeSyntax, for some reason " is replaced with an empty string - unsure why this was applied during initial implementation, when swift-syntax was integrated. As far as I can see, the behaviour changes a little, but it changes in a correct manner, that is, the reported issue is fixed.

I suspect there was an assumption made initially that quotes did not look good, especially when writing unit tests; however, as practice shows, they are needed.

extension Attribute {
    convenience init(_ attribute: AttributeSyntax) {
             ...
              let components = part.split(separator: ":", maxSplits: 1)
              switch components.count {
              case 2:
                  arguments[components[0].trimmed] = components[1].replacingOccurrences(of: "\"", with: "").trimmed as NSString
              case 1:
                  arguments["\(idx)"] = components[0].replacingOccurrences(of: "\"", with: "").trimmed as NSString
              ...
    }
   ...
}