Skip to content

Commit

Permalink
Fix isValidInContext to allow a declaration with a standalone {}-block
Browse files Browse the repository at this point in the history
  • Loading branch information
danny0838 committed Apr 6, 2024
1 parent 454675a commit b84d3ff
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 4 deletions.
11 changes: 7 additions & 4 deletions parse-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -1135,13 +1135,16 @@ function isValidInContext(construct, context) {
return true;
}

// Exclude properties that ended up with a {}-block
// in their value, unless they're custom.
// Exclude properties that ended up with a {}-block plus
// a non-whitespace component in their value, unless they're custom.
if(construct.type == "DECLARATION") {
if(construct.name.slice(0, 2) == "--") return true;
for(const val of construct.value) {
if(val.type == "BLOCK" && val.name == "{") return false;

const block = construct.value.find(t => t.type === "BLOCK" && t.name === "{");
if (block && construct.value.some(t => t.type !== "WHITESPACE" && t !== block)) {
return false;
}

return true;
}
}
Expand Down
69 changes: 69 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3600,6 +3600,75 @@ return [
"important": false
}
},
{
"parser": "parseADeclaration",
"css": "foo:{}",
"expected": {
"type": "DECLARATION",
"name": "foo",
"value": [
{
"type": "BLOCK",
"name": "{",
"value": []
}
],
"important": false
}
},
{
"parser": "parseADeclaration",
"css": "foo: {}",
"expected": {
"type": "DECLARATION",
"name": "foo",
"value": [
{
"type": "BLOCK",
"name": "{",
"value": []
}
],
"important": false
}
},
{
"parser": "parseADeclaration",
"css": "foo:{} ",
"expected": {
"type": "DECLARATION",
"name": "foo",
"value": [
{
"type": "BLOCK",
"name": "{",
"value": []
}
],
"important": false
}
},
{
"parser": "parseADeclaration",
"css": "foo:bar{}",
"expectedThrow": {
"name": "SyntaxError"
}
},
{
"parser": "parseADeclaration",
"css": "foo:{}bar",
"expectedThrow": {
"name": "SyntaxError"
}
},
{
"parser": "parseADeclaration",
"css": "foo:{}{}",
"expectedThrow": {
"name": "SyntaxError"
}
},

// parseAComponentValue()
{
Expand Down

0 comments on commit b84d3ff

Please sign in to comment.