Skip to content

Commit ed791c6

Browse files
refactoring; migrating away from a dedicated macro for every html element
1 parent 8f9a3f1 commit ed791c6

File tree

8 files changed

+575
-1293
lines changed

8 files changed

+575
-1293
lines changed

Package.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,19 @@ let package = Package(
2020
.package(url: "https://github.com/apple/swift-nio", from: "2.75.0")
2121
],
2222
targets: [
23+
.macro(
24+
name: "HTMLKitUtilityMacros",
25+
dependencies: [
26+
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
27+
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
28+
.product(name: "SwiftSyntax", package: "swift-syntax"),
29+
.product(name: "SwiftSyntaxMacros", package: "swift-syntax")
30+
]
31+
),
2332
.target(
2433
name: "HTMLKitUtilities",
2534
dependencies: [
35+
"HTMLKitUtilityMacros",
2636
.product(name: "NIOCore", package: "swift-nio")
2737
]
2838
),

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Using String Interpolation.
119119
>
120120
> Its up to you whether or not to suppress this warning or escape the HTML at runtime using a method described above.
121121
>
122-
> Swift HTMLKit tries to [replace](https://github.com/RandomHashTags/swift-htmlkit/blob/94793984763308ef5275dd9f71ea0b5e83fea417/Sources/HTMLKitMacros/HTMLElement.swift#L423) known interpolation at compile time with a compile time equivalent for the best performance. It is currently limited due to macro expansions being sandboxed and lexical contexts/AST not being available for macro arguments. This means referencing content known at compile time in a html macro won't get replaced by its literal contents. [Read more about this limitation](https://forums.swift.org/t/swift-lexical-lookup-for-referenced-stuff-located-outside-scope-current-file/75776/6).
122+
> Swift HTMLKit tries to [promote](https://github.com/RandomHashTags/swift-htmlkit/blob/94793984763308ef5275dd9f71ea0b5e83fea417/Sources/HTMLKitMacros/HTMLElement.swift#L423) known interpolation at compile time with an equivalent `StaticString` for the best performance. It is currently limited due to macro expansions being sandboxed and lexical contexts/AST not being available for macro arguments. This means referencing content known at compile time in a html macro won't get replaced by its literal contents. [Read more about this limitation](https://forums.swift.org/t/swift-lexical-lookup-for-referenced-stuff-located-outside-scope-current-file/75776/6).
123123
124124
#### Example
125125
```swift

0 commit comments

Comments
 (0)