Skip to content

Commit 3d9aa65

Browse files
brianmhuntclaude
andcommitted
Address PR review: quote-aware parser, multiline regex, stylelint
- Add quote tracking to parseBindingString so commas inside string literals don't split bindings - Use [\s\S]*? instead of .*? to match multiline data-bind values - Make off-by-one intent explicit with null sentinel - Add blank lines after CSS custom properties for stylelint Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4bc2ea1 commit 3d9aa65

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

tko.io/plugins/tsx-tabs.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@
88

99
/**
1010
* Parse a KO binding string into individual {name, value} pairs.
11-
* Respects nested braces, parens, and brackets so that object/array
12-
* values and function calls are not split on internal commas.
11+
* Respects nested braces, parens, brackets, and quoted strings so that
12+
* object/array values and string literals are not split on internal commas.
1313
*/
1414
function parseBindingString(str) {
1515
const bindings = []
1616
let depth = 0
1717
let start = 0
18+
let quote = null
1819

1920
for (let i = 0; i <= str.length; i++) {
20-
const ch = str[i]
21+
const ch = i < str.length ? str[i] : null
22+
23+
if (quote) {
24+
if (ch === '\\') { i++; continue }
25+
if (ch === quote) quote = null
26+
continue
27+
}
28+
29+
if (ch === "'" || ch === '"' || ch === '`') { quote = ch; continue }
2130
if (ch === '{' || ch === '(' || ch === '[') depth++
2231
else if (ch === '}' || ch === ')' || ch === ']') depth--
2332
else if ((ch === ',' || i === str.length) && depth === 0) {
@@ -42,7 +51,7 @@ function parseBindingString(str) {
4251
* Convert HTML with data-bind attributes to TSX with ko-* attributes.
4352
*/
4453
function convertDataBindToTsx(html) {
45-
return html.replace(/data-bind=(["'])(.*?)\1/g, (_match, _quote, bindingStr) => {
54+
return html.replace(/data-bind=(["'])([\s\S]*?)\1/g, (_match, _quote, bindingStr) => {
4655
const bindings = parseBindingString(bindingStr)
4756
if (bindings.length === 0) return _match
4857
return bindings.map(({ name, value }) => `ko-${name}={${value}}`).join(' ')

tko.io/src/styles/tko.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ starlight-tabs {
548548

549549
.tab > [role='tab'] {
550550
--sl-tab-color-border: var(--sl-color-gray-5);
551+
551552
display: flex;
552553
align-items: center;
553554
gap: 0.5rem;
@@ -563,6 +564,7 @@ starlight-tabs {
563564

564565
.tab [role='tab'][aria-selected='true'] {
565566
--sl-tab-color-border: var(--sl-color-text-accent);
567+
566568
color: var(--sl-color-white);
567569
font-weight: 600;
568570
}

0 commit comments

Comments
 (0)