Skip to content

fix(emit): Omit keys from sourcemap object if sourcemaps are enabled #12

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 1 commit into from
Apr 30, 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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = function(content, ...rest) {
const cssModuleInterfaceFilename = filenameToTypingsFilename(filename);
const { read, write } = makeFileHandlers(cssModuleInterfaceFilename);

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

Expand Down
6 changes: 4 additions & 2 deletions test/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const webpack = require('webpack');
const memoryfs = require('memory-fs');

module.exports = (entry, options = {}) => {
const { sourceMap, ...loaderOptions } = options;
const compiler = webpack({
context: path.dirname(entry),
entry,
Expand All @@ -17,12 +18,13 @@ module.exports = (entry, options = {}) => {
use: [
{
loader: require.resolve('../index.js'),
options
options: loaderOptions
},
{
loader: 'css-loader',
options: {
modules: true
modules: true,
sourceMap: !!sourceMap
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Can emit valid declaration 1`] = `
exports[`Can emit valid declaration without sourceMaps 1`] = `
"// This file is automatically generated.
// Please do not change this file!
interface CssExports {
Expand Down
25 changes: 24 additions & 1 deletion test/emit-declaration/emit-declaration.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const compiler = require('../compiler.js');

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

const declaration = fs.readFileSync(
Expand All @@ -11,3 +11,26 @@ test('Can emit valid declaration', async () => {

expect(declaration).toMatchSnapshot();
});

test('Can emit valid declaration with sourceMap', async () => {
await compiler(require.resolve('./index.js'), { sourceMap: true });

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

expect(declaration).toMatchInlineSnapshot(`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used an inline snapshot here because I wanted to have full control over what it was matching against. It also allowed me to add the test first, verify it failed, and then add my fix and re-run the test to verify it passes now. I could not have done that as easily if I generated the snapshots with the broken code.

"// This file is automatically generated.
// Please do not change this file!
interface CssExports {
'otherClass': string;
'someClass': string;
'validClass': string;
}
declare var cssExports: CssExports;
export = cssExports;
"
`);
});