Skip to content
This repository was archived by the owner on Oct 30, 2020. It is now read-only.

Commit d97622d

Browse files
authored
Merge pull request #21 from scriby/master
Fix an issue with imported CSS modules
2 parents 90edeb2 + 6c5faac commit d97622d

File tree

7 files changed

+26
-6
lines changed

7 files changed

+26
-6
lines changed

src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ module.exports = function(input) {
4040
const filename = this.resourcePath;
4141
const cssModuleInterfaceFilename = filenameToTypingsFilename(filename);
4242

43-
let cssModuleKeys = Object.keys(this.exec(content, this.resource));
43+
const keyRegex = /"([^"]+)":/g;
44+
let match;
45+
const cssModuleKeys = [];
46+
47+
while (match = keyRegex.exec(content)) {
48+
if (cssModuleKeys.indexOf(match[1]) < 0) {
49+
cssModuleKeys.push(match[1]);
50+
}
51+
}
4452

4553
let cssModuleDefinition;
4654
if (!query.namedExport) {

test/entry.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {locals as stylesCamelCase} from './example-camelcase.css';
33
import * as stylesNamedExport from './example-namedexport.css';
44
import * as stylesCamelCasedNamedExport from './example-camelcase-namedexport.css';
55
import './example-no-css-modules.css';
6+
import * as compose from './example-compose.css';
67

78
const foo = stylesBase.foo;
89
const barBaz = stylesBase['bar-baz'];
@@ -15,3 +16,5 @@ const fooNamedExport = stylesNamedExport.foo;
1516

1617
const fooCamelCaseNamedExport = stylesCamelCasedNamedExport.foo;
1718
const barBazCamelCaseNamedExport = stylesCamelCasedNamedExport.barBaz;
19+
20+
const composed = compose.test;

test/example-compose.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.test {
2+
composes: shared-style from './example-shared.css';
3+
}

test/example-shared.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.shared-style {
2+
color: black;
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const test: string;

test/expected-example-shared.css.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const sharedStyle: string;

test/webpack.config.babel.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ module.exports = {
77
module: {
88
loaders: [
99
{ test: /\.ts$/, loaders: ['babel', 'ts'] },
10-
{ test: /example.css$/, loader: '../src/index.js?modules' },
11-
{ test: /example-camelcase.css$/, loader: '../src/index.js?modules&camelCase' },
12-
{ test: /example-namedexport.css$/, loader: '../src/index.js?modules&namedExport' },
13-
{ test: /example-camelcase-namedexport.css$/, loader: '../src/index.js?modules&camelCase&namedExport' },
14-
{ test: /example-no-css-modules.css$/, loader: '../src/index.js' },
10+
{ test: /example\.css$/, loader: '../src/index.js?modules' },
11+
{ test: /example-camelcase\.css$/, loader: '../src/index.js?modules&camelCase' },
12+
{ test: /example-namedexport\.css$/, loader: '../src/index.js?modules&namedExport' },
13+
{ test: /example-camelcase-namedexport\.css$/, loader: '../src/index.js?modules&camelCase&namedExport' },
14+
{ test: /example-no-css-modules\.css$/, loader: '../src/index.js' },
15+
{ test: /example-compose\.css$/, loader: '../src/index.js?modules&camelCase&namedExport' }
1516
]
1617
}
1718
};

0 commit comments

Comments
 (0)