less 4.5.1 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lessc +37 -23
- package/dist/less.js +14497 -11745
- package/dist/less.min.js +4 -4
- package/dist/less.min.js.map +1 -1
- package/lib/less/constants.js +5 -7
- package/lib/less/contexts.js +71 -55
- package/lib/less/data/colors.js +150 -153
- package/lib/less/data/index.js +4 -7
- package/lib/less/data/unit-conversions.js +2 -5
- package/lib/less/default-options.js +36 -26
- package/lib/less/deprecation.js +67 -0
- package/lib/less/environment/abstract-file-manager.js +62 -50
- package/lib/less/environment/abstract-plugin-loader.js +69 -46
- package/lib/less/environment/environment-api.ts +21 -0
- package/lib/less/environment/environment.js +34 -30
- package/lib/less/environment/file-manager-api.ts +77 -0
- package/lib/less/functions/boolean.js +13 -13
- package/lib/less/functions/color-blending.js +39 -31
- package/lib/less/functions/color.js +153 -137
- package/lib/less/functions/data-uri.js +73 -64
- package/lib/less/functions/default.js +9 -11
- package/lib/less/functions/function-caller.js +35 -34
- package/lib/less/functions/function-registry.js +16 -17
- package/lib/less/functions/index.js +33 -33
- package/lib/less/functions/list.js +88 -75
- package/lib/less/functions/math-helper.js +8 -11
- package/lib/less/functions/math.js +21 -21
- package/lib/less/functions/number.js +42 -53
- package/lib/less/functions/string.js +18 -22
- package/lib/less/functions/style.js +21 -20
- package/lib/less/functions/svg.js +83 -82
- package/lib/less/functions/types.js +28 -32
- package/lib/less/import-manager.js +73 -64
- package/lib/less/index.js +65 -65
- package/lib/less/less-error.js +63 -45
- package/lib/less/logger.js +11 -14
- package/lib/less/parse-tree.js +52 -53
- package/lib/less/parse.js +44 -44
- package/lib/less/parser/parser-input.js +151 -113
- package/lib/less/parser/parser.js +864 -658
- package/lib/less/plugin-manager.js +57 -46
- package/lib/less/render.js +17 -23
- package/lib/less/source-map-builder.js +52 -43
- package/lib/less/source-map-output.js +56 -43
- package/lib/less/transform-tree.js +40 -30
- package/lib/less/tree/anonymous.js +52 -28
- package/lib/less/tree/assignment.js +44 -27
- package/lib/less/tree/atrule-syntax.js +4 -6
- package/lib/less/tree/atrule.js +247 -140
- package/lib/less/tree/attribute.js +55 -24
- package/lib/less/tree/call.js +70 -42
- package/lib/less/tree/color.js +194 -145
- package/lib/less/tree/combinator.js +31 -21
- package/lib/less/tree/comment.js +44 -23
- package/lib/less/tree/condition.js +61 -36
- package/lib/less/tree/container.js +90 -34
- package/lib/less/tree/debug-info.js +28 -15
- package/lib/less/tree/declaration.js +97 -52
- package/lib/less/tree/detached-ruleset.js +42 -24
- package/lib/less/tree/dimension.js +127 -71
- package/lib/less/tree/element.js +82 -52
- package/lib/less/tree/expression.js +75 -50
- package/lib/less/tree/extend.js +71 -42
- package/lib/less/tree/import.js +184 -110
- package/lib/less/tree/index.js +52 -81
- package/lib/less/tree/javascript.js +43 -32
- package/lib/less/tree/js-eval-node.js +46 -32
- package/lib/less/tree/keyword.js +25 -17
- package/lib/less/tree/media.js +77 -35
- package/lib/less/tree/merge-rules.js +47 -0
- package/lib/less/tree/mixin-call.js +181 -98
- package/lib/less/tree/mixin-definition.js +211 -117
- package/lib/less/tree/namespace-value.js +63 -44
- package/lib/less/tree/negative.js +34 -21
- package/lib/less/tree/nested-at-rule.js +149 -66
- package/lib/less/tree/node.js +225 -90
- package/lib/less/tree/operation.js +59 -34
- package/lib/less/tree/paren.js +34 -17
- package/lib/less/tree/property.js +66 -35
- package/lib/less/tree/query-in-parens.js +52 -60
- package/lib/less/tree/quoted.js +93 -44
- package/lib/less/tree/ruleset.js +632 -318
- package/lib/less/tree/selector.js +151 -77
- package/lib/less/tree/unicode-descriptor.js +14 -12
- package/lib/less/tree/unit.js +111 -63
- package/lib/less/tree/url.js +62 -38
- package/lib/less/tree/value.js +50 -34
- package/lib/less/tree/variable-call.js +47 -30
- package/lib/less/tree/variable.js +53 -31
- package/lib/less/utils.js +44 -47
- package/lib/less/visitors/extend-visitor.js +233 -172
- package/lib/less/visitors/import-sequencer.js +24 -24
- package/lib/less/visitors/import-visitor.js +62 -52
- package/lib/less/visitors/index.js +14 -17
- package/lib/less/visitors/join-selector-visitor.js +40 -37
- package/lib/less/visitors/set-tree-visibility-visitor.js +32 -18
- package/lib/less/visitors/to-css-visitor.js +135 -128
- package/lib/less/visitors/visitor.js +60 -45
- package/lib/less-browser/add-default-options.js +23 -13
- package/lib/less-browser/bootstrap.js +23 -17
- package/lib/less-browser/browser.js +24 -21
- package/lib/less-browser/cache.js +17 -19
- package/lib/less-browser/error-reporting.js +52 -44
- package/lib/less-browser/file-manager.js +52 -42
- package/lib/less-browser/image-size.js +12 -12
- package/lib/less-browser/index.js +131 -105
- package/lib/less-browser/log-listener.js +30 -31
- package/lib/less-browser/plugin-loader.js +10 -10
- package/lib/less-browser/utils.js +19 -21
- package/lib/less-node/environment.js +32 -8
- package/lib/less-node/file-manager.js +62 -45
- package/lib/less-node/fs.js +11 -8
- package/lib/less-node/image-size.js +40 -31
- package/lib/less-node/index.js +28 -19
- package/lib/less-node/lessc-helper.js +20 -21
- package/lib/less-node/plugin-loader.js +35 -27
- package/lib/less-node/url-file-manager.js +33 -31
- package/package.json +25 -18
- package/.eslintignore +0 -6
- package/.eslintrc.js +0 -63
- package/Gruntfile.js +0 -403
- package/bower.json +0 -22
- package/lib/less/constants.js.map +0 -1
- package/lib/less/contexts.js.map +0 -1
- package/lib/less/data/colors.js.map +0 -1
- package/lib/less/data/index.js.map +0 -1
- package/lib/less/data/unit-conversions.js.map +0 -1
- package/lib/less/default-options.js.map +0 -1
- package/lib/less/environment/abstract-file-manager.js.map +0 -1
- package/lib/less/environment/abstract-plugin-loader.js.map +0 -1
- package/lib/less/environment/environment-api.js +0 -3
- package/lib/less/environment/environment-api.js.map +0 -1
- package/lib/less/environment/environment.js.map +0 -1
- package/lib/less/environment/file-manager-api.js +0 -3
- package/lib/less/environment/file-manager-api.js.map +0 -1
- package/lib/less/functions/boolean.js.map +0 -1
- package/lib/less/functions/color-blending.js.map +0 -1
- package/lib/less/functions/color.js.map +0 -1
- package/lib/less/functions/data-uri.js.map +0 -1
- package/lib/less/functions/default.js.map +0 -1
- package/lib/less/functions/function-caller.js.map +0 -1
- package/lib/less/functions/function-registry.js.map +0 -1
- package/lib/less/functions/index.js.map +0 -1
- package/lib/less/functions/list.js.map +0 -1
- package/lib/less/functions/math-helper.js.map +0 -1
- package/lib/less/functions/math.js.map +0 -1
- package/lib/less/functions/number.js.map +0 -1
- package/lib/less/functions/string.js.map +0 -1
- package/lib/less/functions/style.js.map +0 -1
- package/lib/less/functions/svg.js.map +0 -1
- package/lib/less/functions/types.js.map +0 -1
- package/lib/less/import-manager.js.map +0 -1
- package/lib/less/index.js.map +0 -1
- package/lib/less/less-error.js.map +0 -1
- package/lib/less/logger.js.map +0 -1
- package/lib/less/parse-tree.js.map +0 -1
- package/lib/less/parse.js.map +0 -1
- package/lib/less/parser/parser-input.js.map +0 -1
- package/lib/less/parser/parser.js.map +0 -1
- package/lib/less/plugin-manager.js.map +0 -1
- package/lib/less/render.js.map +0 -1
- package/lib/less/source-map-builder.js.map +0 -1
- package/lib/less/source-map-output.js.map +0 -1
- package/lib/less/transform-tree.js.map +0 -1
- package/lib/less/tree/anonymous.js.map +0 -1
- package/lib/less/tree/assignment.js.map +0 -1
- package/lib/less/tree/atrule-syntax.js.map +0 -1
- package/lib/less/tree/atrule.js.map +0 -1
- package/lib/less/tree/attribute.js.map +0 -1
- package/lib/less/tree/call.js.map +0 -1
- package/lib/less/tree/color.js.map +0 -1
- package/lib/less/tree/combinator.js.map +0 -1
- package/lib/less/tree/comment.js.map +0 -1
- package/lib/less/tree/condition.js.map +0 -1
- package/lib/less/tree/container.js.map +0 -1
- package/lib/less/tree/debug-info.js.map +0 -1
- package/lib/less/tree/declaration.js.map +0 -1
- package/lib/less/tree/detached-ruleset.js.map +0 -1
- package/lib/less/tree/dimension.js.map +0 -1
- package/lib/less/tree/element.js.map +0 -1
- package/lib/less/tree/expression.js.map +0 -1
- package/lib/less/tree/extend.js.map +0 -1
- package/lib/less/tree/import.js.map +0 -1
- package/lib/less/tree/index.js.map +0 -1
- package/lib/less/tree/javascript.js.map +0 -1
- package/lib/less/tree/js-eval-node.js.map +0 -1
- package/lib/less/tree/keyword.js.map +0 -1
- package/lib/less/tree/media.js.map +0 -1
- package/lib/less/tree/mixin-call.js.map +0 -1
- package/lib/less/tree/mixin-definition.js.map +0 -1
- package/lib/less/tree/namespace-value.js.map +0 -1
- package/lib/less/tree/negative.js.map +0 -1
- package/lib/less/tree/nested-at-rule.js.map +0 -1
- package/lib/less/tree/node.js.map +0 -1
- package/lib/less/tree/operation.js.map +0 -1
- package/lib/less/tree/paren.js.map +0 -1
- package/lib/less/tree/property.js.map +0 -1
- package/lib/less/tree/query-in-parens.js.map +0 -1
- package/lib/less/tree/quoted.js.map +0 -1
- package/lib/less/tree/ruleset.js.map +0 -1
- package/lib/less/tree/selector.js.map +0 -1
- package/lib/less/tree/unicode-descriptor.js.map +0 -1
- package/lib/less/tree/unit.js.map +0 -1
- package/lib/less/tree/url.js.map +0 -1
- package/lib/less/tree/value.js.map +0 -1
- package/lib/less/tree/variable-call.js.map +0 -1
- package/lib/less/tree/variable.js.map +0 -1
- package/lib/less/utils.js.map +0 -1
- package/lib/less/visitors/extend-visitor.js.map +0 -1
- package/lib/less/visitors/import-sequencer.js.map +0 -1
- package/lib/less/visitors/import-visitor.js.map +0 -1
- package/lib/less/visitors/index.js.map +0 -1
- package/lib/less/visitors/join-selector-visitor.js.map +0 -1
- package/lib/less/visitors/set-tree-visibility-visitor.js.map +0 -1
- package/lib/less/visitors/to-css-visitor.js.map +0 -1
- package/lib/less/visitors/visitor.js.map +0 -1
- package/lib/less-browser/add-default-options.js.map +0 -1
- package/lib/less-browser/bootstrap.js.map +0 -1
- package/lib/less-browser/browser.js.map +0 -1
- package/lib/less-browser/cache.js.map +0 -1
- package/lib/less-browser/error-reporting.js.map +0 -1
- package/lib/less-browser/file-manager.js.map +0 -1
- package/lib/less-browser/image-size.js.map +0 -1
- package/lib/less-browser/index.js.map +0 -1
- package/lib/less-browser/log-listener.js.map +0 -1
- package/lib/less-browser/plugin-loader.js.map +0 -1
- package/lib/less-browser/utils.js.map +0 -1
- package/lib/less-node/environment.js.map +0 -1
- package/lib/less-node/file-manager.js.map +0 -1
- package/lib/less-node/fs.js.map +0 -1
- package/lib/less-node/image-size.js.map +0 -1
- package/lib/less-node/index.js.map +0 -1
- package/lib/less-node/lessc-helper.js.map +0 -1
- package/lib/less-node/plugin-loader.js.map +0 -1
- package/lib/less-node/url-file-manager.js.map +0 -1
- package/scripts/coverage-lines.js +0 -207
- package/scripts/coverage-report.js +0 -158
- package/scripts/postinstall.js +0 -61
- package/test/.eslintrc.json +0 -9
- package/test/README.md +0 -3
- package/test/browser/common.js +0 -251
- package/test/browser/css/global-vars/simple.css +0 -3
- package/test/browser/css/modify-vars/simple.css +0 -8
- package/test/browser/css/plugin/plugin.css +0 -3
- package/test/browser/css/postProcessor/postProcessor.css +0 -4
- package/test/browser/css/relative-urls/urls.css +0 -36
- package/test/browser/css/rewrite-urls/urls.css +0 -36
- package/test/browser/css/rootpath/urls.css +0 -35
- package/test/browser/css/rootpath-relative/urls.css +0 -35
- package/test/browser/css/rootpath-rewrite-urls/urls.css +0 -35
- package/test/browser/css/urls.css +0 -54
- package/test/browser/generator/benchmark.config.js +0 -50
- package/test/browser/generator/generate.js +0 -78
- package/test/browser/generator/runner.config.js +0 -184
- package/test/browser/generator/runner.js +0 -2
- package/test/browser/generator/template.js +0 -104
- package/test/browser/generator/utils.js +0 -14
- package/test/browser/less/console-errors/test-error.less +0 -3
- package/test/browser/less/console-errors/test-error.txt +0 -2
- package/test/browser/less/errors/image-height-error.less +0 -3
- package/test/browser/less/errors/image-height-error.txt +0 -4
- package/test/browser/less/errors/image-size-error.less +0 -3
- package/test/browser/less/errors/image-size-error.txt +0 -4
- package/test/browser/less/errors/image-width-error.less +0 -3
- package/test/browser/less/errors/image-width-error.txt +0 -4
- package/test/browser/less/global-vars/simple.less +0 -3
- package/test/browser/less/imports/urls.less +0 -4
- package/test/browser/less/imports/urls2.less +0 -4
- package/test/browser/less/modify-vars/imports/simple2.less +0 -4
- package/test/browser/less/modify-vars/simple.less +0 -8
- package/test/browser/less/nested-gradient-with-svg-gradient/mixin-consumer.less +0 -5
- package/test/browser/less/nested-gradient-with-svg-gradient/svg-gradient-mixin.less +0 -15
- package/test/browser/less/plugin/plugin.js +0 -4
- package/test/browser/less/plugin/plugin.less +0 -4
- package/test/browser/less/postProcessor/postProcessor.less +0 -4
- package/test/browser/less/relative-urls/urls.less +0 -34
- package/test/browser/less/rewrite-urls/urls.less +0 -34
- package/test/browser/less/rootpath/urls.less +0 -33
- package/test/browser/less/rootpath-relative/urls.less +0 -33
- package/test/browser/less/rootpath-rewrite-urls/urls.less +0 -33
- package/test/browser/less/urls.less +0 -62
- package/test/browser/runner-VisitorPlugin-options.js +0 -3
- package/test/browser/runner-VisitorPlugin.js +0 -3
- package/test/browser/runner-browser-options.js +0 -51
- package/test/browser/runner-browser-spec.js +0 -12
- package/test/browser/runner-console-errors.js +0 -5
- package/test/browser/runner-errors-options.js +0 -6
- package/test/browser/runner-errors-spec.js +0 -3
- package/test/browser/runner-filemanagerPlugin-options.js +0 -5
- package/test/browser/runner-filemanagerPlugin.js +0 -3
- package/test/browser/runner-global-vars-options.js +0 -7
- package/test/browser/runner-global-vars-spec.js +0 -3
- package/test/browser/runner-main-options.js +0 -17
- package/test/browser/runner-main-spec.js +0 -7
- package/test/browser/runner-modify-vars-options.js +0 -5
- package/test/browser/runner-modify-vars-spec.js +0 -33
- package/test/browser/runner-no-js-errors-options.js +0 -4
- package/test/browser/runner-no-js-errors-spec.js +0 -3
- package/test/browser/runner-postProcessorPlugin-options.js +0 -3
- package/test/browser/runner-postProcessorPlugin.js +0 -3
- package/test/browser/runner-preProcessorPlugin-options.js +0 -3
- package/test/browser/runner-preProcessorPlugin.js +0 -3
- package/test/browser/runner-production-options.js +0 -3
- package/test/browser/runner-production-spec.js +0 -5
- package/test/browser/runner-relative-urls-options.js +0 -3
- package/test/browser/runner-relative-urls-spec.js +0 -3
- package/test/browser/runner-rewrite-urls-options.js +0 -3
- package/test/browser/runner-rewrite-urls-spec.js +0 -3
- package/test/browser/runner-rootpath-options.js +0 -3
- package/test/browser/runner-rootpath-relative-options.js +0 -4
- package/test/browser/runner-rootpath-relative-spec.js +0 -3
- package/test/browser/runner-rootpath-rewrite-urls-options.js +0 -4
- package/test/browser/runner-rootpath-rewrite-urls-spec.js +0 -3
- package/test/browser/runner-rootpath-spec.js +0 -3
- package/test/browser/runner-strict-units-options.js +0 -5
- package/test/browser/runner-strict-units-spec.js +0 -3
- package/test/index.js +0 -307
- package/test/less-test.js +0 -984
- package/test/mocha-playwright/runner.js +0 -210
- package/test/modify-vars.js +0 -28
- package/test/plugins/filemanager/index.js +0 -19
- package/test/plugins/postprocess/index.js +0 -14
- package/test/plugins/preprocess/index.js +0 -19
- package/test/plugins/visitor/index.js +0 -24
- package/test/sourcemaps/basic.json +0 -1
- package/test/sourcemaps/comprehensive.json +0 -1
- package/test/sourcemaps/custom-props.json +0 -1
- package/test/sourcemaps/index.html +0 -17
- package/test/sourcemaps/sourcemaps-basepath.json +0 -1
- package/test/sourcemaps/sourcemaps-include-source.json +0 -1
- package/test/sourcemaps/sourcemaps-rootpath.json +0 -1
- package/test/sourcemaps/sourcemaps-url.json +0 -1
- package/test/sourcemaps-disable-annotation/basic.json +0 -1
- package/test/sourcemaps-variable-selector/basic.json +0 -1
- package/test/test-es6.ts +0 -17
- package/test.less +0 -1
- package/tsconfig.build.json +0 -7
- package/tsconfig.json +0 -21
package/lib/less/tree/extend.js
CHANGED
|
@@ -1,46 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, TreeVisitor, FileInfo, VisibilityInfo } from './node.js' */
|
|
3
|
+
import Node from './node.js';
|
|
4
|
+
import Selector from './selector.js';
|
|
5
|
+
|
|
6
|
+
class Extend extends Node {
|
|
7
|
+
get type() { return 'Extend'; }
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {Selector} selector
|
|
11
|
+
* @param {string} option
|
|
12
|
+
* @param {number} index
|
|
13
|
+
* @param {FileInfo} currentFileInfo
|
|
14
|
+
* @param {VisibilityInfo} [visibilityInfo]
|
|
15
|
+
*/
|
|
16
|
+
constructor(selector, option, index, currentFileInfo, visibilityInfo) {
|
|
17
|
+
super();
|
|
18
|
+
this.selector = selector;
|
|
19
|
+
this.option = option;
|
|
20
|
+
this.object_id = Extend.next_id++;
|
|
21
|
+
/** @type {number[]} */
|
|
22
|
+
this.parent_ids = [this.object_id];
|
|
23
|
+
this._index = index;
|
|
24
|
+
this._fileInfo = currentFileInfo;
|
|
25
|
+
this.copyVisibilityInfo(visibilityInfo);
|
|
26
|
+
/** @type {boolean} */
|
|
27
|
+
this.allowRoot = true;
|
|
28
|
+
/** @type {boolean} */
|
|
29
|
+
this.allowBefore = false;
|
|
30
|
+
/** @type {boolean} */
|
|
31
|
+
this.allowAfter = false;
|
|
32
|
+
|
|
33
|
+
switch (option) {
|
|
34
|
+
case '!all':
|
|
35
|
+
case 'all':
|
|
36
|
+
this.allowBefore = true;
|
|
37
|
+
this.allowAfter = true;
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
this.allowBefore = false;
|
|
41
|
+
this.allowAfter = false;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
this.setParent(this.selector, this);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @param {TreeVisitor} visitor */
|
|
48
|
+
accept(visitor) {
|
|
49
|
+
this.selector = /** @type {Selector} */ (visitor.visit(this.selector));
|
|
25
50
|
}
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
eval: function (context) {
|
|
34
|
-
return new Extend(this.selector.eval(context), this.option, this.getIndex(), this.fileInfo(), this.visibilityInfo());
|
|
35
|
-
},
|
|
51
|
+
|
|
52
|
+
/** @param {EvalContext} context */
|
|
53
|
+
eval(context) {
|
|
54
|
+
return new Extend(/** @type {Selector} */ (this.selector.eval(context)), this.option, this.getIndex(), this.fileInfo(), this.visibilityInfo());
|
|
55
|
+
}
|
|
56
|
+
|
|
36
57
|
// remove when Nodes have JSDoc types
|
|
37
58
|
// eslint-disable-next-line no-unused-vars
|
|
38
|
-
|
|
59
|
+
/** @param {EvalContext} [context] */
|
|
60
|
+
clone(context) {
|
|
39
61
|
return new Extend(this.selector, this.option, this.getIndex(), this.fileInfo(), this.visibilityInfo());
|
|
40
|
-
}
|
|
62
|
+
}
|
|
63
|
+
|
|
41
64
|
// it concatenates (joins) all selectors in selector array
|
|
42
|
-
|
|
43
|
-
|
|
65
|
+
/** @param {Selector[]} selectors */
|
|
66
|
+
findSelfSelectors(selectors) {
|
|
67
|
+
/** @type {import('./element.js').default[]} */
|
|
68
|
+
let selfElements = [];
|
|
69
|
+
let i, selectorElements;
|
|
70
|
+
|
|
44
71
|
for (i = 0; i < selectors.length; i++) {
|
|
45
72
|
selectorElements = selectors[i].elements;
|
|
46
73
|
// duplicate the logic in genCSS function inside the selector node.
|
|
@@ -50,10 +77,12 @@ Extend.prototype = Object.assign(new node_1.default(), {
|
|
|
50
77
|
}
|
|
51
78
|
selfElements = selfElements.concat(selectors[i].elements);
|
|
52
79
|
}
|
|
53
|
-
|
|
80
|
+
|
|
81
|
+
/** @type {Selector[]} */
|
|
82
|
+
this.selfSelectors = [new Selector(selfElements)];
|
|
54
83
|
this.selfSelectors[0].copyVisibilityInfo(this.visibilityInfo());
|
|
55
84
|
}
|
|
56
|
-
}
|
|
85
|
+
}
|
|
86
|
+
|
|
57
87
|
Extend.next_id = 0;
|
|
58
|
-
|
|
59
|
-
//# sourceMappingURL=extend.js.map
|
|
88
|
+
export default Extend;
|
package/lib/less/tree/import.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, CSSOutput, TreeVisitor, FileInfo, VisibilityInfo } from './node.js' */
|
|
3
|
+
import Node from './node.js';
|
|
4
|
+
import Media from './media.js';
|
|
5
|
+
import URL from './url.js';
|
|
6
|
+
import Quoted from './quoted.js';
|
|
7
|
+
import Ruleset from './ruleset.js';
|
|
8
|
+
import Anonymous from './anonymous.js';
|
|
9
|
+
import Expression from './expression.js';
|
|
10
|
+
import * as utils from '../utils.js';
|
|
11
|
+
import LessError from '../less-error.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {object} ImportOptions
|
|
15
|
+
* @property {boolean} [less]
|
|
16
|
+
* @property {boolean} [inline]
|
|
17
|
+
* @property {boolean} [isPlugin]
|
|
18
|
+
* @property {boolean} [reference]
|
|
19
|
+
*/
|
|
20
|
+
|
|
13
21
|
//
|
|
14
22
|
// CSS @import node
|
|
15
23
|
//
|
|
@@ -22,38 +30,73 @@ var expression_1 = tslib_1.__importDefault(require("./expression"));
|
|
|
22
30
|
// `import,push`, we also pass it a callback, which it'll call once
|
|
23
31
|
// the file has been fetched, and parsed.
|
|
24
32
|
//
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
class Import extends Node {
|
|
34
|
+
get type() { return 'Import'; }
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {Node} path
|
|
38
|
+
* @param {Node | null} features
|
|
39
|
+
* @param {ImportOptions} options
|
|
40
|
+
* @param {number} index
|
|
41
|
+
* @param {FileInfo} [currentFileInfo]
|
|
42
|
+
* @param {VisibilityInfo} [visibilityInfo]
|
|
43
|
+
*/
|
|
44
|
+
constructor(path, features, options, index, currentFileInfo, visibilityInfo) {
|
|
45
|
+
super();
|
|
46
|
+
/** @type {ImportOptions} */
|
|
47
|
+
this.options = options;
|
|
48
|
+
this._index = index;
|
|
49
|
+
this._fileInfo = currentFileInfo;
|
|
50
|
+
this.path = path;
|
|
51
|
+
/** @type {Node | null} */
|
|
52
|
+
this.features = features;
|
|
53
|
+
/** @type {boolean} */
|
|
54
|
+
this.allowRoot = true;
|
|
55
|
+
|
|
56
|
+
/** @type {boolean | undefined} */
|
|
57
|
+
this.css = undefined;
|
|
58
|
+
/** @type {boolean | undefined} */
|
|
59
|
+
this.layerCss = undefined;
|
|
60
|
+
/** @type {(Ruleset & { imports?: object, filename?: string, functions?: object, functionRegistry?: { addMultiple: (fns: object) => void } }) | undefined} */
|
|
61
|
+
this.root = undefined;
|
|
62
|
+
/** @type {string | undefined} */
|
|
63
|
+
this.importedFilename = undefined;
|
|
64
|
+
/** @type {boolean | (() => boolean) | undefined} */
|
|
65
|
+
this.skip = undefined;
|
|
66
|
+
/** @type {{ message: string, index: number, filename: string } | undefined} */
|
|
67
|
+
this.error = undefined;
|
|
68
|
+
|
|
69
|
+
if (this.options.less !== undefined || this.options.inline) {
|
|
70
|
+
this.css = !this.options.less || this.options.inline;
|
|
71
|
+
} else {
|
|
72
|
+
const pathValue = this.getPath();
|
|
73
|
+
if (pathValue && /[#.&?]css([?;].*)?$/.test(pathValue)) {
|
|
74
|
+
this.css = true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
this.copyVisibilityInfo(visibilityInfo);
|
|
78
|
+
if (this.features) {
|
|
79
|
+
this.setParent(this.features, /** @type {Node} */ (this));
|
|
39
80
|
}
|
|
81
|
+
this.setParent(this.path, /** @type {Node} */ (this));
|
|
40
82
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
45
|
-
Import.prototype = Object.assign(new node_1.default(), {
|
|
46
|
-
type: 'Import',
|
|
47
|
-
accept: function (visitor) {
|
|
83
|
+
|
|
84
|
+
/** @param {TreeVisitor} visitor */
|
|
85
|
+
accept(visitor) {
|
|
48
86
|
if (this.features) {
|
|
49
87
|
this.features = visitor.visit(this.features);
|
|
50
88
|
}
|
|
51
89
|
this.path = visitor.visit(this.path);
|
|
52
90
|
if (!this.options.isPlugin && !this.options.inline && this.root) {
|
|
53
|
-
this.root = visitor.visit(this.root);
|
|
91
|
+
this.root = /** @type {Ruleset} */ (visitor.visit(this.root));
|
|
54
92
|
}
|
|
55
|
-
}
|
|
56
|
-
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @param {EvalContext} context
|
|
97
|
+
* @param {CSSOutput} output
|
|
98
|
+
*/
|
|
99
|
+
genCSS(context, output) {
|
|
57
100
|
if (this.css && this.path._fileInfo.reference === undefined) {
|
|
58
101
|
output.add('@import ', this._fileInfo, this._index);
|
|
59
102
|
this.path.genCSS(context, output);
|
|
@@ -63,79 +106,105 @@ Import.prototype = Object.assign(new node_1.default(), {
|
|
|
63
106
|
}
|
|
64
107
|
output.add(';');
|
|
65
108
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** @returns {string | undefined} */
|
|
112
|
+
getPath() {
|
|
113
|
+
return (this.path instanceof URL) ?
|
|
114
|
+
/** @type {string} */ (/** @type {Node} */ (this.path.value).value) :
|
|
115
|
+
/** @type {string | undefined} */ (this.path.value);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** @returns {boolean | RegExpMatchArray | null} */
|
|
119
|
+
isVariableImport() {
|
|
120
|
+
let path = this.path;
|
|
121
|
+
if (path instanceof URL) {
|
|
122
|
+
path = /** @type {Node} */ (path.value);
|
|
75
123
|
}
|
|
76
|
-
if (path instanceof
|
|
124
|
+
if (path instanceof Quoted) {
|
|
77
125
|
return path.containsVariables();
|
|
78
126
|
}
|
|
127
|
+
|
|
79
128
|
return true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** @param {EvalContext} context */
|
|
132
|
+
evalForImport(context) {
|
|
133
|
+
let path = this.path;
|
|
134
|
+
|
|
135
|
+
if (path instanceof URL) {
|
|
136
|
+
path = /** @type {Node} */ (path.value);
|
|
85
137
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
138
|
+
|
|
139
|
+
return new Import(path.eval(context), this.features, this.options, this._index || 0, this._fileInfo, this.visibilityInfo());
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** @param {EvalContext} context */
|
|
143
|
+
evalPath(context) {
|
|
144
|
+
const path = this.path.eval(context);
|
|
145
|
+
const fileInfo = this._fileInfo;
|
|
146
|
+
|
|
147
|
+
if (!(path instanceof URL)) {
|
|
92
148
|
// Add the rootpath if the URL requires a rewrite
|
|
93
|
-
|
|
149
|
+
const pathValue = /** @type {string} */ (path.value);
|
|
94
150
|
if (fileInfo &&
|
|
95
151
|
pathValue &&
|
|
96
152
|
context.pathRequiresRewrite(pathValue)) {
|
|
97
153
|
path.value = context.rewritePath(pathValue, fileInfo.rootpath);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
path.value = context.normalizePath(path.value);
|
|
154
|
+
} else {
|
|
155
|
+
path.value = context.normalizePath(/** @type {string} */ (path.value));
|
|
101
156
|
}
|
|
102
157
|
}
|
|
158
|
+
|
|
103
159
|
return path;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** @param {EvalContext} context */
|
|
163
|
+
// @ts-ignore - Import.eval returns Node | Node[] | Import (wider than Node.eval's Node return)
|
|
164
|
+
eval(context) {
|
|
165
|
+
const result = this.doEval(context);
|
|
107
166
|
if (this.options.reference || this.blocksVisibility()) {
|
|
108
|
-
if (
|
|
167
|
+
if (Array.isArray(result)) {
|
|
109
168
|
result.forEach(function (node) {
|
|
110
169
|
node.addVisibilityBlock();
|
|
111
170
|
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
result.addVisibilityBlock();
|
|
171
|
+
} else {
|
|
172
|
+
/** @type {Node} */ (result).addVisibilityBlock();
|
|
115
173
|
}
|
|
116
174
|
}
|
|
117
175
|
return result;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** @param {EvalContext} context */
|
|
179
|
+
doEval(context) {
|
|
180
|
+
/** @type {Ruleset | undefined} */
|
|
181
|
+
let ruleset;
|
|
182
|
+
const features = this.features && this.features.eval(context);
|
|
183
|
+
|
|
123
184
|
if (this.options.isPlugin) {
|
|
124
185
|
if (this.root && this.root.eval) {
|
|
125
186
|
try {
|
|
126
187
|
this.root.eval(context);
|
|
127
188
|
}
|
|
128
189
|
catch (e) {
|
|
129
|
-
|
|
130
|
-
|
|
190
|
+
const err = /** @type {{ message: string }} */ (e);
|
|
191
|
+
err.message = 'Plugin error during evaluation';
|
|
192
|
+
throw new LessError(
|
|
193
|
+
/** @type {{ message: string, index?: number, filename?: string }} */ (e),
|
|
194
|
+
/** @type {{ imports: object }} */ (/** @type {unknown} */ (this.root)).imports,
|
|
195
|
+
/** @type {{ filename: string }} */ (/** @type {unknown} */ (this.root)).filename
|
|
196
|
+
);
|
|
131
197
|
}
|
|
132
198
|
}
|
|
133
|
-
|
|
199
|
+
const frame0 = /** @type {Ruleset & { functionRegistry?: { addMultiple: (fns: object) => void } }} */ (context.frames[0]);
|
|
200
|
+
const registry = frame0 && frame0.functionRegistry;
|
|
134
201
|
if (registry && this.root && this.root.functions) {
|
|
135
202
|
registry.addMultiple(this.root.functions);
|
|
136
203
|
}
|
|
204
|
+
|
|
137
205
|
return [];
|
|
138
206
|
}
|
|
207
|
+
|
|
139
208
|
if (this.skip) {
|
|
140
209
|
if (typeof this.skip === 'function') {
|
|
141
210
|
this.skip = this.skip();
|
|
@@ -145,12 +214,12 @@ Import.prototype = Object.assign(new node_1.default(), {
|
|
|
145
214
|
}
|
|
146
215
|
}
|
|
147
216
|
if (this.features) {
|
|
148
|
-
|
|
217
|
+
let featureValue = /** @type {Node[]} */ (this.features.value);
|
|
149
218
|
if (Array.isArray(featureValue) && featureValue.length >= 1) {
|
|
150
|
-
|
|
151
|
-
if (expr.type === 'Expression' && Array.isArray(expr.value) && expr.value.length >= 2) {
|
|
152
|
-
featureValue = expr.value;
|
|
153
|
-
|
|
219
|
+
const expr = featureValue[0];
|
|
220
|
+
if (expr.type === 'Expression' && Array.isArray(expr.value) && /** @type {Node[]} */ (expr.value).length >= 2) {
|
|
221
|
+
featureValue = /** @type {Node[]} */ (expr.value);
|
|
222
|
+
const isLayer = featureValue[0].type === 'Keyword' && featureValue[0].value === 'layer'
|
|
154
223
|
&& featureValue[1].type === 'Paren';
|
|
155
224
|
if (isLayer) {
|
|
156
225
|
this.css = false;
|
|
@@ -159,14 +228,20 @@ Import.prototype = Object.assign(new node_1.default(), {
|
|
|
159
228
|
}
|
|
160
229
|
}
|
|
161
230
|
if (this.options.inline) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
231
|
+
const contents = new Anonymous(
|
|
232
|
+
/** @type {string} */ (/** @type {unknown} */ (this.root)),
|
|
233
|
+
0,
|
|
234
|
+
{
|
|
235
|
+
filename: this.importedFilename,
|
|
236
|
+
reference: this.path._fileInfo && this.path._fileInfo.reference
|
|
237
|
+
},
|
|
238
|
+
true,
|
|
239
|
+
true
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
return this.features ? new Media([contents], /** @type {Node[]} */ (this.features.value)) : [contents];
|
|
243
|
+
} else if (this.css || this.layerCss) {
|
|
244
|
+
const newImport = new Import(this.evalPath(context), features, this.options, this._index || 0);
|
|
170
245
|
if (this.layerCss) {
|
|
171
246
|
newImport.css = this.layerCss;
|
|
172
247
|
newImport.path._fileInfo = this._fileInfo;
|
|
@@ -175,43 +250,42 @@ Import.prototype = Object.assign(new node_1.default(), {
|
|
|
175
250
|
throw this.error;
|
|
176
251
|
}
|
|
177
252
|
return newImport;
|
|
178
|
-
}
|
|
179
|
-
else if (this.root) {
|
|
253
|
+
} else if (this.root) {
|
|
180
254
|
if (this.features) {
|
|
181
|
-
|
|
255
|
+
let featureValue = /** @type {Node[]} */ (this.features.value);
|
|
182
256
|
if (Array.isArray(featureValue) && featureValue.length === 1) {
|
|
183
|
-
|
|
184
|
-
if (expr.type === 'Expression' && Array.isArray(expr.value) && expr.value.length >= 2) {
|
|
185
|
-
featureValue = expr.value;
|
|
186
|
-
|
|
257
|
+
const expr = featureValue[0];
|
|
258
|
+
if (expr.type === 'Expression' && Array.isArray(expr.value) && /** @type {Node[]} */ (expr.value).length >= 2) {
|
|
259
|
+
featureValue = /** @type {Node[]} */ (expr.value);
|
|
260
|
+
const isLayer = featureValue[0].type === 'Keyword' && featureValue[0].value === 'layer'
|
|
187
261
|
&& featureValue[1].type === 'Paren';
|
|
188
262
|
if (isLayer) {
|
|
189
263
|
this.layerCss = true;
|
|
190
|
-
featureValue[0] = new
|
|
264
|
+
featureValue[0] = new Expression(/** @type {Node[]} */ (featureValue.slice(0, 2)));
|
|
191
265
|
featureValue.splice(1, 1);
|
|
192
|
-
featureValue[0].noSpacing = true;
|
|
266
|
+
/** @type {Expression} */ (featureValue[0]).noSpacing = true;
|
|
193
267
|
return this;
|
|
194
268
|
}
|
|
195
269
|
}
|
|
196
270
|
}
|
|
197
271
|
}
|
|
198
|
-
ruleset = new
|
|
272
|
+
ruleset = new Ruleset(null, utils.copyArray(this.root.rules));
|
|
199
273
|
ruleset.evalImports(context);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
else {
|
|
274
|
+
|
|
275
|
+
return this.features ? new Media(ruleset.rules, /** @type {Node[]} */ (this.features.value)) : ruleset.rules;
|
|
276
|
+
} else {
|
|
203
277
|
if (this.features) {
|
|
204
|
-
|
|
278
|
+
let featureValue = /** @type {Node[]} */ (this.features.value);
|
|
205
279
|
if (Array.isArray(featureValue) && featureValue.length >= 1) {
|
|
206
|
-
featureValue = featureValue[0].value;
|
|
280
|
+
featureValue = /** @type {Node[]} */ (featureValue[0].value);
|
|
207
281
|
if (Array.isArray(featureValue) && featureValue.length >= 2) {
|
|
208
|
-
|
|
282
|
+
const isLayer = featureValue[0].type === 'Keyword' && featureValue[0].value === 'layer'
|
|
209
283
|
&& featureValue[1].type === 'Paren';
|
|
210
284
|
if (isLayer) {
|
|
211
285
|
this.css = true;
|
|
212
|
-
featureValue[0] = new
|
|
286
|
+
featureValue[0] = new Expression(/** @type {Node[]} */ (featureValue.slice(0, 2)));
|
|
213
287
|
featureValue.splice(1, 1);
|
|
214
|
-
featureValue[0].noSpacing = true;
|
|
288
|
+
/** @type {Expression} */ (featureValue[0]).noSpacing = true;
|
|
215
289
|
return this;
|
|
216
290
|
}
|
|
217
291
|
}
|
|
@@ -220,6 +294,6 @@ Import.prototype = Object.assign(new node_1.default(), {
|
|
|
220
294
|
return [];
|
|
221
295
|
}
|
|
222
296
|
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export default Import;
|