diff --git a/lib/processors/minifier.js b/lib/processors/minifier.js index 3da3e6d03..6676bde55 100644 --- a/lib/processors/minifier.js +++ b/lib/processors/minifier.js @@ -274,6 +274,7 @@ export default async function({ filename, dbgFilename, code, + resourcePath, sourceMapOptions }, taskUtil); resource.setString(result.code); diff --git a/lib/processors/minifierWorker.js b/lib/processors/minifierWorker.js index 943422903..a54e75f94 100644 --- a/lib/processors/minifierWorker.js +++ b/lib/processors/minifierWorker.js @@ -30,6 +30,7 @@ const copyrightCommentsAndBundleCommentPattern = /copyright|\(c\)(?:[0-9]+|\s+[0 * @param {string} parameters.filename * @param {string} parameters.dbgFilename * @param {string} parameters.code + * @param {string} parameters.resourcePath * @param {object} parameters.sourceMapOptions * @returns {Promise} Promise resolving once minification of the resource has finished */ @@ -37,6 +38,7 @@ export default async function execMinification({ filename, dbgFilename, code, + resourcePath, sourceMapOptions }) { try { @@ -61,7 +63,7 @@ export default async function execMinification({ } catch (err) { // Note: err.filename contains the debug-name throw new Error( - `Minification failed with error: ${err.message} in file ${filename} ` + + `Minification failed with error: ${err.message} in file ${resourcePath} ` + `(line ${err.line}, col ${err.col}, pos ${err.pos})`, { cause: err }); diff --git a/test/lib/tasks/minify.integration.js b/test/lib/tasks/minify.integration.js index 678ee931c..066dadc6c 100644 --- a/test/lib/tasks/minify.integration.js +++ b/test/lib/tasks/minify.integration.js @@ -274,3 +274,70 @@ ${SOURCE_MAPPING_URL}=test.js.map`; } t.deepEqual(await resSourceMap.getString(), expectedSourceMap, "Correct source map content"); }); + +test.serial("integration: minify error", async (t) => { + const taskUtil = { + setTag: t.context.sinon.stub(), + STANDARD_TAGS: { + HasDebugVariant: "1️⃣", + IsDebugVariant: "2️⃣", + OmitFromBuildResult: "3️⃣" + }, + registerCleanupTask: t.context.sinon.stub() + }; + const {reader, workspace} = createWorkspace(); + const content = ` +// Top level return will cause a parsing error +return;`; + const testResource = resourceFactory.createResource({ + path: "/resources/my/namespace/test.js", + string: content + }); + await reader.write(testResource); + + await t.throwsAsync(() => { + return minify({ + workspace, + taskUtil, + options: { + pattern: "/resources/my/namespace/test.js", + omitSourceMapResources: true + } + }); + }, { + message: + `Minification failed with error: 'return' outside of function in file ` + + `/resources/my/namespace/test.js (line 3, col 0, pos 48)` + }, `Threw with expected error message`); + + // Ensure to call cleanup task so that workerpool is terminated - otherwise the test will time out! + const cleanupTask = taskUtil.registerCleanupTask.getCall(0).args[0]; + await cleanupTask(); +}); + + +test.serial("integration: minify error (without taskUtil)", async (t) => { + const {reader, workspace} = createWorkspace(); + const content = ` +// Top level return will cause a parsing error +return;`; + const testResource = resourceFactory.createResource({ + path: "/resources/my/namespace/test.js", + string: content + }); + await reader.write(testResource); + + await t.throwsAsync(() => { + return minify({ + workspace, + options: { + pattern: "/resources/my/namespace/test.js", + omitSourceMapResources: true + } + }); + }, { + message: + `Minification failed with error: 'return' outside of function in file ` + + `/resources/my/namespace/test.js (line 3, col 0, pos 48)` + }, `Threw with expected error message`); +});