From 74fa2447b1b19346321bb17be59c1c9e888732a9 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Mon, 28 Oct 2019 10:38:46 -0400 Subject: [PATCH] error on empty css declarations - fixes #3801 --- src/compiler/parse/read/style.ts | 7 +++++++ .../invalid-empty-css-declaration/errors.json | 12 ++++++++++++ .../invalid-empty-css-declaration/input.svelte | 11 +++++++++++ 3 files changed, 30 insertions(+) create mode 100644 test/validator/samples/invalid-empty-css-declaration/errors.json create mode 100644 test/validator/samples/invalid-empty-css-declaration/input.svelte diff --git a/src/compiler/parse/read/style.ts b/src/compiler/parse/read/style.ts index 4a16475d6b..dd9d1286f2 100644 --- a/src/compiler/parse/read/style.ts +++ b/src/compiler/parse/read/style.ts @@ -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; diff --git a/test/validator/samples/invalid-empty-css-declaration/errors.json b/test/validator/samples/invalid-empty-css-declaration/errors.json new file mode 100644 index 0000000000..f141168077 --- /dev/null +++ b/test/validator/samples/invalid-empty-css-declaration/errors.json @@ -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: \n ^" +}] \ No newline at end of file diff --git a/test/validator/samples/invalid-empty-css-declaration/input.svelte b/test/validator/samples/invalid-empty-css-declaration/input.svelte new file mode 100644 index 0000000000..1262b8e08a --- /dev/null +++ b/test/validator/samples/invalid-empty-css-declaration/input.svelte @@ -0,0 +1,11 @@ +
+ + \ No newline at end of file