source: imaps-frontend/node_modules/clean-css/lib/optimizer/level-2/properties/populate-components.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: 1.8 KB
Line 
1var configuration = require('../../configuration');
2var InvalidPropertyError = require('../../invalid-property-error');
3
4function populateComponents(properties, validator, warnings) {
5 var component;
6 var j, m;
7
8 for (var i = properties.length - 1; i >= 0; i--) {
9 var property = properties[i];
10 var descriptor = configuration[property.name];
11
12 if (!property.dynamic && descriptor && descriptor.shorthand) {
13 if (onlyValueIsVariable(property, validator) || moreThanOneValueIsVariable(property, validator)) {
14 property.optimizable = false;
15 continue;
16 }
17
18 property.shorthand = true;
19 property.dirty = true;
20
21 try {
22 property.components = descriptor.breakUp(property, configuration, validator);
23
24 if (descriptor.shorthandComponents) {
25 for (j = 0, m = property.components.length; j < m; j++) {
26 component = property.components[j];
27 component.components = configuration[component.name].breakUp(component, configuration, validator);
28 }
29 }
30 } catch (e) {
31 if (e instanceof InvalidPropertyError) {
32 property.components = []; // this will set property.unused to true below
33 warnings.push(e.message);
34 } else {
35 throw e;
36 }
37 }
38
39 if (property.components.length > 0) {
40 property.multiplex = property.components[0].multiplex;
41 } else {
42 property.unused = true;
43 }
44 }
45 }
46}
47
48function onlyValueIsVariable(property, validator) {
49 return property.value.length == 1 && validator.isVariable(property.value[0][1]);
50}
51
52function moreThanOneValueIsVariable(property, validator) {
53 return property.value.length > 1
54 && property.value.filter(
55 function(value) {
56 return validator.isVariable(value[1]);
57 }
58 ).length > 1;
59}
60
61module.exports = populateComponents;
Note: See TracBrowser for help on using the repository browser.