From 01e99ad737f6c9f85245f63bbe3e757bc3d7465d Mon Sep 17 00:00:00 2001 From: Francis Marineau Date: Sun, 10 Aug 2014 20:46:01 -0400 Subject: [PATCH] Added comments --- lib/engine.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/engine.js b/lib/engine.js index eb41ee2..e015e06 100644 --- a/lib/engine.js +++ b/lib/engine.js @@ -5,21 +5,24 @@ module.exports = function(cssString) { var cssObject = css.parse(cssString); var longPropertiesPositions = []; + // Loop through every rule of the stylesheet cssObject.stylesheet.rules.forEach(function(rule) { - if (rule.type === "rule") { + if (rule.type === "rule") { // Exclude comments and other things that aren't rules var declarations = []; + // Create an array of the rule's declarations indexed by their property name rule.declarations.forEach(function(declaration) { declarations[declaration.property] = declaration; }); + // Loop through all of the shorthandable properties to find if the current one can be shortened shorthands.forEach(function(shorthand) { - var shorthandValue = shorthand.getShorthandValue(shorthand, declarations); + var shorthandValue = shorthand.getShorthandValue(shorthand, declarations); // Defined in properties.js - if (shorthandValue !== "") { + if (shorthandValue !== "") { // If there are no the specific properties of the shorthand, "getShorthandValue" returns an empty string var newDeclarations = []; - // Add the new shorthand property + // Add the new shorthanded property newDeclarations.push({ type: 'declaration', property: shorthand.shorthandProperty, @@ -36,6 +39,7 @@ module.exports = function(cssString) { } }); + // Replace the rule's old declarations with the new shorthanded ones rule.declarations = newDeclarations; } });