From 1e281099c9619efc871357b6b9001abfe81d25f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Wed, 29 May 2019 14:37:56 +0200 Subject: [PATCH 1/2] fix: No exported locals found (#15) --- index.js | 4 ---- test/emit-empty-declaration/.gitignore | 1 + .../emit-empty-declaration.test.js.snap | 12 ++++++++++++ .../emit-empty-declaration.test.js | 13 +++++++++++++ test/emit-empty-declaration/index.css | 3 +++ test/emit-empty-declaration/index.js | 1 + 6 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 test/emit-empty-declaration/.gitignore create mode 100644 test/emit-empty-declaration/__snapshots__/emit-empty-declaration.test.js.snap create mode 100644 test/emit-empty-declaration/emit-empty-declaration.test.js create mode 100644 test/emit-empty-declaration/index.css create mode 100644 test/emit-empty-declaration/index.js diff --git a/index.js b/index.js index 6f318ed..6c7a989 100644 --- a/index.js +++ b/index.js @@ -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]); diff --git a/test/emit-empty-declaration/.gitignore b/test/emit-empty-declaration/.gitignore new file mode 100644 index 0000000..cc5d7db --- /dev/null +++ b/test/emit-empty-declaration/.gitignore @@ -0,0 +1 @@ +index.css.d.ts diff --git a/test/emit-empty-declaration/__snapshots__/emit-empty-declaration.test.js.snap b/test/emit-empty-declaration/__snapshots__/emit-empty-declaration.test.js.snap new file mode 100644 index 0000000..9ecd79a --- /dev/null +++ b/test/emit-empty-declaration/__snapshots__/emit-empty-declaration.test.js.snap @@ -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; +" +`; diff --git a/test/emit-empty-declaration/emit-empty-declaration.test.js b/test/emit-empty-declaration/emit-empty-declaration.test.js new file mode 100644 index 0000000..88e3977 --- /dev/null +++ b/test/emit-empty-declaration/emit-empty-declaration.test.js @@ -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(); +}); diff --git a/test/emit-empty-declaration/index.css b/test/emit-empty-declaration/index.css new file mode 100644 index 0000000..9f89559 --- /dev/null +++ b/test/emit-empty-declaration/index.css @@ -0,0 +1,3 @@ +html { + /* No class selectors in this file ... */ +} \ No newline at end of file diff --git a/test/emit-empty-declaration/index.js b/test/emit-empty-declaration/index.js new file mode 100644 index 0000000..3a29aed --- /dev/null +++ b/test/emit-empty-declaration/index.js @@ -0,0 +1 @@ +import "./index.css"; From 501f22a98c52a360190e86beb0d7995dc658881d Mon Sep 17 00:00:00 2001 From: Mark Dalgleish Date: Thu, 30 May 2019 07:33:42 +1000 Subject: [PATCH 2/2] refactor: Add trailing line --- test/emit-empty-declaration/index.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/emit-empty-declaration/index.css b/test/emit-empty-declaration/index.css index 9f89559..2da8ff0 100644 --- a/test/emit-empty-declaration/index.css +++ b/test/emit-empty-declaration/index.css @@ -1,3 +1,3 @@ html { /* No class selectors in this file ... */ -} \ No newline at end of file +}