Skip to content

Commit 401bf91

Browse files
chore(release): 4.0.0-rc.4
1 parent dc6cd6a commit 401bf91

File tree

5 files changed

+254
-250
lines changed

5 files changed

+254
-250
lines changed

.eslintrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"ecmaVersion": 2018
44
},
55
"env": {
6-
"node": true,
76
"es6": true,
7+
"node": true,
88
"jest": true
99
},
10-
"extends": "eslint:recommended"
10+
"extends": ["eslint:recommended", "prettier"]
1111
}

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [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
7+
8+
### Fixes
9+
10+
- compatibility with plugins other plugins
11+
612
## [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
713

814
### Fixes

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-modules-local-by-default",
3-
"version": "4.0.0-rc.3",
3+
"version": "4.0.0-rc.4",
44
"description": "A CSS Modules transform to make local scope the default",
55
"main": "src/index.js",
66
"author": "Mark Dalgleish",
@@ -40,6 +40,7 @@
4040
"devDependencies": {
4141
"coveralls": "^3.1.0",
4242
"eslint": "^7.10.0",
43+
"eslint-config-prettier": "^6.12.0",
4344
"husky": "^4.3.0",
4445
"jest": "^26.5.2",
4546
"lint-staged": "^10.4.0",

src/index.js

+85-92
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const isSpacing = (node) => node.type === "combinator" && node.value === " ";
99
function normalizeNodeArray(nodes) {
1010
const array = [];
1111

12-
nodes.forEach(function (x) {
12+
nodes.forEach((x) => {
1313
if (Array.isArray(x)) {
14-
normalizeNodeArray(x).forEach(function (item) {
14+
normalizeNodeArray(x).forEach((item) => {
1515
array.push(item);
1616
});
1717
} else if (x) {
@@ -43,7 +43,7 @@ function localizeNode(rule, mode, localAliasMap) {
4343

4444
context.hasPureGlobals = false;
4545

46-
newNodes = node.nodes.map(function (n) {
46+
newNodes = node.nodes.map((n) => {
4747
const nContext = {
4848
global: context.global,
4949
lastWasSpacing: true,
@@ -301,8 +301,8 @@ function isWordAFunctionArgument(wordNode, functionNode) {
301301
: false;
302302
}
303303

304-
function localizeDeclValues(localize, decl, context) {
305-
const valueNodes = valueParser(decl.value);
304+
function localizeDeclarationValues(localize, declaration, context) {
305+
const valueNodes = valueParser(declaration.value);
306306

307307
valueNodes.walk((node, index, nodes) => {
308308
const subContext = {
@@ -313,11 +313,12 @@ function localizeDeclValues(localize, decl, context) {
313313
};
314314
nodes[index] = localizeDeclNode(node, subContext);
315315
});
316-
decl.value = valueNodes.toString();
316+
317+
declaration.value = valueNodes.toString();
317318
}
318319

319-
function localizeDecl(decl, context) {
320-
const isAnimation = /animation$/i.test(decl.prop);
320+
function localizeDeclaration(declaration, context) {
321+
const isAnimation = /animation$/i.test(declaration.prop);
321322

322323
if (isAnimation) {
323324
const validIdent = /^-?[_a-z][_a-z0-9-]*$/i;
@@ -360,7 +361,7 @@ function localizeDecl(decl, context) {
360361
const didParseAnimationName = false;
361362
let parsedAnimationKeywords = {};
362363
let stepsFunctionNode = null;
363-
const valueNodes = valueParser(decl.value).walk((node) => {
364+
const valueNodes = valueParser(declaration.value).walk((node) => {
364365
/* If div-token appeared (represents as comma ','), a possibility of an animation-keywords should be reflesh. */
365366
if (node.type === "div") {
366367
parsedAnimationKeywords = {};
@@ -400,26 +401,24 @@ function localizeDecl(decl, context) {
400401
return localizeDeclNode(node, subContext);
401402
});
402403

403-
decl.value = valueNodes.toString();
404+
declaration.value = valueNodes.toString();
404405

405406
return;
406407
}
407408

408-
const isAnimationName = /animation(-name)?$/i.test(decl.prop);
409+
const isAnimationName = /animation(-name)?$/i.test(declaration.prop);
409410

410411
if (isAnimationName) {
411-
return localizeDeclValues(true, decl, context);
412+
return localizeDeclarationValues(true, declaration, context);
412413
}
413414

414-
const hasUrl = /url\(/i.test(decl.value);
415+
const hasUrl = /url\(/i.test(declaration.value);
415416

416417
if (hasUrl) {
417-
return localizeDeclValues(false, decl, context);
418+
return localizeDeclarationValues(false, declaration, context);
418419
}
419420
}
420421

421-
const isVisited = Symbol("isVisited");
422-
423422
module.exports = (options = {}) => {
424423
if (options && options.mode) {
425424
if (
@@ -442,102 +441,96 @@ module.exports = (options = {}) => {
442441
const localAliasMap = new Map();
443442

444443
return {
445-
Root(root) {
444+
OnceExit(root) {
446445
const { icssImports } = extractICSS(root, false);
447446

448447
Object.keys(icssImports).forEach((key) => {
449448
Object.keys(icssImports[key]).forEach((prop) => {
450449
localAliasMap.set(prop, icssImports[key][prop]);
451450
});
452451
});
453-
},
454-
AtRule(atRule) {
455-
if (atRule[isVisited]) {
456-
return;
457-
}
458452

459-
if (/keyframes$/i.test(atRule.name)) {
460-
const globalMatch = /^\s*:global\s*\((.+)\)\s*$/.exec(
461-
atRule.params
462-
);
463-
const localMatch = /^\s*:local\s*\((.+)\)\s*$/.exec(atRule.params);
464-
465-
let globalKeyframes = globalMode;
453+
root.walkAtRules((atRule) => {
454+
if (/keyframes$/i.test(atRule.name)) {
455+
const globalMatch = /^\s*:global\s*\((.+)\)\s*$/.exec(
456+
atRule.params
457+
);
458+
const localMatch = /^\s*:local\s*\((.+)\)\s*$/.exec(
459+
atRule.params
460+
);
466461

467-
if (globalMatch) {
468-
if (pureMode) {
469-
throw atRule.error(
470-
"@keyframes :global(...) is not allowed in pure mode"
471-
);
462+
let globalKeyframes = globalMode;
463+
464+
if (globalMatch) {
465+
if (pureMode) {
466+
throw atRule.error(
467+
"@keyframes :global(...) is not allowed in pure mode"
468+
);
469+
}
470+
atRule.params = globalMatch[1];
471+
globalKeyframes = true;
472+
} else if (localMatch) {
473+
atRule.params = localMatch[0];
474+
globalKeyframes = false;
475+
} else if (!globalMode) {
476+
if (atRule.params && !localAliasMap.has(atRule.params)) {
477+
atRule.params = ":local(" + atRule.params + ")";
478+
}
472479
}
473-
atRule.params = globalMatch[1];
474-
globalKeyframes = true;
475-
} else if (localMatch) {
476-
atRule.params = localMatch[0];
477-
globalKeyframes = false;
478-
} else if (!globalMode) {
479-
if (atRule.params && !localAliasMap.has(atRule.params)) {
480-
atRule.params = ":local(" + atRule.params + ")";
481-
}
482-
}
483480

484-
atRule.walkDecls(function (decl) {
485-
localizeDecl(decl, {
486-
localAliasMap,
487-
options: options,
488-
global: globalKeyframes,
489-
});
490-
});
491-
} else if (atRule.nodes) {
492-
atRule.nodes.forEach(function (decl) {
493-
if (decl.type === "decl") {
494-
localizeDecl(decl, {
481+
atRule.walkDecls((declaration) => {
482+
localizeDeclaration(declaration, {
495483
localAliasMap,
496484
options: options,
497-
global: globalMode,
485+
global: globalKeyframes,
498486
});
499-
}
500-
});
501-
}
502-
503-
atRule[isVisited] = true;
504-
},
505-
Rule(rule) {
506-
if (rule[isVisited]) {
507-
return;
508-
}
509-
510-
if (
511-
rule.parent &&
512-
rule.parent.type === "atrule" &&
513-
/keyframes$/i.test(rule.parent.name)
514-
) {
515-
// ignore keyframe rules
516-
return;
517-
}
487+
});
488+
} else if (atRule.nodes) {
489+
atRule.nodes.forEach((declaration) => {
490+
if (declaration.type === "decl") {
491+
localizeDeclaration(declaration, {
492+
localAliasMap,
493+
options: options,
494+
global: globalMode,
495+
});
496+
}
497+
});
498+
}
499+
});
518500

519-
const context = localizeNode(rule, options.mode, localAliasMap);
501+
root.walkRules((rule) => {
502+
if (
503+
rule.parent &&
504+
rule.parent.type === "atrule" &&
505+
/keyframes$/i.test(rule.parent.name)
506+
) {
507+
// ignore keyframe rules
508+
return;
509+
}
520510

521-
context.options = options;
522-
context.localAliasMap = localAliasMap;
511+
const context = localizeNode(rule, options.mode, localAliasMap);
523512

524-
if (pureMode && context.hasPureGlobals) {
525-
throw rule.error(
526-
'Selector "' +
527-
rule.selector +
528-
'" is not pure ' +
529-
"(pure selectors must contain at least one local class or id)"
530-
);
531-
}
513+
context.options = options;
514+
context.localAliasMap = localAliasMap;
532515

533-
rule.selector = context.selector;
516+
if (pureMode && context.hasPureGlobals) {
517+
throw rule.error(
518+
'Selector "' +
519+
rule.selector +
520+
'" is not pure ' +
521+
"(pure selectors must contain at least one local class or id)"
522+
);
523+
}
534524

535-
// Less-syntax mixins parse as rules with no nodes
536-
if (rule.nodes) {
537-
rule.nodes.forEach((decl) => localizeDecl(decl, context));
538-
}
525+
rule.selector = context.selector;
539526

540-
rule[isVisited] = true;
527+
// Less-syntax mixins parse as rules with no nodes
528+
if (rule.nodes) {
529+
rule.nodes.forEach((declaration) =>
530+
localizeDeclaration(declaration, context)
531+
);
532+
}
533+
});
541534
},
542535
};
543536
},

0 commit comments

Comments
 (0)