Files
swift-mirror/test/Utils/update-verify-tests/Inputs/unstringify-macro.swift
Henrik G. Olsson 3891080750 [utils] add support for expected-expansion to update-verify-tests
`expected-expansion` can be a bit unergonomic to use, because it requires
pointing out not only the line, but also the column (which is not always
obvious), and the nested diagnostics have to refer to absolute lines
that aren't present in the source file. This makes both creating and
updating these test cases easier through automation.
2025-11-07 13:34:39 -08:00

20 lines
634 B
Swift

import SwiftSyntax
import SwiftSyntaxBuilder
import SwiftSyntaxMacros
public struct UnstringifyPeerMacro: PeerMacro {
public static func expansion(
of node: AttributeSyntax,
providingPeersOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
do {
let argumentList = node.arguments!.as(LabeledExprListSyntax.self)!
let arguments = [LabeledExprSyntax](argumentList)
let arg = arguments.first!.expression.as(StringLiteralExprSyntax.self)!
let content = arg.representedLiteralValue!
return [DeclSyntax("\(raw: content)")]
}
}
}