postcss-merge-rules
Advanced tools
Comparing version
{ | ||
"name": "postcss-merge-rules", | ||
"version": "5.0.6", | ||
"version": "5.1.0", | ||
"description": "Merge CSS rules with PostCSS.", | ||
"types": "types/index.d.ts", | ||
"main": "src/index.js", | ||
"files": [ | ||
"LICENSE-MIT", | ||
"src" | ||
"src", | ||
"types" | ||
], | ||
@@ -27,3 +29,3 @@ "keywords": [ | ||
"caniuse-api": "^3.0.0", | ||
"cssnano-utils": "^3.0.2", | ||
"cssnano-utils": "^3.1.0", | ||
"postcss-selector-parser": "^6.0.5" | ||
@@ -38,4 +40,5 @@ }, | ||
"devDependencies": { | ||
"@types/caniuse-api": "^3.0.2", | ||
"postcss": "^8.2.15", | ||
"postcss-discard-comments": "^5.0.3" | ||
"postcss-discard-comments": "^5.1.0" | ||
}, | ||
@@ -42,0 +45,0 @@ "peerDependencies": { |
@@ -11,4 +11,4 @@ 'use strict'; | ||
/** | ||
* @param {postcss.Declaration} a | ||
* @param {postcss.Declaration} b | ||
* @param {import('postcss').Declaration} a | ||
* @param {import('postcss').Declaration} b | ||
* @return {boolean} | ||
@@ -23,4 +23,4 @@ */ | ||
/** | ||
* @param {postcss.Declaration[]} array | ||
* @param {postcss.Declaration} decl | ||
* @param {import('postcss').Declaration[]} array | ||
* @param {import('postcss').Declaration} decl | ||
* @return {number} | ||
@@ -34,6 +34,6 @@ */ | ||
* Returns filtered array of matched or unmatched declarations | ||
* @param {postcss.Declaration[]} a | ||
* @param {postcss.Declaration[]} b | ||
* @param {import('postcss').Declaration[]} a | ||
* @param {import('postcss').Declaration[]} b | ||
* @param {boolean} [not=false] | ||
* @return {postcss.Declaration[]} | ||
* @return {import('postcss').Declaration[]} | ||
*/ | ||
@@ -48,4 +48,4 @@ function intersect(a, b, not) { | ||
/** | ||
* @param {postcss.Declaration[]} a | ||
* @param {postcss.Declaration[]} b | ||
* @param {import('postcss').Declaration[]} a | ||
* @param {import('postcss').Declaration[]} b | ||
* @return {boolean} | ||
@@ -61,4 +61,4 @@ */ | ||
/** | ||
* @param {postcss.Rule} ruleA | ||
* @param {postcss.Rule} ruleB | ||
* @param {import('postcss').Rule} ruleA | ||
* @param {import('postcss').Rule} ruleB | ||
* @param {string[]=} browsers | ||
@@ -78,4 +78,7 @@ * @param {Map<string, boolean>=} compatibilityCache | ||
const parent = sameParent(ruleA, ruleB); | ||
const { name } = ruleA.parent; | ||
const parent = sameParent( | ||
/** @type {any} */ (ruleA), | ||
/** @type {any} */ (ruleB) | ||
); | ||
const { name } = /** @type {any} */ (ruleA).parent; | ||
if (parent && name && name.includes('keyframes')) { | ||
@@ -88,11 +91,18 @@ return false; | ||
/** | ||
* @param {postcss.Rule} rule | ||
* @return {postcss.Declaration[]} | ||
* @param {import('postcss').Rule} rule | ||
* @return {import('postcss').Declaration[]} | ||
*/ | ||
function getDecls(rule) { | ||
return rule.nodes.filter((node) => node.type === 'decl'); | ||
return /** @type {import('postcss').Declaration[]} */ ( | ||
rule.nodes.filter((node) => node.type === 'decl') | ||
); | ||
} | ||
/** @type {(...rules: import('postcss').Rule[]) => string} */ | ||
const joinSelectors = (...rules) => rules.map((s) => s.selector).join(); | ||
/** | ||
* @param {...import('postcss').Rule} rules | ||
* @return {number} | ||
*/ | ||
function ruleLength(...rules) { | ||
@@ -104,3 +114,3 @@ return rules.map((r) => (r.nodes.length ? String(r) : '')).join('').length; | ||
* @param {string} prop | ||
* @return {{prefix: string, base:string, rest:string[]}} | ||
* @return {{prefix: string?, base:string?, rest:string[]}} | ||
*/ | ||
@@ -166,4 +176,4 @@ function splitProp(prop) { | ||
/** | ||
* @param {postcss.Rule} first | ||
* @param {postcss.Rule} second | ||
* @param {import('postcss').Rule} first | ||
* @param {import('postcss').Rule} second | ||
* @return {boolean} merged | ||
@@ -190,5 +200,5 @@ */ | ||
/** | ||
* @param {postcss.Rule} first | ||
* @param {postcss.Rule} second | ||
* @return {postcss.Rule} mergedRule | ||
* @param {import('postcss').Rule} first | ||
* @param {import('postcss').Rule} second | ||
* @return {import('postcss').Rule} mergedRule | ||
*/ | ||
@@ -203,3 +213,7 @@ function partialMerge(first, second) { | ||
// Grab next cousin | ||
const parentSibling = second.parent.next(); | ||
/** @type {any} */ | ||
const parentSibling = | ||
/** @type {import('postcss').Container<import('postcss').ChildNode>} */ ( | ||
second.parent | ||
).next(); | ||
nextRule = parentSibling && parentSibling.nodes && parentSibling.nodes[0]; | ||
@@ -276,3 +290,5 @@ } | ||
second.parent.insertBefore(second, receivingBlock); | ||
/** @type {import('postcss').Container<import('postcss').ChildNode>} */ ( | ||
second.parent | ||
).insertBefore(second, receivingBlock); | ||
@@ -283,4 +299,5 @@ const firstClone = first.clone(); | ||
/** | ||
* @param {function(postcss.Declaration):void} callback | ||
* @return {function(postcss.Declaration)} | ||
* @param {function(import('postcss').Declaration):void} callback | ||
* @this {import('postcss').Rule} | ||
* @return {function(import('postcss').Declaration)} | ||
*/ | ||
@@ -324,6 +341,6 @@ function moveDecl(callback) { | ||
* @param {Map<string, boolean>} compatibilityCache | ||
* @return {function(postcss.Rule)} | ||
* @return {function(import('postcss').Rule)} | ||
*/ | ||
function selectorMerger(browsers, compatibilityCache) { | ||
/** @type {postcss.Rule} */ | ||
/** @type {import('postcss').Rule | null} */ | ||
let cache = null; | ||
@@ -360,6 +377,12 @@ return function (rule) { | ||
rule.walk((decl) => { | ||
if (~indexOfDeclaration(cached, decl)) { | ||
return decl.remove(); | ||
if ( | ||
~indexOfDeclaration( | ||
cached, | ||
/** @type {import('postcss').Declaration} */ (decl) | ||
) | ||
) { | ||
decl.remove(); | ||
return; | ||
} | ||
cache.append(decl); | ||
/** @type {import('postcss').Rule} */ (cache).append(decl); | ||
}); | ||
@@ -374,3 +397,6 @@ rule.remove(); | ||
} | ||
/** | ||
* @type {import('postcss').PluginCreator<void>} | ||
* @return {import('postcss').Plugin} | ||
*/ | ||
function pluginCreator() { | ||
@@ -381,2 +407,3 @@ return { | ||
prepare(result) { | ||
/** @type {typeof result.opts & browserslist.Options} */ | ||
const resultOpts = result.opts || {}; | ||
@@ -383,0 +410,0 @@ const browsers = browserslist(null, { |
@@ -18,5 +18,8 @@ 'use strict'; | ||
const level2Sel = new Set(['=', '~=', '|=']); | ||
const level3Sel = new Set(['^=', '$=', '*=']); | ||
/** | ||
* @param {string} selector | ||
* @return {string[]} | ||
* @return {RegExpMatchArray | null} | ||
*/ | ||
@@ -27,9 +30,20 @@ function filterPrefixes(selector) { | ||
// Internet Explorer use :-ms-input-placeholder. | ||
// Microsoft Edge use ::-ms-input-placeholder. | ||
/** | ||
* Internet Explorer use :-ms-input-placeholder. | ||
* Microsoft Edge use ::-ms-input-placeholder. | ||
* | ||
* @type {(selector: string) => number} | ||
*/ | ||
const findMsInputPlaceholder = (selector) => | ||
~selector.search(/-ms-input-placeholder/i); | ||
/** | ||
* @param {string[]} selectorsA | ||
* @param {string[]} selectorsB | ||
* @return {boolean} | ||
*/ | ||
function sameVendor(selectorsA, selectorsB) { | ||
/** @type {(selectors: string[]) => string} */ | ||
let same = (selectors) => selectors.map(filterPrefixes).join(); | ||
/** @type {(selectors: string[]) => string | undefined} */ | ||
let findMsVendor = (selectors) => selectors.find(findMsInputPlaceholder); | ||
@@ -104,2 +118,6 @@ return ( | ||
/** | ||
* @param {string} selector | ||
* @return {boolean} | ||
*/ | ||
function isCssMixin(selector) { | ||
@@ -109,2 +127,6 @@ return selector[selector.length - 1] === ':'; | ||
/** | ||
* @param {string} selector | ||
* @return {boolean} | ||
*/ | ||
function isHostPseudoClass(selector) { | ||
@@ -117,2 +139,6 @@ return selector.includes(':host'); | ||
// Move to util in future | ||
/** | ||
* @param {string} feature | ||
* @param {string[] | undefined} browsers | ||
*/ | ||
function isSupportedCached(feature, browsers) { | ||
@@ -123,3 +149,3 @@ const key = JSON.stringify({ feature, browsers }); | ||
if (!result) { | ||
result = isSupported(feature, browsers); | ||
result = isSupported(feature, /** @type {string[]} */ (browsers)); | ||
isSupportedCache.set(key, result); | ||
@@ -131,2 +157,8 @@ } | ||
/** | ||
* @param {string[]} selectors | ||
* @param{string[]=} browsers | ||
* @param{Map<string,boolean>=} compatibilityCache | ||
* @return {boolean} | ||
*/ | ||
function ensureCompatibility(selectors, browsers, compatibilityCache) { | ||
@@ -154,3 +186,4 @@ // Should not merge mixins | ||
if (type === 'pseudo') { | ||
const entry = pseudoElements[value]; | ||
const entry = | ||
pseudoElements[/** @type {keyof pseudoElements} */ (value)]; | ||
if (!entry && noVendor(value)) { | ||
@@ -176,10 +209,9 @@ compatible = false; | ||
} | ||
if (value) { | ||
// [foo="bar"], [foo~="bar"], [foo|="bar"] | ||
if (['=', '~=', '|='].includes(node.operator)) { | ||
if (level2Sel.has(/** @type {string} */ (node.operator))) { | ||
compatible = isSupportedCached(cssSel2, browsers); | ||
} | ||
// [foo^="bar"], [foo$="bar"], [foo*="bar"] | ||
if (['^=', '$=', '*='].includes(node.operator)) { | ||
if (level3Sel.has(/** @type {string} */ (node.operator))) { | ||
compatible = isSupportedCached(cssSel3, browsers); | ||
@@ -186,0 +218,0 @@ } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
24206
20.18%7
40%668
26.52%0
-100%3
50%Updated