From d6e38e6545059e7e35588e07a61eab0d861bcda2 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Mon, 4 Mar 2019 18:17:39 +0300 Subject: [PATCH] fix: don't generate invalid escaping classes (#9) --- src/index.js | 14 ++++++++++---- test/test-cases/export-class/expected.css | 5 +++++ test/test-cases/export-class/source.css | 4 ++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 5af4818..a46d67e 100644 --- a/src/index.js +++ b/src/index.js @@ -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 ); @@ -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 + ), }); } } diff --git a/test/test-cases/export-class/expected.css b/test/test-cases/export-class/expected.css index 9370948..a21c8da 100644 --- a/test/test-cases/export-class/expected.css +++ b/test/test-cases/export-class/expected.css @@ -6,6 +6,10 @@ color: red; } +._input__\:\:\:\: { + color: rebeccapurple; +} + @media (max-width: 520px) { /* selector doubled to increase specificity */ ._input__exportName._input__exportName { @@ -19,5 +23,6 @@ :export { exportName: _input__exportName; + ::::: _input__\:\:\:\:; newExport: _input__newExport; } diff --git a/test/test-cases/export-class/source.css b/test/test-cases/export-class/source.css index e34d30c..ae9a680 100644 --- a/test/test-cases/export-class/source.css +++ b/test/test-cases/export-class/source.css @@ -6,6 +6,10 @@ color: red; } +:local(.\:\:\:\:) { + color: rebeccapurple; +} + @media (max-width: 520px) { /* selector doubled to increase specificity */ :local(.exportName):local(.exportName) {