Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions nativescript-core/css/css-tree-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
}
};
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -116,6 +116,10 @@ function transformAst(node, css, type = null) {
};
}

if (node.type === "Raw") {
return null;
}

throw Error(`Unknown node type ${node.type}`);
}

Expand Down
10 changes: 10 additions & 0 deletions unit-tests/css-tree-parser/css-tree-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
Expand Down