postcss-reduce-idents
Advanced tools
Comparing version 5.0.3 to 5.1.0
{ | ||
"name": "postcss-reduce-idents", | ||
"version": "5.0.3", | ||
"version": "5.1.0", | ||
"description": "Reduce custom identifiers with PostCSS.", | ||
"main": "src/index.js", | ||
"types": "types/index.d.ts", | ||
"files": [ | ||
"src", | ||
"LICENSE-MIT" | ||
"LICENSE-MIT", | ||
"types" | ||
], | ||
@@ -10,0 +12,0 @@ "keywords": [ |
@@ -8,2 +8,17 @@ 'use strict'; | ||
/** @typedef {{ | ||
counter?: boolean, counterStyle?: boolean, | ||
keyframes?: boolean, gridTemplate?: boolean, | ||
encoder?: (value: string, index: number) => string}} Options | ||
*/ | ||
/** @typedef {{ | ||
* collect: (node: import('postcss').AnyNode, encoder: (value: string, num: number) => string) => void, | ||
* transform: () => void | ||
* }} Reducer | ||
*/ | ||
/** | ||
* @type {import('postcss').PluginCreator<Options>} | ||
* @param {Options} arg | ||
* @return {import('postcss').Plugin} | ||
*/ | ||
function pluginCreator({ | ||
@@ -16,2 +31,3 @@ counter = true, | ||
} = {}) { | ||
/** @type {Reducer[]} */ | ||
const reducers = []; | ||
@@ -18,0 +34,0 @@ |
'use strict'; | ||
/** | ||
* @param {string} value | ||
* @param {(value: string, num: number) => string} encoder | ||
* @param {Record<string, {ident: string, count: number}>} cache | ||
* @return {void} | ||
*/ | ||
module.exports = function (value, encoder, cache) { | ||
@@ -3,0 +9,0 @@ if (cache[value]) { |
@@ -5,3 +5,3 @@ 'use strict'; | ||
const RESERVED_KEYWORDS = [ | ||
const RESERVED_KEYWORDS = new Set([ | ||
'unset', | ||
@@ -68,7 +68,13 @@ 'initial', | ||
'disclosure-close', | ||
]; | ||
]); | ||
/** | ||
* @return {import('../index.js').Reducer} | ||
*/ | ||
module.exports = function () { | ||
/** @type {Record<string, {ident: string, count: number}>} */ | ||
let cache = {}; | ||
/** @type {import('postcss').AtRule[]} */ | ||
let atRules = []; | ||
/** @type {import('postcss').Declaration[]} */ | ||
let decls = []; | ||
@@ -78,8 +84,8 @@ | ||
collect(node, encoder) { | ||
const { name, prop, type } = node; | ||
const { type } = node; | ||
if ( | ||
type === 'atrule' && | ||
/counter-style/i.test(name) && | ||
RESERVED_KEYWORDS.indexOf(node.params.toLowerCase()) === -1 | ||
/counter-style/i.test(node.name) && | ||
!RESERVED_KEYWORDS.has(node.params.toLowerCase()) | ||
) { | ||
@@ -91,3 +97,3 @@ addToCache(node.params, encoder, cache); | ||
if (type === 'decl' && /(list-style|system)/i.test(prop)) { | ||
if (type === 'decl' && /(list-style|system)/i.test(node.prop)) { | ||
decls.push(node); | ||
@@ -94,0 +100,0 @@ } |
@@ -6,7 +6,13 @@ 'use strict'; | ||
const RESERVED_KEYWORDS = ['unset', 'initial', 'inherit', 'none']; | ||
const RESERVED_KEYWORDS = new Set(['unset', 'initial', 'inherit', 'none']); | ||
/** | ||
* @return {import('../index.js').Reducer} | ||
*/ | ||
module.exports = function () { | ||
/** @type {Record<string, {ident: string, count: number}>} */ | ||
let cache = {}; | ||
/** @type {{value: import('postcss-value-parser').ParsedValue}[]} */ | ||
let declOneCache = []; | ||
/** @type {import('postcss').Declaration[]} */ | ||
let declTwoCache = []; | ||
@@ -16,3 +22,3 @@ | ||
collect(node, encoder) { | ||
const { prop, type } = node; | ||
const { type } = node; | ||
@@ -22,17 +28,20 @@ if (type !== 'decl') { | ||
} | ||
const { prop } = node; | ||
if (/counter-(reset|increment)/i.test(prop)) { | ||
node.value = valueParser(node.value).walk((child) => { | ||
if ( | ||
child.type === 'word' && | ||
!isNum(child) && | ||
RESERVED_KEYWORDS.indexOf(child.value.toLowerCase()) === -1 | ||
) { | ||
addToCache(child.value, encoder, cache); | ||
/** @type {unknown} */ (node.value) = valueParser(node.value).walk( | ||
(child) => { | ||
if ( | ||
child.type === 'word' && | ||
!isNum(child) && | ||
!RESERVED_KEYWORDS.has(child.value.toLowerCase()) | ||
) { | ||
addToCache(child.value, encoder, cache); | ||
child.value = cache[child.value].ident; | ||
child.value = cache[child.value].ident; | ||
} | ||
} | ||
}); | ||
); | ||
declOneCache.push(node); | ||
declOneCache.push(/** @type {any} */ (node)); | ||
} else if (/content/i.test(prop)) { | ||
@@ -74,3 +83,3 @@ declTwoCache.push(node); | ||
declOneCache.forEach((decl) => { | ||
decl.value = decl.value | ||
/** @type {unknown} */ (decl.value) = decl.value | ||
.walk((node) => { | ||
@@ -77,0 +86,0 @@ if (node.type === 'word' && !isNum(node)) { |
'use strict'; | ||
/** | ||
* @param {string} val | ||
* @param {number} num | ||
* @return {string} | ||
*/ | ||
module.exports = function encode(val, num) { | ||
@@ -3,0 +8,0 @@ let base = 52; |
@@ -6,6 +6,17 @@ 'use strict'; | ||
const RESERVED_KEYWORDS = ['auto', 'span', 'inherit', 'initial', 'unset']; | ||
const RESERVED_KEYWORDS = new Set([ | ||
'auto', | ||
'span', | ||
'inherit', | ||
'initial', | ||
'unset', | ||
]); | ||
/** | ||
* @return {import('../index.js').Reducer} | ||
*/ | ||
module.exports = function () { | ||
/** @type {Record<string, {ident: string, count: number}>} */ | ||
let cache = {}; | ||
/** @type {import('postcss').Declaration[]} */ | ||
let declCache = []; | ||
@@ -26,6 +37,3 @@ | ||
node.value = node.value.replace(word, '.'); | ||
} else if ( | ||
word && | ||
RESERVED_KEYWORDS.indexOf(word.toLowerCase()) === -1 | ||
) { | ||
} else if (word && !RESERVED_KEYWORDS.has(word.toLowerCase())) { | ||
addToCache(word, encoder, cache); | ||
@@ -40,6 +48,3 @@ } | ||
valueParser(node.value).walk((child) => { | ||
if ( | ||
child.type === 'word' && | ||
RESERVED_KEYWORDS.indexOf(child.value) === -1 | ||
) { | ||
if (child.type === 'word' && !RESERVED_KEYWORDS.has(child.value)) { | ||
addToCache(child.value, encoder, cache); | ||
@@ -46,0 +51,0 @@ } |
'use strict'; | ||
const { unit } = require('postcss-value-parser'); | ||
/** | ||
* @param {import('postcss-value-parser').Node} node | ||
* @return {import('postcss-value-parser').Dimension | false} | ||
*/ | ||
module.exports = function isNum(node) { | ||
return unit(node.value); | ||
}; |
@@ -5,7 +5,13 @@ 'use strict'; | ||
const RESERVED_KEYWORDS = ['none', 'inherit', 'initial', 'unset']; | ||
const RESERVED_KEYWORDS = new Set(['none', 'inherit', 'initial', 'unset']); | ||
/** | ||
* @return {import('../index.js').Reducer} | ||
*/ | ||
module.exports = function () { | ||
/** @type {Record<string, {ident: string, count: number}>} */ | ||
let cache = {}; | ||
/** @type {import('postcss').AtRule[]} */ | ||
let atRules = []; | ||
/** @type {import('postcss').Declaration[]} */ | ||
let decls = []; | ||
@@ -15,8 +21,8 @@ | ||
collect(node, encoder) { | ||
const { name, prop, type } = node; | ||
const { type } = node; | ||
if ( | ||
type === 'atrule' && | ||
/keyframes/i.test(name) && | ||
RESERVED_KEYWORDS.indexOf(node.params.toLowerCase()) === -1 | ||
/keyframes/i.test(node.name) && | ||
!RESERVED_KEYWORDS.has(node.params.toLowerCase()) | ||
) { | ||
@@ -27,3 +33,3 @@ addToCache(node.params, encoder, cache); | ||
if (type === 'decl' && /animation/i.test(prop)) { | ||
if (type === 'decl' && /animation/i.test(node.prop)) { | ||
decls.push(node); | ||
@@ -30,0 +36,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
21748
19
475
0