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

fix: preserve leading underscore in class names #543

Merged
merged 1 commit into from
May 29, 2017
Merged
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
28 changes: 11 additions & 17 deletions lib/processCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var loaderUtils = require("loader-utils");
var assign = require("object-assign");
var getLocalIdent = require("./getLocalIdent");

var icssUtils = require('icss-utils');
var localByDefault = require("postcss-modules-local-by-default");
var extractImports = require("postcss-modules-extract-imports");
var modulesScope = require("postcss-modules-scope");
Expand Down Expand Up @@ -65,24 +66,17 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
});
}

css.walkRules(function(rule) {
if(rule.selector === ":export") {
rule.walkDecls(function(decl) {
exports[decl.prop] = decl.value;
});
rule.remove();
} else if(/^:import\(.+\)$/.test(rule.selector)) {
var match = /^:import\((.+)\)$/.exec(rule.selector);
var url = loaderUtils.parseString(match[1]);
rule.walkDecls(function(decl) {
imports["$" + decl.prop] = importItems.length;
importItems.push({
url: url,
export: decl.value
});
var icss = icssUtils.extractICSS(css);
exports = icss.icssExports;
Object.keys(icss.icssImports).forEach(function(key) {
var url = loaderUtils.parseString(key);
Object.keys(icss.icssImports[key]).forEach(function(prop) {
imports["$" + prop] = importItems.length;
importItems.push({
url: url,
export: icss.icssImports[key][prop]
});
rule.remove();
}
})
});

Object.keys(exports).forEach(function(exportName) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"babel-code-frame": "^6.11.0",
"css-selector-tokenizer": "^0.7.0",
"cssnano": ">=2.6.1 <4",
"icss-utils": "^2.1.0",
"loader-utils": "^1.0.2",
"lodash.camelcase": "^4.3.0",
"object-assign": "^4.0.1",
Expand Down
5 changes: 5 additions & 0 deletions test/localTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,9 @@ describe("local", function() {
], {
test: "_--test"
}, "?localIdentName=--[local]");
testLocal("saves underscore prefix in exported class names", ":export { _test: _test }", [
[1, "", ""]
], {
_test: '_test'
}, "?localIdentName=[local]");
});
18 changes: 14 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,6 @@ conventional-recommended-bump@^0.3.0:
meow "^3.3.0"
object-assign "^4.0.1"

convert-source-map@^1.3.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.4.0.tgz#e3dad195bf61bfe13a7a3c73e9876ec14a0268f3"

core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
Expand Down Expand Up @@ -1164,6 +1160,12 @@ icss-replace-symbols@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/icss-replace-symbols/-/icss-replace-symbols-1.0.2.tgz#cb0b6054eb3af6edc9ab1d62d01933e2d4c8bfa5"

icss-utils@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/icss-utils/-/icss-utils-2.1.0.tgz#83f0a0ec378bf3246178b6c2ad9136f135b1c962"
dependencies:
postcss "^6.0.1"

ignore@^3.2.0:
version "3.2.4"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.2.4.tgz#4055e03596729a8fabe45a43c100ad5ed815c4e8"
Expand Down Expand Up @@ -2036,6 +2038,14 @@ postcss@^5.0.10, postcss@^5.0.11, postcss@^5.0.12, postcss@^5.0.13, postcss@^5.0
source-map "^0.5.6"
supports-color "^3.2.3"

postcss@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-6.0.1.tgz#000dbd1f8eef217aa368b9a212c5fc40b2a8f3f2"
dependencies:
chalk "^1.1.3"
source-map "^0.5.6"
supports-color "^3.2.3"

prelude-ls@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
Expand Down