less 4.5.1 → 4.6.1
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/README.md +70 -5
- package/bin/lessc +37 -23
- package/dist/less.js +14501 -11745
- package/dist/less.min.js +4 -4
- package/dist/less.min.js.map +1 -1
- package/index.cjs +41 -0
- 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 +29 -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
|
@@ -1,46 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, CSSOutput, TreeVisitor } from './node.js' */
|
|
3
|
+
import Node from './node.js';
|
|
4
|
+
import Color from './color.js';
|
|
5
|
+
import Dimension from './dimension.js';
|
|
6
|
+
import * as Constants from '../constants.js';
|
|
7
|
+
const MATH = Constants.Math;
|
|
8
|
+
|
|
9
|
+
class Operation extends Node {
|
|
10
|
+
get type() { return 'Operation'; }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} op
|
|
14
|
+
* @param {Node[]} operands
|
|
15
|
+
* @param {boolean} isSpaced
|
|
16
|
+
*/
|
|
17
|
+
constructor(op, operands, isSpaced) {
|
|
18
|
+
super();
|
|
19
|
+
this.op = op.trim();
|
|
20
|
+
this.operands = operands;
|
|
21
|
+
this.isSpaced = isSpaced;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @param {TreeVisitor} visitor */
|
|
25
|
+
accept(visitor) {
|
|
17
26
|
this.operands = visitor.visitArray(this.operands);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {EvalContext} context
|
|
31
|
+
* @returns {Node}
|
|
32
|
+
*/
|
|
33
|
+
eval(context) {
|
|
34
|
+
let a = this.operands[0].eval(context), b = this.operands[1].eval(context), op;
|
|
35
|
+
|
|
21
36
|
if (context.isMathOn(this.op)) {
|
|
22
37
|
op = this.op === './' ? '/' : this.op;
|
|
23
|
-
if (a instanceof
|
|
24
|
-
a = a.toColor();
|
|
38
|
+
if (a instanceof Dimension && b instanceof Color) {
|
|
39
|
+
a = /** @type {Dimension} */ (a).toColor();
|
|
25
40
|
}
|
|
26
|
-
if (b instanceof
|
|
27
|
-
b = b.toColor();
|
|
41
|
+
if (b instanceof Dimension && a instanceof Color) {
|
|
42
|
+
b = /** @type {Dimension} */ (b).toColor();
|
|
28
43
|
}
|
|
29
|
-
if (
|
|
30
|
-
if (
|
|
31
|
-
|
|
44
|
+
if (!/** @type {Dimension | Color} */ (a).operate || !/** @type {Dimension | Color} */ (b).operate) {
|
|
45
|
+
if (
|
|
46
|
+
(a instanceof Operation || b instanceof Operation)
|
|
47
|
+
&& /** @type {Operation} */ (a).op === '/' && context.math === MATH.PARENS_DIVISION
|
|
48
|
+
) {
|
|
32
49
|
return new Operation(this.op, [a, b], this.isSpaced);
|
|
33
50
|
}
|
|
34
51
|
throw { type: 'Operation',
|
|
35
52
|
message: 'Operation on an invalid type' };
|
|
36
53
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
54
|
+
|
|
55
|
+
if (a instanceof Dimension) {
|
|
56
|
+
return a.operate(context, op, /** @type {Dimension} */ (b));
|
|
57
|
+
}
|
|
58
|
+
return /** @type {Color} */ (a).operate(context, op, /** @type {Color} */ (b));
|
|
59
|
+
} else {
|
|
40
60
|
return new Operation(this.op, [a, b], this.isSpaced);
|
|
41
61
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {EvalContext} context
|
|
66
|
+
* @param {CSSOutput} output
|
|
67
|
+
*/
|
|
68
|
+
genCSS(context, output) {
|
|
44
69
|
this.operands[0].genCSS(context, output);
|
|
45
70
|
if (this.isSpaced) {
|
|
46
71
|
output.add(' ');
|
|
@@ -51,6 +76,6 @@ Operation.prototype = Object.assign(new node_1.default(), {
|
|
|
51
76
|
}
|
|
52
77
|
this.operands[1].genCSS(context, output);
|
|
53
78
|
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default Operation;
|
package/lib/less/tree/paren.js
CHANGED
|
@@ -1,24 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, CSSOutput } from './node.js' */
|
|
3
|
+
import Node from './node.js';
|
|
4
|
+
|
|
5
|
+
class Paren extends Node {
|
|
6
|
+
get type() { return 'Paren'; }
|
|
7
|
+
|
|
8
|
+
/** @param {Node} node */
|
|
9
|
+
constructor(node) {
|
|
10
|
+
super();
|
|
11
|
+
this.value = node;
|
|
12
|
+
/** @type {boolean | undefined} */
|
|
13
|
+
this.noSpacing = undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {EvalContext} context
|
|
18
|
+
* @param {CSSOutput} output
|
|
19
|
+
*/
|
|
20
|
+
genCSS(context, output) {
|
|
11
21
|
output.add('(');
|
|
12
|
-
this.value.genCSS(context, output);
|
|
22
|
+
/** @type {Node} */ (this.value).genCSS(context, output);
|
|
13
23
|
output.add(')');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {EvalContext} context
|
|
28
|
+
* @returns {Paren}
|
|
29
|
+
*/
|
|
30
|
+
eval(context) {
|
|
31
|
+
const paren = new Paren(/** @type {Node} */ (this.value).eval(context));
|
|
32
|
+
|
|
17
33
|
if (this.noSpacing) {
|
|
18
34
|
paren.noSpacing = true;
|
|
19
35
|
}
|
|
36
|
+
|
|
20
37
|
return paren;
|
|
21
38
|
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default Paren;
|
|
@@ -1,39 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, FileInfo } from './node.js' */
|
|
3
|
+
import Node from './node.js';
|
|
4
|
+
import Declaration from './declaration.js';
|
|
5
|
+
import Ruleset from './ruleset.js';
|
|
6
|
+
|
|
7
|
+
class Property extends Node {
|
|
8
|
+
get type() { return 'Property'; }
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} name
|
|
12
|
+
* @param {number} index
|
|
13
|
+
* @param {FileInfo} currentFileInfo
|
|
14
|
+
*/
|
|
15
|
+
constructor(name, index, currentFileInfo) {
|
|
16
|
+
super();
|
|
17
|
+
this.name = name;
|
|
18
|
+
this._index = index;
|
|
19
|
+
this._fileInfo = currentFileInfo;
|
|
20
|
+
/** @type {boolean | undefined} */
|
|
21
|
+
this.evaluating = undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {EvalContext} context
|
|
26
|
+
* @returns {Node}
|
|
27
|
+
*/
|
|
28
|
+
eval(context) {
|
|
29
|
+
let property;
|
|
30
|
+
const name = this.name;
|
|
16
31
|
// TODO: shorten this reference
|
|
17
|
-
|
|
32
|
+
const mergeRules = /** @type {{ less: { visitors: { ToCSSVisitor: { prototype: { _mergeRules: (rules: Declaration[]) => void } } } } }} */ (context.pluginManager).less.visitors.ToCSSVisitor.prototype._mergeRules;
|
|
33
|
+
|
|
18
34
|
if (this.evaluating) {
|
|
19
35
|
throw { type: 'Name',
|
|
20
|
-
message:
|
|
36
|
+
message: `Recursive property reference for ${name}`,
|
|
21
37
|
filename: this.fileInfo().filename,
|
|
22
38
|
index: this.getIndex() };
|
|
23
39
|
}
|
|
40
|
+
|
|
24
41
|
this.evaluating = true;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
42
|
+
|
|
43
|
+
property = this.find(context.frames, function (/** @type {Node} */ frame) {
|
|
44
|
+
let v;
|
|
45
|
+
const vArr = /** @type {Ruleset} */ (frame).property(name);
|
|
28
46
|
if (vArr) {
|
|
29
|
-
for (
|
|
47
|
+
for (let i = 0; i < vArr.length; i++) {
|
|
30
48
|
v = vArr[i];
|
|
31
|
-
|
|
49
|
+
|
|
50
|
+
vArr[i] = new Declaration(v.name,
|
|
51
|
+
v.value,
|
|
52
|
+
v.important,
|
|
53
|
+
v.merge,
|
|
54
|
+
v.index,
|
|
55
|
+
v.currentFileInfo,
|
|
56
|
+
v.inline,
|
|
57
|
+
v.variable
|
|
58
|
+
);
|
|
32
59
|
}
|
|
33
60
|
mergeRules(vArr);
|
|
61
|
+
|
|
34
62
|
v = vArr[vArr.length - 1];
|
|
35
63
|
if (v.important) {
|
|
36
|
-
|
|
64
|
+
const importantScope = context.importantScope[context.importantScope.length - 1];
|
|
37
65
|
importantScope.important = v.important;
|
|
38
66
|
}
|
|
39
67
|
v = v.value.eval(context);
|
|
@@ -43,23 +71,26 @@ Property.prototype = Object.assign(new node_1.default(), {
|
|
|
43
71
|
if (property) {
|
|
44
72
|
this.evaluating = false;
|
|
45
73
|
return property;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
74
|
+
} else {
|
|
48
75
|
throw { type: 'Name',
|
|
49
|
-
message:
|
|
76
|
+
message: `Property '${name}' is undefined`,
|
|
50
77
|
filename: this.currentFileInfo.filename,
|
|
51
78
|
index: this.index };
|
|
52
79
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {Node[]} obj
|
|
84
|
+
* @param {(frame: Node) => Node | undefined} fun
|
|
85
|
+
* @returns {Node | null}
|
|
86
|
+
*/
|
|
87
|
+
find(obj, fun) {
|
|
88
|
+
for (let i = 0, r; i < obj.length; i++) {
|
|
56
89
|
r = fun.call(obj, obj[i]);
|
|
57
|
-
if (r) {
|
|
58
|
-
return r;
|
|
59
|
-
}
|
|
90
|
+
if (r) { return r; }
|
|
60
91
|
}
|
|
61
92
|
return null;
|
|
62
93
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default Property;
|
|
@@ -1,72 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, CSSOutput, TreeVisitor } from './node.js' */
|
|
3
|
+
import Node from './node.js';
|
|
4
|
+
|
|
5
|
+
class QueryInParens extends Node {
|
|
6
|
+
get type() { return 'QueryInParens'; }
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} op
|
|
10
|
+
* @param {Node} l
|
|
11
|
+
* @param {Node} m
|
|
12
|
+
* @param {string | null} op2
|
|
13
|
+
* @param {Node | null} r
|
|
14
|
+
* @param {number} i
|
|
15
|
+
*/
|
|
16
|
+
constructor(op, l, m, op2, r, i) {
|
|
17
|
+
super();
|
|
18
|
+
this.op = op.trim();
|
|
19
|
+
this.lvalue = l;
|
|
20
|
+
this.mvalue = m;
|
|
21
|
+
this.op2 = op2 ? op2.trim() : null;
|
|
22
|
+
/** @type {Node | null} */
|
|
23
|
+
this.rvalue = r;
|
|
24
|
+
this._index = i;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @param {TreeVisitor} visitor */
|
|
28
|
+
accept(visitor) {
|
|
19
29
|
this.lvalue = visitor.visit(this.lvalue);
|
|
20
30
|
this.mvalue = visitor.visit(this.mvalue);
|
|
21
31
|
if (this.rvalue) {
|
|
22
32
|
this.rvalue = visitor.visit(this.rvalue);
|
|
23
33
|
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
if (variableDeclaration) {
|
|
46
|
-
this.mvalue = this.mvalueCopy;
|
|
47
|
-
this.mvalue = this.mvalue.eval(context);
|
|
48
|
-
this.mvalues.push(this.mvalue);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
this.mvalue = this.mvalue.eval(context);
|
|
52
|
-
}
|
|
53
|
-
if (this.rvalue) {
|
|
54
|
-
this.rvalue = this.rvalue.eval(context);
|
|
55
|
-
}
|
|
56
|
-
return this;
|
|
57
|
-
},
|
|
58
|
-
genCSS: function (context, output) {
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** @param {EvalContext} context */
|
|
37
|
+
eval(context) {
|
|
38
|
+
const node = new QueryInParens(
|
|
39
|
+
this.op,
|
|
40
|
+
this.lvalue.eval(context),
|
|
41
|
+
this.mvalue.eval(context),
|
|
42
|
+
this.op2,
|
|
43
|
+
this.rvalue ? this.rvalue.eval(context) : null,
|
|
44
|
+
this._index || 0
|
|
45
|
+
);
|
|
46
|
+
return node;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {EvalContext} context
|
|
51
|
+
* @param {CSSOutput} output
|
|
52
|
+
*/
|
|
53
|
+
genCSS(context, output) {
|
|
59
54
|
this.lvalue.genCSS(context, output);
|
|
60
55
|
output.add(' ' + this.op + ' ');
|
|
61
|
-
if (this.mvalues.length > 0) {
|
|
62
|
-
this.mvalue = this.mvalues.shift();
|
|
63
|
-
}
|
|
64
56
|
this.mvalue.genCSS(context, output);
|
|
65
57
|
if (this.rvalue) {
|
|
66
58
|
output.add(' ' + this.op2 + ' ');
|
|
67
59
|
this.rvalue.genCSS(context, output);
|
|
68
60
|
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default QueryInParens;
|
package/lib/less/tree/quoted.js
CHANGED
|
@@ -1,46 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, CSSOutput, FileInfo } from './node.js' */
|
|
3
|
+
import Node from './node.js';
|
|
4
|
+
import Variable from './variable.js';
|
|
5
|
+
import Property from './property.js';
|
|
6
|
+
|
|
7
|
+
class Quoted extends Node {
|
|
8
|
+
get type() { return 'Quoted'; }
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} str
|
|
12
|
+
* @param {string} [content]
|
|
13
|
+
* @param {boolean} [escaped]
|
|
14
|
+
* @param {number} [index]
|
|
15
|
+
* @param {FileInfo} [currentFileInfo]
|
|
16
|
+
*/
|
|
17
|
+
constructor(str, content, escaped, index, currentFileInfo) {
|
|
18
|
+
super();
|
|
19
|
+
/** @type {boolean} */
|
|
20
|
+
this.escaped = (escaped === undefined) ? true : escaped;
|
|
21
|
+
/** @type {string} */
|
|
22
|
+
this.value = content || '';
|
|
23
|
+
/** @type {string} */
|
|
24
|
+
this.quote = str.charAt(0);
|
|
25
|
+
this._index = index;
|
|
26
|
+
this._fileInfo = currentFileInfo;
|
|
27
|
+
/** @type {RegExp} */
|
|
28
|
+
this.variableRegex = /@\{([\w-]+)\}/g;
|
|
29
|
+
/** @type {RegExp} */
|
|
30
|
+
this.propRegex = /\$\{([\w-]+)\}/g;
|
|
31
|
+
/** @type {boolean | undefined} */
|
|
32
|
+
this.allowRoot = escaped;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {EvalContext} context
|
|
37
|
+
* @param {CSSOutput} output
|
|
38
|
+
*/
|
|
39
|
+
genCSS(context, output) {
|
|
20
40
|
if (!this.escaped) {
|
|
21
41
|
output.add(this.quote, this.fileInfo(), this.getIndex());
|
|
22
42
|
}
|
|
23
|
-
output.add(this.value);
|
|
43
|
+
output.add(/** @type {string} */ (this.value));
|
|
24
44
|
if (!this.escaped) {
|
|
25
45
|
output.add(this.quote);
|
|
26
46
|
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @returns {RegExpMatchArray | null} */
|
|
50
|
+
containsVariables() {
|
|
51
|
+
return /** @type {string} */ (this.value).match(this.variableRegex);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @param {EvalContext} context */
|
|
55
|
+
eval(context) {
|
|
56
|
+
const that = this;
|
|
57
|
+
let value = /** @type {string} */ (this.value);
|
|
58
|
+
/**
|
|
59
|
+
* @param {string} _
|
|
60
|
+
* @param {string} name1
|
|
61
|
+
* @param {string} name2
|
|
62
|
+
* @returns {string}
|
|
63
|
+
*/
|
|
64
|
+
const variableReplacement = function (_, name1, name2) {
|
|
65
|
+
const v = new Variable(`@${name1 ?? name2}`, that.getIndex(), that.fileInfo()).eval(context);
|
|
66
|
+
return (v instanceof Quoted) ? /** @type {string} */ (v.value) : v.toCSS(context);
|
|
37
67
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
68
|
+
/**
|
|
69
|
+
* @param {string} _
|
|
70
|
+
* @param {string} name1
|
|
71
|
+
* @param {string} name2
|
|
72
|
+
* @returns {string}
|
|
73
|
+
*/
|
|
74
|
+
const propertyReplacement = function (_, name1, name2) {
|
|
75
|
+
const v = new Property(`$${name1 ?? name2}`, that.getIndex(), that.fileInfo()).eval(context);
|
|
76
|
+
return (v instanceof Quoted) ? /** @type {string} */ (v.value) : v.toCSS(context);
|
|
41
77
|
};
|
|
78
|
+
/**
|
|
79
|
+
* @param {string} value
|
|
80
|
+
* @param {RegExp} regexp
|
|
81
|
+
* @param {(substring: string, ...args: string[]) => string} replacementFnc
|
|
82
|
+
* @returns {string}
|
|
83
|
+
*/
|
|
42
84
|
function iterativeReplace(value, regexp, replacementFnc) {
|
|
43
|
-
|
|
85
|
+
let evaluatedValue = value;
|
|
44
86
|
do {
|
|
45
87
|
value = evaluatedValue.toString();
|
|
46
88
|
evaluatedValue = value.replace(regexp, replacementFnc);
|
|
@@ -50,16 +92,23 @@ Quoted.prototype = Object.assign(new node_1.default(), {
|
|
|
50
92
|
value = iterativeReplace(value, this.variableRegex, variableReplacement);
|
|
51
93
|
value = iterativeReplace(value, this.propRegex, propertyReplacement);
|
|
52
94
|
return new Quoted(this.quote + value + this.quote, value, this.escaped, this.getIndex(), this.fileInfo());
|
|
53
|
-
}
|
|
54
|
-
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param {Node} other
|
|
99
|
+
* @returns {number | undefined}
|
|
100
|
+
*/
|
|
101
|
+
compare(other) {
|
|
55
102
|
// when comparing quoted strings allow the quote to differ
|
|
56
|
-
if (other.type === 'Quoted' && !this.escaped &&
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
103
|
+
if (other.type === 'Quoted' && !this.escaped && !/** @type {Quoted} */ (other).escaped) {
|
|
104
|
+
return Node.numericCompare(
|
|
105
|
+
/** @type {string} */ (this.value),
|
|
106
|
+
/** @type {string} */ (other.value)
|
|
107
|
+
);
|
|
108
|
+
} else {
|
|
109
|
+
return other.toCSS && this.toCSS(/** @type {EvalContext} */ ({})) === other.toCSS(/** @type {EvalContext} */ ({})) ? 0 : undefined;
|
|
61
110
|
}
|
|
62
111
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default Quoted;
|