Skip to content

Commit

Permalink
error on empty css declarations - fixes #3801
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Oct 28, 2019
1 parent e55bf40 commit 74fa244
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/compiler/parse/read/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export default function read_style(parser: Parser, start: number, attributes: No
}
}

if (node.type === 'Declaration' && node.value.type === 'Value' && node.value.children.length === 0) {
parser.error({
code: `invalid-declaration`,
message: `Declaration cannot be empty`
}, node.start);
}

if (node.loc) {
node.start = node.loc.start.offset;
node.end = node.loc.end.offset;
Expand Down
12 changes: 12 additions & 0 deletions test/validator/samples/invalid-empty-css-declaration/errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[{
"code": "invalid-declaration",
"message": "Declaration cannot be empty",
"start": {
"line": 11, "column": 0, "character": 93
},
"end": {
"line": 11, "column": 0, "character": 93
},
"pos": 93,
"frame": " 9: color: blue;\n10: }\n11: </style>\n ^"
}]
11 changes: 11 additions & 0 deletions test/validator/samples/invalid-empty-css-declaration/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class='foo bar'></div>

<style>
.foo {
color:;
}
.bar {
font:;
color: blue;
}
</style>

0 comments on commit 74fa244

Please sign in to comment.