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

postcss-modules-local-by-default

Package Overview
Dependencies
Maintainers
3
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-modules-local-by-default - npm Package Compare versions

Comparing version 2.0.6 to 3.0.0

45

index.js

@@ -6,5 +6,20 @@ 'use strict';

const valueParser = require('postcss-value-parser');
const { extractICSS } = require('icss-utils');
const isSpacing = node => node.type === 'combinator' && node.value === ' ';
function getImportLocalAliases(icssImports) {
const localAliases = new Map();
Object.keys(icssImports).forEach(key => {
Object.keys(icssImports[key]).forEach(prop => {
localAliases.set(prop, icssImports[key][prop]);
});
});
return localAliases;
}
function maybeLocalizeValue(value, localAliasMap) {
if (localAliasMap.has(value)) return value;
}
function normalizeNodeArray(nodes) {

@@ -29,3 +44,3 @@ const array = [];

function localizeNode(rule, mode, options) {
function localizeNode(rule, mode, localAliasMap) {
const isScopePseudo = node =>

@@ -196,3 +211,10 @@ node.value === ':local' || node.value === ':global';

case 'class': {
if (!context.global) {
if (context.global) {
break;
}
const isImportedValue = localAliasMap.has(node.value);
const isImportedWithExplicitScope = isImportedValue && context.explicit;
if (!isImportedValue || isImportedWithExplicitScope) {
const innerNode = node.clone();

@@ -237,4 +259,6 @@ innerNode.spaces = { before: '', after: '' };

if (context.localizeNextItem) {
node.value = ':local(' + node.value + ')';
context.localizeNextItem = false;
if (!context.localAliasMap.has(node.value)) {
node.value = ':local(' + node.value + ')';
context.localizeNextItem = false;
}
}

@@ -367,2 +391,3 @@ break;

localizeNextItem: shouldParseAnimationName && !context.global,
localAliasMap: context.localAliasMap,
};

@@ -382,2 +407,3 @@ return localizeDeclNode(node, subContext);

localizeNextItem: localize && !context.global,
localAliasMap: context.localAliasMap,
};

@@ -432,2 +458,5 @@ nodes[index] = localizeDeclNode(node, subContext);

return function(css) {
const { icssImports } = extractICSS(css, false);
const localAliasMap = getImportLocalAliases(icssImports);
css.walkAtRules(function(atrule) {

@@ -450,6 +479,8 @@ if (/keyframes$/i.test(atrule.name)) {

} else if (!globalMode) {
atrule.params = ':local(' + atrule.params + ')';
if (atrule.params && !localAliasMap.has(atrule.params))
atrule.params = ':local(' + atrule.params + ')';
}
atrule.walkDecls(function(decl) {
localizeDecl(decl, {
localAliasMap,
options: options,

@@ -463,2 +494,3 @@ global: globalKeyframes,

localizeDecl(decl, {
localAliasMap,
options: options,

@@ -490,5 +522,6 @@ global: globalMode,

const context = localizeNode(rule, options.mode);
const context = localizeNode(rule, options.mode, localAliasMap);
context.options = options;
context.localAliasMap = localAliasMap;

@@ -495,0 +528,0 @@ if (pureMode && context.hasPureGlobals) {

3

package.json
{
"name": "postcss-modules-local-by-default",
"version": "2.0.6",
"version": "3.0.0",
"description": "A CSS Modules transform to make local scope the default",

@@ -26,2 +26,3 @@ "main": "index.js",

"dependencies": {
"icss-utils": "^4.0.0",
"postcss": "^7.0.6",

@@ -28,0 +29,0 @@ "postcss-selector-parser": "^6.0.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