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 7, 2024
1 parent 454675a commit 4ebbcc5
Show file tree
Hide file tree
Showing 2 changed files with 103 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
96 changes: 96 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3600,6 +3600,102 @@ 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"
}
},
{
"parser": "parseADeclaration",
"css": "-foo:bar{}",
"expectedThrow": {
"name": "SyntaxError"
}
},
{
"parser": "parseADeclaration",
"css": "--foo:bar{}",
"expected": {
"type": "DECLARATION",
"name": "--foo",
"value": [
{
"type": "IDENT",
"value": "bar"
},
{
"type": "BLOCK",
"name": "{",
"value": []
}
],
"important": false
}
},

// parseAComponentValue()
{
Expand Down

0 comments on commit 4ebbcc5

Please sign in to comment.