diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:43:05 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 22:18:30 +0800 |
| commit | 89e95b3f143682ed9a006991bacf45c9dcba4818 (patch) | |
| tree | 4f44cf41b828577d583890bdd5a1c31e8491a6ba /node_modules/clean-css/lib/optimizer/level-2/merge-non-adjacent-by-body.js | |
| parent | aa7f0199255277949790b41c56e8ec97dd4f0da4 (diff) | |
| download | xmake-docs-vuepress.tar.gz xmake-docs-vuepress.zip | |
remove node_modulesvuepress
Diffstat (limited to 'node_modules/clean-css/lib/optimizer/level-2/merge-non-adjacent-by-body.js')
| -rw-r--r-- | node_modules/clean-css/lib/optimizer/level-2/merge-non-adjacent-by-body.js | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/node_modules/clean-css/lib/optimizer/level-2/merge-non-adjacent-by-body.js b/node_modules/clean-css/lib/optimizer/level-2/merge-non-adjacent-by-body.js deleted file mode 100644 index 82db950f..00000000 --- a/node_modules/clean-css/lib/optimizer/level-2/merge-non-adjacent-by-body.js +++ /dev/null @@ -1,80 +0,0 @@ -var isMergeable = require('./is-mergeable'); - -var sortSelectors = require('../level-1/sort-selectors'); -var tidyRules = require('../level-1/tidy-rules'); - -var OptimizationLevel = require('../../options/optimization-level').OptimizationLevel; - -var serializeBody = require('../../writer/one-time').body; -var serializeRules = require('../../writer/one-time').rules; - -var Token = require('../../tokenizer/token'); - -function unsafeSelector(value) { - return /\.|\*| :/.test(value); -} - -function isBemElement(token) { - var asString = serializeRules(token[1]); - return asString.indexOf('__') > -1 || asString.indexOf('--') > -1; -} - -function withoutModifier(selector) { - return selector.replace(/--[^ ,>\+~:]+/g, ''); -} - -function removeAnyUnsafeElements(left, candidates) { - var leftSelector = withoutModifier(serializeRules(left[1])); - - for (var body in candidates) { - var right = candidates[body]; - var rightSelector = withoutModifier(serializeRules(right[1])); - - if (rightSelector.indexOf(leftSelector) > -1 || leftSelector.indexOf(rightSelector) > -1) - delete candidates[body]; - } -} - -function mergeNonAdjacentByBody(tokens, context) { - var options = context.options; - var mergeSemantically = options.level[OptimizationLevel.Two].mergeSemantically; - var adjacentSpace = options.compatibility.selectors.adjacentSpace; - var selectorsSortingMethod = options.level[OptimizationLevel.One].selectorsSortingMethod; - var mergeablePseudoClasses = options.compatibility.selectors.mergeablePseudoClasses; - var mergeablePseudoElements = options.compatibility.selectors.mergeablePseudoElements; - var multiplePseudoMerging = options.compatibility.selectors.multiplePseudoMerging; - var candidates = {}; - - for (var i = tokens.length - 1; i >= 0; i--) { - var token = tokens[i]; - if (token[0] != Token.RULE) - continue; - - if (token[2].length > 0 && (!mergeSemantically && unsafeSelector(serializeRules(token[1])))) - candidates = {}; - - if (token[2].length > 0 && mergeSemantically && isBemElement(token)) - removeAnyUnsafeElements(token, candidates); - - var candidateBody = serializeBody(token[2]); - var oldToken = candidates[candidateBody]; - if (oldToken && - isMergeable(serializeRules(token[1]), mergeablePseudoClasses, mergeablePseudoElements, multiplePseudoMerging) && - isMergeable(serializeRules(oldToken[1]), mergeablePseudoClasses, mergeablePseudoElements, multiplePseudoMerging)) { - - if (token[2].length > 0) { - token[1] = tidyRules(oldToken[1].concat(token[1]), false, adjacentSpace, false, context.warnings); - token[1] = token[1].length > 1 ? sortSelectors(token[1], selectorsSortingMethod) : token[1]; - } else { - token[1] = oldToken[1].concat(token[1]); - } - - oldToken[2] = []; - candidates[candidateBody] = null; - } - - candidates[serializeBody(token[2])] = token; - } -} - -module.exports = mergeNonAdjacentByBody; |
