less 4.9.0 → 5.0.0-alpha.2
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 +19 -5
- package/bin/lessc +190 -630
- package/dist/less-node.cjs +399 -14570
- package/index.cjs +5 -2
- package/lib/index.js +164 -0
- package/lib/lessc-helper.js +52 -0
- package/lib/logger.js +76 -0
- package/lib/options.d.ts +46 -0
- package/lib/options.js +145 -0
- package/lib/types.js +20 -0
- package/lib/version.js +19 -0
- package/package.json +32 -39
- package/dist/less.cjs +0 -15215
- package/dist/less.js +0 -15215
- package/dist/less.min.js +0 -11
- package/dist/less.min.js.map +0 -1
- package/lib/less/constants.js +0 -13
- package/lib/less/contexts.js +0 -165
- package/lib/less/data/colors.js +0 -150
- package/lib/less/data/index.js +0 -4
- package/lib/less/data/unit-conversions.js +0 -21
- package/lib/less/default-options.js +0 -89
- package/lib/less/deprecation.js +0 -82
- package/lib/less/environment/abstract-file-manager.js +0 -140
- package/lib/less/environment/abstract-plugin-loader.js +0 -185
- package/lib/less/environment/environment-api.ts +0 -21
- package/lib/less/environment/environment.js +0 -59
- package/lib/less/environment/file-manager-api.ts +0 -77
- package/lib/less/functions/boolean.js +0 -29
- package/lib/less/functions/color-blending.js +0 -85
- package/lib/less/functions/color.js +0 -452
- package/lib/less/functions/data-uri.js +0 -74
- package/lib/less/functions/default.js +0 -26
- package/lib/less/functions/function-caller.js +0 -55
- package/lib/less/functions/function-registry.js +0 -36
- package/lib/less/functions/index.js +0 -35
- package/lib/less/functions/list.js +0 -158
- package/lib/less/functions/math-helper.js +0 -22
- package/lib/less/functions/math.js +0 -30
- package/lib/less/functions/number.js +0 -95
- package/lib/less/functions/string.js +0 -39
- package/lib/less/functions/style.js +0 -29
- package/lib/less/functions/svg.js +0 -87
- package/lib/less/functions/types.js +0 -70
- package/lib/less/import-manager.js +0 -183
- package/lib/less/index.js +0 -95
- package/lib/less/less-error.js +0 -166
- package/lib/less/logger.js +0 -34
- package/lib/less/parse-tree.js +0 -124
- package/lib/less/parse.js +0 -87
- package/lib/less/parser/lookup-pattern.js +0 -26
- package/lib/less/parser/parser-input.js +0 -400
- package/lib/less/parser/parser.js +0 -2998
- package/lib/less/plugin-manager.js +0 -168
- package/lib/less/render.js +0 -41
- package/lib/less/source-map-builder.js +0 -82
- package/lib/less/source-map-output.js +0 -151
- package/lib/less/transform-tree.js +0 -102
- package/lib/less/tree/anonymous.js +0 -61
- package/lib/less/tree/assignment.js +0 -48
- package/lib/less/tree/atrule-syntax.js +0 -8
- package/lib/less/tree/atrule.js +0 -340
- package/lib/less/tree/attribute.js +0 -63
- package/lib/less/tree/call.js +0 -132
- package/lib/less/tree/color.js +0 -285
- package/lib/less/tree/combinator.js +0 -38
- package/lib/less/tree/comment.js +0 -48
- package/lib/less/tree/condition.js +0 -65
- package/lib/less/tree/container.js +0 -104
- package/lib/less/tree/debug-info.js +0 -80
- package/lib/less/tree/declaration.js +0 -139
- package/lib/less/tree/detached-ruleset.js +0 -45
- package/lib/less/tree/dimension.js +0 -215
- package/lib/less/tree/element.js +0 -93
- package/lib/less/tree/expression.js +0 -100
- package/lib/less/tree/extend.js +0 -88
- package/lib/less/tree/import.js +0 -299
- package/lib/less/tree/index.js +0 -56
- package/lib/less/tree/interpolated-variable.js +0 -106
- package/lib/less/tree/javascript.js +0 -45
- package/lib/less/tree/js-eval-node.js +0 -80
- package/lib/less/tree/keyword.js +0 -28
- package/lib/less/tree/media.js +0 -90
- package/lib/less/tree/merge-rules.js +0 -47
- package/lib/less/tree/mixin-call.js +0 -283
- package/lib/less/tree/mixin-definition.js +0 -319
- package/lib/less/tree/namespace-value.js +0 -95
- package/lib/less/tree/negative.js +0 -37
- package/lib/less/tree/nested-at-rule.js +0 -239
- package/lib/less/tree/node.js +0 -310
- package/lib/less/tree/operation.js +0 -81
- package/lib/less/tree/paren.js +0 -41
- package/lib/less/tree/property.js +0 -96
- package/lib/less/tree/query-in-parens.js +0 -64
- package/lib/less/tree/quoted.js +0 -131
- package/lib/less/tree/ruleset.js +0 -1068
- package/lib/less/tree/selector.js +0 -201
- package/lib/less/tree/unicode-descriptor.js +0 -14
- package/lib/less/tree/unit.js +0 -170
- package/lib/less/tree/url.js +0 -83
- package/lib/less/tree/value.js +0 -60
- package/lib/less/tree/variable-call.js +0 -60
- package/lib/less/tree/variable.js +0 -85
- package/lib/less/utils.js +0 -126
- package/lib/less/visitors/extend-visitor.js +0 -505
- package/lib/less/visitors/import-sequencer.js +0 -56
- package/lib/less/visitors/import-visitor.js +0 -203
- package/lib/less/visitors/index.js +0 -15
- package/lib/less/visitors/join-selector-visitor.js +0 -65
- package/lib/less/visitors/set-tree-visibility-visitor.js +0 -57
- package/lib/less/visitors/to-css-visitor.js +0 -332
- package/lib/less/visitors/visitor.js +0 -165
- package/lib/less-browser/add-default-options.js +0 -53
- package/lib/less-browser/bootstrap.js +0 -67
- package/lib/less-browser/browser.js +0 -65
- package/lib/less-browser/cache.js +0 -43
- package/lib/less-browser/error-reporting.js +0 -170
- package/lib/less-browser/file-manager.js +0 -112
- package/lib/less-browser/image-size.js +0 -28
- package/lib/less-browser/index.js +0 -284
- package/lib/less-browser/log-listener.js +0 -42
- package/lib/less-browser/plugin-loader.js +0 -24
- package/lib/less-browser/utils.js +0 -30
- package/lib/less-node/environment.js +0 -43
- package/lib/less-node/file-manager.js +0 -156
- package/lib/less-node/fs.js +0 -14
- package/lib/less-node/image-size.js +0 -78
- package/lib/less-node/index.js +0 -31
- package/lib/less-node/lessc-helper.js +0 -95
- package/lib/less-node/plugin-loader.js +0 -62
- package/lib/less-node/url-file-manager.js +0 -60
package/lib/less/tree/media.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
/** @import { EvalContext, CSSOutput, FileInfo, VisibilityInfo } from './node.js' */
|
|
3
|
-
/** @import { NestableAtRuleThis } from './nested-at-rule.js' */
|
|
4
|
-
/** @import { RulesetLikeNode } from './atrule.js' */
|
|
5
|
-
import Node from './node.js';
|
|
6
|
-
import Ruleset from './ruleset.js';
|
|
7
|
-
import Value from './value.js';
|
|
8
|
-
import Selector from './selector.js';
|
|
9
|
-
import AtRule from './atrule.js';
|
|
10
|
-
import NestableAtRulePrototype from './nested-at-rule.js';
|
|
11
|
-
|
|
12
|
-
class Media extends AtRule {
|
|
13
|
-
get type() { return 'Media'; }
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {Node[] | null} value
|
|
17
|
-
* @param {Node[]} features
|
|
18
|
-
* @param {number} [index]
|
|
19
|
-
* @param {FileInfo} [currentFileInfo]
|
|
20
|
-
* @param {VisibilityInfo} [visibilityInfo]
|
|
21
|
-
*/
|
|
22
|
-
constructor(value, features, index, currentFileInfo, visibilityInfo) {
|
|
23
|
-
super();
|
|
24
|
-
this._index = index;
|
|
25
|
-
this._fileInfo = currentFileInfo;
|
|
26
|
-
|
|
27
|
-
const selectors = (new Selector([], null, null, this._index, this._fileInfo)).createEmptySelectors();
|
|
28
|
-
|
|
29
|
-
/** @type {Value} */
|
|
30
|
-
this.features = new Value(features);
|
|
31
|
-
/** @type {RulesetLikeNode[]} */
|
|
32
|
-
this.rules = [new Ruleset(selectors, value)];
|
|
33
|
-
/** @type {RulesetLikeNode} */ (this.rules[0]).allowImports = true;
|
|
34
|
-
this.copyVisibilityInfo(visibilityInfo);
|
|
35
|
-
this.allowRoot = true;
|
|
36
|
-
this.setParent(selectors, /** @type {Node} */ (/** @type {unknown} */ (this)));
|
|
37
|
-
this.setParent(this.features, /** @type {Node} */ (/** @type {unknown} */ (this)));
|
|
38
|
-
this.setParent(this.rules, /** @type {Node} */ (/** @type {unknown} */ (this)));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @param {EvalContext} context
|
|
43
|
-
* @param {CSSOutput} output
|
|
44
|
-
*/
|
|
45
|
-
genCSS(context, output) {
|
|
46
|
-
output.add('@media ', this._fileInfo, this._index);
|
|
47
|
-
this.features.genCSS(context, output);
|
|
48
|
-
this.outputRuleset(context, output, this.rules);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @param {EvalContext} context
|
|
53
|
-
* @returns {Node}
|
|
54
|
-
*/
|
|
55
|
-
eval(context) {
|
|
56
|
-
if (!context.mediaBlocks) {
|
|
57
|
-
context.mediaBlocks = [];
|
|
58
|
-
context.mediaPath = [];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const media = new Media(null, [], this._index, this._fileInfo, this.visibilityInfo());
|
|
62
|
-
if (this.debugInfo) {
|
|
63
|
-
/** @type {RulesetLikeNode} */ (this.rules[0]).debugInfo = this.debugInfo;
|
|
64
|
-
media.debugInfo = this.debugInfo;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
media.features = /** @type {Value} */ (this.features.eval(context));
|
|
68
|
-
|
|
69
|
-
context.mediaPath.push(/** @type {Node} */ (/** @type {unknown} */ (media)));
|
|
70
|
-
context.mediaBlocks.push(/** @type {Node} */ (/** @type {unknown} */ (media)));
|
|
71
|
-
|
|
72
|
-
const fr = /** @type {RulesetLikeNode} */ (context.frames[0]).functionRegistry;
|
|
73
|
-
if (fr) {
|
|
74
|
-
/** @type {RulesetLikeNode} */ (this.rules[0]).functionRegistry = fr.inherit();
|
|
75
|
-
}
|
|
76
|
-
context.frames.unshift(this.rules[0]);
|
|
77
|
-
media.rules = [/** @type {RulesetLikeNode} */ (this.rules[0].eval(context))];
|
|
78
|
-
context.frames.shift();
|
|
79
|
-
|
|
80
|
-
context.mediaPath.pop();
|
|
81
|
-
|
|
82
|
-
return context.mediaPath.length === 0 ? /** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (media)).evalTop(context) :
|
|
83
|
-
/** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (media)).evalNested(context);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Apply NestableAtRulePrototype methods (accept, isRulesetLike override AtRule's versions)
|
|
88
|
-
Object.assign(Media.prototype, NestableAtRulePrototype);
|
|
89
|
-
|
|
90
|
-
export default Media;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import Expression from './expression.js';
|
|
3
|
-
import Value from './value.js';
|
|
4
|
-
import Node from './node.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Merges declarations with merge flags (+ or ,) into combined values.
|
|
8
|
-
* Used by both the ToCSSVisitor and AtRule eval.
|
|
9
|
-
* @param {Node[]} rules
|
|
10
|
-
*/
|
|
11
|
-
export default function mergeRules(rules) {
|
|
12
|
-
if (!rules) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** @type {Record<string, Array<Node & { merge: string, name: string, value: Node, important: string }>>} */
|
|
17
|
-
const groups = {};
|
|
18
|
-
/** @type {Array<Array<Node & { merge: string, name: string, value: Node, important: string }>>} */
|
|
19
|
-
const groupsArr = [];
|
|
20
|
-
|
|
21
|
-
for (let i = 0; i < rules.length; i++) {
|
|
22
|
-
const rule = /** @type {Node & { merge: string, name: string }} */ (rules[i]);
|
|
23
|
-
if (rule.merge) {
|
|
24
|
-
const key = rule.name;
|
|
25
|
-
groups[key] ? rules.splice(i--, 1) :
|
|
26
|
-
groupsArr.push(groups[key] = []);
|
|
27
|
-
groups[key].push(/** @type {Node & { merge: string, name: string, value: Node, important: string }} */ (rule));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
groupsArr.forEach(group => {
|
|
32
|
-
if (group.length > 0) {
|
|
33
|
-
const result = group[0];
|
|
34
|
-
/** @type {Node[]} */
|
|
35
|
-
let space = [];
|
|
36
|
-
const comma = [new Expression(space)];
|
|
37
|
-
group.forEach(rule => {
|
|
38
|
-
if ((rule.merge === '+') && (space.length > 0)) {
|
|
39
|
-
comma.push(new Expression(space = []));
|
|
40
|
-
}
|
|
41
|
-
space.push(rule.value);
|
|
42
|
-
result.important = result.important || rule.important;
|
|
43
|
-
});
|
|
44
|
-
result.value = new Value(comma);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
@@ -1,283 +0,0 @@
|
|
|
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) {
|
|
51
|
-
if (this.selector) {
|
|
52
|
-
this.selector = /** @type {Selector} */ (visitor.visit(this.selector));
|
|
53
|
-
}
|
|
54
|
-
if (this.arguments.length) {
|
|
55
|
-
this.arguments = /** @type {MixinArg[]} */ (/** @type {unknown} */ (visitor.visitArray(/** @type {Node[]} */ (/** @type {unknown} */ (this.arguments)))));
|
|
56
|
-
}
|
|
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
|
-
*/
|
|
114
|
-
function calcDefGroup(mixin, mixinPath) {
|
|
115
|
-
/** @type {number} */
|
|
116
|
-
let f;
|
|
117
|
-
/** @type {number} */
|
|
118
|
-
let p;
|
|
119
|
-
/** @type {Node & { matchCondition?: Function }} */
|
|
120
|
-
let namespace;
|
|
121
|
-
|
|
122
|
-
for (f = 0; f < 2; f++) {
|
|
123
|
-
conditionResult[f] = true;
|
|
124
|
-
defaultFunc.value(f);
|
|
125
|
-
for (p = 0; p < mixinPath.length && conditionResult[f]; p++) {
|
|
126
|
-
namespace = mixinPath[p];
|
|
127
|
-
if (namespace.matchCondition) {
|
|
128
|
-
conditionResult[f] = conditionResult[f] && namespace.matchCondition(null, context);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (mixin.matchCondition) {
|
|
132
|
-
conditionResult[f] = conditionResult[f] && mixin.matchCondition(args, context);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (conditionResult[0] || conditionResult[1]) {
|
|
136
|
-
if (conditionResult[0] != conditionResult[1]) {
|
|
137
|
-
return conditionResult[1] ?
|
|
138
|
-
defTrue : defFalse;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return defNone;
|
|
142
|
-
}
|
|
143
|
-
return defFalseEitherCase;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
for (i = 0; i < this.arguments.length; i++) {
|
|
147
|
-
arg = this.arguments[i];
|
|
148
|
-
argValue = arg.value.eval(context);
|
|
149
|
-
if (arg.expand && Array.isArray(argValue.value)) {
|
|
150
|
-
const expandedValues = /** @type {Node[]} */ (argValue.value);
|
|
151
|
-
for (m = 0; m < expandedValues.length; m++) {
|
|
152
|
-
args.push({value: expandedValues[m]});
|
|
153
|
-
}
|
|
154
|
-
} else if (argValue.type === 'Expression' && Array.isArray(argValue.value) && argValue.value.length === 0) {
|
|
155
|
-
// an unset variadic holds no captured args; omit it so the callee
|
|
156
|
-
// falls through to its own parameter defaults instead of receiving empty
|
|
157
|
-
|
|
158
|
-
} else {
|
|
159
|
-
args.push({name: arg.name, value: argValue});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
noArgumentsFilter = function(/** @type {MixinSearchFrame} */ rule) {return rule.matchArgs(null, context);};
|
|
164
|
-
|
|
165
|
-
for (i = 0; i < context.frames.length; i++) {
|
|
166
|
-
if ((mixins = /** @type {MixinSearchFrame} */ (context.frames[i]).find(this.selector, null, /** @type {(rule: Node) => boolean} */ (/** @type {unknown} */ (noArgumentsFilter)))).length > 0) {
|
|
167
|
-
isOneFound = true;
|
|
168
|
-
|
|
169
|
-
// To make `default()` function independent of definition order we have two "subpasses" here.
|
|
170
|
-
// At first we evaluate each guard *twice* (with `default() == true` and `default() == false`),
|
|
171
|
-
// and build candidate list with corresponding flags. Then, when we know all possible matches,
|
|
172
|
-
// we make a final decision.
|
|
173
|
-
|
|
174
|
-
for (m = 0; m < mixins.length; m++) {
|
|
175
|
-
mixin = mixins[m].rule;
|
|
176
|
-
mixinPath = mixins[m].path;
|
|
177
|
-
isRecursive = false;
|
|
178
|
-
for (f = 0; f < context.frames.length; f++) {
|
|
179
|
-
if ((!(mixin instanceof MixinDefinition)) && mixin === (/** @type {Node & { originalRuleset?: Node }} */ (context.frames[f]).originalRuleset || context.frames[f])) {
|
|
180
|
-
isRecursive = true;
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (isRecursive) {
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (mixin.matchArgs(args, context)) {
|
|
189
|
-
candidate = {mixin, group: calcDefGroup(mixin, mixinPath)};
|
|
190
|
-
|
|
191
|
-
if (/** @type {{ mixin: Node, group: number }} */ (candidate).group !== defFalseEitherCase) {
|
|
192
|
-
candidates.push(/** @type {{ mixin: Node & { rules?: Node[], originalRuleset?: Node, matchArgs: Function, matchCondition?: Function, evalCall?: Function }, group: number }} */ (candidate));
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
match = true;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
defaultFunc.reset();
|
|
200
|
-
|
|
201
|
-
count = [0, 0, 0];
|
|
202
|
-
for (m = 0; m < candidates.length; m++) {
|
|
203
|
-
count[candidates[m].group]++;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (count[defNone] > 0) {
|
|
207
|
-
defaultResult = defFalse;
|
|
208
|
-
} else {
|
|
209
|
-
defaultResult = defTrue;
|
|
210
|
-
if ((count[defTrue] + count[defFalse]) > 1) {
|
|
211
|
-
throw { type: 'Runtime',
|
|
212
|
-
message: `Ambiguous use of \`default()\` found when matching for \`${this.format(args)}\``,
|
|
213
|
-
index: this.getIndex(), filename: this.fileInfo().filename };
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
for (m = 0; m < candidates.length; m++) {
|
|
218
|
-
candidate = candidates[m].group;
|
|
219
|
-
if ((candidate === defNone) || (candidate === defaultResult)) {
|
|
220
|
-
try {
|
|
221
|
-
mixin = candidates[m].mixin;
|
|
222
|
-
if (!(mixin instanceof MixinDefinition)) {
|
|
223
|
-
originalRuleset = /** @type {Node & { originalRuleset?: Node }} */ (mixin).originalRuleset || mixin;
|
|
224
|
-
mixin = new MixinDefinition('', [], mixin.rules, null, false, null, originalRuleset.visibilityInfo());
|
|
225
|
-
/** @type {Node & { originalRuleset?: Node }} */ (mixin).originalRuleset = originalRuleset;
|
|
226
|
-
}
|
|
227
|
-
const newRules = /** @type {MixinDefinition} */ (mixin).evalCall(context, args, this.important).rules;
|
|
228
|
-
this._setVisibilityToReplacement(newRules);
|
|
229
|
-
Array.prototype.push.apply(rules, newRules);
|
|
230
|
-
} catch (e) {
|
|
231
|
-
throw { .../** @type {object} */ (e), index: this.getIndex(), filename: this.fileInfo().filename };
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (match) {
|
|
237
|
-
return /** @type {Node} */ (/** @type {unknown} */ (rules));
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (isOneFound) {
|
|
242
|
-
throw { type: 'Runtime',
|
|
243
|
-
message: `No matching definition was found for \`${this.format(args)}\``,
|
|
244
|
-
index: this.getIndex(), filename: this.fileInfo().filename };
|
|
245
|
-
} else {
|
|
246
|
-
throw { type: 'Name',
|
|
247
|
-
message: `${this.selector.toCSS(/** @type {EvalContext} */ ({})).trim()} is undefined`,
|
|
248
|
-
index: this.getIndex(), filename: this.fileInfo().filename };
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/** @param {Node[]} replacement */
|
|
253
|
-
_setVisibilityToReplacement(replacement) {
|
|
254
|
-
/** @type {number} */
|
|
255
|
-
let i;
|
|
256
|
-
/** @type {Node} */
|
|
257
|
-
let rule;
|
|
258
|
-
if (this.blocksVisibility()) {
|
|
259
|
-
for (i = 0; i < replacement.length; i++) {
|
|
260
|
-
rule = replacement[i];
|
|
261
|
-
rule.addVisibilityBlock();
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/** @param {MixinArg[]} args */
|
|
267
|
-
format(args) {
|
|
268
|
-
return `${this.selector.toCSS(/** @type {EvalContext} */ ({})).trim()}(${args ? args.map(function (/** @type {MixinArg} */ a) {
|
|
269
|
-
let argValue = '';
|
|
270
|
-
if (a.name) {
|
|
271
|
-
argValue += `${a.name}:`;
|
|
272
|
-
}
|
|
273
|
-
if (a.value.toCSS) {
|
|
274
|
-
argValue += a.value.toCSS(/** @type {EvalContext} */ ({}));
|
|
275
|
-
} else {
|
|
276
|
-
argValue += '???';
|
|
277
|
-
}
|
|
278
|
-
return argValue;
|
|
279
|
-
}).join(', ') : ''})`;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export default MixinCall;
|