-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: simplify style logic in template compiler (#314)
* fix: simplify style logic in template compiler * fix: remove unused API to fix linting error * fix: use camelCase instead of kebab-case for css properties * docs: add comments to clarify the style changes
- Loading branch information
Showing
11 changed files
with
133 additions
and
262 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
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
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
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
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
68 changes: 68 additions & 0 deletions
68
packages/lwc-template-compiler/src/parser/__tests__/style.spec.ts
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,68 @@ | ||
import { parseStyleText, parseClassNames } from '../style'; | ||
|
||
describe('parseStyleText', () => { | ||
it('should parse simple style text', () => { | ||
const res = parseStyleText('color: blue'); | ||
expect(res).toEqual({ color: 'blue' }); | ||
}); | ||
|
||
it('should parse simple style text with trailing coma', () => { | ||
const res = parseStyleText('color: blue;'); | ||
expect(res).toEqual({ | ||
color: 'blue' | ||
}); | ||
}); | ||
|
||
it('should parse simple style with multiple values', () => { | ||
const res = parseStyleText('box-shadow: 10px 5px 5px black;'); | ||
expect(res).toEqual({ | ||
boxShadow: '10px 5px 5px black' | ||
}); | ||
}); | ||
|
||
it('should parse multiple declaration', () => { | ||
const res = parseStyleText(`font-size: 12px;background: blue; color:red ;`); | ||
expect(res).toEqual({ | ||
fontSize: '12px', | ||
background: 'blue', | ||
color: 'red' | ||
}); | ||
}); | ||
|
||
it('should parse css functions', () => { | ||
const res = parseStyleText(`background-color:rgba(255,0,0,0.3)`); | ||
expect(res).toEqual({ | ||
backgroundColor: 'rgba(255,0,0,0.3)' | ||
}); | ||
}); | ||
|
||
it('should support base 64 encoded strings', () => { | ||
const image = 'url("data:image/webp;base64,AAAAAAAAAAA")'; | ||
const res = parseStyleText(`background: ${image}`); | ||
expect(res).toEqual({ | ||
background: image | ||
}); | ||
}); | ||
}); | ||
|
||
describe('parseClassNames', () => { | ||
it('should support a single class', () => { | ||
const res = parseClassNames('foo'); | ||
expect(res).toEqual({ foo: true }); | ||
}); | ||
|
||
it('should support simple class list', () => { | ||
const res = parseClassNames('foo bar'); | ||
expect(res).toEqual({ foo: true, bar: true }); | ||
}); | ||
|
||
it('should support simple class list with trailing spaces', () => { | ||
const res = parseClassNames(' foo bar '); | ||
expect(res).toEqual({ foo: true, bar: true }); | ||
}); | ||
|
||
it('should support simple class list multiple spaces', () => { | ||
const res = parseClassNames('foo bar'); | ||
expect(res).toEqual({ foo: true, bar: true }); | ||
}); | ||
}); |
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
Oops, something went wrong.