From bbff7403fbf46f9ad92240ac213df8d30ef31b64 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 20 Sep 2018 02:56:13 +0200 Subject: update packages --- node_modules/clean-css/lib/clean.js | 16 ++++ .../clean-css/lib/optimizer/level-1/optimize.js | 32 ++++--- .../clean-css/lib/optimizer/level-1/tidy-rules.js | 2 +- .../clean-css/lib/optimizer/level-2/break-up.js | 86 ++++++++++++++++- .../lib/optimizer/level-2/can-override.js | 56 ++++++++--- .../clean-css/lib/optimizer/level-2/compactable.js | 87 ++++++++++++++++- .../level-2/properties/override-properties.js | 8 +- .../optimizer/level-2/remove-unused-at-rules.js | 14 ++- .../clean-css/lib/optimizer/level-2/restore.js | 18 +++- node_modules/clean-css/lib/optimizer/validator.js | 106 ++++++++++++++------- node_modules/clean-css/lib/options/format.js | 33 ++++++- .../lib/reader/input-source-map-tracker.js | 4 + node_modules/clean-css/lib/reader/read-sources.js | 11 ++- node_modules/clean-css/lib/tokenizer/marker.js | 2 +- node_modules/clean-css/lib/tokenizer/token.js | 1 + node_modules/clean-css/lib/tokenizer/tokenize.js | 63 ++++++++++-- node_modules/clean-css/lib/writer/helpers.js | 34 +++++-- node_modules/clean-css/lib/writer/simple.js | 6 +- node_modules/clean-css/lib/writer/source-maps.js | 5 +- 19 files changed, 485 insertions(+), 99 deletions(-) (limited to 'node_modules/clean-css/lib') diff --git a/node_modules/clean-css/lib/clean.js b/node_modules/clean-css/lib/clean.js index 62308efec..8cdb4b793 100644 --- a/node_modules/clean-css/lib/clean.js +++ b/node_modules/clean-css/lib/clean.js @@ -46,6 +46,22 @@ var CleanCSS = module.exports = function CleanCSS(options) { }; }; + +// for compatibility with optimize-css-assets-webpack-plugin +CleanCSS.process = function (input, opts) { + var cleanCss; + var optsTo = opts.to; + + delete opts.to; + cleanCss = new CleanCSS(Object.assign({ returnPromise: true, rebaseTo: optsTo }, opts)); + + return cleanCss.minify(input) + .then(function(output) { + return { css: output.styles }; + }); +}; + + CleanCSS.prototype.minify = function (input, maybeSourceMap, maybeCallback) { var options = this.options; diff --git a/node_modules/clean-css/lib/optimizer/level-1/optimize.js b/node_modules/clean-css/lib/optimizer/level-1/optimize.js index 82cb9531d..13cfd8c52 100644 --- a/node_modules/clean-css/lib/optimizer/level-1/optimize.js +++ b/node_modules/clean-css/lib/optimizer/level-1/optimize.js @@ -19,6 +19,8 @@ var Marker = require('../../tokenizer/marker'); var formatPosition = require('../../utils/format-position'); var split = require('../../utils/split'); +var serializeRules = require('../../writer/one-time').rules; + var IgnoreProperty = 'ignore-property'; var CHARSET_TOKEN = '@charset'; @@ -29,6 +31,7 @@ var DEFAULT_ROUNDING_PRECISION = require('../../options/rounding-precision').DEF var WHOLE_PIXEL_VALUE = /(?:^|\s|\()(-?\d+)px/; var TIME_VALUE = /^(\-?[\d\.]+)(m?s)$/; +var HEX_VALUE_PATTERN = /[0-9a-f]/i; var PROPERTY_NAME_PATTERN = /^(?:\-chrome\-|\-[\w\-]+\w|\w[\w\-]+\w|\-\-\S+)$/; var IMPORT_PREFIX_PATTERN = /^@import/i; var QUOTED_PATTERN = /^('.*'|".*")$/; @@ -98,11 +101,15 @@ function optimizeColors(name, value, compatibility) { .replace(/hsl\((-?\d+),(-?\d+)%?,(-?\d+)%?\)/g, function (match, hue, saturation, lightness) { return shortenHsl(hue, saturation, lightness); }) - .replace(/(^|[^='"])#([0-9a-f]{6})($|[^0-9a-f])/gi, function (match, prefix, color, suffix) { - if (color[0] == color[1] && color[2] == color[3] && color[4] == color[5]) { - return (prefix + '#' + color[0] + color[2] + color[4]).toLowerCase() + suffix; + .replace(/(^|[^='"])#([0-9a-f]{6})/gi, function (match, prefix, color, at, inputValue) { + var suffix = inputValue[at + match.length]; + + if (suffix && HEX_VALUE_PATTERN.test(suffix)) { + return match; + } else if (color[0] == color[1] && color[2] == color[3] && color[4] == color[5]) { + return (prefix + '#' + color[0] + color[2] + color[4]).toLowerCase(); } else { - return (prefix + '#' + color).toLowerCase() + suffix; + return (prefix + '#' + color).toLowerCase(); } }) .replace(/(^|[^='"])#([0-9a-f]{3})/gi, function (match, prefix, color) { @@ -329,7 +336,7 @@ function optimizeZeroUnits(name, value) { } function removeQuotes(name, value) { - if (name == 'content' || name.indexOf('font-feature-settings') > -1 || name.indexOf('grid-') > -1) { + if (name == 'content' || name.indexOf('font-variation-settings') > -1 || name.indexOf('font-feature-settings') > -1 || name.indexOf('grid-') > -1) { return value; } @@ -344,8 +351,9 @@ function removeUrlQuotes(value) { value; } -function transformValue(propertyName, propertyValue, transformCallback) { - var transformedValue = transformCallback(propertyName, propertyValue); +function transformValue(propertyName, propertyValue, rule, transformCallback) { + var selector = serializeRules(rule); + var transformedValue = transformCallback(propertyName, propertyValue, selector); if (transformedValue === undefined) { return propertyValue; @@ -358,7 +366,7 @@ function transformValue(propertyName, propertyValue, transformCallback) { // -function optimizeBody(properties, context) { +function optimizeBody(rule, properties, context) { var options = context.options; var levelOptions = options.level[OptimizationLevel.One]; var property, name, type, value; @@ -403,7 +411,7 @@ function optimizeBody(properties, context) { } if (property.block) { - optimizeBody(property.value[0][1], context); + optimizeBody(rule, property.value[0][1], context); continue; } @@ -462,7 +470,7 @@ function optimizeBody(properties, context) { } } - value = transformValue(name, value, levelOptions.transform); + value = transformValue(name, value, rule, levelOptions.transform); if (value === IgnoreProperty) { property.unused = true; @@ -632,7 +640,7 @@ function level1Optimize(tokens, context) { mayHaveCharset = true; break; case Token.AT_RULE_BLOCK: - optimizeBody(token[2], context); + optimizeBody(token[1], token[2], context); afterRules = true; break; case Token.NESTED_BLOCK: @@ -646,7 +654,7 @@ function level1Optimize(tokens, context) { case Token.RULE: token[1] = levelOptions.tidySelectors ? tidyRules(token[1], !ie7Hack, adjacentSpace, format, context.warnings) : token[1]; token[1] = token[1].length > 1 ? sortSelectors(token[1], levelOptions.selectorsSortingMethod) : token[1]; - optimizeBody(token[2], context); + optimizeBody(token[1], token[2], context); afterRules = true; break; } diff --git a/node_modules/clean-css/lib/optimizer/level-1/tidy-rules.js b/node_modules/clean-css/lib/optimizer/level-1/tidy-rules.js index 0af3b2fe7..d046d0efd 100644 --- a/node_modules/clean-css/lib/optimizer/level-1/tidy-rules.js +++ b/node_modules/clean-css/lib/optimizer/level-1/tidy-rules.js @@ -68,7 +68,7 @@ function removeWhitespace(value, format) { character = value[i]; isNewLineNix = character == Marker.NEW_LINE_NIX; - isNewLineWin = character == Marker.NEW_LINE_NIX && value[i - 1] == Marker.NEW_LINE_WIN; + isNewLineWin = character == Marker.NEW_LINE_NIX && value[i - 1] == Marker.CARRIAGE_RETURN; isQuoted = isSingleQuoted || isDoubleQuoted; isRelation = !isAttribute && !isEscaped && roundBracketLevel === 0 && RELATION_PATTERN.test(character); isWhitespace = WHITESPACE_PATTERN.test(character); diff --git a/node_modules/clean-css/lib/optimizer/level-2/break-up.js b/node_modules/clean-css/lib/optimizer/level-2/break-up.js index b48ccf23d..5301cb898 100644 --- a/node_modules/clean-css/lib/optimizer/level-2/break-up.js +++ b/node_modules/clean-css/lib/optimizer/level-2/break-up.js @@ -105,7 +105,7 @@ function animation(property, compactable, validator) { } else if (validator.isTime(value[1]) && !delaySet) { delay.value = [value]; delaySet = true; - } else if ((validator.isGlobal(value[1]) || validator.isAnimationTimingFunction(value[1])) && !timingSet) { + } else if ((validator.isGlobal(value[1]) || validator.isTimingFunction(value[1])) && !timingSet) { timing.value = [value]; timingSet = true; } else if ((validator.isAnimationIterationCountKeyword(value[1]) || validator.isPositiveNumber(value[1])) && !iterationSet) { @@ -299,6 +299,10 @@ function font(property, compactable, validator) { return components; } + if (values.length < 2 || !_anyIsFontSize(values, validator) || !_anyIsFontFamily(values, validator)) { + throw new InvalidPropertyError('Invalid font values at ' + formatPosition(property.all[property.position][1][2][0]) + '. Ignoring.'); + } + if (values.length > 1 && _anyIsInherit(values)) { throw new InvalidPropertyError('Invalid font values at ' + formatPosition(values[0][2][0]) + '. Ignoring.'); } @@ -377,6 +381,36 @@ function font(property, compactable, validator) { return components; } +function _anyIsFontSize(values, validator) { + var value; + var i, l; + + for (i = 0, l = values.length; i < l; i++) { + value = values[i]; + + if (validator.isFontSizeKeyword(value[1]) || validator.isUnit(value[1]) && !validator.isDynamicUnit(value[1]) || validator.isFunction(value[1])) { + return true; + } + } + + return false; +} + +function _anyIsFontFamily(values, validator) { + var value; + var i, l; + + for (i = 0, l = values.length; i < l; i++) { + value = values[i]; + + if (validator.isIdentifier(value[1])) { + return true; + } + } + + return false; +} + function fourValues(property, compactable) { var componentNames = compactable[property.name].components; var components = []; @@ -489,6 +523,53 @@ function listStyle(property, compactable, validator) { return components; } +function transition(property, compactable, validator) { + var prop = _wrapDefault(property.name + '-property', property, compactable); + var duration = _wrapDefault(property.name + '-duration', property, compactable); + var timing = _wrapDefault(property.name + '-timing-function', property, compactable); + var delay = _wrapDefault(property.name + '-delay', property, compactable); + var components = [prop, duration, timing, delay]; + var values = property.value; + var value; + var durationSet = false; + var delaySet = false; + var propSet = false; + var timingSet = false; + var i; + var l; + + if (property.value.length == 1 && property.value[0][1] == 'inherit') { + prop.value = duration.value = timing.value = delay.value = property.value; + return components; + } + + if (values.length > 1 && _anyIsInherit(values)) { + throw new InvalidPropertyError('Invalid animation values at ' + formatPosition(values[0][2][0]) + '. Ignoring.'); + } + + for (i = 0, l = values.length; i < l; i++) { + value = values[i]; + + if (validator.isTime(value[1]) && !durationSet) { + duration.value = [value]; + durationSet = true; + } else if (validator.isTime(value[1]) && !delaySet) { + delay.value = [value]; + delaySet = true; + } else if ((validator.isGlobal(value[1]) || validator.isTimingFunction(value[1])) && !timingSet) { + timing.value = [value]; + timingSet = true; + } else if (validator.isIdentifier(value[1]) && !propSet) { + prop.value = [value]; + propSet = true; + } else { + throw new InvalidPropertyError('Invalid animation value at ' + formatPosition(value[2][0]) + '. Ignoring.'); + } + } + + return components; +} + function widthStyleColor(property, compactable, validator) { var descriptor = compactable[property.name]; var components = [ @@ -558,5 +639,6 @@ module.exports = { fourValues: fourValues, listStyle: listStyle, multiplex: multiplex, - outline: widthStyleColor + outline: widthStyleColor, + transition: transition }; diff --git a/node_modules/clean-css/lib/optimizer/level-2/can-override.js b/node_modules/clean-css/lib/optimizer/level-2/can-override.js index 10d3bba17..3dae08f0e 100644 --- a/node_modules/clean-css/lib/optimizer/level-2/can-override.js +++ b/node_modules/clean-css/lib/optimizer/level-2/can-override.js @@ -20,16 +20,6 @@ function animationName(validator, value1, value2) { return validator.isAnimationNameKeyword(value2) || validator.isIdentifier(value2); } -function animationTimingFunction(validator, value1, value2) { - if (!understandable(validator, value1, value2, 0, true) && !(validator.isAnimationTimingFunction(value2) || validator.isGlobal(value2))) { - return false; - } else if (validator.isVariable(value1) && validator.isVariable(value2)) { - return true; - } - - return validator.isAnimationTimingFunction(value2) || validator.isGlobal(value2); -} - function areSameFunction(validator, value1, value2) { if (!validator.isFunction(value1) || !validator.isFunction(value2)) { return false; @@ -129,14 +119,22 @@ function keywordWithGlobal(propertyName) { }; } +function propertyName(validator, value1, value2) { + if (!understandable(validator, value1, value2, 0, true) && !validator.isIdentifier(value2)) { + return false; + } else if (validator.isVariable(value1) && validator.isVariable(value2)) { + return true; + } + + return validator.isIdentifier(value2); +} + function sameFunctionOrValue(validator, value1, value2) { return areSameFunction(validator, value1, value2) ? true : value1 === value2; } - - function textShadow(validator, value1, value2) { if (!understandable(validator, value1, value2, 0, true) && !(validator.isUnit(value2) || validator.isColor(value2) || validator.isGlobal(value2))) { return false; @@ -165,6 +163,16 @@ function time(validator, value1, value2) { return sameFunctionOrValue(validator, value1, value2); } +function timingFunction(validator, value1, value2) { + if (!understandable(validator, value1, value2, 0, true) && !(validator.isTimingFunction(value2) || validator.isGlobal(value2))) { + return false; + } else if (validator.isVariable(value1) && validator.isVariable(value2)) { + return true; + } + + return validator.isTimingFunction(value2) || validator.isGlobal(value2); +} + function unit(validator, value1, value2) { if (!understandable(validator, value1, value2, 0, true) && !validator.isUnit(value2)) { return false; @@ -191,6 +199,24 @@ function unitOrKeywordWithGlobal(propertyName) { }; } +function unitOrNumber(validator, value1, value2) { + if (!understandable(validator, value1, value2, 0, true) && !(validator.isUnit(value2) || validator.isNumber(value2))) { + return false; + } else if (validator.isVariable(value1) && validator.isVariable(value2)) { + return true; + } else if ((validator.isUnit(value1) || validator.isNumber(value1)) && !(validator.isUnit(value2) || validator.isNumber(value2))) { + return false; + } else if (validator.isUnit(value2) || validator.isNumber(value2)) { + return true; + } else if (validator.isUnit(value1) || validator.isNumber(value1)) { + return false; + } else if (validator.isFunction(value1) && !validator.isPrefixed(value1) && validator.isFunction(value2) && !validator.isPrefixed(value2)) { + return true; + } + + return sameFunctionOrValue(validator, value1, value2); +} + function zIndex(validator, value1, value2) { if (!understandable(validator, value1, value2, 0, true) && !validator.isZIndex(value2)) { return false; @@ -206,8 +232,11 @@ module.exports = { color: color, components: components, image: image, + propertyName: propertyName, time: time, - unit: unit + timingFunction: timingFunction, + unit: unit, + unitOrNumber: unitOrNumber }, property: { animationDirection: keywordWithGlobal('animation-direction'), @@ -215,7 +244,6 @@ module.exports = { animationIterationCount: animationIterationCount, animationName: animationName, animationPlayState: keywordWithGlobal('animation-play-state'), - animationTimingFunction: animationTimingFunction, backgroundAttachment: keyword('background-attachment'), backgroundClip: keywordWithGlobal('background-clip'), backgroundOrigin: keyword('background-origin'), diff --git a/node_modules/clean-css/lib/optimizer/level-2/compactable.js b/node_modules/clean-css/lib/optimizer/level-2/compactable.js index 97e7e2aca..73f42a10e 100644 --- a/node_modules/clean-css/lib/optimizer/level-2/compactable.js +++ b/node_modules/clean-css/lib/optimizer/level-2/compactable.js @@ -38,7 +38,7 @@ var compactable = { 'animation': { canOverride: canOverride.generic.components([ canOverride.generic.time, - canOverride.property.animationTimingFunction, + canOverride.generic.timingFunction, canOverride.generic.time, canOverride.property.animationIterationCount, canOverride.property.animationDirection, @@ -99,6 +99,7 @@ var compactable = { ], defaultValue: '0s', intoMultiplexMode: 'real', + keepUnlessDefault: 'animation-delay', vendorPrefixes: [ '-moz-', '-o-', @@ -158,7 +159,7 @@ var compactable = { ] }, 'animation-timing-function': { - canOverride: canOverride.property.animationTimingFunction, + canOverride: canOverride.generic.timingFunction, componentOf: [ 'animation' ], @@ -680,7 +681,7 @@ var compactable = { defaultValue: 'auto' }, 'line-height': { - canOverride: canOverride.generic.unit, + canOverride: canOverride.generic.unitOrNumber, defaultValue: 'normal', shortestValue: '0' }, @@ -917,6 +918,82 @@ var compactable = { '-webkit-' ] }, + 'transition': { + breakUp: breakUp.multiplex(breakUp.transition), + canOverride: canOverride.generic.components([ + canOverride.property.transitionProperty, + canOverride.generic.time, + canOverride.generic.timingFunction, + canOverride.generic.time + ]), + components: [ + 'transition-property', + 'transition-duration', + 'transition-timing-function', + 'transition-delay' + ], + defaultValue: 'none', + restore: restore.multiplex(restore.withoutDefaults), + shorthand: true, + vendorPrefixes: [ + '-moz-', + '-o-', + '-webkit-' + ] + }, + 'transition-delay': { + canOverride: canOverride.generic.time, + componentOf: [ + 'transition' + ], + defaultValue: '0s', + intoMultiplexMode: 'real', + vendorPrefixes: [ + '-moz-', + '-o-', + '-webkit-' + ] + }, + 'transition-duration': { + canOverride: canOverride.generic.time, + componentOf: [ + 'transition' + ], + defaultValue: '0s', + intoMultiplexMode: 'real', + vendorPrefixes: [ + '-moz-', + '-o-', + '-webkit-' + ] + }, + 'transition-property': { + canOverride: canOverride.generic.propertyName, + componentOf: [ + 'transition' + ], + defaultValue: 'all', + intoMultiplexMode: 'placeholder', + placeholderValue: '_', // it's a short value that won't match any property and still be a valid `transition-property` + vendorPrefixes: [ + '-moz-', + '-o-', + '-webkit-' + ] + }, + 'transition-timing-function': { + canOverride: canOverride.generic.timingFunction, + componentOf: [ + 'transition' + ], + defaultValue: 'ease', + intoMultiplexMode: 'real', + vendorPrefixes: [ + '-moz-', + '-o-', + '-webkit-' + ] + }, 'vertical-align': { canOverride: canOverride.property.verticalAlign, defaultValue: 'baseline' @@ -955,6 +1032,10 @@ function cloneDescriptor(propertyName, prefix) { }); } + if ('keepUnlessDefault' in clonedDescriptor) { + clonedDescriptor.keepUnlessDefault = prefix + clonedDescriptor.keepUnlessDefault; + } + return clonedDescriptor; } diff --git a/node_modules/clean-css/lib/optimizer/level-2/properties/override-properties.js b/node_modules/clean-css/lib/optimizer/level-2/properties/override-properties.js index 3749720c9..0f7b97a9f 100644 --- a/node_modules/clean-css/lib/optimizer/level-2/properties/override-properties.js +++ b/node_modules/clean-css/lib/optimizer/level-2/properties/override-properties.js @@ -8,7 +8,6 @@ var sameVendorPrefixesIn = require('./vendor-prefixes').same; var compactable = require('../compactable'); var deepClone = require('../clone').deep; -var deepClone = require('../clone').deep; var restoreWithComponents = require('../restore-with-components'); var shallowClone = require('../clone').shallow; @@ -95,10 +94,11 @@ function turnShorthandValueIntoMultiplex(property, size) { } function turnLonghandValueIntoMultiplex(property, size) { - var withRealValue = compactable[property.name].intoMultiplexMode == 'real'; - var withValue = withRealValue ? + var descriptor = compactable[property.name]; + var withRealValue = descriptor.intoMultiplexMode == 'real'; + var withValue = descriptor.intoMultiplexMode == 'real' ? property.value.slice(0) : - compactable[property.name].defaultValue; + (descriptor.intoMultiplexMode == 'placeholder' ? descriptor.placeholderValue : descriptor.defaultValue); var i = multiplexSize(property); var j; var m = withValue.length; diff --git a/node_modules/clean-css/lib/optimizer/level-2/remove-unused-at-rules.js b/node_modules/clean-css/lib/optimizer/level-2/remove-unused-at-rules.js index 7285991a4..798d3939f 100644 --- a/node_modules/clean-css/lib/optimizer/level-2/remove-unused-at-rules.js +++ b/node_modules/clean-css/lib/optimizer/level-2/remove-unused-at-rules.js @@ -8,6 +8,14 @@ var Token = require('../../tokenizer/token'); var animationNameRegex = /^(\-moz\-|\-o\-|\-webkit\-)?animation-name$/; var animationRegex = /^(\-moz\-|\-o\-|\-webkit\-)?animation$/; var keyframeRegex = /^@(\-moz\-|\-o\-|\-webkit\-)?keyframes /; +var importantRegex = /\s{0,31}!important$/; +var optionalMatchingQuotesRegex = /^(['"]?)(.*)\1$/; + +function normalize(value) { + return value + .replace(optionalMatchingQuotesRegex, '$2') + .replace(importantRegex, ''); +} function removeUnusedAtRules(tokens, context) { removeUnusedAtRule(tokens, matchCounterStyle, markCounterStylesAsUsed, context); @@ -107,7 +115,7 @@ function matchFontFace(token, atRules) { property = token[2][i]; if (property[1][1] == 'font-family') { - match = property[2][1].toLowerCase(); + match = normalize(property[2][1].toLowerCase()); atRules[match] = atRules[match] || []; atRules[match].push(token); break; @@ -134,7 +142,7 @@ function markFontFacesAsUsed(atRules) { component = wrappedProperty.components[6]; for (j = 0, m = component.value.length; j < m; j++) { - normalizedMatch = component.value[j][1].toLowerCase(); + normalizedMatch = normalize(component.value[j][1].toLowerCase()); if (normalizedMatch in atRules) { delete atRules[normalizedMatch]; @@ -146,7 +154,7 @@ function markFontFacesAsUsed(atRules) { if (property[1][1] == 'font-family') { for (j = 2, m = property.length; j < m; j++) { - normalizedMatch = property[j][1].toLowerCase(); + normalizedMatch = normalize(property[j][1].toLowerCase()); if (normalizedMatch in atRules) { delete atRules[normalizedMatch]; diff --git a/node_modules/clean-css/lib/optimizer/level-2/restore.js b/node_modules/clean-css/lib/optimizer/level-2/restore.js index 13f12e496..f9c2f0d33 100644 --- a/node_modules/clean-css/lib/optimizer/level-2/restore.js +++ b/node_modules/clean-css/lib/optimizer/level-2/restore.js @@ -264,8 +264,9 @@ function withoutDefaults(property, compactable) { var component = components[i]; var descriptor = compactable[component.name]; - if (component.value[0][1] != descriptor.defaultValue) + if (component.value[0][1] != descriptor.defaultValue || ('keepUnlessDefault' in descriptor) && !isDefault(components, compactable, descriptor.keepUnlessDefault)) { restored.unshift(component.value[0]); + } } if (restored.length === 0) @@ -277,6 +278,21 @@ function withoutDefaults(property, compactable) { return restored; } +function isDefault(components, compactable, propertyName) { + var component; + var i, l; + + for (i = 0, l = components.length; i < l; i++) { + component = components[i]; + + if (component.name == propertyName && component.value[0][1] == compactable[propertyName].defaultValue) { + return true; + } + } + + return false; +} + module.exports = { background: background, borderRadius: borderRadius, diff --git a/node_modules/clean-css/lib/optimizer/validator.js b/node_modules/clean-css/lib/optimizer/validator.js index cfccd0f9d..fd3fb97e4 100644 --- a/node_modules/clean-css/lib/optimizer/validator.js +++ b/node_modules/clean-css/lib/optimizer/validator.js @@ -3,20 +3,28 @@ var functionVendorRegexStr = '\\-(\\-|[A-Z]|[0-9])+\\(.*?\\)'; var variableRegexStr = 'var\\(\\-\\-[^\\)]+\\)'; var functionAnyRegexStr = '(' + variableRegexStr + '|' + functionNoVendorRegexStr + '|' + functionVendorRegexStr + ')'; -var animationTimingFunctionRegex = /^(cubic\-bezier|steps)\([^\)]+\)$/; var calcRegex = new RegExp('^(\\-moz\\-|\\-webkit\\-)?calc\\([^\\)]+\\)$', 'i'); +var decimalRegex = /[0-9]/; var functionAnyRegex = new RegExp('^' + functionAnyRegexStr + '$', 'i'); -var hslColorRegex = /^hsl\(\s*[\-\.\d]+\s*,\s*[\.\d]+%\s*,\s*[\.\d]+%\s*\)|hsla\(\s*[\-\.\d]+\s*,\s*[\.\d]+%\s*,\s*[\.\d]+%\s*,\s*[\.\d]+\s*\)$/; +var hslColorRegex = /^hsl\(\s{0,31}[\-\.]?\d+\s{0,31},\s{0,31}\.?\d+%\s{0,31},\s{0,31}\.?\d+%\s{0,31}\)|hsla\(\s{0,31}[\-\.]?\d+\s{0,31},\s{0,31}\.?\d+%\s{0,31},\s{0,31}\.?\d+%\s{0,31},\s{0,31}\.?\d+\s{0,31}\)$/; var identifierRegex = /^(\-[a-z0-9_][a-z0-9\-_]*|[a-z][a-z0-9\-_]*)$/i; -var longHexColorRegex = /^#[0-9a-f]{6}$/i; var namedEntityRegex = /^[a-z]+$/i; var prefixRegex = /^-([a-z0-9]|-)*$/i; -var rgbColorRegex = /^rgb\(\s*[\d]{1,3}\s*,\s*[\d]{1,3}\s*,\s*[\d]{1,3}\s*\)|rgba\(\s*[\d]{1,3}\s*,\s*[\d]{1,3}\s*,\s*[\d]{1,3}\s*,\s*[\.\d]+\s*\)$/; -var shortHexColorRegex = /^#[0-9a-f]{3}$/i; -var timeRegex = new RegExp('^(\\-?\\+?\\.?\\d+\\.?\\d*(s|ms))$'); +var rgbColorRegex = /^rgb\(\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\d]{1,3}\s{0,31}\)|rgba\(\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\.\d]+\s{0,31}\)$/; +var timingFunctionRegex = /^(cubic\-bezier|steps)\([^\)]+\)$/; +var validTimeUnits = ['ms', 's']; var urlRegex = /^url\([\s\S]+\)$/i; var variableRegex = new RegExp('^' + variableRegexStr + '$', 'i'); +var eightValueColorRegex = /^#[0-9a-f]{8}$/i; +var fourValueColorRegex = /^#[0-9a-f]{4}$/i; +var sixValueColorRegex = /^#[0-9a-f]{6}$/i; +var threeValueColorRegex = /^#[0-9a-f]{3}$/i; + +var DECIMAL_DOT = '.'; +var MINUS_SIGN = '-'; +var PLUS_SIGN = '+'; + var Keywords = { '^': [ 'inherit', @@ -36,6 +44,15 @@ var Keywords = { 'ridge', 'solid' ], + '*-timing-function': [ + 'ease', + 'ease-in', + 'ease-in-out', + 'ease-out', + 'linear', + 'step-end', + 'step-start' + ], 'animation-direction': [ 'alternate', 'alternate-reverse', @@ -58,15 +75,6 @@ var Keywords = { 'paused', 'running' ], - 'animation-timing-function': [ - 'ease', - 'ease-in', - 'ease-in-out', - 'ease-out', - 'linear', - 'step-end', - 'step-start' - ], 'background-attachment': [ 'fixed', 'inherit', @@ -337,14 +345,6 @@ var Units = [ 'vw' ]; -function isAnimationTimingFunction() { - var isTimingFunctionKeyword = isKeyword('animation-timing-function'); - - return function (value) { - return isTimingFunctionKeyword(value) || animationTimingFunctionRegex.test(value); - }; -} - function isColor(value) { return value != 'auto' && ( @@ -368,7 +368,7 @@ function isFunction(value) { } function isHexColor(value) { - return shortHexColorRegex.test(value) || longHexColorRegex.test(value); + return threeValueColorRegex.test(value) || fourValueColorRegex.test(value) || sixValueColorRegex.test(value) || eightValueColorRegex.test(value); } function isHslColor(value) { @@ -394,7 +394,7 @@ function isNamedEntity(value) { } function isNumber(value) { - return value.length > 0 && ('' + parseFloat(value)) === value; + return scanForNumber(value) == value.length; } function isRgbColor(value) { @@ -415,11 +415,27 @@ function isVariable(value) { } function isTime(value) { - return timeRegex.test(value); + var numberUpTo = scanForNumber(value); + + return numberUpTo == value.length && parseInt(value) === 0 || + numberUpTo > -1 && validTimeUnits.indexOf(value.slice(numberUpTo + 1)) > -1; +} + +function isTimingFunction() { + var isTimingFunctionKeyword = isKeyword('*-timing-function'); + + return function (value) { + return isTimingFunctionKeyword(value) || timingFunctionRegex.test(value); + }; } -function isUnit(compatibleCssUnitRegex, value) { - return compatibleCssUnitRegex.test(value); +function isUnit(validUnits, value) { + var numberUpTo = scanForNumber(value); + + return numberUpTo == value.length && parseInt(value) === 0 || + numberUpTo > -1 && validUnits.indexOf(value.slice(numberUpTo + 1)) > -1 || + value == 'auto' || + value == 'inherit'; } function isUrl(value) { @@ -432,13 +448,38 @@ function isZIndex(value) { isKeyword('^')(value); } +function scanForNumber(value) { + var hasDot = false; + var hasSign = false; + var character; + var i, l; + + for (i = 0, l = value.length; i < l; i++) { + character = value[i]; + + if (i === 0 && (character == PLUS_SIGN || character == MINUS_SIGN)) { + hasSign = true; + } else if (i > 0 && hasSign && (character == PLUS_SIGN || character == MINUS_SIGN)) { + return i - 1; + } else if (character == DECIMAL_DOT && !hasDot) { + hasDot = true; + } else if (character == DECIMAL_DOT && hasDot) { + return i - 1; + } else if (decimalRegex.test(character)) { + continue; + } else { + return i - 1; + } + } + + return i; +} + function validator(compatibility) { var validUnits = Units.slice(0).filter(function (value) { return !(value in compatibility.units) || compatibility.units[value] === true; }); - var compatibleCssUnitRegex = new RegExp('^(\\-?\\.?\\d+\\.?\\d*(' + validUnits.join('|') + '|)|auto|inherit)$', 'i'); - return { colorOpacity: compatibility.colors.opacity, isAnimationDirectionKeyword: isKeyword('animation-direction'), @@ -446,7 +487,7 @@ function validator(compatibility) { isAnimationIterationCountKeyword: isKeyword('animation-iteration-count'), isAnimationNameKeyword: isKeyword('animation-name'), isAnimationPlayStateKeyword: isKeyword('animation-play-state'), - isAnimationTimingFunction: isAnimationTimingFunction(), + isTimingFunction: isTimingFunction(), isBackgroundAttachmentKeyword: isKeyword('background-attachment'), isBackgroundClipKeyword: isKeyword('background-clip'), isBackgroundOriginKeyword: isKeyword('background-origin'), @@ -471,12 +512,13 @@ function validator(compatibility) { isLineHeightKeyword: isKeyword('line-height'), isListStylePositionKeyword: isKeyword('list-style-position'), isListStyleTypeKeyword: isKeyword('list-style-type'), + isNumber: isNumber, isPrefixed: isPrefixed, isPositiveNumber: isPositiveNumber, isRgbColor: isRgbColor, isStyleKeyword: isKeyword('*-style'), isTime: isTime, - isUnit: isUnit.bind(null, compatibleCssUnitRegex), + isUnit: isUnit.bind(null, validUnits), isUrl: isUrl, isVariable: isVariable, isWidth: isKeyword('width'), diff --git a/node_modules/clean-css/lib/options/format.js b/node_modules/clean-css/lib/options/format.js index afcf5c967..48c7efa8e 100644 --- a/node_modules/clean-css/lib/options/format.js +++ b/node_modules/clean-css/lib/options/format.js @@ -1,3 +1,5 @@ +var systemLineBreak = require('os').EOL; + var override = require('../utils/override'); var Breaks = { @@ -12,6 +14,12 @@ var Breaks = { BetweenSelectors: 'betweenSelectors' }; +var BreakWith = { + CarriageReturnLineFeed: '\r\n', + LineFeed: '\n', + System: systemLineBreak +}; + var IndentWith = { Space: ' ', Tab: '\t' @@ -25,10 +33,12 @@ var Spaces = { var DEFAULTS = { breaks: breaks(false), + breakWith: BreakWith.System, indentBy: 0, indentWith: IndentWith.Space, spaces: spaces(false), - wrapAt: false + wrapAt: false, + semicolonAfterLastProperty: false }; var BEAUTIFY_ALIAS = 'beautify'; @@ -75,6 +85,10 @@ function formatFrom(source) { return false; } + if (typeof source == 'object' && 'breakWith' in source) { + source = override(source, { breakWith: mapBreakWith(source.breakWith) }); + } + if (typeof source == 'object' && 'indentBy' in source) { source = override(source, { indentBy: parseInt(source.indentBy) }); } @@ -133,6 +147,8 @@ function toHash(string) { accumulator[name] = parseInt(value); } else if (name == 'indentWith') { accumulator[name] = mapIndentWith(value); + } else if (name == 'breakWith') { + accumulator[name] = mapBreakWith(value); } return accumulator; @@ -167,6 +183,21 @@ function normalizeValue(value) { } } +function mapBreakWith(value) { + switch (value) { + case 'windows': + case 'crlf': + case BreakWith.CarriageReturnLineFeed: + return BreakWith.CarriageReturnLineFeed; + case 'unix': + case 'lf': + case BreakWith.LineFeed: + return BreakWith.LineFeed; + default: + return systemLineBreak; + } +} + function mapIndentWith(value) { switch (value) { case 'space': diff --git a/node_modules/clean-css/lib/reader/input-source-map-tracker.js b/node_modules/clean-css/lib/reader/input-source-map-tracker.js index ea2c03467..4b8730c29 100644 --- a/node_modules/clean-css/lib/reader/input-source-map-tracker.js +++ b/node_modules/clean-css/lib/reader/input-source-map-tracker.js @@ -34,6 +34,10 @@ function originalPositionFor(maps, metadata, range, selectorFallbacks) { originalPosition = maps[source].originalPositionFor(position); } + if (!originalPosition || originalPosition.column < 0) { + return metadata; + } + if (originalPosition.line === null && line > 1 && selectorFallbacks > 0) { return originalPositionFor(maps, [line - 1, column, source], range, selectorFallbacks - 1); } diff --git a/node_modules/clean-css/lib/reader/read-sources.js b/node_modules/clean-css/lib/reader/read-sources.js index c9173ed62..1338f6adc 100644 --- a/node_modules/clean-css/lib/reader/read-sources.js +++ b/node_modules/clean-css/lib/reader/read-sources.js @@ -288,7 +288,6 @@ function inlineLocalStylesheet(uri, mediaQuery, metadata, inlinerContext) { path.resolve(inlinerContext.rebaseTo, uri); var relativeToCurrentPath = path.relative(currentPath, absoluteUri); var importedStyles; - var importedTokens; var isAllowed = isAllowedResource(uri, false, inlinerContext.inline); var normalizedPath = normalizePath(relativeToCurrentPath); var isLoaded = normalizedPath in inlinerContext.externalContext.sourcesContent; @@ -316,10 +315,14 @@ function inlineLocalStylesheet(uri, mediaQuery, metadata, inlinerContext) { inlinerContext.externalContext.sourcesContent[normalizedPath] = importedStyles; inlinerContext.externalContext.stats.originalSize += importedStyles.length; - importedTokens = fromStyles(importedStyles, inlinerContext.externalContext, inlinerContext, function (tokens) { return tokens; }); - importedTokens = wrapInMedia(importedTokens, mediaQuery, metadata); + return fromStyles(importedStyles, inlinerContext.externalContext, inlinerContext, function (importedTokens) { + importedTokens = wrapInMedia(importedTokens, mediaQuery, metadata); - inlinerContext.outputTokens = inlinerContext.outputTokens.concat(importedTokens); + inlinerContext.outputTokens = inlinerContext.outputTokens.concat(importedTokens); + inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1); + + return doInlineImports(inlinerContext); + }); } inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1); diff --git a/node_modules/clean-css/lib/tokenizer/marker.js b/node_modules/clean-css/lib/tokenizer/marker.js index 767a5f0e8..270fdbc3b 100644 --- a/node_modules/clean-css/lib/tokenizer/marker.js +++ b/node_modules/clean-css/lib/tokenizer/marker.js @@ -2,6 +2,7 @@ var Marker = { ASTERISK: '*', AT: '@', BACK_SLASH: '\\', + CARRIAGE_RETURN: '\r', CLOSE_CURLY_BRACKET: '}', CLOSE_ROUND_BRACKET: ')', CLOSE_SQUARE_BRACKET: ']', @@ -12,7 +13,6 @@ var Marker = { FORWARD_SLASH: '/', INTERNAL: '-clean-css-', NEW_LINE_NIX: '\n', - NEW_LINE_WIN: '\r', OPEN_CURLY_BRACKET: '{', OPEN_ROUND_BRACKET: '(', OPEN_SQUARE_BRACKET: '[', diff --git a/node_modules/clean-css/lib/tokenizer/token.js b/node_modules/clean-css/lib/tokenizer/token.js index acd0154ee..a1d726f0e 100644 --- a/node_modules/clean-css/lib/tokenizer/token.js +++ b/node_modules/clean-css/lib/tokenizer/token.js @@ -9,6 +9,7 @@ var Token = { PROPERTY_BLOCK: 'property-block', // e.g. `--var:{color:red}` PROPERTY_NAME: 'property-name', // e.g. `color` PROPERTY_VALUE: 'property-value', // e.g. `red` + RAW: 'raw', // e.g. anything between /* clean-css ignore:start */ and /* clean-css ignore:end */ comments RULE: 'rule', // e.g `div > a{...}` RULE_SCOPE: 'rule-scope' // e.g `div > a` }; diff --git a/node_modules/clean-css/lib/tokenizer/tokenize.js b/node_modules/clean-css/lib/tokenizer/tokenize.js index 018b89de8..39c9e67bc 100644 --- a/node_modules/clean-css/lib/tokenizer/tokenize.js +++ b/node_modules/clean-css/lib/tokenizer/tokenize.js @@ -28,6 +28,9 @@ var BLOCK_RULES = [ '@supports' ]; +var IGNORE_END_COMMENT_PATTERN = /\/\* clean\-css ignore:end \*\/$/; +var IGNORE_START_COMMENT_PATTERN = /^\/\* clean\-css ignore:start \*\//; + var PAGE_MARGIN_BOXES = [ '@bottom-center', '@bottom-left', @@ -56,7 +59,7 @@ var EXTRA_PAGE_BOXES = [ '@right' ]; -var REPEAT_PATTERN = /^\[\s*\d+\s*\]$/; +var REPEAT_PATTERN = /^\[\s{0,31}\d+\s{0,31}\]$/; var RULE_WORD_SEPARATOR_PATTERN = /[\s\(]/; var TAIL_BROKEN_VALUE_PATTERN = /[\s|\}]*$/; @@ -88,20 +91,25 @@ function intoTokens(source, externalContext, internalContext, isNested) { var buffer = []; var buffers = []; var serializedBuffer; + var serializedBufferPart; var roundBracketLevel = 0; var isQuoted; var isSpace; var isNewLineNix; var isNewLineWin; + var isCarriageReturn; var isCommentStart; var wasCommentStart = false; var isCommentEnd; var wasCommentEnd = false; + var isCommentEndMarker; var isEscaped; var wasEscaped = false; + var isRaw = false; var seekingValue = false; var seekingPropertyBlockClosing = false; var position = internalContext.position; + var lastCommentStartAt; for (; position.index < source.length; position.index++) { var character = source[position.index]; @@ -109,9 +117,12 @@ function intoTokens(source, externalContext, internalContext, isNested) { isQuoted = level == Level.SINGLE_QUOTE || level == Level.DOUBLE_QUOTE; isSpace = character == Marker.SPACE || character == Marker.TAB; isNewLineNix = character == Marker.NEW_LINE_NIX; - isNewLineWin = character == Marker.NEW_LINE_NIX && source[position.index - 1] == Marker.NEW_LINE_WIN; + isNewLineWin = character == Marker.NEW_LINE_NIX && source[position.index - 1] == Marker.CARRIAGE_RETURN; + isCarriageReturn = character == Marker.CARRIAGE_RETURN && source[position.index + 1] && source[position.index + 1] != Marker.NEW_LINE_NIX; isCommentStart = !wasCommentEnd && level != Level.COMMENT && !isQuoted && character == Marker.ASTERISK && source[position.index - 1] == Marker.FORWARD_SLASH; - isCommentEnd = !wasCommentStart && level == Level.COMMENT && character == Marker.FORWARD_SLASH && source[position.index - 1] == Marker.ASTERISK; + isCommentEndMarker = !wasCommentStart && !isQuoted && character == Marker.FORWARD_SLASH && source[position.index - 1] == Marker.ASTERISK; + isCommentEnd = level == Level.COMMENT && isCommentEndMarker; + roundBracketLevel = Math.max(roundBracketLevel, 0); metadata = buffer.length === 0 ? [position.line, position.column, position.source] : @@ -122,6 +133,8 @@ function intoTokens(source, externalContext, internalContext, isNested) { buffer.push(character); } else if (!isCommentEnd && level == Level.COMMENT) { buffer.push(character); + } else if (!isCommentStart && !isCommentEnd && isRaw) { + buffer.push(character); } else if (isCommentStart && (level == Level.BLOCK || level == Level.RULE) && buffer.length > 1) { // comment start within block preceded by some content, e.g. div/*<-- metadatas.push(metadata); @@ -138,6 +151,33 @@ function intoTokens(source, externalContext, internalContext, isNested) { levels.push(level); level = Level.COMMENT; buffer.push(character); + } else if (isCommentEnd && isIgnoreStartComment(buffer)) { + // ignore:start comment end, e.g. /* clean-css ignore:start */<-- + serializedBuffer = buffer.join('').trim() + character; + lastToken = [Token.COMMENT, serializedBuffer, [originalMetadata(metadata, serializedBuffer, externalContext)]]; + newTokens.push(lastToken); + + isRaw = true; + metadata = metadatas.pop() || null; + buffer = buffers.pop() || []; + } else if (isCommentEnd && isIgnoreEndComment(buffer)) { + // ignore:start comment end, e.g. /* clean-css ignore:end */<-- + serializedBuffer = buffer.join('') + character; + lastCommentStartAt = serializedBuffer.lastIndexOf(Marker.FORWARD_SLASH + Marker.ASTERISK); + + serializedBufferPart = serializedBuffer.substring(0, lastCommentStartAt); + lastToken = [Token.RAW, serializedBufferPart, [originalMetadata(metadata, serializedBufferPart, externalContext)]]; + newTokens.push(lastToken); + + serializedBufferPart = serializedBuffer.substring(lastCommentStartAt); + metadata = [position.line, position.column - serializedBufferPart.length + 1, position.source]; + lastToken = [Token.COMMENT, serializedBufferPart, [originalMetadata(metadata, serializedBufferPart, externalContext)]]; + newTokens.push(lastToken); + + isRaw = false; + level = levels.pop(); + metadata = metadatas.pop() || null; + buffer = buffers.pop() || []; } else if (isCommentEnd) { // comment end, e.g. /* comment */<-- serializedBuffer = buffer.join('').trim() + character; @@ -147,6 +187,9 @@ function intoTokens(source, externalContext, internalContext, isNested) { level = levels.pop(); metadata = metadatas.pop() || null; buffer = buffers.pop() || []; + } else if (isCommentEndMarker && source[position.index + 1] != Marker.ASTERISK) { + externalContext.warnings.push('Unexpected \'*/\' at ' + formatPosition([position.line, position.column, position.source]) + '.'); + buffer = []; } else if (character == Marker.SINGLE_QUOTE && !isQuoted) { // single quotation start, e.g. a[href^='https<-- levels.push(level); @@ -442,7 +485,7 @@ function intoTokens(source, externalContext, internalContext, isNested) { } else if (buffer.length == 1 && isNewLineWin) { // ignore windows newline which is composed of two characters buffer.pop(); - } else if (buffer.length > 0 || !isSpace && !isNewLineNix && !isNewLineWin) { + } else if (buffer.length > 0 || !isSpace && !isNewLineNix && !isNewLineWin && !isCarriageReturn) { // any character buffer.push(character); } @@ -452,8 +495,8 @@ function intoTokens(source, externalContext, internalContext, isNested) { wasCommentStart = isCommentStart; wasCommentEnd = isCommentEnd; - position.line = (isNewLineWin || isNewLineNix) ? position.line + 1 : position.line; - position.column = (isNewLineWin || isNewLineNix) ? 0 : position.column + 1; + position.line = (isNewLineWin || isNewLineNix || isCarriageReturn) ? position.line + 1 : position.line; + position.column = (isNewLineWin || isNewLineNix || isCarriageReturn) ? 0 : position.column + 1; } if (seekingValue) { @@ -474,6 +517,14 @@ function intoTokens(source, externalContext, internalContext, isNested) { return allTokens; } +function isIgnoreStartComment(buffer) { + return IGNORE_START_COMMENT_PATTERN.test(buffer.join('') + Marker.FORWARD_SLASH); +} + +function isIgnoreEndComment(buffer) { + return IGNORE_END_COMMENT_PATTERN.test(buffer.join('') + Marker.FORWARD_SLASH); +} + function originalMetadata(metadata, value, externalContext, selectorFallbacks) { var source = metadata[2]; diff --git a/node_modules/clean-css/lib/writer/helpers.js b/node_modules/clean-css/lib/writer/helpers.js index da13cf6eb..11727402c 100644 --- a/node_modules/clean-css/lib/writer/helpers.js +++ b/node_modules/clean-css/lib/writer/helpers.js @@ -1,4 +1,3 @@ -var lineBreak = require('os').EOL; var emptyCharacter = ''; var Breaks = require('../options/format').Breaks; @@ -79,7 +78,20 @@ function property(context, tokens, position, lastPropertyAt) { var store = context.store; var token = tokens[position]; var isPropertyBlock = token[2][0] == Token.PROPERTY_BLOCK; - var needsSemicolon = position < lastPropertyAt || isPropertyBlock; + + var needsSemicolon; + if ( context.format ) { + if ( context.format.semicolonAfterLastProperty || isPropertyBlock ) { + needsSemicolon = true; + } else if ( position < lastPropertyAt ) { + needsSemicolon = true; + } else { + needsSemicolon = false; + } + } else { + needsSemicolon = position < lastPropertyAt || isPropertyBlock; + } + var isLast = position === lastPropertyAt; switch (token[0]) { @@ -101,6 +113,9 @@ function property(context, tokens, position, lastPropertyAt) { store(context, colon(context)); value(context, token); store(context, needsSemicolon ? semicolon(context, Breaks.AfterProperty, isLast) : emptyCharacter); + break; + case Token.RAW: + store(context, token); } } @@ -137,7 +152,7 @@ function openBrace(context, where, needsPrefixSpace) { context.indentWith = context.format.indentWith.repeat(context.indentBy); return (needsPrefixSpace && allowsSpace(context, Spaces.BeforeBlockBegins) ? Marker.SPACE : emptyCharacter) + Marker.OPEN_CURLY_BRACKET + - (allowsBreak(context, where) ? lineBreak : emptyCharacter) + + (allowsBreak(context, where) ? context.format.breakWith : emptyCharacter) + context.indentWith; } else { return Marker.OPEN_CURLY_BRACKET; @@ -148,10 +163,10 @@ function closeBrace(context, where, beforeBlockEnd, isLast) { if (context.format) { context.indentBy -= context.format.indentBy; context.indentWith = context.format.indentWith.repeat(context.indentBy); - return (allowsBreak(context, Breaks.AfterProperty) || beforeBlockEnd && allowsBreak(context, Breaks.BeforeBlockEnds) ? lineBreak : emptyCharacter) + + return (allowsBreak(context, Breaks.AfterProperty) || beforeBlockEnd && allowsBreak(context, Breaks.BeforeBlockEnds) ? context.format.breakWith : emptyCharacter) + context.indentWith + Marker.CLOSE_CURLY_BRACKET + - (isLast ? emptyCharacter : (allowsBreak(context, where) ? lineBreak : emptyCharacter) + context.indentWith); + (isLast ? emptyCharacter : (allowsBreak(context, where) ? context.format.breakWith : emptyCharacter) + context.indentWith); } else { return Marker.CLOSE_CURLY_BRACKET; } @@ -165,13 +180,13 @@ function colon(context) { function semicolon(context, where, isLast) { return context.format ? - Marker.SEMICOLON + (isLast || !allowsBreak(context, where) ? emptyCharacter : lineBreak + context.indentWith) : + Marker.SEMICOLON + (isLast || !allowsBreak(context, where) ? emptyCharacter : context.format.breakWith + context.indentWith) : Marker.SEMICOLON; } function comma(context) { return context.format ? - Marker.COMMA + (allowsBreak(context, Breaks.BetweenSelectors) ? lineBreak : emptyCharacter) + context.indentWith : + Marker.COMMA + (allowsBreak(context, Breaks.BetweenSelectors) ? context.format.breakWith : emptyCharacter) + context.indentWith : Marker.COMMA; } @@ -204,7 +219,10 @@ function all(context, tokens) { break; case Token.COMMENT: store(context, token); - store(context, allowsBreak(context, Breaks.AfterComment) ? lineBreak : emptyCharacter); + store(context, allowsBreak(context, Breaks.AfterComment) ? context.format.breakWith : emptyCharacter); + break; + case Token.RAW: + store(context, token); break; case Token.RULE: rules(context, token[1]); diff --git a/node_modules/clean-css/lib/writer/simple.js b/node_modules/clean-css/lib/writer/simple.js index 21e7f88a7..20fde2a29 100644 --- a/node_modules/clean-css/lib/writer/simple.js +++ b/node_modules/clean-css/lib/writer/simple.js @@ -1,7 +1,5 @@ var all = require('./helpers').all; -var lineBreak = require('os').EOL; - function store(serializeContext, token) { var value = typeof token == 'string' ? token : @@ -15,8 +13,8 @@ function store(serializeContext, token) { function wrap(serializeContext, value) { if (serializeContext.column + value.length > serializeContext.format.wrapAt) { - track(serializeContext, lineBreak); - serializeContext.output.push(lineBreak); + track(serializeContext, serializeContext.format.breakWith); + serializeContext.output.push(serializeContext.format.breakWith); } } diff --git a/node_modules/clean-css/lib/writer/source-maps.js b/node_modules/clean-css/lib/writer/source-maps.js index 4729eb055..6856579f0 100644 --- a/node_modules/clean-css/lib/writer/source-maps.js +++ b/node_modules/clean-css/lib/writer/source-maps.js @@ -1,7 +1,6 @@ var SourceMapGenerator = require('source-map').SourceMapGenerator; var all = require('./helpers').all; -var lineBreak = require('os').EOL; var isRemoteResource = require('../utils/is-remote-resource'); var isWindows = process.platform == 'win32'; @@ -23,8 +22,8 @@ function store(serializeContext, element) { function wrap(serializeContext, value) { if (serializeContext.column + value.length > serializeContext.format.wrapAt) { - track(serializeContext, lineBreak, false); - serializeContext.output.push(lineBreak); + track(serializeContext, serializeContext.format.breakWith, false); + serializeContext.output.push(serializeContext.format.breakWith); } } -- cgit v1.2.3