Skip to content

Commit

Permalink
fix(css/parser): Fix parsing of hsla(var(--foo), 1) (#8443)
Browse files Browse the repository at this point in the history
**Description:**

```css
.test {
    border-color: hsla(var(--ds-gray-200-value), 1);
}
```

should be compiled as

```css

.test {
    border-color: hsla(var(--ds-gray-200-value), 1);
}
```

Previously, it was

```
.test {
    border-color: hsla(var(--ds-gray-200-value),);
}

```


**Related issue:**

 - https://linear.app/vercel/issue/PACK-2175
  • Loading branch information
kdy1 committed Dec 23, 2023
1 parent eea8ba3 commit d89b60a
Show file tree
Hide file tree
Showing 8 changed files with 415 additions and 2 deletions.
@@ -0,0 +1,4 @@
.test {
border-color: hsla(var(--ds-gray-200-value), 1);
--ds-gray-200: hsla(var(--ds-gray-200-value), 1);
}
@@ -0,0 +1,4 @@
.test {
border-color: hsla(var(--ds-gray-200-value), 1);
--ds-gray-200: hsla(var(--ds-gray-200-value), 1);
}
6 changes: 4 additions & 2 deletions crates/swc_css_parser/src/parser/values_and_units/mod.rs
Expand Up @@ -726,8 +726,10 @@ where
}
}

if is!(self, ",") && is_legacy_syntax {
values.push(ComponentValue::Delimiter(self.parse()?));
if (is!(self, ",") || has_variable) && is_legacy_syntax {
if is!(self, ",") {
values.push(ComponentValue::Delimiter(self.parse()?));
}

self.input.skip_ws();

Expand Down
3 changes: 3 additions & 0 deletions crates/swc_css_parser/tests/fixture/vercel-2175/input.css
@@ -0,0 +1,3 @@
.test {
border-color: hsla(var(--ds-gray-200-value), 1);
}
@@ -0,0 +1 @@
{}
177 changes: 177 additions & 0 deletions crates/swc_css_parser/tests/fixture/vercel-2175/output.json
@@ -0,0 +1,177 @@
{
"type": "Stylesheet",
"span": {
"start": 1,
"end": 63,
"ctxt": 0
},
"rules": [
{
"type": "QualifiedRule",
"span": {
"start": 1,
"end": 63,
"ctxt": 0
},
"prelude": {
"type": "SelectorList",
"span": {
"start": 1,
"end": 6,
"ctxt": 0
},
"children": [
{
"type": "ComplexSelector",
"span": {
"start": 1,
"end": 6,
"ctxt": 0
},
"children": [
{
"type": "CompoundSelector",
"span": {
"start": 1,
"end": 6,
"ctxt": 0
},
"nestingSelector": null,
"typeSelector": null,
"subclassSelectors": [
{
"type": "ClassSelector",
"span": {
"start": 1,
"end": 6,
"ctxt": 0
},
"text": {
"type": "Ident",
"span": {
"start": 2,
"end": 6,
"ctxt": 0
},
"value": "test",
"raw": "test"
}
}
]
}
]
}
]
},
"block": {
"type": "SimpleBlock",
"span": {
"start": 7,
"end": 63,
"ctxt": 0
},
"name": {
"type": "PreservedToken",
"span": {
"start": 7,
"end": 8,
"ctxt": 0
},
"token": "LBrace"
},
"value": [
{
"type": "Declaration",
"span": {
"start": 13,
"end": 60,
"ctxt": 0
},
"name": {
"type": "Ident",
"span": {
"start": 13,
"end": 25,
"ctxt": 0
},
"value": "border-color",
"raw": "border-color"
},
"value": [
{
"type": "Function",
"span": {
"start": 27,
"end": 60,
"ctxt": 0
},
"name": {
"type": "Ident",
"span": {
"start": 27,
"end": 31,
"ctxt": 0
},
"value": "hsla",
"raw": "hsla"
},
"value": [
{
"type": "Function",
"span": {
"start": 32,
"end": 56,
"ctxt": 0
},
"name": {
"type": "Ident",
"span": {
"start": 32,
"end": 35,
"ctxt": 0
},
"value": "var",
"raw": "var"
},
"value": [
{
"type": "DashedIdent",
"span": {
"start": 36,
"end": 55,
"ctxt": 0
},
"value": "ds-gray-200-value",
"raw": "--ds-gray-200-value"
}
]
},
{
"type": "Delimiter",
"span": {
"start": 56,
"end": 57,
"ctxt": 0
},
"value": ","
},
{
"type": "Number",
"span": {
"start": 58,
"end": 59,
"ctxt": 0
},
"value": 1.0,
"raw": "1"
}
]
}
],
"important": null
}
]
}
}
]
}

0 comments on commit d89b60a

Please sign in to comment.