source: imaps-frontend/node_modules/clean-css/lib/optimizer/level-2/merge-adjacent.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.2 KB
Line 
1var isMergeable = require('./is-mergeable');
2
3var optimizeProperties = require('./properties/optimize');
4
5var sortSelectors = require('../level-1/sort-selectors');
6var tidyRules = require('../level-1/tidy-rules');
7
8var OptimizationLevel = require('../../options/optimization-level').OptimizationLevel;
9
10var serializeBody = require('../../writer/one-time').body;
11var serializeRules = require('../../writer/one-time').rules;
12
13var Token = require('../../tokenizer/token');
14
15function mergeAdjacent(tokens, context) {
16 var lastToken = [null, [], []];
17 var options = context.options;
18 var adjacentSpace = options.compatibility.selectors.adjacentSpace;
19 var selectorsSortingMethod = options.level[OptimizationLevel.One].selectorsSortingMethod;
20 var mergeablePseudoClasses = options.compatibility.selectors.mergeablePseudoClasses;
21 var mergeablePseudoElements = options.compatibility.selectors.mergeablePseudoElements;
22 var mergeLimit = options.compatibility.selectors.mergeLimit;
23 var multiplePseudoMerging = options.compatibility.selectors.multiplePseudoMerging;
24
25 for (var i = 0, l = tokens.length; i < l; i++) {
26 var token = tokens[i];
27
28 if (token[0] != Token.RULE) {
29 lastToken = [null, [], []];
30 continue;
31 }
32
33 if (lastToken[0] == Token.RULE && serializeRules(token[1]) == serializeRules(lastToken[1])) {
34 Array.prototype.push.apply(lastToken[2], token[2]);
35 optimizeProperties(lastToken[2], true, true, context);
36 token[2] = [];
37 } else if (lastToken[0] == Token.RULE && serializeBody(token[2]) == serializeBody(lastToken[2])
38 && isMergeable(serializeRules(token[1]), mergeablePseudoClasses, mergeablePseudoElements, multiplePseudoMerging)
39 && isMergeable(
40 serializeRules(lastToken[1]),
41 mergeablePseudoClasses,
42 mergeablePseudoElements,
43 multiplePseudoMerging
44 )
45 && lastToken[1].length < mergeLimit) {
46 lastToken[1] = tidyRules(lastToken[1].concat(token[1]), false, adjacentSpace, false, context.warnings);
47 lastToken[1] = lastToken.length > 1 ? sortSelectors(lastToken[1], selectorsSortingMethod) : lastToken[1];
48 token[2] = [];
49 } else {
50 lastToken = token;
51 }
52 }
53}
54
55module.exports = mergeAdjacent;
Note: See TracBrowser for help on using the repository browser.