-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSSCompiler.ts
31 lines (29 loc) · 876 Bytes
/
CSSCompiler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import PostCSS from "postcss";
import Nested from "postcss-nested";
import Extend from "postcss-extend";
import Clean from "postcss-csso";
import {
Node,
isTaggedTemplateExpression,
TaggedTemplateExpression,
isNoSubstitutionTemplateLiteral
} from "typescript";
export default class CSS {
static Processor = PostCSS([Extend, Nested, Clean]);
static Styles = {};
static IsPostCSS(Node: Node) {
return isTaggedTemplateExpression(Node) && Node.tag.getText() === "css";
}
static AddBlock(Node: TaggedTemplateExpression, Parent?: string) {
try {
if (isNoSubstitutionTemplateLiteral(Node.template)) {
const Text = Node.template.text;
this.Styles[Parent || Node.pos] =
Parent ? `${Parent} { ${Text} }` : Text;
return [];
}
} catch (Ex) {
console.error("[PostCSS]", Ex.message, Ex.stack);
}
}
}