Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

fix: do not match too many characters when removing sourceMappingURL … #286

Merged
merged 4 commits into from Sep 22, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils.js
Expand Up @@ -87,7 +87,7 @@ ${
}

// Matches only the last occurrence of sourceMappingURL
const innerRegex = /\s*[#@]\s*sourceMappingURL\s*=\s*([^\s'"]*)\s*/;
const innerRegex = /\s*[#@]\s*sourceMappingURL\s*=\s*(.*?(?=[\s'"]|\\n|$)(?:\\n)?)\s*/;

/* eslint-disable prefer-template */
const sourceMappingURLRegex = RegExp(
Expand Down
6 changes: 6 additions & 0 deletions test/__snapshots__/inline-option.test.js.snap
Expand Up @@ -55,6 +55,12 @@ exports[`"inline" option should work with "no-fallback" value and "esModule" wit

exports[`"inline" option should work with "no-fallback" value and "esModule" with "true" value: warnings 1`] = `Array []`;

exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("eval-source-map" value): errors 1`] = `Array []`;

exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("eval-source-map" value): result 1`] = `"{\\"postMessage\\":true,\\"onmessage\\":true}"`;

exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("eval-source-map" value): warnings 1`] = `Array []`;

exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("source-map" value): errors 1`] = `Array []`;

exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("source-map" value): errors 2`] = `Array []`;
Expand Down
36 changes: 36 additions & 0 deletions test/inline-option.test.js
Expand Up @@ -62,6 +62,42 @@ describe('"inline" option', () => {
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('should work with "no-fallback" value and the "devtool" option ("eval-source-map" value)', async () => {
const compiler = getCompiler(
'./basic/entry.js',
{ inline: 'no-fallback' },
{ devtool: 'eval-source-map' }
);
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);
const moduleSource = getModuleSource('./basic/worker.js', stats);
const sourceUrlInternalIndex = moduleSource.indexOf(
'sourceURL=webpack-internal:///./basic/worker.js'
);

expect(moduleSource.indexOf('inline.js') > 0).toBe(true);
expect(
moduleSource.indexOf('__webpack_public_path__ + "test.worker.js"') === -1
).toBe(true);
expect(
moduleSource.indexOf(
'sourceMappingURL=data:application/json;charset=utf-8;base64,'
) === -1
).toBe(true);
expect(sourceUrlInternalIndex >= 0).toBe(true);
expect(
moduleSource.lastIndexOf('//', sourceUrlInternalIndex) >
moduleSource.lastIndexOf('\\n', sourceUrlInternalIndex) ||
moduleSource.lastIndexOf('/*', sourceUrlInternalIndex) >
moduleSource.lastIndexOf('*/', sourceUrlInternalIndex)
).toBe(true);
expect(stats.compilation.assets['test.worker.js']).toBeUndefined();
expect(stats.compilation.assets['test.worker.js.map']).toBeUndefined();
expect(result).toMatchSnapshot('result');
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('should work with "no-fallback" value and the "devtool" option ("source-map" value)', async () => {
const compiler = getCompiler(
'./basic/entry.js',
Expand Down