-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Identify CSS units and variables (#1450)
Assume CSS unit is a word or `%` after a number, CSS variable is a word inside `var()`. `%` is not recognized as a part of number, but the leading `-` is. When using minus operator in `calc` function, we must type a space in both sides of `-` (value like `calc(100%-5px)` is wrong), so if we met a pattern like `-[\d.]` in a CSS value (not in selector, rule or variable), it must be the start of a negative number.
- Loading branch information
1 parent
0cc8c56
commit 5fcee96
Showing
6 changed files
with
144 additions
and
6 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
width: calc(100% + 20px); | ||
width: calc(100% - 20px); | ||
width: calc(5px * 2); | ||
width: calc(10px / 2); | ||
height: -20px; | ||
content: 'this - is not an operator'; | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["property", "width"], | ||
["punctuation", ":"], | ||
["function", "calc"], | ||
["punctuation", "("], | ||
["number", "100"], | ||
["unit", "%"], | ||
["operator", "+"], | ||
["number", "20"], | ||
["unit", "px"], | ||
["punctuation", ")"], | ||
["punctuation", ";"], | ||
|
||
["property", "width"], | ||
["punctuation", ":"], | ||
["function", "calc"], | ||
["punctuation", "("], | ||
["number", "100"], | ||
["unit", "%"], | ||
["operator", "-"], | ||
["number", "20"], | ||
["unit", "px"], | ||
["punctuation", ")"], | ||
["punctuation", ";"], | ||
|
||
["property", "width"], | ||
["punctuation", ":"], | ||
["function", "calc"], | ||
["punctuation", "("], | ||
["number", "5"], | ||
["unit", "px"], | ||
["operator", "*"], | ||
["number", "2"], | ||
["punctuation", ")"], | ||
["punctuation", ";"], | ||
|
||
["property", "width"], | ||
["punctuation", ":"], | ||
["function", "calc"], | ||
["punctuation", "("], | ||
["number", "10"], | ||
["unit", "px"], | ||
["operator", "/"], | ||
["number", "2"], | ||
["punctuation", ")"], | ||
["punctuation", ";"], | ||
|
||
["property", "height"], | ||
["punctuation", ":"], | ||
["number", "-20"], | ||
["unit", "px"], | ||
["punctuation", ";"], | ||
|
||
["property", "content"], | ||
["punctuation", ":"], | ||
["string", "'this - is not an operator'"], | ||
["punctuation", ";"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for operators. |
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,21 @@ | ||
100% | ||
1rem | ||
500ms | ||
.5s | ||
-3px | ||
-0.618vw | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["number", "100"], ["unit", "%"], | ||
["number", "1"], ["unit", "rem"], | ||
["number", "500"], ["unit", "ms"], | ||
["number", ".5"], ["unit", "s"], | ||
["number", "-3"], ["unit", "px"], | ||
["number", "-0.618"], ["unit", "vw"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for units. |
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,34 @@ | ||
var(--color-primary) | ||
var(--level-3) | ||
calc(100% - var(--margin-size) * 2) | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["function", "var"], | ||
["punctuation", "("], | ||
["variable", "--color-primary"], | ||
["punctuation", ")"], | ||
|
||
["function", "var"], | ||
["punctuation", "("], | ||
["variable", "--level-3"], | ||
["punctuation", ")"], | ||
|
||
["function", "calc"], | ||
["punctuation", "("], | ||
["number", "100"], | ||
["unit", "%"], | ||
["operator", "-"], | ||
["function", "var"], | ||
["punctuation", "("], | ||
["variable", "--margin-size"], | ||
["punctuation", ")"], | ||
["operator", "*"], | ||
["number", "2"], | ||
["punctuation", ")"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for variables. |