Skip to content

Commit

Permalink
Restore missed changes for Ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Sep 25, 2023
1 parent 775524e commit f2d3c17
Show file tree
Hide file tree
Showing 9 changed files with 651 additions and 69 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@
- Added `TokenStream#lookupTypeNonSC()` method
- Added `<dashed-ident>` to generic types
- Changed `Ratio` parsing:
- Left and right parts contain nodes instead of strings
- Both left and right parts of a ratio can now be any number; validation of number range is no longer within the parser's scope.
- Both parts can now be functions. Although not explicitly mentioned in the specification, mathematical functions can replace numbers, addressing potential use cases (#162).
- As per the [CSS Values and Units Level 4](https://drafts.csswg.org/css-values-4/#ratios) specification, the right part of `Ratio` can be omitted. While this can't be a parser output (which would produce a `Number` node), it's feasible during `Ratio` node construction or transformation.
Expand Down
10 changes: 8 additions & 2 deletions fixtures/ast/atrule/atrule/media.json
Expand Up @@ -158,8 +158,14 @@
"name": "foo",
"value": {
"type": "Ratio",
"left": "1",
"right": "2"
"left": {
"type": "Number",
"value": "1"
},
"right": {
"type": "Number",
"value": "2"
}
}
},
{
Expand Down
229 changes: 221 additions & 8 deletions fixtures/ast/mediaQuery/FeatureRange.json
Expand Up @@ -58,8 +58,14 @@
"kind": "media",
"left": {
"type": "Ratio",
"left": "1",
"right": "2"
"left": {
"type": "Number",
"value": "1"
},
"right": {
"type": "Number",
"value": "2"
}
},
"leftComparison": "<",
"middle": {
Expand Down Expand Up @@ -97,6 +103,44 @@
]
}
},
"function first": {
"source": "(calc(1 + 2)<foo)",
"ast": {
"type": "Condition",
"kind": "media",
"children": [
{
"type": "FeatureRange",
"kind": "media",
"left": {
"type": "Function",
"name": "calc",
"children": [
{
"type": "Number",
"value": "1"
},
{
"type": "Operator",
"value": " + "
},
{
"type": "Number",
"value": "2"
}
]
},
"leftComparison": "<",
"middle": {
"type": "Identifier",
"name": "foo"
},
"rightComparison": null,
"right": null
}
]
}
},
"full form": {
"source": "(100px<bar<200px)",
"ast": {
Expand Down Expand Up @@ -166,20 +210,38 @@
"kind": "media",
"left": {
"type": "Ratio",
"left": "1",
"right": "2"
"left": {
"type": "Number",
"value": "1"
},
"right": {
"type": "Number",
"value": "2"
}
},
"leftComparison": "<",
"middle": {
"type": "Ratio",
"left": "1",
"right": "3"
"left": {
"type": "Number",
"value": "1"
},
"right": {
"type": "Number",
"value": "3"
}
},
"rightComparison": "<",
"right": {
"type": "Ratio",
"left": "1",
"right": "4"
"left": {
"type": "Number",
"value": "1"
},
"right": {
"type": "Number",
"value": "4"
}
}
}
]
Expand Down Expand Up @@ -242,6 +304,157 @@
]
}
},
"function in ratio": [
{
"source": "(2/calc(1 + 2)<foo)",
"ast": {
"type": "Condition",
"kind": "media",
"children": [
{
"type": "FeatureRange",
"kind": "media",
"left": {
"type": "Ratio",
"left": {
"type": "Number",
"value": "2"
},
"right": {
"type": "Function",
"name": "calc",
"children": [
{
"type": "Number",
"value": "1"
},
{
"type": "Operator",
"value": " + "
},
{
"type": "Number",
"value": "2"
}
]
}
},
"leftComparison": "<",
"middle": {
"type": "Identifier",
"name": "foo"
},
"rightComparison": null,
"right": null
}
]
}
},
{
"source": "(calc(1 + 2)/2<foo)",
"ast": {
"type": "Condition",
"kind": "media",
"children": [
{
"type": "FeatureRange",
"kind": "media",
"left": {
"type": "Ratio",
"left": {
"type": "Function",
"name": "calc",
"children": [
{
"type": "Number",
"value": "1"
},
{
"type": "Operator",
"value": " + "
},
{
"type": "Number",
"value": "2"
}
]
},
"right": {
"type": "Number",
"value": "2"
}
},
"leftComparison": "<",
"middle": {
"type": "Identifier",
"name": "foo"
},
"rightComparison": null,
"right": null
}
]
}
},
{
"source": "(calc(1 + 2)/calc(1 + 2)<foo)",
"ast": {
"type": "Condition",
"kind": "media",
"children": [
{
"type": "FeatureRange",
"kind": "media",
"left": {
"type": "Ratio",
"left": {
"type": "Function",
"name": "calc",
"children": [
{
"type": "Number",
"value": "1"
},
{
"type": "Operator",
"value": " + "
},
{
"type": "Number",
"value": "2"
}
]
},
"right": {
"type": "Function",
"name": "calc",
"children": [
{
"type": "Number",
"value": "1"
},
{
"type": "Operator",
"value": " + "
},
{
"type": "Number",
"value": "2"
}
]
}
},
"leftComparison": "<",
"middle": {
"type": "Identifier",
"name": "foo"
},
"rightComparison": null,
"right": null
}
]
}
}
],
"error": [
{
"source": "(foo > 123 123)",
Expand Down
20 changes: 16 additions & 4 deletions fixtures/ast/mediaQuery/MediaQuery.json
Expand Up @@ -105,8 +105,14 @@
"name": "foo",
"value": {
"type": "Ratio",
"left": "3",
"right": "4"
"left": {
"type": "Number",
"value": "3"
},
"right": {
"type": "Number",
"value": "4"
}
}
}
]
Expand Down Expand Up @@ -182,8 +188,14 @@
"name": "foo",
"value": {
"type": "Ratio",
"left": "3",
"right": "4"
"left": {
"type": "Number",
"value": "3"
},
"right": {
"type": "Number",
"value": "4"
}
}
}
]
Expand Down

0 comments on commit f2d3c17

Please sign in to comment.