diff --git a/nativescript-core/css/css-tree-parser.ts b/nativescript-core/css/css-tree-parser.ts index b7aa1413f..e0fba18da 100644 --- a/nativescript-core/css/css-tree-parser.ts +++ b/nativescript-core/css/css-tree-parser.ts @@ -39,7 +39,7 @@ function transformAst(node, css, type = null) { return { type: "stylesheet", stylesheet: { - rules: node.children.map(child => transformAst(child, css)).toArray(), + rules: node.children.map(child => transformAst(child, css)).filter(child => child !== null).toArray(), parsingErrors: [] } }; @@ -78,7 +78,7 @@ function transformAst(node, css, type = null) { } if (node.type === "Block") { - return node.children.map(child => transformAst(child, css, type)).toArray(); + return node.children.map(child => transformAst(child, css, type)).filter(child => child !== null).toArray(); } if (node.type === "Rule") { @@ -116,6 +116,10 @@ function transformAst(node, css, type = null) { }; } + if (node.type === "Raw") { + return null; + } + throw Error(`Unknown node type ${node.type}`); } diff --git a/unit-tests/css-tree-parser/css-tree-parser.ts b/unit-tests/css-tree-parser/css-tree-parser.ts index c72e7f098..e3e738d99 100644 --- a/unit-tests/css-tree-parser/css-tree-parser.ts +++ b/unit-tests/css-tree-parser/css-tree-parser.ts @@ -11,6 +11,16 @@ describe("css-tree parser compatible with rework ", () => { assert.deepEqual(cssTreeAST, reworkAST); }); + it("empty rule", () => { + const css = `.test { + color: red; + ; + }`; + const reworkAST = reworkCssParse(css, { source: "file.css" }); + const cssTreeAST = cssTreeParse(css, "file.css"); + assert.deepEqual(cssTreeAST, reworkAST); + }); + it("@keyframes", () => { const testCase = ".test { animation-name: test; } @keyframes test { from { background-color: red; } to { background-color: blue; } } .test { color: red; }"; const reworkAST = reworkCssParse(testCase, { source: "file.css" });