1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var visitor_1 = tslib_1.__importDefault(require("./visitor"));
|
5 | var JoinSelectorVisitor = (function () {
|
6 | function JoinSelectorVisitor() {
|
7 | this.contexts = [[]];
|
8 | this._visitor = new visitor_1.default(this);
|
9 | }
|
10 | JoinSelectorVisitor.prototype.run = function (root) {
|
11 | return this._visitor.visit(root);
|
12 | };
|
13 | JoinSelectorVisitor.prototype.visitDeclaration = function (declNode, visitArgs) {
|
14 | visitArgs.visitDeeper = false;
|
15 | };
|
16 | JoinSelectorVisitor.prototype.visitMixinDefinition = function (mixinDefinitionNode, visitArgs) {
|
17 | visitArgs.visitDeeper = false;
|
18 | };
|
19 | JoinSelectorVisitor.prototype.visitRuleset = function (rulesetNode, visitArgs) {
|
20 | var context = this.contexts[this.contexts.length - 1];
|
21 | var paths = [];
|
22 | var selectors;
|
23 | this.contexts.push(paths);
|
24 | if (!rulesetNode.root) {
|
25 | selectors = rulesetNode.selectors;
|
26 | if (selectors) {
|
27 | selectors = selectors.filter(function (selector) { return selector.getIsOutput(); });
|
28 | rulesetNode.selectors = selectors.length ? selectors : (selectors = null);
|
29 | if (selectors) {
|
30 | rulesetNode.joinSelectors(paths, context, selectors);
|
31 | }
|
32 | }
|
33 | if (!selectors) {
|
34 | rulesetNode.rules = null;
|
35 | }
|
36 | rulesetNode.paths = paths;
|
37 | }
|
38 | };
|
39 | JoinSelectorVisitor.prototype.visitRulesetOut = function (rulesetNode) {
|
40 | this.contexts.length = this.contexts.length - 1;
|
41 | };
|
42 | JoinSelectorVisitor.prototype.visitMedia = function (mediaNode, visitArgs) {
|
43 | var context = this.contexts[this.contexts.length - 1];
|
44 | mediaNode.rules[0].root = (context.length === 0 || context[0].multiMedia);
|
45 | };
|
46 | JoinSelectorVisitor.prototype.visitAtRule = function (atRuleNode, visitArgs) {
|
47 | var context = this.contexts[this.contexts.length - 1];
|
48 | if (atRuleNode.rules && atRuleNode.rules.length) {
|
49 | atRuleNode.rules[0].root = (atRuleNode.isRooted || context.length === 0 || null);
|
50 | }
|
51 | };
|
52 | return JoinSelectorVisitor;
|
53 | }());
|
54 | exports.default = JoinSelectorVisitor;
|
55 |
|
\ | No newline at end of file |