Skip to content

Commit 94528e0

Browse files
authored
fix: transform logical (#165)
* fix: transform logical * chore: fix compile
1 parent ea446af commit 94528e0

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@emotion/hash": "^0.8.0",
4545
"@emotion/unitless": "^0.7.5",
4646
"classnames": "^2.3.1",
47-
"csstype": "^3.0.10",
47+
"csstype": "3.1.2",
4848
"rc-util": "^5.35.0",
4949
"stylis": "^4.0.13"
5050
},

src/hooks/useCompatibleInsertionEffect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const { useInsertionEffect } = fullClone;
1313
type UseCompatibleInsertionEffect = (
1414
renderEffect: EffectCallback,
1515
effect: (polyfill?: boolean) => ReturnType<EffectCallback>,
16-
deps?: React.DependencyList,
16+
deps: React.DependencyList,
1717
) => void;
1818

1919
/**

src/transformers/legacyLogicalProperties.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@ function splitValues(
2020
let brackets = 0;
2121
return [
2222
splitStyle.reduce<string[]>((list, item) => {
23-
if (item.includes('(')) {
24-
temp += item;
25-
brackets += item.split('(').length - 1;
26-
} else if (item.includes(')')) {
27-
temp += item;
28-
brackets -= item.split(')').length - 1;
29-
if (brackets === 0) {
30-
list.push(temp);
31-
temp = '';
32-
}
23+
if (item.includes('(') || item.includes(')')) {
24+
const left = item.split('(').length - 1;
25+
const right = item.split(')').length - 1;
26+
brackets += left - right;
27+
}
28+
if (brackets === 0) {
29+
list.push(temp + item);
30+
temp = '';
3331
} else if (brackets > 0) {
3432
temp += item;
35-
} else {
36-
list.push(item);
3733
}
3834
return list;
3935
}, []),

tests/transform.spec.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,27 @@ describe('transform', () => {
159159
const styleText = document.head.querySelector('style')?.innerHTML;
160160
expect(styleText).toContain('33px!important');
161161
});
162+
163+
it('split with calc() and var()', () => {
164+
const { container } = render(
165+
<Wrapper
166+
css={{
167+
'.box': {
168+
marginBlock: 'calc(var(--a) + var(--b)) calc(2px + var(--c))',
169+
marginInline: 'calc(2px + 1px)',
170+
marginInlineEnd: '3px',
171+
},
172+
}}
173+
/>,
174+
);
175+
176+
expect(container.querySelector('.box')).toHaveStyle({
177+
marginTop: 'calc(var(--a) + var(--b))',
178+
marginBottom: 'calc(2px + var(--c))',
179+
marginLeft: 'calc(2px + 1px)',
180+
marginRight: '3px',
181+
});
182+
});
162183
});
163184

164185
describe('px2rem', () => {

0 commit comments

Comments
 (0)