"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var utils_1 = require("../utils");
var utils_2 = require("../../utils");
describe(__filename + "#", function () {
    it("can render a simple style", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n        .a {\n          color: b;\n        }\n      </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>[class]._80f4925f_a { color:b; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("displays an error if style url not found", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, err;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "\n        <style>\n          .rule {\n            background: url('/not/found.png')\n          }\n        </style>\n      "
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph, utils_2.noop, {
                            resolveFile: function () {
                                return null;
                            }
                        })];
                case 1:
                    engine = _a.sent();
                    try {
                        engine.run("/entry.pc");
                    }
                    catch (e) {
                        err = e;
                    }
                    chai_1.expect(err).to.eql({
                        errorKind: "Runtime",
                        uri: "/entry.pc",
                        location: { start: 59, end: 91 },
                        message: "Unable to resolve file: /not/found.png from /entry.pc"
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    describe("Mixins", function () {
        it("can be created & used", function () { return __awaiter(void 0, void 0, void 0, function () {
            var graph, engine, text, _a;
            return __generator(this, function (_c) {
                switch (_c.label) {
                    case 0:
                        graph = {
                            "/entry.pc": "<style>\n          @mixin a {\n            color: blue;\n          }\n          div {\n            @include a;\n          }\n        </style>"
                        };
                        return [4 /*yield*/, utils_1.createMockEngine(graph)];
                    case 1:
                        engine = _c.sent();
                        _a = utils_1.stringifyLoadResult;
                        return [4 /*yield*/, engine.run("/entry.pc")];
                    case 2:
                        text = _a.apply(void 0, [_c.sent()]);
                        chai_1.expect(text).to.eql("<style>div[data-pc-80f4925f] { color:blue; }</style>");
                        return [2 /*return*/];
                }
            });
        }); });
        it("Displays an error if a mixin is not found", function () { return __awaiter(void 0, void 0, void 0, function () {
            var graph, engine, err, e_1;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        graph = {
                            "/entry.pc": "<style>\n          div {\n            @include a;\n          }\n        </style>"
                        };
                        return [4 /*yield*/, utils_1.createMockEngine(graph)];
                    case 1:
                        engine = _a.sent();
                        _a.label = 2;
                    case 2:
                        _a.trys.push([2, 4, , 5]);
                        return [4 /*yield*/, engine.run("/entry.pc")];
                    case 3:
                        _a.sent();
                        return [3 /*break*/, 5];
                    case 4:
                        e_1 = _a.sent();
                        err = e_1;
                        return [3 /*break*/, 5];
                    case 5:
                        chai_1.expect(err).to.eql({
                            errorKind: "Runtime",
                            uri: "/entry.pc",
                            location: { start: 45, end: 46 },
                            message: "Reference not found."
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it("can use an imported mixin", function () { return __awaiter(void 0, void 0, void 0, function () {
            var graph, engine, text, _a;
            return __generator(this, function (_c) {
                switch (_c.label) {
                    case 0:
                        graph = {
                            "/entry.pc": "<import as=\"mod\" src=\"./module.pc\"  /><style>\n          div {\n            @include mod.a;\n          }\n        </style>",
                            "/module.pc": "<style>\n          @export {\n            @mixin a {\n              color: orange;\n            }\n          }\n        </style>"
                        };
                        return [4 /*yield*/, utils_1.createMockEngine(graph)];
                    case 1:
                        engine = _c.sent();
                        _a = utils_1.stringifyLoadResult;
                        return [4 /*yield*/, engine.run("/entry.pc")];
                    case 2:
                        text = _a.apply(void 0, [_c.sent()]);
                        chai_1.expect(text).to.eql("<style>div[data-pc-80f4925f] { color:orange; }</style>");
                        return [2 /*return*/];
                }
            });
        }); });
        it("Displays an error if an imported mixin is not found", function () { return __awaiter(void 0, void 0, void 0, function () {
            var graph, engine, err, e_2;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        graph = {
                            "/entry.pc": "<import as=\"mod\" src=\"./module.pc\"  /><style>\n          div {\n            @include mod.a;\n          }\n        </style>",
                            "/module.pc": "<style>\n        </style>"
                        };
                        return [4 /*yield*/, utils_1.createMockEngine(graph)];
                    case 1:
                        engine = _a.sent();
                        _a.label = 2;
                    case 2:
                        _a.trys.push([2, 4, , 5]);
                        return [4 /*yield*/, engine.run("/entry.pc")];
                    case 3:
                        _a.sent();
                        return [3 /*break*/, 5];
                    case 4:
                        e_2 = _a.sent();
                        err = e_2;
                        return [3 /*break*/, 5];
                    case 5:
                        chai_1.expect(err).to.eql({
                            errorKind: "Runtime",
                            uri: "/entry.pc",
                            location: { start: 87, end: 88 },
                            message: "Reference not found."
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it("Displays an error if the import is not found", function () { return __awaiter(void 0, void 0, void 0, function () {
            var graph, engine, err, e_3;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        graph = {
                            "/entry.pc": "<style>\n          div {\n            @include mod.a;\n          }\n        </style>"
                        };
                        return [4 /*yield*/, utils_1.createMockEngine(graph)];
                    case 1:
                        engine = _a.sent();
                        _a.label = 2;
                    case 2:
                        _a.trys.push([2, 4, , 5]);
                        return [4 /*yield*/, engine.run("/entry.pc")];
                    case 3:
                        _a.sent();
                        return [3 /*break*/, 5];
                    case 4:
                        e_3 = _a.sent();
                        err = e_3;
                        return [3 /*break*/, 5];
                    case 5:
                        chai_1.expect(err).to.eql({
                            errorKind: "Runtime",
                            uri: "/entry.pc",
                            location: { start: 45, end: 48 },
                            message: "Reference not found."
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        // expectation is still incorrect, just want to make sure that this doesn't break the engine
        it("Smoke -- can use nested refs", function () { return __awaiter(void 0, void 0, void 0, function () {
            var graph, engine, err, e_4;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        graph = {
                            "/entry.pc": "<style>\n          div {\n            @include a.b.c;\n          }\n        </style>"
                        };
                        return [4 /*yield*/, utils_1.createMockEngine(graph)];
                    case 1:
                        engine = _a.sent();
                        _a.label = 2;
                    case 2:
                        _a.trys.push([2, 4, , 5]);
                        return [4 /*yield*/, engine.run("/entry.pc")];
                    case 3:
                        _a.sent();
                        return [3 /*break*/, 5];
                    case 4:
                        e_4 = _a.sent();
                        err = e_4;
                        return [3 /*break*/, 5];
                    case 5:
                        chai_1.expect(err).to.eql({
                            errorKind: "Runtime",
                            uri: "/entry.pc",
                            location: { start: 45, end: 46 },
                            message: "Reference not found."
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it("Displays an error if a mixin is used but not exported", function () { return __awaiter(void 0, void 0, void 0, function () {
            var graph, engine, err, e_5;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        graph = {
                            "/entry.pc": "<import as=\"mod\" src=\"./module.pc\"  /><style>\n          div {\n            @include mod.abcde;\n          }\n        </style>",
                            "/module.pc": "<style>\n          @mixin abcde {\n            color: orange;\n          }\n        </style>"
                        };
                        return [4 /*yield*/, utils_1.createMockEngine(graph)];
                    case 1:
                        engine = _a.sent();
                        _a.label = 2;
                    case 2:
                        _a.trys.push([2, 4, , 5]);
                        return [4 /*yield*/, engine.run("/entry.pc")];
                    case 3:
                        _a.sent();
                        return [3 /*break*/, 5];
                    case 4:
                        e_5 = _a.sent();
                        err = e_5;
                        return [3 /*break*/, 5];
                    case 5:
                        chai_1.expect(err).to.eql({
                            errorKind: "Runtime",
                            uri: "/entry.pc",
                            location: { start: 87, end: 92 },
                            message: "This mixin is private."
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it("Display an error if a mixins is already defined in the upper scope", function () { return __awaiter(void 0, void 0, void 0, function () {
            var graph, engine, err, e_6;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        graph = {
                            "/entry.pc": "<style>\n          @mixin abcde {\n            color: blue;\n          }\n          \n          @mixin abcde {\n            color: orange;\n          }\n        </style>"
                        };
                        return [4 /*yield*/, utils_1.createMockEngine(graph)];
                    case 1:
                        engine = _a.sent();
                        _a.label = 2;
                    case 2:
                        _a.trys.push([2, 4, , 5]);
                        return [4 /*yield*/, engine.run("/entry.pc")];
                    case 3:
                        _a.sent();
                        return [3 /*break*/, 5];
                    case 4:
                        e_6 = _a.sent();
                        err = e_6;
                        return [3 /*break*/, 5];
                    case 5:
                        chai_1.expect(err).to.eql({
                            errorKind: "Runtime",
                            uri: "/entry.pc",
                            location: { start: 98, end: 103 },
                            message: "This mixin is already declared in the upper scope."
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it("properly concats using multiple &", function () { return __awaiter(void 0, void 0, void 0, function () {
            var graph, engine, result;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        graph = {
                            "/entry.pc": "<style>\n          .company_list {\n            list-style: none;\n            margin: 0;\n            padding: 0;\n        \n            & li {\n        \n              display: block;\n              padding: var(--spacing-600) 0;\n        \n              & + & {\n                border-top: 1px solid var(--color-black-100);\n              }\n            }\n          }\n        </style>"
                        };
                        return [4 /*yield*/, utils_1.createMockEngine(graph)];
                    case 1:
                        engine = _a.sent();
                        return [4 /*yield*/, engine.run("/entry.pc")];
                    case 2:
                        result = _a.sent();
                        chai_1.expect(utils_1.stringifyLoadResult(result)).to.eql("<style>[class]._80f4925f_company_list { list-style:none; margin:0; padding:0; } [class]._80f4925f_company_list li[data-pc-80f4925f] { display:block; padding:var(--spacing-600) 0; } [class]._80f4925f_company_list li[data-pc-80f4925f] + [class]._80f4925f_company_list li[data-pc-80f4925f] { border-top:1px solid var(--color-black-100); }</style>");
                        return [2 /*return*/];
                }
            });
        }); });
    });
    it("can use escape key in classname", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n        .a\\:b {\n          color: blue;\n        }\n      </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _a.sent();
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    result = _a.sent();
                    chai_1.expect(utils_1.stringifyLoadResult(result)).to.eql("<style>[class]._80f4925f_a\\:b { color:blue; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("can use single line comment", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n\n\n      // :checked\n      input:checked {\n        & + .tab-label {\n          background: var(--midnight-darker);\n          &::after {\n            transform: rotate(90deg);\n          }\n        }\n        & ~ .tab-content {\n          max-height: 100vh;\n          padding: 1em;\n        }\n      }\n      \n      </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _a.sent();
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    result = _a.sent();
                    chai_1.expect(utils_1.stringifyLoadResult(result)).to.eql("<style>input:checked[data-pc-80f4925f] + [class]._80f4925f_tab-label { background:var(--midnight-darker); } input:checked[data-pc-80f4925f] + [class]._80f4925f_tab-label::after { transform:rotate(90deg); } input:checked[data-pc-80f4925f] ~ [class]._80f4925f_tab-content { max-height:100vh; padding:1em; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("errors if comment is unterminated", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, err, e_7;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n        /* foreverrrrrr\n      </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _a.sent();
                    _a.label = 2;
                case 2:
                    _a.trys.push([2, 4, , 5]);
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 3:
                    _a.sent();
                    return [3 /*break*/, 5];
                case 4:
                    e_7 = _a.sent();
                    err = e_7;
                    return [3 /*break*/, 5];
                case 5:
                    chai_1.expect(err).to.eql({
                        errorKind: "Graph",
                        uri: "/entry.pc",
                        info: {
                            kind: "Unterminated",
                            message: "Unterminated element.",
                            location: { start: 0, end: 7 }
                        }
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    it("CSS vars are collected in the evaluated output", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n        .element {\n          --color: test;\n        }\n      </style>ab"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _a.sent();
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    result = _a.sent();
                    chai_1.expect(result.exports.style.variables["--color"]).to.eql({
                        name: "--color",
                        value: "test",
                        source: {
                            uri: "/entry.pc",
                            location: {
                                start: 37,
                                end: 51
                            }
                        }
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    it("CSS class names are pulled out", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n\n        // comment test\n        [a] {\n          & .color {\n\n          }\n        }\n        @export {\n          .div {\n\n          }\n        }\n        .element {\n          &.child {\n\n          }\n          &--child {\n\n          }\n        }\n      </style>ab"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _a.sent();
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    result = _a.sent();
                    chai_1.expect(result.exports.style.classNames).to.eql({
                        color: { name: "color", public: false, scopedName: "_80f4925f_color" },
                        div: { name: "div", public: true, scopedName: "_80f4925f_div" },
                        child: { name: "child", public: false, scopedName: "child" },
                        "element--child": {
                            name: "element--child",
                            public: false,
                            scopedName: "_80f4925f_element--child"
                        },
                        element: {
                            name: "element",
                            public: false,
                            scopedName: "_80f4925f_element"
                        }
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    it("maintains space with & selector", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      .todo {\n        &:hover .destroy {\n            display: inline-block;\n        }\n        & .todo {\n          &--item .destroy {\n            display: inline-block;\n          }\n        }\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _a.sent();
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    result = _a.sent();
                    chai_1.expect(utils_1.stringifyLoadResult(result)).to.eql("<style>[class]._80f4925f_todo:hover [class]._80f4925f_destroy { display:inline-block; } [class]._80f4925f_todo [class]._80f4925f_todo--item [class]._80f4925f_destroy { display:inline-block; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("can parse nested tag selectors", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      a {\n        & svg:a {\n          margin-right: 4px;\n        }\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _a.sent();
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    result = _a.sent();
                    chai_1.expect(utils_1.stringifyLoadResult(result)).to.eql("<style>a[data-pc-80f4925f] svg:a[data-pc-80f4925f] { margin-right:4px; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("can render keyframes with a dash in the name", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      @keyframes lds-something3 {\n\n      }\n\n      div {\n        animation: lds-something3 1s;\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _a.sent();
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    result = _a.sent();
                    chai_1.expect(utils_1.stringifyLoadResult(result)).to.eql("<style>@keyframes _80f4925f_lds-something3 { } div[data-pc-80f4925f] { animation:_80f4925f_lds-something3 1s; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("can evaluated multiple nested selectors without &", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      a {\n        > b {\n          color: blue;\n        }\n        + c {\n          color: black;\n        }\n        ~ d {\n          color: red;\n        }\n        :not(.div) {\n          color: voilet;\n        }\n        ::active {\n          color: green;\n        }\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _a.sent();
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    result = _a.sent();
                    chai_1.expect(utils_1.stringifyLoadResult(result)).to.eql("<style>a[data-pc-80f4925f] > b[data-pc-80f4925f] { color:blue; } a[data-pc-80f4925f] + c[data-pc-80f4925f] { color:black; } a[data-pc-80f4925f] ~ d[data-pc-80f4925f] { color:red; } a[data-pc-80f4925f] [data-pc-80f4925f]:not([class]._80f4925f_div) { color:voilet; } a[data-pc-80f4925f] [data-pc-80f4925f]::active { color:green; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("AST location is correct with unicode characters", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, ast;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      /* \uD83D\uDC4D\uD83C\uDFFB */\n      // \uD83D\uDC4D\uD83C\uDFFB\n      .div {\n        content: \"\uD83D\uDC4C\"\n      }\n      .another {\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _a.sent();
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    _a.sent();
                    ast = engine.getLoadedAst("/entry.pc");
                    chai_1.expect(ast.children[0].sheet.rules[1].location).to.eql({
                        start: 88,
                        end: 111
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    it("includes keyframes in export", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      @keyframes a {\n\n      }\n      @export {\n        @keyframes b {\n\n        }\n      }\n\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _a.sent();
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    result = _a.sent();
                    chai_1.expect(result.exports.style.keyframes).to.eql({
                        b: {
                            name: "b",
                            public: true,
                            source: {
                                uri: "/entry.pc",
                                location: {
                                    start: 73,
                                    end: 94
                                }
                            }
                        },
                        a: {
                            name: "a",
                            public: false,
                            source: {
                                uri: "/entry.pc",
                                location: {
                                    start: 25,
                                    end: 44
                                }
                            }
                        }
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    it("can export class names with _ prefix", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      @export {\n        ._b {\n\n        }\n      }\n\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _a.sent();
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    result = _a.sent();
                    chai_1.expect(result.exports.style.classNames).to.eql({
                        _b: { name: "_b", scopedName: "_80f4925f__b", public: true }
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    // Addresses https://github.com/crcn/paperclip/issues/319
    it("shows an error if including a mixin that doesn't exist within a mixin that's exported", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, err, e_8;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      @export {\n        @mixin ab {\n          @include no-boom;\n        }\n      }\n\n      .test {\n        @include ab;\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _a.sent();
                    _a.label = 2;
                case 2:
                    _a.trys.push([2, 4, , 5]);
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 3:
                    _a.sent();
                    return [3 /*break*/, 5];
                case 4:
                    e_8 = _a.sent();
                    err = e_8;
                    return [3 /*break*/, 5];
                case 5:
                    chai_1.expect(err).to.eql({
                        errorKind: "Runtime",
                        uri: "/entry.pc",
                        location: { start: 63, end: 70 },
                        message: "Reference not found."
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    // Addresses https://github.com/crcn/paperclip/issues/326
    it("can have nested pseudo selectors", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      .parent {\n        .child:first-child {\n          color: blue\n        }\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>[class]._80f4925f_child:first-child { color:blue ; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    // Addresses: https://github.com/crcn/paperclip/issues/340
    it("Can use mixins in other style blocks defined in the same page", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      @mixin a {\n        color: blue;\n      }\n    </style>\n    <style>\n      .div {\n        @include a;\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>[class]._80f4925f_div { color:blue; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    // Addresses https://github.com/crcn/paperclip/issues/417
    it("properly renders global * selector", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      div {\n        > :global(*) {\n          color: blue;\n        }\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>div[data-pc-80f4925f] > * { color:blue; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("Certain declarations are auto-prefixed", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      div {\n        mask-image: d;\n        \n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>div[data-pc-80f4925f] { mask-image:d; -webkit-mask-image:d; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("Properly renders nested selectors", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      .a {\n        .b {\n          &--c&--d {\n            color: blue;\n          }\n        }\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>[class]._80f4925f_a [class]._80f4925f_b--c[class]._80f4925f_a [class]._80f4925f_b--d { color:blue; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("Can include style rules within mixins", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      @mixin test {\n        .a {\n          color: blue;\n        }\n      }\n\n      @include test;\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>[class]._80f4925f_a { color:blue; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("Can include mixin rules into a style rule", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      @mixin test {\n        .e {\n          color: blue;\n        }\n      }\n\n      a {\n        b, c, d {\n          @include test;\n        }\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>a[data-pc-80f4925f] b[data-pc-80f4925f] [class]._80f4925f_e { color:blue; } a[data-pc-80f4925f] c[data-pc-80f4925f] [class]._80f4925f_e { color:blue; } a[data-pc-80f4925f] d[data-pc-80f4925f] [class]._80f4925f_e { color:blue; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("Can include media declarations within style rule", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      a {\n        @media screen and (max-width: 450px) {\n          color: red;\n        }\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>@media screen and (max-width: 450px) { a[data-pc-80f4925f] { color:red; } }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("Can include a nested rule within a media rule", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      a {\n        @media screen and (max-width: 450px) {\n          color: red;\n          b {\n            color: orange;\n          }\n        }\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>@media screen and (max-width: 450px) { a[data-pc-80f4925f] b[data-pc-80f4925f] { color:orange; } a[data-pc-80f4925f] { color:red; } }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("Can define a selector mixin with @content", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      @mixin div {\n        div {\n          @content;\n        }\n      }\n\n      @include div {\n        color: red;\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>div[data-pc-80f4925f] { color:red; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("Can include @content with a rule", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      @mixin desktop {\n        a {\n          @content;\n        }\n      }\n\n      @include desktop {\n        b {\n          color: red;\n        }\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>a[data-pc-80f4925f] b[data-pc-80f4925f] { color:red; }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("Can include @content within @media", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      @mixin desktop {\n        @media a {\n          @content;\n        }\n      }\n\n      @include desktop {\n        b {\n          color: red;\n        }\n        c {\n          color: red;\n        }\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>@media a { b[data-pc-80f4925f] { color:red; } c[data-pc-80f4925f] { color:red; } { } }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("can include a media query mixin", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      @mixin desktop {\n        @media screen and (max-width: 400px) {\n          @content;\n        }\n      }\n    \n      .test {\n        font-family: sans-serif;\n        @include desktop {\n          font-size: 40px;\n        }\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>[class]._80f4925f_test { font-family:sans-serif; } @media screen and (max-width: 400px) { [class]._80f4925f_test { font-size:40px; } }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
    it("properly orders include with nested selector", function () { return __awaiter(void 0, void 0, void 0, function () {
        var graph, engine, text, _a;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    graph = {
                        "/entry.pc": "<style>\n      @mixin desktop {\n        @media screen and (max-width: 400px) {\n          @content;\n        }\n      }\n    \n      .test {\n        font-family: sans-serif;\n        .b {\n          color: blue;\n        }\n        @include desktop {\n          .b {\n            font-size: 40px;\n          }\n        }\n      }\n    </style>"
                    };
                    return [4 /*yield*/, utils_1.createMockEngine(graph)];
                case 1:
                    engine = _c.sent();
                    _a = utils_1.stringifyLoadResult;
                    return [4 /*yield*/, engine.run("/entry.pc")];
                case 2:
                    text = _a.apply(void 0, [_c.sent()]);
                    chai_1.expect(text).to.eql("<style>[class]._80f4925f_test { font-family:sans-serif; } [class]._80f4925f_test [class]._80f4925f_b { color:blue; } @media screen and (max-width: 400px) { [class]._80f4925f_test [class]._80f4925f_b { font-size:40px; } [class]._80f4925f_test { } }</style>");
                    return [2 /*return*/];
            }
        });
    }); });
});
