postcss-modules-local-by-default
Advanced tools
Comparing version 4.0.0-rc.2 to 4.0.0-rc.3
@@ -6,2 +6,8 @@ # Change Log | ||
## [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 | ||
### Fixes | ||
- compatibility with plugins other plugins | ||
## [4.0.0-rc.2](https://github.com/postcss-modules-local-by-default/compare/v4.0.0-rc.1...v4.0.0-rc.2) - 2020-10-08 | ||
@@ -8,0 +14,0 @@ |
{ | ||
"name": "postcss-modules-local-by-default", | ||
"version": "4.0.0-rc.2", | ||
"version": "4.0.0-rc.3", | ||
"description": "A CSS Modules transform to make local scope the default", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
182
src/index.js
@@ -29,7 +29,2 @@ "use strict"; | ||
function localizeNode(rule, mode, localAliasMap) { | ||
const isScopePseudo = (node) => | ||
node.value === ":local" || node.value === ":global"; | ||
const isImportExportPseudo = (node) => | ||
node.value === ":import" || node.value === ":export"; | ||
const transform = (node, context) => { | ||
@@ -39,2 +34,3 @@ if (context.ignoreNextSpacing && !isSpacing(node)) { | ||
} | ||
if (context.enforceNoSpacing && isSpacing(node)) { | ||
@@ -45,2 +41,3 @@ throw new Error("Missing whitespace before " + context.enforceNoSpacing); | ||
let newNodes; | ||
switch (node.type) { | ||
@@ -107,4 +104,5 @@ case "root": { | ||
const isNested = !!node.length; | ||
const isScoped = isScopePseudo(node); | ||
const isImportExport = isImportExportPseudo(node); | ||
const isScoped = node.value === ":local" || node.value === ":global"; | ||
const isImportExport = | ||
node.value === ":import" || node.value === ":export"; | ||
@@ -310,87 +308,5 @@ if (isImportExport) { | ||
function localizeAnimationShorthandDeclValues(decl, context) { | ||
const validIdent = /^-?[_a-z][_a-z0-9-]*$/i; | ||
/* | ||
The spec defines some keywords that you can use to describe properties such as the timing | ||
function. These are still valid animation names, so as long as there is a property that accepts | ||
a keyword, it is given priority. Only when all the properties that can take a keyword are | ||
exhausted can the animation name be set to the keyword. I.e. | ||
animation: infinite infinite; | ||
The animation will repeat an infinite number of times from the first argument, and will have an | ||
animation name of infinite from the second. | ||
*/ | ||
const animationKeywords = { | ||
$alternate: 1, | ||
"$alternate-reverse": 1, | ||
$backwards: 1, | ||
$both: 1, | ||
$ease: 1, | ||
"$ease-in": 1, | ||
"$ease-in-out": 1, | ||
"$ease-out": 1, | ||
$forwards: 1, | ||
$infinite: 1, | ||
$linear: 1, | ||
$none: Infinity, // No matter how many times you write none, it will never be an animation name | ||
$normal: 1, | ||
$paused: 1, | ||
$reverse: 1, | ||
$running: 1, | ||
"$step-end": 1, | ||
"$step-start": 1, | ||
$initial: Infinity, | ||
$inherit: Infinity, | ||
$unset: Infinity, | ||
}; | ||
const didParseAnimationName = false; | ||
let parsedAnimationKeywords = {}; | ||
let stepsFunctionNode = null; | ||
const valueNodes = valueParser(decl.value).walk((node) => { | ||
/* If div-token appeared (represents as comma ','), a possibility of an animation-keywords should be reflesh. */ | ||
if (node.type === "div") { | ||
parsedAnimationKeywords = {}; | ||
} | ||
if (node.type === "function" && node.value.toLowerCase() === "steps") { | ||
stepsFunctionNode = node; | ||
} | ||
const value = | ||
node.type === "word" && !isWordAFunctionArgument(node, stepsFunctionNode) | ||
? node.value.toLowerCase() | ||
: null; | ||
let shouldParseAnimationName = false; | ||
if (!didParseAnimationName && value && validIdent.test(value)) { | ||
if ("$" + value in animationKeywords) { | ||
parsedAnimationKeywords["$" + value] = | ||
"$" + value in parsedAnimationKeywords | ||
? parsedAnimationKeywords["$" + value] + 1 | ||
: 0; | ||
shouldParseAnimationName = | ||
parsedAnimationKeywords["$" + value] >= | ||
animationKeywords["$" + value]; | ||
} else { | ||
shouldParseAnimationName = true; | ||
} | ||
} | ||
const subContext = { | ||
options: context.options, | ||
global: context.global, | ||
localizeNextItem: shouldParseAnimationName && !context.global, | ||
localAliasMap: context.localAliasMap, | ||
}; | ||
return localizeDeclNode(node, subContext); | ||
}); | ||
decl.value = valueNodes.toString(); | ||
} | ||
function localizeDeclValues(localize, decl, context) { | ||
const valueNodes = valueParser(decl.value); | ||
valueNodes.walk((node, index, nodes) => { | ||
@@ -412,3 +328,85 @@ const subContext = { | ||
if (isAnimation) { | ||
return localizeAnimationShorthandDeclValues(decl, context); | ||
const validIdent = /^-?[_a-z][_a-z0-9-]*$/i; | ||
/* | ||
The spec defines some keywords that you can use to describe properties such as the timing | ||
function. These are still valid animation names, so as long as there is a property that accepts | ||
a keyword, it is given priority. Only when all the properties that can take a keyword are | ||
exhausted can the animation name be set to the keyword. I.e. | ||
animation: infinite infinite; | ||
The animation will repeat an infinite number of times from the first argument, and will have an | ||
animation name of infinite from the second. | ||
*/ | ||
const animationKeywords = { | ||
$alternate: 1, | ||
"$alternate-reverse": 1, | ||
$backwards: 1, | ||
$both: 1, | ||
$ease: 1, | ||
"$ease-in": 1, | ||
"$ease-in-out": 1, | ||
"$ease-out": 1, | ||
$forwards: 1, | ||
$infinite: 1, | ||
$linear: 1, | ||
$none: Infinity, // No matter how many times you write none, it will never be an animation name | ||
$normal: 1, | ||
$paused: 1, | ||
$reverse: 1, | ||
$running: 1, | ||
"$step-end": 1, | ||
"$step-start": 1, | ||
$initial: Infinity, | ||
$inherit: Infinity, | ||
$unset: Infinity, | ||
}; | ||
const didParseAnimationName = false; | ||
let parsedAnimationKeywords = {}; | ||
let stepsFunctionNode = null; | ||
const valueNodes = valueParser(decl.value).walk((node) => { | ||
/* If div-token appeared (represents as comma ','), a possibility of an animation-keywords should be reflesh. */ | ||
if (node.type === "div") { | ||
parsedAnimationKeywords = {}; | ||
} | ||
if (node.type === "function" && node.value.toLowerCase() === "steps") { | ||
stepsFunctionNode = node; | ||
} | ||
const value = | ||
node.type === "word" && | ||
!isWordAFunctionArgument(node, stepsFunctionNode) | ||
? node.value.toLowerCase() | ||
: null; | ||
let shouldParseAnimationName = false; | ||
if (!didParseAnimationName && value && validIdent.test(value)) { | ||
if ("$" + value in animationKeywords) { | ||
parsedAnimationKeywords["$" + value] = | ||
"$" + value in parsedAnimationKeywords | ||
? parsedAnimationKeywords["$" + value] + 1 | ||
: 0; | ||
shouldParseAnimationName = | ||
parsedAnimationKeywords["$" + value] >= | ||
animationKeywords["$" + value]; | ||
} else { | ||
shouldParseAnimationName = true; | ||
} | ||
} | ||
const subContext = { | ||
options: context.options, | ||
global: context.global, | ||
localizeNextItem: shouldParseAnimationName && !context.global, | ||
localAliasMap: context.localAliasMap, | ||
}; | ||
return localizeDeclNode(node, subContext); | ||
}); | ||
decl.value = valueNodes.toString(); | ||
return; | ||
} | ||
@@ -453,3 +451,3 @@ | ||
return { | ||
Once(root) { | ||
Root(root) { | ||
const { icssImports } = extractICSS(root, false); | ||
@@ -456,0 +454,0 @@ |
25107
456