Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-custom-properties-fallback

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-custom-properties-fallback - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

dist/import-from.js

53

dist/plugin.js

@@ -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 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc