postcss-modules-local-by-default
Advanced tools
Comparing version 4.0.0-rc.3 to 4.0.0-rc.4
@@ -6,2 +6,8 @@ # Change Log | ||
## [4.0.0-rc.4](https://github.com/postcss-modules-local-by-default/compare/v4.0.0-rc.3...v4.0.0-rc.4) - 2020-10-11 | ||
### Fixes | ||
- compatibility with plugins other plugins | ||
## [4.0.0-rc.3](https://github.com/postcss-modules-local-by-default/compare/v4.0.0-rc.2...v4.0.0-rc.3) - 2020-10-08 | ||
@@ -8,0 +14,0 @@ |
{ | ||
"name": "postcss-modules-local-by-default", | ||
"version": "4.0.0-rc.3", | ||
"version": "4.0.0-rc.4", | ||
"description": "A CSS Modules transform to make local scope the default", | ||
@@ -43,2 +43,3 @@ "main": "src/index.js", | ||
"eslint": "^7.10.0", | ||
"eslint-config-prettier": "^6.12.0", | ||
"husky": "^4.3.0", | ||
@@ -45,0 +46,0 @@ "jest": "^26.5.2", |
175
src/index.js
@@ -12,5 +12,5 @@ "use strict"; | ||
nodes.forEach(function (x) { | ||
nodes.forEach((x) => { | ||
if (Array.isArray(x)) { | ||
normalizeNodeArray(x).forEach(function (item) { | ||
normalizeNodeArray(x).forEach((item) => { | ||
array.push(item); | ||
@@ -47,3 +47,3 @@ }); | ||
newNodes = node.nodes.map(function (n) { | ||
newNodes = node.nodes.map((n) => { | ||
const nContext = { | ||
@@ -306,4 +306,4 @@ global: context.global, | ||
function localizeDeclValues(localize, decl, context) { | ||
const valueNodes = valueParser(decl.value); | ||
function localizeDeclarationValues(localize, declaration, context) { | ||
const valueNodes = valueParser(declaration.value); | ||
@@ -319,7 +319,8 @@ valueNodes.walk((node, index, nodes) => { | ||
}); | ||
decl.value = valueNodes.toString(); | ||
declaration.value = valueNodes.toString(); | ||
} | ||
function localizeDecl(decl, context) { | ||
const isAnimation = /animation$/i.test(decl.prop); | ||
function localizeDeclaration(declaration, context) { | ||
const isAnimation = /animation$/i.test(declaration.prop); | ||
@@ -367,3 +368,3 @@ if (isAnimation) { | ||
let stepsFunctionNode = null; | ||
const valueNodes = valueParser(decl.value).walk((node) => { | ||
const valueNodes = valueParser(declaration.value).walk((node) => { | ||
/* If div-token appeared (represents as comma ','), a possibility of an animation-keywords should be reflesh. */ | ||
@@ -408,3 +409,3 @@ if (node.type === "div") { | ||
decl.value = valueNodes.toString(); | ||
declaration.value = valueNodes.toString(); | ||
@@ -414,17 +415,15 @@ return; | ||
const isAnimationName = /animation(-name)?$/i.test(decl.prop); | ||
const isAnimationName = /animation(-name)?$/i.test(declaration.prop); | ||
if (isAnimationName) { | ||
return localizeDeclValues(true, decl, context); | ||
return localizeDeclarationValues(true, declaration, context); | ||
} | ||
const hasUrl = /url\(/i.test(decl.value); | ||
const hasUrl = /url\(/i.test(declaration.value); | ||
if (hasUrl) { | ||
return localizeDeclValues(false, decl, context); | ||
return localizeDeclarationValues(false, declaration, context); | ||
} | ||
} | ||
const isVisited = Symbol("isVisited"); | ||
module.exports = (options = {}) => { | ||
@@ -452,3 +451,3 @@ if (options && options.mode) { | ||
return { | ||
Root(root) { | ||
OnceExit(root) { | ||
const { icssImports } = extractICSS(root, false); | ||
@@ -461,90 +460,84 @@ | ||
}); | ||
}, | ||
AtRule(atRule) { | ||
if (atRule[isVisited]) { | ||
return; | ||
} | ||
if (/keyframes$/i.test(atRule.name)) { | ||
const globalMatch = /^\s*:global\s*\((.+)\)\s*$/.exec( | ||
atRule.params | ||
); | ||
const localMatch = /^\s*:local\s*\((.+)\)\s*$/.exec(atRule.params); | ||
root.walkAtRules((atRule) => { | ||
if (/keyframes$/i.test(atRule.name)) { | ||
const globalMatch = /^\s*:global\s*\((.+)\)\s*$/.exec( | ||
atRule.params | ||
); | ||
const localMatch = /^\s*:local\s*\((.+)\)\s*$/.exec( | ||
atRule.params | ||
); | ||
let globalKeyframes = globalMode; | ||
let globalKeyframes = globalMode; | ||
if (globalMatch) { | ||
if (pureMode) { | ||
throw atRule.error( | ||
"@keyframes :global(...) is not allowed in pure mode" | ||
); | ||
if (globalMatch) { | ||
if (pureMode) { | ||
throw atRule.error( | ||
"@keyframes :global(...) is not allowed in pure mode" | ||
); | ||
} | ||
atRule.params = globalMatch[1]; | ||
globalKeyframes = true; | ||
} else if (localMatch) { | ||
atRule.params = localMatch[0]; | ||
globalKeyframes = false; | ||
} else if (!globalMode) { | ||
if (atRule.params && !localAliasMap.has(atRule.params)) { | ||
atRule.params = ":local(" + atRule.params + ")"; | ||
} | ||
} | ||
atRule.params = globalMatch[1]; | ||
globalKeyframes = true; | ||
} else if (localMatch) { | ||
atRule.params = localMatch[0]; | ||
globalKeyframes = false; | ||
} else if (!globalMode) { | ||
if (atRule.params && !localAliasMap.has(atRule.params)) { | ||
atRule.params = ":local(" + atRule.params + ")"; | ||
} | ||
} | ||
atRule.walkDecls(function (decl) { | ||
localizeDecl(decl, { | ||
localAliasMap, | ||
options: options, | ||
global: globalKeyframes, | ||
}); | ||
}); | ||
} else if (atRule.nodes) { | ||
atRule.nodes.forEach(function (decl) { | ||
if (decl.type === "decl") { | ||
localizeDecl(decl, { | ||
atRule.walkDecls((declaration) => { | ||
localizeDeclaration(declaration, { | ||
localAliasMap, | ||
options: options, | ||
global: globalMode, | ||
global: globalKeyframes, | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} else if (atRule.nodes) { | ||
atRule.nodes.forEach((declaration) => { | ||
if (declaration.type === "decl") { | ||
localizeDeclaration(declaration, { | ||
localAliasMap, | ||
options: options, | ||
global: globalMode, | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
atRule[isVisited] = true; | ||
}, | ||
Rule(rule) { | ||
if (rule[isVisited]) { | ||
return; | ||
} | ||
root.walkRules((rule) => { | ||
if ( | ||
rule.parent && | ||
rule.parent.type === "atrule" && | ||
/keyframes$/i.test(rule.parent.name) | ||
) { | ||
// ignore keyframe rules | ||
return; | ||
} | ||
if ( | ||
rule.parent && | ||
rule.parent.type === "atrule" && | ||
/keyframes$/i.test(rule.parent.name) | ||
) { | ||
// ignore keyframe rules | ||
return; | ||
} | ||
const context = localizeNode(rule, options.mode, localAliasMap); | ||
const context = localizeNode(rule, options.mode, localAliasMap); | ||
context.options = options; | ||
context.localAliasMap = localAliasMap; | ||
context.options = options; | ||
context.localAliasMap = localAliasMap; | ||
if (pureMode && context.hasPureGlobals) { | ||
throw rule.error( | ||
'Selector "' + | ||
rule.selector + | ||
'" is not pure ' + | ||
"(pure selectors must contain at least one local class or id)" | ||
); | ||
} | ||
if (pureMode && context.hasPureGlobals) { | ||
throw rule.error( | ||
'Selector "' + | ||
rule.selector + | ||
'" is not pure ' + | ||
"(pure selectors must contain at least one local class or id)" | ||
); | ||
} | ||
rule.selector = context.selector; | ||
rule.selector = context.selector; | ||
// Less-syntax mixins parse as rules with no nodes | ||
if (rule.nodes) { | ||
rule.nodes.forEach((decl) => localizeDecl(decl, context)); | ||
} | ||
rule[isVisited] = true; | ||
// Less-syntax mixins parse as rules with no nodes | ||
if (rule.nodes) { | ||
rule.nodes.forEach((declaration) => | ||
localizeDeclaration(declaration, context) | ||
); | ||
} | ||
}); | ||
}, | ||
@@ -551,0 +544,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
25455
8
451