[79a0317] | 1 | var configuration = require('../../configuration');
|
---|
| 2 | var InvalidPropertyError = require('../../invalid-property-error');
|
---|
| 3 |
|
---|
| 4 | function 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 |
|
---|
| 48 | function onlyValueIsVariable(property, validator) {
|
---|
| 49 | return property.value.length == 1 && validator.isVariable(property.value[0][1]);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | function 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 |
|
---|
| 61 | module.exports = populateComponents;
|
---|