Skip to content

Commit 8268373

Browse files
fixed bonker errors relating to Swift 6 changes
1 parent 0984876 commit 8268373

File tree

5 files changed

+10
-31
lines changed

5 files changed

+10
-31
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ let package = Package(
2525
.product(name: "SwiftSyntax", package: "swift-syntax"),
2626
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
2727
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
28+
.product(name: "SwiftDiagnostics", package: "swift-syntax")
2829
]
2930
),
3031
.target(

Sources/HTMLKit/HTMLKit.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// Created by Evan Anderson on 9/14/24.
66
//
77

8-
import HTMLKitMacros
9-
108
// MARK: Elements
119
@freestanding(expression)
1210
public macro html(xmlns: String? = nil, _ innerHTML: [String]) -> String = #externalMacro(module: "HTMLKitMacros", type: "HTMLElement")

Sources/HTMLKitMacros/HTMLElement.swift

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,27 @@
55
// Created by Evan Anderson on 9/14/24.
66
//
77

8-
import SwiftCompilerPlugin
98
import SwiftSyntax
109
import SwiftSyntaxMacros
11-
import SwiftSyntaxBuilder
12-
import SwiftDiagnostics
1310

1411
struct HTMLElement : ExpressionMacro {
1512
static func expansion(of node: some FreestandingMacroExpansionSyntax, in context: some MacroExpansionContext) throws -> ExprSyntax {
16-
return "\(raw: parse_element(node: node, context: context))"
13+
return "\"\(raw: parse_element(node: node, context: context))\""
1714
}
1815
}
1916

2017
extension HTMLElement {
2118
static func parse_element(node: some FreestandingMacroExpansionSyntax, context: some MacroExpansionContext) -> String {
22-
let macroName:String = node.macroName.text
23-
let type:HTMLElementType = HTMLElementType(rawValue: macroName) ?? HTMLElementType.a
19+
let type:HTMLElementType = HTMLElementType(rawValue: node.macroName.text) ?? HTMLElementType.a
2420
let data:ElementData = parse_arguments(elementType: type, arguments: node.arguments)
2521
var string:String = (type == .html ? "<!DOCTYPE html>" : "") + "<" + type.rawValue + data.attributes + ">" + data.innerHTML
2622
if !type.isVoid {
2723
string += "</" + type.rawValue + ">"
2824
}
29-
return "\"" + string + "\""
25+
return string
3026
}
3127
static func parse_arguments(elementType: HTMLElementType, arguments: LabeledExprListSyntax) -> ElementData {
32-
var attributes:[String] = []
33-
var innerHTML:[String] = []
28+
var attributes:[String] = [], innerHTML:[String] = []
3429
for element in arguments.children(viewMode: .all) {
3530
if let child:LabeledExprSyntax = element.as(LabeledExprSyntax.self) {
3631
if let key:String = child.label?.text {
@@ -72,8 +67,7 @@ extension HTMLElement {
7267
}
7368

7469
struct ElementData {
75-
let attributes:String
76-
let innerHTML:String
70+
let attributes:String, innerHTML:String
7771

7872
init(attributes: [String], innerHTML: [String]) {
7973
self.attributes = attributes.isEmpty ? "" : " " + attributes.joined(separator: " ")
@@ -212,7 +206,7 @@ private extension HTMLElement {
212206
}
213207

214208
// MARK: HTMLElementType
215-
public enum HTMLElementType : String, CaseIterable {
209+
enum HTMLElementType : String {
216210
case html
217211

218212
case a
@@ -346,7 +340,7 @@ public enum HTMLElementType : String, CaseIterable {
346340

347341
case wbr
348342

349-
public var isVoid : Bool {
343+
var isVoid : Bool {
350344
switch self {
351345
case .area, .base, .br, .col, .embed, .hr, .img, .input, .link, .meta, .source, .track, .wbr:
352346
return true

Sources/HTMLKitMacros/HTMLKitMacros.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@
77

88
import SwiftCompilerPlugin
99
import SwiftSyntaxMacros
10-
import SwiftDiagnostics
11-
12-
// MARK: ErrorDiagnostic
13-
struct ErrorDiagnostic : DiagnosticMessage {
14-
let message:String
15-
let diagnosticID:MessageID
16-
let severity:DiagnosticSeverity = DiagnosticSeverity.error
17-
18-
init(id: String, message: String) {
19-
self.message = message
20-
self.diagnosticID = MessageID(domain: "HTMLKitMacros", id: id)
21-
}
22-
}
2310

2411
@main
2512
struct HTMLKitMacros : CompilerPlugin {

Tests/HTMLKitTests/HTMLKitTests.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,12 @@ extension HTMLKitTests {
6868
#a([#div([#abbr()]), #address()]),
6969
#div(),
7070
#button(disabled: true),
71-
#video(autoplay: true, controls: false, height: nil, preload: .auto, src: "ezclap", width: 5),
72-
#video(autoplay: true, controls: false, height: nil, preload: .auto, src: "ezclap", width: "1cm"),
71+
#video(autoplay: true, controls: false, height: nil, preload: .auto, src: "ezclap", width: .centimeters(1)),
7372
]
7473
)
7574
])
7675
])
77-
XCTAssertEqual(test, "<!DOCTYPE html><html><body><div class=\"bing bong\" title=\"just seeing what blow's\" draggable=\"false\" inputmode=\"email\" hidden=\"hidden\">poggies<div></div><a><div><abbr></abbr></div><address></address></a><div></div><button disabled></button><video autoplay preload=\"auto\" src=\"ezclap\" width=\"5\"></video><video autoplay preload=\"auto\" src=\"ezclap\" width=\"1cm\"></video></div></body></html>")
76+
XCTAssertEqual(test, "<!DOCTYPE html><html><body><div class=\"bing bong\" title=\"just seeing what blow's\" draggable=\"false\" inputmode=\"email\" hidden=\"hidden\">poggies<div></div><a><div><abbr></abbr></div><address></address></a><div></div><button disabled></button><video autoplay preload=\"auto\" src=\"ezclap\" width=\"1.0cm\"></video></div></body></html>")
7877
}
7978
}
8079

0 commit comments

Comments
 (0)