postcss-custom-properties-fallback
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,22 +0,20 @@ | ||
'use strict'; | ||
const getCustomPropertiesFromImports = require('./import-from.js'); | ||
const getCustomPropertiesFromImports = require('./import-from'); | ||
const valueParser = require('postcss-value-parser'); | ||
// match custom property inclusions | ||
const valueParser = require('postcss-value-parser'); // match custom property inclusions | ||
// @TODO optimize to skip vars with fallbacks already | ||
const customPropertiesRegExp = /(^|[^\w-])var\([\W\w]+\)/; | ||
// whether the declaration should be potentially transformed | ||
const isTransformableDecl = (decl) => customPropertiesRegExp.test(decl.value); | ||
// eslint-disable-next-line no-empty-pattern | ||
module.exports = (opts) => ({ | ||
const customPropertiesRegExp = /(^|[^\w-])var\([\W\w]+\)/; // whether the declaration should be potentially transformed | ||
const isTransformableDecl = decl => customPropertiesRegExp.test(decl.value); // eslint-disable-next-line no-empty-pattern | ||
module.exports = opts => ({ | ||
postcssPlugin: 'postcss-custom-properties-fallback', | ||
prepare() { | ||
// sources to import custom selectors from | ||
const importFrom = [].concat(Object(opts).importFrom || []); | ||
// promise any custom selectors are imported | ||
const importFrom = [].concat(Object(opts).importFrom || []); // promise any custom selectors are imported | ||
const customPropertiesPromise = getCustomPropertiesFromImports(importFrom); | ||
return { | ||
@@ -26,6 +24,4 @@ async Declaration(node) { | ||
const customProperties = await customPropertiesPromise; | ||
const parsed = valueParser(node.value); | ||
parsed.walk((node) => { | ||
parsed.walk(node => { | ||
// Only deal with vars without a fallback | ||
@@ -35,17 +31,26 @@ if (node.type !== 'function' || node.nodes.length !== 1) { | ||
} | ||
const fallback = customProperties[node.nodes[0].value]; | ||
if (fallback) { | ||
node.nodes.push( | ||
{ type: 'divider', value: ',' }, | ||
{ type: 'space', value: ' ' }, | ||
{ type: 'word', value: fallback } | ||
); | ||
node.nodes.push({ | ||
type: 'divider', | ||
value: ',' | ||
}, { | ||
type: 'space', | ||
value: ' ' | ||
}, { | ||
type: 'word', | ||
value: fallback | ||
}); | ||
} | ||
}); | ||
node.value = parsed.toString(); | ||
} | ||
}, | ||
} | ||
}; | ||
}, | ||
} | ||
}); | ||
//# sourceMappingURL=plugin.js.map |
@@ -13,3 +13,3 @@ { | ||
}, | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "dist/plugin.js", | ||
@@ -20,3 +20,3 @@ "files": [ | ||
"scripts": { | ||
"build": "rollup -c", | ||
"build": "microbundle ./src/* --target node -f cjs", | ||
"prepare": "npm run -s build", | ||
@@ -35,4 +35,4 @@ "test": "tap test/*.js --no-coverage", | ||
"eslint": "^7.13.0", | ||
"microbundle": "^0.12.4", | ||
"postcss": "^8.1.8", | ||
"rollup": "^2.33.2", | ||
"tap": "^14.10.8" | ||
@@ -39,0 +39,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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
17131
7
123
2