Repository navigation
Add Swift highlighting - #29
Conversation
Interpolated, multi-line, and raw strings with nested quotes in interpolations, regex literals vs division, nested block comments, contextual keywords, attributes, and directives. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Adds Swift to the default entry and language barrel, with a size and benchmark profile, a representative fixture, docs tables, and a minor changeset. The all-language convenience entry grows from 16.82 KB to 17.73 KB gzip and its budget rises to 18.0 KB; core and existing selective profiles are unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 0b8d429 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (18)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThis change adds a Swift language definition to the highlighter, registers it in the language union, all-language registry, and exports, and adds Swift tests, benchmark coverage, bundle-size limits, and documentation. ChangesSwift language support
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Change: Feature Suggested reviewers: Merge Risk: ⚪ Minimal · up to This adds Swift highlighting as an isolated, opt-in language module. Core and existing selective bundles are reported unchanged. No concrete merge-blocking risk was found. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Changes
Swift fences currently fall back to plaintext. This adds an isolated
swiftdefinition (no aliases), registers it in the default entry, and exposes it as a selective import (@tanstack/highlight/languages/swift). It follows the same shape as the batch in #27: one module on the existingcollectPatternRangeshelpers with a small linear scanner for comments and strings, no new token classes, no new dependencies, no cross-language imports, and no changes to core or to existing language modules.Context-aware behaviour: interpolated, multi-line, and raw
#"…"#strings with nested quotes and parentheses inside\( ), nested block comments,#/…/#and bare/…/regex literals vs division, argument labels, contextual keywords (open,package,set,some, … only in keyword position), attributes, and#directives and macros.The branch is one commit for the module and tests, then one registration commit (default entry, barrel, size and bench profiles, fixture, docs tables, changeset).
Size tradeoff
Core + Swift, local Node 26: 7.30 KB minified / 3.41 KB gzip / 3.13 KB Brotli, with a 3.55 KB gzip budget. Core and every existing selective profile are unchanged. The all-language convenience entry grows from 49.99 KB minified / 16.82 KB gzip to 52.74 KB / 17.73 KB gzip, and its budget rises from 17.1 KB to 18.0 KB gzip.
Deliberate limits
stringtoken; a comment inside\( )is not recognised./…/regexes are recognised only after=,(,,,:,[,{,return, orcase, and never span lines; elsewhere/is division.#/…/#has no such limit.Text(/Foo(aretype(same choice as the Dart module); all-caps names likeURL(stay plain; single-letter generics stay plain.</>are operators;?.is?plus a plain.; tuple accesspoint.0stays plain.functiononly for.name {at line start or when the closure starts with$0,!$0, a capture list, orparams in.(, or[;get/setonly in accessor positions.Notes
Validation
pnpm run verifypasses locally on Node 26.4.0: typecheck, build, docs verification, skills validation, publint, package and packed-runtime checks, 216 tests in 20 files, 26 size profiles, and 21 benchmark profiles.test/swift.test.ts: 14 tests with a realistic showcase, focused regressions for every context-aware behaviour, negative cases for delimiters inside the wrong context, and plaintext fallback; every assertion also checks byte-for-byte source reconstruction.pnpm run changeset:status: one minor bump for@tanstack/highlight.🤖 Generated with Claude Code
Summary by CodeRabbit