feat(css): Added optional css-tree parser (#8076)

* feat(css): Added optional css-tree parser

* test: css-tree parser compat tests

* test: more css-tree compat tests
This commit is contained in:
Darin Dimitrov
2019-12-05 10:23:32 +02:00
committed by Alexander Vakrilov
parent f5d6e4f5ed
commit 49a7607f4e
6 changed files with 242 additions and 5 deletions

View File

@ -12,6 +12,9 @@ import {
CSS3Parser,
CSSNativeScript
} from "../../css/parser";
import {
cssTreeParse
} from "../../css/css-tree-parser";
import {
RuleSet,
@ -50,11 +53,15 @@ function ensureCssAnimationParserModule() {
}
}
let parser: "rework" | "nativescript" = "rework";
let parser: "rework" | "nativescript" | "css-tree" = "rework";
try {
const appConfig = require("~/package.json");
if (appConfig && appConfig.cssParser === "nativescript") {
parser = "nativescript";
if (appConfig) {
if (appConfig.cssParser === "css-tree") {
parser = "css-tree";
} else if (appConfig.cssParser === "nativescript") {
parser = "nativescript";
}
}
} catch (e) {
//
@ -220,6 +227,10 @@ class CSSSource {
private parseCSSAst() {
if (this._source) {
switch (parser) {
case "css-tree":
this._ast = cssTreeParse(this._source, this._file);
return;
case "nativescript":
const cssparser = new CSS3Parser(this._source);
const stylesheet = cssparser.parseAStylesheet();