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,60 +1,127 @@
|
|
|
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, TreeVisitor, FileInfo } from './node.js' */
|
|
3
|
+
/** @import { FunctionRegistry } from './nested-at-rule.js' */
|
|
4
|
+
import Node from './node.js';
|
|
5
|
+
import Selector from './selector.js';
|
|
6
|
+
import MixinDefinition from './mixin-definition.js';
|
|
7
|
+
import defaultFunc from '../functions/default.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {{ name?: string, value: Node, expand?: boolean }} MixinArg
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {Node & {
|
|
15
|
+
* rules?: Node[],
|
|
16
|
+
* selectors?: Selector[],
|
|
17
|
+
* originalRuleset?: Node,
|
|
18
|
+
* matchArgs: (args: MixinArg[] | null, context: EvalContext) => boolean,
|
|
19
|
+
* matchCondition?: (args: MixinArg[] | null, context: EvalContext) => boolean,
|
|
20
|
+
* find: (selector: Selector, self?: Node | null, filter?: (rule: Node) => boolean) => Array<{ rule: Node & { rules?: Node[], originalRuleset?: Node, matchArgs: Function, matchCondition?: Function, evalCall?: Function }, path: Node[] }>,
|
|
21
|
+
* functionRegistry?: FunctionRegistry
|
|
22
|
+
* }} MixinSearchFrame
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
class MixinCall extends Node {
|
|
26
|
+
get type() { return 'MixinCall'; }
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {import('./element.js').default[]} elements
|
|
30
|
+
* @param {MixinArg[]} [args]
|
|
31
|
+
* @param {number} [index]
|
|
32
|
+
* @param {FileInfo} [currentFileInfo]
|
|
33
|
+
* @param {string} [important]
|
|
34
|
+
*/
|
|
35
|
+
constructor(elements, args, index, currentFileInfo, important) {
|
|
36
|
+
super();
|
|
37
|
+
/** @type {Selector} */
|
|
38
|
+
this.selector = new Selector(elements);
|
|
39
|
+
/** @type {MixinArg[]} */
|
|
40
|
+
this.arguments = args || [];
|
|
41
|
+
this._index = index;
|
|
42
|
+
this._fileInfo = currentFileInfo;
|
|
43
|
+
/** @type {string | undefined} */
|
|
44
|
+
this.important = important;
|
|
45
|
+
this.allowRoot = true;
|
|
46
|
+
this.setParent(this.selector, /** @type {Node} */ (/** @type {unknown} */ (this)));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @param {TreeVisitor} visitor */
|
|
50
|
+
accept(visitor) {
|
|
20
51
|
if (this.selector) {
|
|
21
|
-
this.selector = visitor.visit(this.selector);
|
|
52
|
+
this.selector = /** @type {Selector} */ (visitor.visit(this.selector));
|
|
22
53
|
}
|
|
23
54
|
if (this.arguments.length) {
|
|
24
|
-
this.arguments = visitor.visitArray(this.arguments);
|
|
55
|
+
this.arguments = /** @type {MixinArg[]} */ (/** @type {unknown} */ (visitor.visitArray(/** @type {Node[]} */ (/** @type {unknown} */ (this.arguments)))));
|
|
25
56
|
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {EvalContext} context
|
|
61
|
+
* @returns {Node}
|
|
62
|
+
*/
|
|
63
|
+
eval(context) {
|
|
64
|
+
/** @type {{ rule: Node & { rules?: Node[], originalRuleset?: Node, matchArgs: Function, matchCondition?: Function, evalCall?: Function }, path: Node[] }[] | undefined} */
|
|
65
|
+
let mixins;
|
|
66
|
+
/** @type {Node & { rules?: Node[], originalRuleset?: Node, matchArgs: Function, matchCondition?: Function, evalCall?: Function }} */
|
|
67
|
+
let mixin;
|
|
68
|
+
/** @type {Node[]} */
|
|
69
|
+
let mixinPath;
|
|
70
|
+
/** @type {MixinArg[]} */
|
|
71
|
+
const args = [];
|
|
72
|
+
/** @type {MixinArg} */
|
|
73
|
+
let arg;
|
|
74
|
+
/** @type {Node} */
|
|
75
|
+
let argValue;
|
|
76
|
+
/** @type {Node[]} */
|
|
77
|
+
const rules = [];
|
|
78
|
+
let match = false;
|
|
79
|
+
/** @type {number} */
|
|
80
|
+
let i;
|
|
81
|
+
/** @type {number} */
|
|
82
|
+
let m;
|
|
83
|
+
/** @type {number} */
|
|
84
|
+
let f;
|
|
85
|
+
/** @type {boolean} */
|
|
86
|
+
let isRecursive;
|
|
87
|
+
/** @type {boolean | undefined} */
|
|
88
|
+
let isOneFound;
|
|
89
|
+
/** @type {{ mixin: Node & { rules?: Node[], originalRuleset?: Node, matchArgs: Function, matchCondition?: Function, evalCall?: Function }, group: number }[]} */
|
|
90
|
+
const candidates = [];
|
|
91
|
+
/** @type {{ mixin: Node & { rules?: Node[], originalRuleset?: Node, matchArgs: Function, matchCondition?: Function, evalCall?: Function }, group: number } | number} */
|
|
92
|
+
let candidate;
|
|
93
|
+
/** @type {boolean[]} */
|
|
94
|
+
const conditionResult = [];
|
|
95
|
+
/** @type {number | undefined} */
|
|
96
|
+
let defaultResult;
|
|
97
|
+
const defFalseEitherCase = -1;
|
|
98
|
+
const defNone = 0;
|
|
99
|
+
const defTrue = 1;
|
|
100
|
+
const defFalse = 2;
|
|
101
|
+
/** @type {number[]} */
|
|
102
|
+
let count;
|
|
103
|
+
/** @type {Node | undefined} */
|
|
104
|
+
let originalRuleset;
|
|
105
|
+
/** @type {((rule: MixinSearchFrame) => boolean) | undefined} */
|
|
106
|
+
let noArgumentsFilter;
|
|
107
|
+
|
|
108
|
+
this.selector = /** @type {Selector} */ (this.selector.eval(context));
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {Node & { matchCondition?: Function }} mixin
|
|
112
|
+
* @param {Node[]} mixinPath
|
|
113
|
+
*/
|
|
53
114
|
function calcDefGroup(mixin, mixinPath) {
|
|
54
|
-
|
|
115
|
+
/** @type {number} */
|
|
116
|
+
let f;
|
|
117
|
+
/** @type {number} */
|
|
118
|
+
let p;
|
|
119
|
+
/** @type {Node & { matchCondition?: Function }} */
|
|
120
|
+
let namespace;
|
|
121
|
+
|
|
55
122
|
for (f = 0; f < 2; f++) {
|
|
56
123
|
conditionResult[f] = true;
|
|
57
|
-
|
|
124
|
+
defaultFunc.value(f);
|
|
58
125
|
for (p = 0; p < mixinPath.length && conditionResult[f]; p++) {
|
|
59
126
|
namespace = mixinPath[p];
|
|
60
127
|
if (namespace.matchCondition) {
|
|
@@ -70,37 +137,42 @@ MixinCall.prototype = Object.assign(new node_1.default(), {
|
|
|
70
137
|
return conditionResult[1] ?
|
|
71
138
|
defTrue : defFalse;
|
|
72
139
|
}
|
|
140
|
+
|
|
73
141
|
return defNone;
|
|
74
142
|
}
|
|
75
143
|
return defFalseEitherCase;
|
|
76
144
|
}
|
|
145
|
+
|
|
77
146
|
for (i = 0; i < this.arguments.length; i++) {
|
|
78
147
|
arg = this.arguments[i];
|
|
79
148
|
argValue = arg.value.eval(context);
|
|
80
149
|
if (arg.expand && Array.isArray(argValue.value)) {
|
|
81
|
-
|
|
82
|
-
for (m = 0; m <
|
|
83
|
-
args.push({
|
|
150
|
+
const expandedValues = /** @type {Node[]} */ (argValue.value);
|
|
151
|
+
for (m = 0; m < expandedValues.length; m++) {
|
|
152
|
+
args.push({value: expandedValues[m]});
|
|
84
153
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
args.push({ name: arg.name, value: argValue });
|
|
154
|
+
} else {
|
|
155
|
+
args.push({name: arg.name, value: argValue});
|
|
88
156
|
}
|
|
89
157
|
}
|
|
90
|
-
|
|
158
|
+
|
|
159
|
+
noArgumentsFilter = function(/** @type {MixinSearchFrame} */ rule) {return rule.matchArgs(null, context);};
|
|
160
|
+
|
|
91
161
|
for (i = 0; i < context.frames.length; i++) {
|
|
92
|
-
if ((mixins = context.frames[i].find(this.selector, null, noArgumentsFilter)).length > 0) {
|
|
162
|
+
if ((mixins = /** @type {MixinSearchFrame} */ (context.frames[i]).find(this.selector, null, /** @type {(rule: Node) => boolean} */ (/** @type {unknown} */ (noArgumentsFilter)))).length > 0) {
|
|
93
163
|
isOneFound = true;
|
|
164
|
+
|
|
94
165
|
// To make `default()` function independent of definition order we have two "subpasses" here.
|
|
95
166
|
// At first we evaluate each guard *twice* (with `default() == true` and `default() == false`),
|
|
96
167
|
// and build candidate list with corresponding flags. Then, when we know all possible matches,
|
|
97
168
|
// we make a final decision.
|
|
169
|
+
|
|
98
170
|
for (m = 0; m < mixins.length; m++) {
|
|
99
171
|
mixin = mixins[m].rule;
|
|
100
172
|
mixinPath = mixins[m].path;
|
|
101
173
|
isRecursive = false;
|
|
102
174
|
for (f = 0; f < context.frames.length; f++) {
|
|
103
|
-
if ((!(mixin instanceof
|
|
175
|
+
if ((!(mixin instanceof MixinDefinition)) && mixin === (/** @type {Node & { originalRuleset?: Node }} */ (context.frames[f]).originalRuleset || context.frames[f])) {
|
|
104
176
|
isRecursive = true;
|
|
105
177
|
break;
|
|
106
178
|
}
|
|
@@ -108,89 +180,100 @@ MixinCall.prototype = Object.assign(new node_1.default(), {
|
|
|
108
180
|
if (isRecursive) {
|
|
109
181
|
continue;
|
|
110
182
|
}
|
|
183
|
+
|
|
111
184
|
if (mixin.matchArgs(args, context)) {
|
|
112
|
-
candidate = {
|
|
113
|
-
|
|
114
|
-
|
|
185
|
+
candidate = {mixin, group: calcDefGroup(mixin, mixinPath)};
|
|
186
|
+
|
|
187
|
+
if (/** @type {{ mixin: Node, group: number }} */ (candidate).group !== defFalseEitherCase) {
|
|
188
|
+
candidates.push(/** @type {{ mixin: Node & { rules?: Node[], originalRuleset?: Node, matchArgs: Function, matchCondition?: Function, evalCall?: Function }, group: number }} */ (candidate));
|
|
115
189
|
}
|
|
190
|
+
|
|
116
191
|
match = true;
|
|
117
192
|
}
|
|
118
193
|
}
|
|
119
|
-
|
|
194
|
+
|
|
195
|
+
defaultFunc.reset();
|
|
196
|
+
|
|
120
197
|
count = [0, 0, 0];
|
|
121
198
|
for (m = 0; m < candidates.length; m++) {
|
|
122
199
|
count[candidates[m].group]++;
|
|
123
200
|
}
|
|
201
|
+
|
|
124
202
|
if (count[defNone] > 0) {
|
|
125
203
|
defaultResult = defFalse;
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
204
|
+
} else {
|
|
128
205
|
defaultResult = defTrue;
|
|
129
206
|
if ((count[defTrue] + count[defFalse]) > 1) {
|
|
130
207
|
throw { type: 'Runtime',
|
|
131
|
-
message:
|
|
208
|
+
message: `Ambiguous use of \`default()\` found when matching for \`${this.format(args)}\``,
|
|
132
209
|
index: this.getIndex(), filename: this.fileInfo().filename };
|
|
133
210
|
}
|
|
134
211
|
}
|
|
212
|
+
|
|
135
213
|
for (m = 0; m < candidates.length; m++) {
|
|
136
214
|
candidate = candidates[m].group;
|
|
137
215
|
if ((candidate === defNone) || (candidate === defaultResult)) {
|
|
138
216
|
try {
|
|
139
217
|
mixin = candidates[m].mixin;
|
|
140
|
-
if (!(mixin instanceof
|
|
141
|
-
originalRuleset = mixin.originalRuleset || mixin;
|
|
142
|
-
mixin = new
|
|
143
|
-
mixin.originalRuleset = originalRuleset;
|
|
218
|
+
if (!(mixin instanceof MixinDefinition)) {
|
|
219
|
+
originalRuleset = /** @type {Node & { originalRuleset?: Node }} */ (mixin).originalRuleset || mixin;
|
|
220
|
+
mixin = new MixinDefinition('', [], mixin.rules, null, false, null, originalRuleset.visibilityInfo());
|
|
221
|
+
/** @type {Node & { originalRuleset?: Node }} */ (mixin).originalRuleset = originalRuleset;
|
|
144
222
|
}
|
|
145
|
-
|
|
223
|
+
const newRules = /** @type {MixinDefinition} */ (mixin).evalCall(context, args, this.important).rules;
|
|
146
224
|
this._setVisibilityToReplacement(newRules);
|
|
147
225
|
Array.prototype.push.apply(rules, newRules);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
throw { message: e.message, index: this.getIndex(), filename: this.fileInfo().filename, stack: e.stack };
|
|
226
|
+
} catch (e) {
|
|
227
|
+
throw { .../** @type {object} */ (e), index: this.getIndex(), filename: this.fileInfo().filename };
|
|
151
228
|
}
|
|
152
229
|
}
|
|
153
230
|
}
|
|
231
|
+
|
|
154
232
|
if (match) {
|
|
155
|
-
return rules;
|
|
233
|
+
return /** @type {Node} */ (/** @type {unknown} */ (rules));
|
|
156
234
|
}
|
|
157
235
|
}
|
|
158
236
|
}
|
|
159
237
|
if (isOneFound) {
|
|
160
|
-
throw { type:
|
|
161
|
-
message:
|
|
162
|
-
index:
|
|
238
|
+
throw { type: 'Runtime',
|
|
239
|
+
message: `No matching definition was found for \`${this.format(args)}\``,
|
|
240
|
+
index: this.getIndex(), filename: this.fileInfo().filename };
|
|
241
|
+
} else {
|
|
242
|
+
throw { type: 'Name',
|
|
243
|
+
message: `${this.selector.toCSS(/** @type {EvalContext} */ ({})).trim()} is undefined`,
|
|
244
|
+
index: this.getIndex(), filename: this.fileInfo().filename };
|
|
163
245
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** @param {Node[]} replacement */
|
|
249
|
+
_setVisibilityToReplacement(replacement) {
|
|
250
|
+
/** @type {number} */
|
|
251
|
+
let i;
|
|
252
|
+
/** @type {Node} */
|
|
253
|
+
let rule;
|
|
172
254
|
if (this.blocksVisibility()) {
|
|
173
255
|
for (i = 0; i < replacement.length; i++) {
|
|
174
256
|
rule = replacement[i];
|
|
175
257
|
rule.addVisibilityBlock();
|
|
176
258
|
}
|
|
177
259
|
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** @param {MixinArg[]} args */
|
|
263
|
+
format(args) {
|
|
264
|
+
return `${this.selector.toCSS(/** @type {EvalContext} */ ({})).trim()}(${args ? args.map(function (/** @type {MixinArg} */ a) {
|
|
265
|
+
let argValue = '';
|
|
182
266
|
if (a.name) {
|
|
183
|
-
argValue +=
|
|
267
|
+
argValue += `${a.name}:`;
|
|
184
268
|
}
|
|
185
269
|
if (a.value.toCSS) {
|
|
186
|
-
argValue += a.value.toCSS();
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
270
|
+
argValue += a.value.toCSS(/** @type {EvalContext} */ ({}));
|
|
271
|
+
} else {
|
|
189
272
|
argValue += '???';
|
|
190
273
|
}
|
|
191
274
|
return argValue;
|
|
192
|
-
}).join(', ') : ''
|
|
275
|
+
}).join(', ') : ''})`;
|
|
193
276
|
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export default MixinCall;
|