Skip to content

Commit cf3e6fe

Browse files
bartvenemanclaude
andcommitted
refactor: use Wallace str_starts_with for prefix matching
Replace manual case-insensitive prefix matching with Wallace parser's str_starts_with. Note: parameter order is reversed (string, prefix) compared to our internal implementation (prefix, string). Documented parameter order difference in parser-improvements.md. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent f84e8af commit cf3e6fe

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

parser-improvements.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
Issues and enhancement suggestions discovered during css-tree → Wallace parser migration.
44

55
## API Inconsistencies
6-
_(To be filled during migration)_
6+
7+
### `str_starts_with` parameter order
8+
**Issue:** The parameter order for `str_starts_with(string, prefix)` is the opposite of common JavaScript conventions and our internal `startsWith(prefix, string)` function.
9+
10+
**Impact:** When migrating from custom implementations, developers must remember to swap parameters.
11+
12+
**Suggestion:** Consider documenting this clearly or providing an alias that matches common JS conventions where the needle comes before the haystack.
713

814
## Missing Features
915
_(To be filled during migration)_

src/string-utils.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { str_equals } from '@projectwallace/css-parser'
1+
import { str_equals, str_starts_with } from '@projectwallace/css-parser'
22

33
/**
44
* Case-insensitive compare two character codes
@@ -69,17 +69,7 @@ export function endsWith(base: string, maybe: string): boolean {
6969
*
7070
* @returns true if `base` starts with `maybe`, false otherwise
7171
*/
72-
export function startsWith(base: string, maybe: string) {
73-
if (base === maybe) return true
74-
75-
let len = base.length
76-
if (maybe.length < len) return false
77-
78-
for (let i = 0; i < len; i++) {
79-
if (compareChar(base.charCodeAt(i), maybe.charCodeAt(i)) === false) {
80-
return false
81-
}
82-
}
83-
84-
return true
72+
export function startsWith(base: string, maybe: string): boolean {
73+
// Note: parameter order is swapped - Wallace's str_starts_with takes (string, prefix)
74+
return str_starts_with(maybe, base)
8575
}

0 commit comments

Comments
 (0)