MCPcopy
hub / github.com/less/less.js / eval

Method eval

packages/less/lib/less/tree/atrule.js:183–218  ·  view source on GitHub ↗

* @param {EvalContext} context * @returns {Node}

(context)

Source from the content-addressed store, hash-verified

181 * @returns {Node}
182 */
183 eval(context) {
184 let mediaPathBackup, mediaBlocksBackup, value = this.value, rules = this.rules || this.declarations;
185
186 // media stored inside other atrule should not bubble over it
187 // backpup media bubbling information
188 mediaPathBackup = context.mediaPath;
189 mediaBlocksBackup = context.mediaBlocks;
190 // deleted media bubbling information
191 context.mediaPath = [];
192 context.mediaBlocks = [];
193
194 if (value) {
195 value = /** @type {Node} */ (value).eval(context);
196 }
197
198 if (rules) {
199 rules = this.evalRoot(context, rules);
200 }
201 if (Array.isArray(rules) && /** @type {RulesetLikeNode} */ (rules[0]).rules && Array.isArray(/** @type {RulesetLikeNode} */ (rules[0]).rules) && /** @type {Node[]} */ (/** @type {RulesetLikeNode} */ (rules[0]).rules).length) {
202 const allMergeableDeclarations = this.declarationsBlock(/** @type {Node[]} */ (/** @type {RulesetLikeNode} */ (rules[0]).rules), true);
203 if (allMergeableDeclarations && !this.isRooted && !value) {
204 mergeRules(/** @type {Node[]} */ (/** @type {RulesetLikeNode} */ (rules[0]).rules));
205 rules = /** @type {RulesetLikeNode[]} */ (/** @type {RulesetLikeNode} */ (rules[0]).rules);
206 rules.forEach(/** @param {RulesetLikeNode} rule */ rule => { rule.merge = false; });
207 }
208 }
209 if (this.simpleBlock && rules) {
210 /** @type {RulesetLikeNode} */ (rules[0]).functionRegistry = /** @type {RulesetLikeNode} */ (context.frames[0]).functionRegistry.inherit();
211 rules = rules.map(function (/** @type {Node} */ rule) { return rule.eval(context); });
212 }
213
214 // restore media bubbling information
215 context.mediaPath = mediaPathBackup;
216 context.mediaBlocks = mediaBlocksBackup;
217 return /** @type {Node} */ (/** @type {unknown} */ (new AtRule(this.name, value, rules, this.getIndex(), this.fileInfo(), this.debugInfo, this.isRooted, this.visibilityInfo())));
218 }
219
220 /**
221 * @param {EvalContext} context

Callers 1

evalRootMethod · 0.45

Calls 7

evalRootMethod · 0.95
declarationsBlockMethod · 0.95
mergeRulesFunction · 0.85
mapMethod · 0.80
getIndexMethod · 0.80
fileInfoMethod · 0.80
visibilityInfoMethod · 0.80

Tested by

no test coverage detected