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

Commit 0d4624c

Browse files
authored
fix: working with eval source maps (#286)
1 parent 6c8f8ef commit 0d4624c

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

Diff for: src/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ ${
8787
}
8888

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

9292
/* eslint-disable prefer-template */
9393
const sourceMappingURLRegex = RegExp(

Diff for: test/__snapshots__/inline-option.test.js.snap

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ exports[`"inline" option should work with "no-fallback" value and "esModule" wit
5555

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

58+
exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("eval-source-map" value): errors 1`] = `Array []`;
59+
60+
exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("eval-source-map" value): result 1`] = `"{\\"postMessage\\":true,\\"onmessage\\":true}"`;
61+
62+
exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("eval-source-map" value): warnings 1`] = `Array []`;
63+
5864
exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("source-map" value): errors 1`] = `Array []`;
5965

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

Diff for: test/inline-option.test.js

+36
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,42 @@ describe('"inline" option', () => {
6262
expect(getErrors(stats)).toMatchSnapshot('errors');
6363
});
6464

65+
it('should work with "no-fallback" value and the "devtool" option ("eval-source-map" value)', async () => {
66+
const compiler = getCompiler(
67+
'./basic/entry.js',
68+
{ inline: 'no-fallback' },
69+
{ devtool: 'eval-source-map' }
70+
);
71+
const stats = await compile(compiler);
72+
const result = await getResultFromBrowser(stats);
73+
const moduleSource = getModuleSource('./basic/worker.js', stats);
74+
const sourceUrlInternalIndex = moduleSource.indexOf(
75+
'sourceURL=webpack-internal:///./basic/worker.js'
76+
);
77+
78+
expect(moduleSource.indexOf('inline.js') > 0).toBe(true);
79+
expect(
80+
moduleSource.indexOf('__webpack_public_path__ + "test.worker.js"') === -1
81+
).toBe(true);
82+
expect(
83+
moduleSource.indexOf(
84+
'sourceMappingURL=data:application/json;charset=utf-8;base64,'
85+
) === -1
86+
).toBe(true);
87+
expect(sourceUrlInternalIndex >= 0).toBe(true);
88+
expect(
89+
moduleSource.lastIndexOf('//', sourceUrlInternalIndex) >
90+
moduleSource.lastIndexOf('\\n', sourceUrlInternalIndex) ||
91+
moduleSource.lastIndexOf('/*', sourceUrlInternalIndex) >
92+
moduleSource.lastIndexOf('*/', sourceUrlInternalIndex)
93+
).toBe(true);
94+
expect(stats.compilation.assets['test.worker.js']).toBeUndefined();
95+
expect(stats.compilation.assets['test.worker.js.map']).toBeUndefined();
96+
expect(result).toMatchSnapshot('result');
97+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
98+
expect(getErrors(stats)).toMatchSnapshot('errors');
99+
});
100+
65101
it('should work with "no-fallback" value and the "devtool" option ("source-map" value)', async () => {
66102
const compiler = getCompiler(
67103
'./basic/entry.js',

0 commit comments

Comments
 (0)