Skip to content
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

fix: do not output undefined when sourceRoot is unavailable #1036

Merged
merged 1 commit into from
Jan 3, 2020
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 src/runtime/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function cssWithMappingToString(item, useSourceMap) {
if (useSourceMap && typeof btoa === 'function') {
const sourceMapping = toComment(cssMapping);
const sourceURLs = cssMapping.sources.map(
(source) => `/*# sourceURL=${cssMapping.sourceRoot}${source} */`
(source) => `/*# sourceURL=${cssMapping.sourceRoot || ''}${source} */`
);

return [content]
Expand Down
8 changes: 7 additions & 1 deletion test/runtime/__snapshots__/api.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ exports[`api should toString a single module 1`] = `"body { a: 1; }"`;

exports[`api should toString multiple modules 1`] = `"body { b: 2; }body { a: 1; }"`;

exports[`api should toString with a source map without "sourceRoot" 1`] = `
"body { a: 1; }
/*# sourceURL=./path/to/test.scss */
/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC5zY3NzIiwic291cmNlcyI6WyIuL3BhdGgvdG8vdGVzdC5zY3NzIl0sIm1hcHBpbmdzIjoiQUFBQTsifQ== */"
`;

exports[`api should toString with media query 1`] = `"body { b: 2; }body { c: 3; }body { b: 2; }@media print {body { b: 2; }}@media print {body { d: 4; }}@media screen {body { a: 1; }}"`;

exports[`api should toString with source mapping 1`] = `
Expand All @@ -16,4 +22,4 @@ exports[`api should toString with source mapping 1`] = `
/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC5zY3NzIiwic291cmNlcyI6WyIuL3BhdGgvdG8vdGVzdC5zY3NzIl0sIm1hcHBpbmdzIjoiQUFBQTsiLCJzb3VyY2VSb290Ijoid2VicGFjazovLyJ9 */"
`;

exports[`api should toString without source mapping if btoa not avalibale 1`] = `"body { a: 1; }"`;
exports[`api should toString without source mapping if btoa not available 1`] = `"body { a: 1; }"`;
19 changes: 18 additions & 1 deletion test/runtime/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('api', () => {
expect(m.toString()).toMatchSnapshot();
});

it('should toString without source mapping if btoa not avalibale', () => {
it('should toString without source mapping if btoa not available', () => {
global.btoa = null;

const m = api(true);
Expand All @@ -120,4 +120,21 @@ describe('api', () => {

expect(m.toString()).toMatchSnapshot();
});

it.only('should toString with a source map without "sourceRoot"', () => {
const m = api(true);

m.push([
1,
'body { a: 1; }',
'',
{
file: 'test.scss',
sources: ['./path/to/test.scss'],
mappings: 'AAAA;',
},
]);

expect(m.toString()).toMatchSnapshot();
});
});