+ 6. If a ConcatStatement is provided, for instance,
+
+ bar
+
+ we need to preserve the whitespace if any whitelist class is specified which can be found by following steps 1 to 4.
+ */
+ if (!value) {
+ return true;
+ }
+ if (config.elementClassNames === 'all') {
+ return false;
+ }
+ let type = value.type;
+
+ if (type === 'TextNode') {
+ return !isClassIncluded(value.chars, config.elementClassNames);
+ } else if (type === 'StringLiteral') {
+ return !isClassIncluded(value.value, config.elementClassNames);
+ } else if (type === 'PathExpression') {
+ return false;
+ } else if (type === 'MustacheStatement') {
+ let canTrim = true;
+
+ if (['if', 'unless'].indexOf(value.path.original) !== -1) {
+ let params = value.params;
+ for (let i = 1; i < params.length; i++) {
+ canTrim = canTrimUnnecessaryWhiteSpace(params[i], config);
+ if (!canTrim) {
+ break;
+ }
+ }
+ }
+ return canTrim;
+ } else if (type === 'ConcatStatement') {
+ let parts = value.parts;
+
+ return parts.every((part) => {
+ return canTrimUnnecessaryWhiteSpace(part, config);
+ });
+ }
+ return true;
+}
+
+
+const canTrimBlockStatementContent = function(node, config) {
+ // If a block or all the blocks is/are whitelisted (or) named as 'no-minify' then we need to preserve the whitespace.
+ let componentName = node.path.original;
+ if (config.components.indexOf(componentName) !== -1 || componentName === 'no-minify' || config.components === 'all') {
+ return false;
+ }
+ return true;
+};
+
+const canTrimElementNodeContent = function(node, config) {
+ // If a element or all the element is/are whitelisted then we need to preserve the whitespace.
+ if (config.elementNodes.indexOf(node.tag) !== -1 || config.elementNodes === 'all') {
+ return false;
+ }
+ let classAttributes = getElementAttribute(node, 'class');
+ return classAttributes ? canTrimUnnecessaryWhiteSpace(classAttributes, config) : true;
+};
+
+const assignDefaultValues = function(config) {
+ config = config || {};
+ let elementNodes = config.elementNodes || 'all';
+ let elementClassNames = config.elementClassNames || 'all';
+ let components = config.components || 'all';
+ let partials = config.partials || 'all';
+
+ return {
+ elementNodes,
+ elementClassNames,
+ components,
+ partials
+ };
+};
+
module.exports = {
stripWhiteSpace,
isWhitespaceTextNode,
stripNoMinifyBlocks,
- hasLeadingOrTrailingWhiteSpace
+ hasLeadingOrTrailingWhiteSpace,
+ canTrimBlockStatementContent,
+ canTrimElementNodeContent,
+ canTrimModule,
+ assignDefaultValues
};