Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #30

Merged
merged 3 commits into from
Jun 3, 2019
Merged

Dev #30

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/plugins/postcss-module-composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
isGlobal,
removeSpace,
removeNotGlobals,
shouldSkip,
} = require('./utils');

const mainDist = path.resolve(__dirname, '../../dist/quark-loader-output.css');
Expand All @@ -21,7 +22,7 @@ module.exports = postcss.plugin('postcss-module-composer', () => (root) => {
const identifier = rule.selector;
let once = false;
identifier.split(',').forEach((selector) => {
if (!isGlobal(removeSpace(selector))) {
if (!isGlobal(removeSpace(selector)) && !shouldSkip(removeSpace(selector))) {
composerString += `${removeSpace(selector)} {\n`;
rule.walkDecls((decl) => {
composerString += createModuleComposer(decl.prop, decl.value);
Expand All @@ -32,9 +33,11 @@ module.exports = postcss.plugin('postcss-module-composer', () => (root) => {
});
composerString += '}\n';
} else if (once === false) {
const globals = !shouldSkip(rule.selector)
? removeNotGlobals(rule.selector) : rule.selector;
composerString += `${globals} {\n`;
rule.walkDecls((decl) => {
const globals = removeNotGlobals(rule.selector);
composerString += `${globals} {\n${createModuleDeclaration(decl.prop, decl.value)}`;
composerString += `${createModuleDeclaration(decl.prop, decl.value)}`;
hashmap.set(
createModuleSelector(decl.prop, decl.value),
createModuleDeclaration(decl.prop, decl.value),
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const globalSelector = require('./global');

const regex = /\(|\)|%|\.|#|,|\+|:|"|\/|\/|`|'/g;

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

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

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

const shouldSkip = str => str.search(unvalid);

const removeNotGlobals = (str) => {
let result = '';
str.split(',').forEach((item) => {
Expand All @@ -28,4 +30,5 @@ module.exports = {
removeSpace,
removeNotGlobals,
isGlobal,
shouldSkip,
};