Skip to content

Commit 556cedd

Browse files
committed
fix bug, see gajus#101
1 parent 154ad84 commit 556cedd

File tree

5 files changed

+9
-13
lines changed
  • src
  • test/fixtures/react-css-modules
    • merges the resolved styleName with the existing className values
    • uses getClassName to resolve non-literal styleName
    • uses getClassName to resolve non-literal styleName (with already existing className)

5 files changed

+9
-13
lines changed

package.json

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
{
2-
"author": {
3-
"email": "gajus@gajus.com",
4-
"name": "Gajus Kuizinas",
5-
"url": "http://gajus.com"
6-
},
2+
"author": "NE-SmallTown(https://github.com/NE-SmallTown)",
73
"dependencies": {
84
"ajv": "^4.11.4",
95
"babel-plugin-syntax-jsx": "^6.18.0",
@@ -48,10 +44,10 @@
4844
],
4945
"license": "BSD-3-Clause",
5046
"main": "dist/index.js",
51-
"name": "babel-plugin-react-css-modules",
47+
"name": "babel-plugin-react-css-modules-ne-smalltown",
5248
"repository": {
5349
"type": "git",
54-
"url": "https://github.com/gajus/babel-plugin-react-css-modules"
50+
"url": "https://github.com/NE-SmallTown/babel-plugin-react-css-modules.git"
5551
},
5652
"scripts": {
5753
"buildHelper": "mkdirp ./dist/browser && cross-env NODE_ENV=production && babel ./src/getClassName.js --out-file ./dist/browser/getClassName.js --source-maps --no-babelrc --plugins transform-es2015-modules-commonjs,transform-flow-strip-types --presets es2015",
@@ -60,5 +56,5 @@
6056
"precommit": "npm run test",
6157
"test": "cross-env NODE_ENV=test mocha --compilers js:babel-register"
6258
},
63-
"version": "1.1.0"
59+
"version": "2.8.0"
6460
}

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ export default ({
142142
let styleImportName: string;
143143

144144
if (path.node.specifiers.length === 0) {
145-
// eslint-disable-next-line no-process-env
146-
styleImportName = process.env.NODE_ENV === 'test' ? 'random-test' : 'random-' + Math.random();
145+
// use imported file path as import name
146+
styleImportName = path.node.source.value;
147147
} else if (path.node.specifiers.length === 1) {
148148
styleImportName = path.node.specifiers[0].local.name;
149149
} else {

test/fixtures/react-css-modules/merges the resolved styleName with the existing className values/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _getClassName from 'babel-plugin-react-css-modules/dist/browser/getClassN
22
import './bar.css';
33

44
const _styleModuleImportMap = {
5-
'random-test': {
5+
'./bar.css': {
66
'a': 'bar__a'
77
}
88
};

test/fixtures/react-css-modules/uses getClassName to resolve non-literal styleName (with already existing className)/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const _styleModuleImportMap = {
66
'bar': {
77
'a-b': 'bar__a-b'
88
},
9-
'random-test': {
9+
'./foo.css': {
1010
'a-b': 'foo__a-b'
1111
}
1212
};

test/fixtures/react-css-modules/uses getClassName to resolve non-literal styleName/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const _styleModuleImportMap = {
66
'bar': {
77
'a-b': 'bar__a-b'
88
},
9-
'random-test': {
9+
'./foo.css': {
1010
'a-b': 'foo__a-b'
1111
}
1212
};

0 commit comments

Comments
 (0)