Skip to content

fix: Support files without exported locals #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ module.exports = function(content, ...rest) {

const localExports = content.split('exports.locals')[1];

if (!localExports) {
return failed(new Error(`No exported locals found for ${filename}`));
}

while ((match = keyRegex.exec(localExports))) {
if (cssModuleKeys.indexOf(match[1]) < 0) {
cssModuleKeys.push(match[1]);
Expand Down
1 change: 1 addition & 0 deletions test/emit-empty-declaration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index.css.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Can emit valid declaration without classes 1`] = `
"// This file is automatically generated.
// Please do not change this file!
interface CssExports {

}
declare var cssExports: CssExports;
export = cssExports;
"
`;
13 changes: 13 additions & 0 deletions test/emit-empty-declaration/emit-empty-declaration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const fs = require('fs');
const compiler = require('../compiler.js');

test('Can emit valid declaration without classes', async () => {
await compiler(require.resolve('./index.js'));

const declaration = fs.readFileSync(
require.resolve('./index.css.d.ts'),
'utf-8'
);

expect(declaration).toMatchSnapshot();
});
3 changes: 3 additions & 0 deletions test/emit-empty-declaration/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
html {
/* No class selectors in this file ... */
}
1 change: 1 addition & 0 deletions test/emit-empty-declaration/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./index.css";