Skip to content

Commit 6b28c60

Browse files
authored
Replace period in CSS Module classnames (facebook#8492)
1 parent 1f81469 commit 6b28c60

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
const getCSSModuleLocalIdent = require('../getCSSModuleLocalIdent');
11+
12+
const rootContext = '/path';
13+
const defaultClassName = 'class';
14+
const options = { context: undefined, hashPrefix: '', regExp: null };
15+
16+
const tests = [
17+
{
18+
resourcePath: '/path/to/file.module.css',
19+
expected: 'file_class__13tFD',
20+
},
21+
{
22+
resourcePath: '/path/to/file.module.scss',
23+
expected: 'file_class__3lYUI',
24+
},
25+
{
26+
resourcePath: '/path/to/file.module.sass',
27+
expected: 'file_class__2KnOB',
28+
},
29+
{
30+
resourcePath: '/path/to/file.name.module.css',
31+
expected: 'file_name_class__1OzEh',
32+
},
33+
];
34+
35+
describe('getCSSModuleLocalIdent', () => {
36+
tests.forEach(test => {
37+
const { className = defaultClassName, expected, resourcePath } = test;
38+
it(JSON.stringify({ resourcePath, className }), () => {
39+
const ident = getCSSModuleLocalIdent(
40+
{
41+
resourcePath,
42+
rootContext,
43+
},
44+
'[hash:base64]',
45+
className,
46+
options
47+
);
48+
expect(ident).toBe(expected);
49+
});
50+
});
51+
});

packages/react-dev-utils/getCSSModuleLocalIdent.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ module.exports = function getLocalIdent(
3535
fileNameOrFolder + '_' + localName + '__' + hash,
3636
options
3737
);
38-
// remove the .module that appears in every classname when based on the file.
39-
return className.replace('.module_', '_');
38+
// Remove the .module that appears in every classname when based on the file and replace all "." with "_".
39+
return className.replace('.module_', '_').replace(/\./g, '_');
4040
};

0 commit comments

Comments
 (0)