Skip to content

Commit

Permalink
fix: don't generate invalid escaping classes (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Mar 4, 2019
1 parent 67697e6 commit d6e38e6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {

const exports = Object.create(null);

function exportScopedName(name) {
function exportScopedName(name, rawName) {
const scopedName = generateScopedName(
name,
rawName ? rawName : name,
css.source.input.from,
css.source.input.css
);
Expand All @@ -78,11 +78,17 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {
return node;
case 'class':
return selectorParser.className({
value: exportScopedName(node.value),
value: exportScopedName(
node.value,
node.raws && node.raws.value ? node.raws.value : null
),
});
case 'id': {
return selectorParser.id({
value: exportScopedName(node.value),
value: exportScopedName(
node.value,
node.raws && node.raws.value ? node.raws.value : null
),
});
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/test-cases/export-class/expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
color: red;
}

._input__\:\:\:\: {
color: rebeccapurple;
}

@media (max-width: 520px) {
/* selector doubled to increase specificity */
._input__exportName._input__exportName {
Expand All @@ -19,5 +23,6 @@

:export {
exportName: _input__exportName;
::::: _input__\:\:\:\:;
newExport: _input__newExport;
}
4 changes: 4 additions & 0 deletions test/test-cases/export-class/source.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
color: red;
}

:local(.\:\:\:\:) {
color: rebeccapurple;
}

@media (max-width: 520px) {
/* selector doubled to increase specificity */
:local(.exportName):local(.exportName) {
Expand Down

0 comments on commit d6e38e6

Please sign in to comment.