1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | var tslib_1 = require("tslib");
|
---|
4 | var less_error_1 = tslib_1.__importDefault(require("./less-error"));
|
---|
5 | var transform_tree_1 = tslib_1.__importDefault(require("./transform-tree"));
|
---|
6 | var logger_1 = tslib_1.__importDefault(require("./logger"));
|
---|
7 | function default_1(SourceMapBuilder) {
|
---|
8 | var ParseTree = /** @class */ (function () {
|
---|
9 | function ParseTree(root, imports) {
|
---|
10 | this.root = root;
|
---|
11 | this.imports = imports;
|
---|
12 | }
|
---|
13 | ParseTree.prototype.toCSS = function (options) {
|
---|
14 | var evaldRoot;
|
---|
15 | var result = {};
|
---|
16 | var sourceMapBuilder;
|
---|
17 | try {
|
---|
18 | evaldRoot = transform_tree_1.default(this.root, options);
|
---|
19 | }
|
---|
20 | catch (e) {
|
---|
21 | throw new less_error_1.default(e, this.imports);
|
---|
22 | }
|
---|
23 | try {
|
---|
24 | var compress = Boolean(options.compress);
|
---|
25 | if (compress) {
|
---|
26 | logger_1.default.warn('The compress option has been deprecated. ' +
|
---|
27 | 'We recommend you use a dedicated css minifier, for instance see less-plugin-clean-css.');
|
---|
28 | }
|
---|
29 | var toCSSOptions = {
|
---|
30 | compress: compress,
|
---|
31 | dumpLineNumbers: options.dumpLineNumbers,
|
---|
32 | strictUnits: Boolean(options.strictUnits),
|
---|
33 | numPrecision: 8
|
---|
34 | };
|
---|
35 | if (options.sourceMap) {
|
---|
36 | sourceMapBuilder = new SourceMapBuilder(options.sourceMap);
|
---|
37 | result.css = sourceMapBuilder.toCSS(evaldRoot, toCSSOptions, this.imports);
|
---|
38 | }
|
---|
39 | else {
|
---|
40 | result.css = evaldRoot.toCSS(toCSSOptions);
|
---|
41 | }
|
---|
42 | }
|
---|
43 | catch (e) {
|
---|
44 | throw new less_error_1.default(e, this.imports);
|
---|
45 | }
|
---|
46 | if (options.pluginManager) {
|
---|
47 | var postProcessors = options.pluginManager.getPostProcessors();
|
---|
48 | for (var i = 0; i < postProcessors.length; i++) {
|
---|
49 | result.css = postProcessors[i].process(result.css, { sourceMap: sourceMapBuilder, options: options, imports: this.imports });
|
---|
50 | }
|
---|
51 | }
|
---|
52 | if (options.sourceMap) {
|
---|
53 | result.map = sourceMapBuilder.getExternalSourceMap();
|
---|
54 | }
|
---|
55 | result.imports = [];
|
---|
56 | for (var file in this.imports.files) {
|
---|
57 | if (this.imports.files.hasOwnProperty(file) && file !== this.imports.rootFilename) {
|
---|
58 | result.imports.push(file);
|
---|
59 | }
|
---|
60 | }
|
---|
61 | return result;
|
---|
62 | };
|
---|
63 | return ParseTree;
|
---|
64 | }());
|
---|
65 | return ParseTree;
|
---|
66 | }
|
---|
67 | exports.default = default_1;
|
---|
68 | ;
|
---|
69 | //# sourceMappingURL=parse-tree.js.map |
---|