Skip to content

Commit a2d1028

Browse files
committed
Add missing precondition.
1 parent c44ff8b commit a2d1028

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Sources/gyb-swift/AST.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ typealias AST = [ASTNode]
5353
// MARK: - Helper Extensions
5454

5555
extension StringProtocol {
56-
/// The code content from a gyb block (%{...}%).
56+
/// The code content from a gyb block, with delimiters and optional trailing newline removed.
5757
///
58-
/// Removes the %{ prefix, }% suffix, and optional trailing newline.
58+
/// - Precondition: `self` starts with `%{` and ends with `}%` or `}%\n`.
5959
var codeBlockContent: SubSequence {
60+
precondition(hasPrefix("%{"), "Expected %{ prefix")
61+
precondition(
62+
hasSuffix("}%") || hasSuffix("}%\n"),
63+
"Expected }% suffix with optional newline")
6064
let suffixLength = last?.isNewline == true ? 3 : 2 // }%\n or }%
6165
return dropFirst(2).dropLast(suffixLength)
6266
}

0 commit comments

Comments
 (0)