Skip to content

Commit f9dc85e

Browse files
committed
fix: object expression generated on dynamic resolution now use quote to escape properties' name (gajus#14)
1 parent b13ebd3 commit f9dc85e

File tree

7 files changed

+28
-17
lines changed

7 files changed

+28
-17
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"author": {
3-
"email": "gajus@gajus.com",
4-
"name": "Gajus Kuizinas",
5-
"url": "http://gajus.com"
3+
"email": "pcriulan@gmail.com",
4+
"name": "Pierre Criulanscy",
5+
"url": "https://github.com/gajus/babel-plugin-react-css-modules"
66
},
77
"dependencies": {
88
"babel-plugin-syntax-jsx": "^6.18.0",
@@ -42,17 +42,17 @@
4242
],
4343
"license": "BSD-3-Clause",
4444
"main": "dist/index.js",
45-
"name": "babel-plugin-react-css-modules",
45+
"name": "babel-plugin-react-css-modules-fix-11",
4646
"repository": {
4747
"type": "git",
48-
"url": "https://github.com/gajus/babel-plugin-react-css-modules"
48+
"url": "https://github.com/PCreations/babel-plugin-react-css-modules"
4949
},
5050
"scripts": {
5151
"build-helper": "mkdir -p ./dist/browser && 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",
5252
"build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --source-maps && npm run build-helper",
5353
"lint": "eslint ./src",
5454
"precommit": "npm run test",
55-
"test": "NODE_ENV=development npm run lint && npm run build && mocha --compilers js:babel-register && flow"
55+
"test": "NODE_ENV=test npm run lint && npm run build && NODE_ENV=test mocha --compilers js:babel-register && flow"
5656
},
5757
"version": "1.0.0"
5858
}

src/createObjectExpression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const createObjectExpression = (t: BabelTypes, object: Object): ObjectExpression
2525

2626
properties.push(
2727
t.objectProperty(
28-
t.identifier(name),
28+
t.identifier('\'' + name + '\''),
2929
newValue
3030
)
3131
);

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export default ({
7171
let styleImportName: string;
7272

7373
if (path.node.specifiers.length === 0) {
74-
styleImportName = 'random-' + Math.random();
74+
// eslint-disable-next-line no-process-env
75+
styleImportName = process.env.NODE_ENV === 'test' ? 'random-test' : 'random-' + Math.random();
7576
} else if (path.node.specifiers.length === 1) {
7677
styleImportName = path.node.specifiers[0].local.name;
7778
} else {
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import foo from './bar.css';
1+
import bar from './bar.css';
2+
import './foo.css';
23

3-
const styleNameValue = 'a';
4+
const styleNameBar = 'bar.a-b';
5+
const styleNameFoo = 'a-b';
46

5-
<div styleName={styleNameValue}></div>;
7+
<div styleName={styleNameBar}></div>;
8+
<div styleName={styleNameFoo}></div>;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.a {}
1+
.a-b {}
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import _getClassName from 'babel-plugin-react-css-modules/dist/browser/getClassName';
2-
import foo from './bar.css';
2+
import bar from './bar.css';
3+
import './foo.css';
34

45
const _styleModuleImportMap = {
5-
foo: {
6-
a: 'bar__a'
6+
'bar': {
7+
'a-b': 'bar__a-b'
8+
},
9+
'random-test': {
10+
'a-b': 'foo__a-b'
711
}
812
};
9-
const styleNameValue = 'a';
13+
const styleNameBar = 'bar.a-b';
14+
const styleNameFoo = 'a-b';
1015

11-
<div styleName={_getClassName(styleNameValue, _styleModuleImportMap)}></div>;
16+
<div styleName={_getClassName(styleNameBar, _styleModuleImportMap)}></div>;
17+
<div styleName={_getClassName(styleNameFoo, _styleModuleImportMap)}></div>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.a-b {}

0 commit comments

Comments
 (0)