Skip to content

Commit 862e117

Browse files
authored
Merge pull request #30 from mohsenshafiei/dev
Dev
2 parents 4e7b4b3 + 0550ff6 commit 862e117

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/plugins/postcss-module-composer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
isGlobal,
1010
removeSpace,
1111
removeNotGlobals,
12+
shouldSkip,
1213
} = require('./utils');
1314

1415
const mainDist = path.resolve(__dirname, '../../dist/quark-loader-output.css');
@@ -21,7 +22,7 @@ module.exports = postcss.plugin('postcss-module-composer', () => (root) => {
2122
const identifier = rule.selector;
2223
let once = false;
2324
identifier.split(',').forEach((selector) => {
24-
if (!isGlobal(removeSpace(selector))) {
25+
if (!isGlobal(removeSpace(selector)) && !shouldSkip(removeSpace(selector))) {
2526
composerString += `${removeSpace(selector)} {\n`;
2627
rule.walkDecls((decl) => {
2728
composerString += createModuleComposer(decl.prop, decl.value);
@@ -32,9 +33,11 @@ module.exports = postcss.plugin('postcss-module-composer', () => (root) => {
3233
});
3334
composerString += '}\n';
3435
} else if (once === false) {
36+
const globals = !shouldSkip(rule.selector)
37+
? removeNotGlobals(rule.selector) : rule.selector;
38+
composerString += `${globals} {\n`;
3539
rule.walkDecls((decl) => {
36-
const globals = removeNotGlobals(rule.selector);
37-
composerString += `${globals} {\n${createModuleDeclaration(decl.prop, decl.value)}`;
40+
composerString += `${createModuleDeclaration(decl.prop, decl.value)}`;
3841
hashmap.set(
3942
createModuleSelector(decl.prop, decl.value),
4043
createModuleDeclaration(decl.prop, decl.value),

src/plugins/utils/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const globalSelector = require('./global');
22

33
const regex = /\(|\)|%|\.|#|,|\+|:|"|\/|\/|`|'/g;
4-
4+
const unvalid = /^[\w\s.,]+$/;
55
const createModuleComposer = (property, value) => (`\tcomposes: ${property}--${value.replace(/ /g, '-').replace(regex, '')};\n`);
66

77
const createModuleDeclaration = (property, value) => (`\t${property}: ${value};\n`);
@@ -12,6 +12,8 @@ const isGlobal = selector => globalSelector.includes(selector);
1212

1313
const removeSpace = str => str.trim();
1414

15+
const shouldSkip = str => str.search(unvalid);
16+
1517
const removeNotGlobals = (str) => {
1618
let result = '';
1719
str.split(',').forEach((item) => {
@@ -28,4 +30,5 @@ module.exports = {
2830
removeSpace,
2931
removeNotGlobals,
3032
isGlobal,
33+
shouldSkip,
3134
};

0 commit comments

Comments
 (0)