You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace internal string utils with Wallace's from `@projectwallace/css-parser`.
30
30
31
-
### Step 1.1: Replace hasVendorPrefix
32
-
**File:** `src/vendor-prefix.ts`
33
-
34
-
Replace lines 1-12 with:
35
-
```typescript
36
-
import { is_vendor_prefixed } from '@projectwallace/css-parser'
37
-
38
-
export function hasVendorPrefix(keyword: string): boolean {
39
-
return is_vendor_prefixed(keyword)
40
-
}
41
-
```
42
-
43
-
**Validation:** `npm run check && npm run lint && npm test && npm run build`
31
+
**Status:** All 4 string utilities successfully migrated
32
+
**Commits:** 4
44
33
45
-
**Commit:** "refactor: use Wallace is_vendor_prefixed for hasVendorPrefix"
34
+
### Step 1.1: Replace hasVendorPrefix ✅
35
+
**File:** `src/vendor-prefix.ts`
36
+
**Commit:** `61bc022` - "refactor: use Wallace is_vendor_prefixed for hasVendorPrefix"
46
37
47
38
---
48
39
49
-
### Step 1.2: Replace isCustom
40
+
### Step 1.2: Replace isCustom ✅
50
41
**File:** `src/properties/property-utils.ts`
42
+
**Commit:** `3a34b55` - "refactor: use Wallace is_custom for custom property detection"
51
43
52
-
Add import and replace lines 23-27:
53
-
```typescript
54
-
import { is_custom } from '@projectwallace/css-parser'
55
-
56
-
export function isCustom(property: string): boolean {
57
-
return is_custom(property)
58
-
}
59
-
```
60
-
61
-
**Validation:** `npm run check && npm run lint && npm test && npm run build`
44
+
---
62
45
63
-
**Commit:** "refactor: use Wallace is_custom for custom property detection"
46
+
### Step 1.3: Replace strEquals ✅
47
+
**File:** `src/string-utils.ts`
48
+
**Commit:** `f84e8af` - "refactor: use Wallace str_equals for string comparison"
64
49
65
50
---
66
51
67
-
### Step 1.3: Replace strEquals
52
+
### Step 1.4: Replace startsWith ✅
68
53
**File:** `src/string-utils.ts`
54
+
**Commit:** `cf3e6fe` - "refactor: use Wallace str_starts_with for prefix matching"
55
+
**Note:** Parameter order reversed - documented in parser-improvements.md
69
56
70
-
Add import and replace lines 26-39:
71
-
```typescript
72
-
import { str_equals } from '@projectwallace/css-parser'
73
-
74
-
export function strEquals(base: string, maybe: string): boolean {
75
-
return str_equals(base, maybe)
76
-
}
77
-
```
57
+
---
78
58
79
-
**Validation:** `npm run check && npm run lint && npm test && npm run build`
59
+
---
80
60
81
-
**Commit:** "refactor: use Wallace str_equals for string comparison"
61
+
## Migration Challenge Discovered
82
62
83
-
---
63
+
### Structural Incompatibility
64
+
During migration planning, we discovered that Wallace parser and css-tree have fundamentally different AST structures:
84
65
85
-
### Step 1.4: Replace startsWith
86
-
**File:** `src/string-utils.ts`
66
+
1. **Parse-first requirement**: Files like `atrules/atrules.ts` and `values/*.ts` cannot be migrated independently because they receive css-tree nodes from `index.ts`
67
+
2. **Wallace's walk() only works with Wallace nodes**: Cannot use Wallace's walk on css-tree AST
68
+
3. **No compatibility adapter**: Wallace doesn't provide a css-tree compatibility mode
87
69
88
-
Update import and replace lines 81-94:
89
-
```typescript
90
-
import { str_equals, str_starts_with } from '@projectwallace/css-parser'
70
+
### Revised Strategy Options
91
71
92
-
export function startsWith(base: string, maybe: string): boolean {
93
-
return str_starts_with(base, maybe)
94
-
}
95
-
```
72
+
**Option A: All-at-once migration (High Risk)**
73
+
- Migrate `index.ts` completely to Wallace parser in one large change
74
+
- Update all dependent files simultaneously
75
+
- Risk: Large, complex change affecting 770+ lines of walk logic
96
76
97
-
**Note:** `endsWith()` has no Wallace equivalent - keep for now.
77
+
**Option B: Compatibility adapter (Recommended)**
78
+
- Create an adapter layer that wraps Wallace nodes to expose css-tree-compatible API
79
+
- Allows gradual file-by-file migration
80
+
- Adapter handles differences in children storage, location structure, type identification
81
+
- Risk: Additional maintenance burden for adapter layer
98
82
99
-
**Validation:** `npm run check && npm run lint && npm test && npm run build`
83
+
**Option C: Dual parser approach**
84
+
- Keep css-tree for main parsing temporarily
85
+
- Use Wallace utilities (string functions) where beneficial
86
+
- Plan full migration for a major version bump
87
+
- Risk: Dependency on both parsers
100
88
101
-
**Commit:** "refactor: use Wallace str_starts_with for prefix matching"
89
+
### Recommendation
90
+
Phase 1 (string utilities) provides immediate value with zero risk. For the full parser migration, **Option B (compatibility adapter)** would enable the safest gradual migration path, though it requires implementing the adapter first.
102
91
103
92
---
104
93
105
94
## Phase 2: Small Files - Values (5 steps)
95
+
**Status:** ⏸️ BLOCKED - Requires index.ts migration first
Copy file name to clipboardExpand all lines: parser-improvements.md
+12-1Lines changed: 12 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,18 @@ Issues and enhancement suggestions discovered during css-tree → Wallace parser
12
12
**Suggestion:** Consider documenting this clearly or providing an alias that matches common JS conventions where the needle comes before the haystack.
13
13
14
14
## Missing Features
15
-
_(To be filled during migration)_
15
+
16
+
### CSS-Tree Compatibility Mode
17
+
**Issue:** Wallace parser does not provide a css-tree compatibility mode or adapter layer, making migration from css-tree an all-or-nothing proposition.
18
+
19
+
**Impact:** Projects using css-tree cannot gradually migrate - they must rewrite all AST traversal code at once.
20
+
21
+
**Observed Differences:**
22
+
1. **Children storage**: Wallace uses `first_child`/`next_sibling` + `children` array, while css-tree uses a custom List type with `.first`, `.last`, `.size`
0 commit comments