Skip to content

Commit 6a97315

Browse files
bhollismarkdalgleish
authored andcommitted
fix: Include class names that compose other classes (#13)
1 parent e2b1502 commit 6a97315

File tree

6 files changed

+34
-16
lines changed

6 files changed

+34
-16
lines changed

index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,23 @@ module.exports = function(content, ...rest) {
5757
const filename = this.resourcePath;
5858
const { mode = 'emit' } = loaderUtils.getOptions(this) || {};
5959
if (!validModes.includes(mode)) {
60-
return callback(new Error(`Invalid mode option: ${mode}`));
60+
return failed(new Error(`Invalid mode option: ${mode}`));
6161
}
6262

6363
const cssModuleInterfaceFilename = filenameToTypingsFilename(filename);
6464
const { read, write } = makeFileHandlers(cssModuleInterfaceFilename);
6565

66-
const keyRegex = /"([^\\"]+)":\s*"(?:[^\\"]+)",?$/gm;
66+
const keyRegex = /"([^\\"]+)":/g;
6767
let match;
6868
const cssModuleKeys = [];
6969

70-
while ((match = keyRegex.exec(content))) {
70+
const localExports = content.split('exports.locals')[1];
71+
72+
if (!localExports) {
73+
return failed(new Error(`No exported locals found for ${filename}`));
74+
}
75+
76+
while ((match = keyRegex.exec(localExports))) {
7177
if (cssModuleKeys.indexOf(match[1]) < 0) {
7278
cssModuleKeys.push(match[1]);
7379
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"css-loader": "^1.0.0",
3838
"cz-conventional-changelog": "^2.1.0",
3939
"husky": "^1.1.2",
40-
"jest": "^23.6.0",
40+
"jest": "^24.7.1",
4141
"memory-fs": "^0.4.1",
4242
"semantic-release": "^15.9.17",
4343
"travis-deploy-once": "^5.0.9",

test/emit-declaration/__snapshots__/emit-declaration.test.js.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Can emit valid declaration with sourceMap 1`] = `
4+
"// This file is automatically generated.
5+
// Please do not change this file!
6+
interface CssExports {
7+
'composedClass': string;
8+
'otherClass': string;
9+
'someClass': string;
10+
'validClass': string;
11+
}
12+
declare var cssExports: CssExports;
13+
export = cssExports;
14+
"
15+
`;
16+
317
exports[`Can emit valid declaration without sourceMaps 1`] = `
418
"// This file is automatically generated.
519
// Please do not change this file!
620
interface CssExports {
21+
'composedClass': string;
722
'otherClass': string;
823
'someClass': string;
924
'validClass': string;

test/emit-declaration/common.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.baseClass {
2+
position: relative;
3+
}

test/emit-declaration/emit-declaration.test.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,6 @@ test('Can emit valid declaration with sourceMap', async () => {
2020
'utf-8'
2121
);
2222

23-
expect(declaration).toMatchInlineSnapshot(`
24-
"// This file is automatically generated.
25-
// Please do not change this file!
26-
interface CssExports {
27-
'otherClass': string;
28-
'someClass': string;
29-
'validClass': string;
30-
}
31-
declare var cssExports: CssExports;
32-
export = cssExports;
33-
"
34-
`);
23+
expect(declaration).toMatchSnapshot();
3524
});
3625

test/emit-declaration/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@
99
.otherClass {
1010
display: block;
1111
}
12+
13+
.composedClass {
14+
composes: baseClass from './common.css';
15+
color: cornflowerblue;
16+
}

0 commit comments

Comments
 (0)