Skip to content

Commit d24f6cd

Browse files
HTMLElement macro expansion terminology updates
1 parent c1e1c7d commit d24f6cd

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let package = Package(
1313
.library(
1414
name: "HTMLKit",
1515
targets: ["HTMLKit"]
16-
),
16+
)
1717
],
1818
dependencies: [
1919
.package(url: "https://github.com/swiftlang/swift-syntax", from: "600.0.0"),

Sources/HTMLKitMacros/HTMLElement.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import struct NIOCore.ByteBuffer
1818

1919
enum HTMLElement : ExpressionMacro {
2020
static func expansion(of node: some FreestandingMacroExpansionSyntax, in context: some MacroExpansionContext) throws -> ExprSyntax {
21-
let string:String = parse_macro(context: context, expression: node.macroExpansion!)
21+
let string:String = expand_macro(context: context, macro: node.macroExpansion!)
2222
var set:Set<HTMLElementType?> = [.htmlUTF8Bytes, .htmlUTF16Bytes, .htmlUTF8CString, .htmlByteBuffer]
2323

2424
#if canImport(Foundation)
@@ -58,10 +58,12 @@ enum HTMLElement : ExpressionMacro {
5858
}
5959

6060
private extension HTMLElement {
61-
// MARK: Parse Macro
62-
static func parse_macro(context: some MacroExpansionContext, expression: MacroExpansionExprSyntax) -> String {
63-
guard let elementType:HTMLElementType = HTMLElementType(rawValue: expression.macroName.text) else { return "\(expression)" }
64-
let childs:SyntaxChildren = expression.arguments.children(viewMode: .all)
61+
// MARK: Expand Macro
62+
static func expand_macro(context: some MacroExpansionContext, macro: MacroExpansionExprSyntax) -> String {
63+
guard let elementType:HTMLElementType = HTMLElementType(rawValue: macro.macroName.text) else {
64+
return "\(macro)"
65+
}
66+
let childs:SyntaxChildren = macro.arguments.children(viewMode: .all)
6567
if elementType == .escapeHTML {
6668
return childs.compactMap({
6769
guard let child:LabeledExprSyntax = $0.labeled else { return nil }
@@ -167,7 +169,7 @@ private extension HTMLElement {
167169
// MARK: Parse innerHTML
168170
static func parse_inner_html(context: some MacroExpansionContext, elementType: HTMLElementType, child: LabeledExprSyntax) -> String? {
169171
if let macro:MacroExpansionExprSyntax = child.expression.macroExpansion {
170-
var string:String = parse_macro(context: context, expression: macro)
172+
var string:String = expand_macro(context: context, macro: macro)
171173
if elementType == .escapeHTML {
172174
string.escapeHTML(escapeAttributes: false)
173175
}

Sources/HTMLKitMacros/HTMLKitMacros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SwiftCompilerPlugin
99
import SwiftSyntaxMacros
1010
import SwiftDiagnostics
1111

12-
// MARK: ErrorDiagnostic
12+
// MARK: DiagnosticMsg
1313
struct DiagnosticMsg : DiagnosticMessage {
1414
let message:String
1515
let diagnosticID:MessageID

0 commit comments

Comments
 (0)