Skip to content

Commit ff8459f

Browse files
HTMLExpansionResultType case renames
- `chunked` -> `chunks` - `chunkedInline` -> `chunksInline` - `streamed` -> `stream` - `streamedAsync` -> `streamAsync` - minor documentation updates
1 parent f6235fb commit ff8459f

File tree

5 files changed

+64
-48
lines changed

5 files changed

+64
-48
lines changed

Sources/HTMLKitParse/ExpandHTMLMacro.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ extension HTMLKitUtilities {
9393
} else {
9494
// TODO: show compiler diagnostic
9595
}*/
96-
case .chunked(let optimized, let chunkSize):
96+
case .chunks(let optimized, let chunkSize):
9797
return "[" + chunks(encoding: encoding, encodedResult: encodedResult, async: false, optimized: optimized, chunkSize: chunkSize).joined(separator: ", ") + "]"
9898
#if compiler(>=6.2)
99-
case .chunkedInline(let optimized, let chunkSize):
99+
case .chunksInline(let optimized, let chunkSize):
100100
let typeAnnotation:String = "String" // TODO: fix
101101
let chunks = chunks(encoding: encoding, encodedResult: encodedResult, async: false, optimized: optimized, chunkSize: chunkSize).joined(separator: ", ")
102102
return "InlineArray<\(chunks.count), \(typeAnnotation)>([\(chunks)])"
103103
#endif
104-
case .streamed(let optimized, let chunkSize):
104+
case .stream(let optimized, let chunkSize):
105105
return streamed(
106106
encoding: encoding,
107107
encodedResult: encodedResult,
@@ -111,7 +111,7 @@ extension HTMLKitUtilities {
111111
yieldVariableName: nil,
112112
afterYield: nil
113113
)
114-
case .streamedAsync(let optimized, let chunkSize, let yieldVariableName, let afterYield):
114+
case .streamAsync(let optimized, let chunkSize, let yieldVariableName, let afterYield):
115115
return streamed(
116116
encoding: encoding,
117117
encodedResult: encodedResult,

Sources/HTMLKitParse/ParseData.swift

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,16 @@ extension HTMLKitUtilities {
9090
switch expr.memberAccess!.declName.baseName.text {
9191
case "literal": return .literal
9292
//case "literalOptimized": return .literalOptimized
93-
case "chunked": return .chunked()
94-
#if compiler(>=6.2)
95-
case "chunkedInline": return .chunkedInline()
96-
#endif
97-
case "streamed": return .streamed()
98-
case "streamedAsync": return .streamedAsync()
93+
case "chunks": return .chunks()
94+
case "chunksInline":
95+
#if compiler(>=6.2)
96+
return .chunksInline()
97+
#else
98+
return nil // TODO: show compiler diagnostic
99+
#endif
100+
101+
case "stream": return .stream()
102+
case "streamAsync": return .streamAsync()
99103
default: return nil
100104
}
101105
case .functionCallExpr:
@@ -128,17 +132,20 @@ extension HTMLKitUtilities {
128132
}
129133
}
130134
switch function.calledExpression.memberAccess?.declName.baseName.text {
131-
case "chunked":
132-
return .chunked(optimized: optimized, chunkSize: chunkSize)
133-
#if compiler(>=6.2)
134-
case "chunkedInline":
135-
return .chunkedInline(optimized: optimized, chunkSize: chunkSize)
136-
#endif
137-
case "streamed":
138-
return .streamed(optimized: optimized, chunkSize: chunkSize)
139-
case "streamedAsync":
140-
return .streamedAsync(optimized: optimized, chunkSize: chunkSize, yieldVariableName: yieldVariableName, afterYield: afterYield)
135+
case "chunks":
136+
return .chunks(optimized: optimized, chunkSize: chunkSize)
137+
case "chunksInline":
138+
#if compiler(>=6.2)
139+
return .chunksInline(optimized: optimized, chunkSize: chunkSize)
140+
#else
141+
return nil // TODO: show compiler diagnostic
142+
#endif
143+
case "stream":
144+
return .stream(optimized: optimized, chunkSize: chunkSize)
145+
case "streamAsync":
146+
return .streamAsync(optimized: optimized, chunkSize: chunkSize, yieldVariableName: yieldVariableName, afterYield: afterYield)
141147
default:
148+
// TODO: show compiler diagnostic
142149
return nil
143150
}
144151
default:

Sources/HTMLKitUtilities/HTMLExpansionResultType.swift

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,52 @@ public enum HTMLExpansionResultType: Sendable {
1414
//case literalOptimized
1515

1616

17-
// MARK: Chunked
18-
17+
// MARK: Chunks
1918

19+
/// Breaks up the encoded literal into chunks.
20+
///
2021
/// - Parameters:
2122
/// - optimized: Whether or not to use optimized literals. Default is `true`.
2223
/// - chunkSize: The maximum size of an individual literal. Default is `1024`.
2324
/// - Returns: An array of encoded literals of length up-to `chunkSize`.
24-
case chunked(optimized: Bool = true, chunkSize: Int = 1024)
25+
case chunks(optimized: Bool = true, chunkSize: Int = 1024)
2526

2627
#if compiler(>=6.2)
28+
/// Breaks up the encoded literal into chunks.
29+
///
2730
/// - Parameters:
2831
/// - optimized: Whether or not to use optimized literals. Default is `true`.
2932
/// - chunkSize: The maximum size of an individual literal. Default is `1024`.
3033
/// - Returns: An `InlineArray` of encoded literals of length up-to `chunkSize`.
31-
case chunkedInline(optimized: Bool = true, chunkSize: Int = 1024)
34+
case chunksInline(optimized: Bool = true, chunkSize: Int = 1024)
3235
#endif
3336

3437

3538

36-
// MARK: Streamed
37-
39+
// MARK: Stream
3840

3941

42+
/// Breaks up the encoded literal into streamable chunks.
43+
///
4044
/// - Parameters:
4145
/// - optimized: Whether or not to use optimized literals. Default is `true`.
4246
/// - chunkSize: The maximum size of an individual literal. Default is `1024`.
4347
/// - Returns: An `AsyncStream` of encoded literals of length up-to `chunkSize`.
4448
/// - Warning: The values are yielded synchronously.
45-
case streamed(optimized: Bool = true, chunkSize: Int = 1024)
49+
case stream(
50+
optimized: Bool = true,
51+
chunkSize: Int = 1024
52+
)
4653

54+
/// Breaks up the encoded literal into streamable chunks.
55+
///
4756
/// - Parameters:
4857
/// - optimized: Whether or not to use optimized literals. Default is `true`.
4958
/// - chunkSize: The maximum size of an individual literal. Default is `1024`.
5059
/// - afterYield: Work to execute after yielding a result. The `Int` closure parameter is the index of the yielded result.
5160
/// - Returns: An `AsyncStream` of encoded literals of length up-to `chunkSize`.
5261
/// - Warning: The values are yielded synchronously in a new `Task`. Populate `afterYield` with async work to make it completely asynchronous.
53-
case streamedAsync(
62+
case streamAsync(
5463
optimized: Bool = true,
5564
chunkSize: Int = 1024,
5665
_ afterYield: @Sendable (Int) async throws -> Void = { yieldIndex in }
@@ -62,14 +71,14 @@ public enum HTMLExpansionResultTypeAST: Sendable {
6271
case literal
6372
//case literalOptimized
6473

65-
case chunked(optimized: Bool = true, chunkSize: Int = 1024)
74+
case chunks(optimized: Bool = true, chunkSize: Int = 1024)
6675

6776
#if compiler(>=6.2)
68-
case chunkedInline(optimized: Bool = true, chunkSize: Int = 1024)
77+
case chunksInline(optimized: Bool = true, chunkSize: Int = 1024)
6978
#endif
7079

71-
case streamed(optimized: Bool = true, chunkSize: Int = 1024)
72-
case streamedAsync(
80+
case stream(optimized: Bool = true, chunkSize: Int = 1024)
81+
case streamAsync(
7382
optimized: Bool = true,
7483
chunkSize: Int = 1024,
7584
yieldVariableName: String? = nil,

Tests/HTMLKitTests/HTMLKitTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,44 +102,44 @@ extension HTMLKitTests {
102102
div("oh \(yeah)")
103103
}*/
104104

105-
let _:[String] = #html(resultType: .chunked()) {
105+
let _:[String] = #html(resultType: .chunks()) {
106106
div("oh yeah")
107107
}
108-
let _:[StaticString] = #html(resultType: .chunked()) {
108+
let _:[StaticString] = #html(resultType: .chunks()) {
109109
div("oh yeah")
110110
}
111-
/*let _:[String] = #html(resultType: .chunked(chunkSize: 3)) { // TODO: fix
111+
/*let _:[String] = #html(resultType: .chunks(chunkSize: 3)) { // TODO: fix
112112
div("oh \(yeah)")
113113
}*/
114114

115-
let _:AsyncStream<String> = #html(resultType: .streamed()) {
115+
let _:AsyncStream<String> = #html(resultType: .stream()) {
116116
div("oh yeah")
117117
}
118-
let _:AsyncStream<StaticString> = #html(resultType: .streamed()) {
118+
let _:AsyncStream<StaticString> = #html(resultType: .stream()) {
119119
div("oh yeah")
120120
}
121-
let _:AsyncStream<String> = #html(resultType: .streamed(chunkSize: 3)) {
121+
let _:AsyncStream<String> = #html(resultType: .stream(chunkSize: 3)) {
122122
div("oh yeah")
123123
}
124-
let _:AsyncStream<StaticString> = #html(resultType: .streamed(chunkSize: 3)) {
124+
let _:AsyncStream<StaticString> = #html(resultType: .stream(chunkSize: 3)) {
125125
div("oh yeah")
126126
}
127-
/*let _:AsyncStream<String> = #html(resultType: .streamed(chunkSize: 3)) {
127+
/*let _:AsyncStream<String> = #html(resultType: .stream(chunkSize: 3)) {
128128
div("oh\(yeah)") // TODO: fix
129129
}*/
130130

131-
let _:AsyncStream<String> = #html(resultType: .streamedAsync()) {
131+
let _:AsyncStream<String> = #html(resultType: .streamAsync()) {
132132
div("oh yeah")
133133
}
134-
let _:AsyncStream<String> = #html(resultType: .streamedAsync(chunkSize: 3)) {
134+
let _:AsyncStream<String> = #html(resultType: .streamAsync(chunkSize: 3)) {
135135
div("oh yeah")
136136
}
137-
let _:AsyncStream<String> = #html(resultType: .streamedAsync({ _ in
137+
let _:AsyncStream<String> = #html(resultType: .streamAsync({ _ in
138138
try await Task.sleep(for: .milliseconds(50))
139139
})) {
140140
div("oh yeah")
141141
}
142-
let _:AsyncStream<String> = #html(resultType: .streamedAsync(chunkSize: 3, { _ in
142+
let _:AsyncStream<String> = #html(resultType: .streamAsync(chunkSize: 3, { _ in
143143
try await Task.sleep(for: .milliseconds(50))
144144
})) {
145145
div("oh yeah")

Tests/HTMLKitTests/StreamTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct StreamTests {
2424
}
2525
)
2626
var test:AsyncStream<String> = #html(
27-
resultType: .streamedAsync(chunkSize: 50, { _ in
27+
resultType: .streamAsync(chunkSize: 50, { _ in
2828
try await Task.sleep(for: .milliseconds(5))
2929
})) {
3030
html {
@@ -52,7 +52,7 @@ struct StreamTests {
5252
#expect(receivedHTML == expected)
5353

5454
test = #html(
55-
resultType: .streamedAsync(
55+
resultType: .streamAsync(
5656
chunkSize: 40, { yieldIndex in
5757
try await Task.sleep(for: .milliseconds((yieldIndex+1) * 5))
5858
}
@@ -107,7 +107,7 @@ extension StreamTests {
107107
)
108108

109109
var test:AsyncStream<String> = #html(
110-
resultType: .streamedAsync(chunkSize: 50, { _ in
110+
resultType: .streamAsync(chunkSize: 50, { _ in
111111
try await Task.sleep(for: .milliseconds(5))
112112
})) {
113113
html {
@@ -136,7 +136,7 @@ extension StreamTests {
136136
#expect(receivedHTML == expected)
137137

138138
test = #html(
139-
resultType: .streamedAsync(chunkSize: 200, { _ in
139+
resultType: .streamAsync(chunkSize: 200, { _ in
140140
try await Task.sleep(for: .milliseconds(5))
141141
})) {
142142
html {

0 commit comments

Comments
 (0)