-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(transform): confused by comments, whitespace
- property names can't contain whitespace - there can be whitespace before the colon - comments can appear before property names - property values can contain newlines - !important must be at end of value This doesn't cover everything, because, for example, there could be comments mixed into the property value, and we don't look for them. But it's probably not necessary either. Along with the above, capture all the internal whitespace for fidelity between input and output. We are replacing values, not reformatting the CSS.
- Loading branch information
Showing
2 changed files
with
46 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { transform } from './transform' | ||
|
||
const props = { theme: { colors: { black: '#000' } } } | ||
|
||
const transformToStr = (s) => | ||
transform(s) | ||
.map((x) => (typeof x === 'function' ? x(props) : x)) | ||
.join('') | ||
|
||
describe('#transform', () => { | ||
it('replaces name/value pair with various whitespace', () => { | ||
expect(transformToStr('color:black;')).toBe('color:#000;') | ||
expect(transformToStr(' color : black ; ')).toBe(' color : #000 ; ') | ||
}) | ||
|
||
it('replaces name/value pair within rule', () => { | ||
expect(transformToStr('.my-class { color: black; }')).toBe( | ||
'.my-class { color: #000; }', | ||
) | ||
}) | ||
|
||
it('handles !important', () => { | ||
expect(transformToStr('color: black !important;')).toBe( | ||
'color: #000 !important;', | ||
) | ||
}) | ||
|
||
it("isn't confused by comments", () => { | ||
expect(transformToStr('/* hi */color:black;')).toBe('/* hi */color:#000;') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters