Skip to content
This repository was archived by the owner on Dec 5, 2019. It is now read-only.

perf(src/index): regression caused by parsing source maps individually #287

Closed
wants to merge 1 commit into from
Closed
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
44 changes: 19 additions & 25 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,11 @@ class UglifyJsPlugin {
...uglifyOptions,
},
};
this.sourceMapsCache = new WeakMap();
}

buildError(err, file, inputSourceMap, requestShortener) {
static buildError(err, file, sourceMap, requestShortener) {
// Handling error which should have line, col, filename and message
if (err.line) {
const sourceMapCacheKey = { file };
let sourceMap = this.sourceMapsCache.get(sourceMapCacheKey);
if (!sourceMap) {
sourceMap = new SourceMapConsumer(inputSourceMap);
this.sourceMapsCache.set(sourceMapCacheKey, sourceMap);
}
const original = sourceMap && sourceMap.originalPositionFor({
line: err.line,
column: err.col,
Expand All @@ -74,20 +67,11 @@ class UglifyJsPlugin {
return new Error(`${file} from UglifyJs\n${err.message}`);
}

buildWarning(warning, file, inputSourceMap, warningsFilter, requestShortener) {
if (!file || !inputSourceMap) {
static buildWarning(warning, file, sourceMap, warningsFilter, requestShortener) {
if (!file || !sourceMap) {
return warning;
}

const sourceMapCacheKey = { file };

let sourceMap = this.sourceMapsCache.get(sourceMapCacheKey);

if (!sourceMap) {
sourceMap = new SourceMapConsumer(inputSourceMap);
this.sourceMapsCache.set(sourceMapCacheKey, sourceMap);
}

const match = warningRegex.exec(warning);
const line = +match[1];
const column = +match[2];
Expand Down Expand Up @@ -187,11 +171,15 @@ class UglifyJsPlugin {

tasks.push(task);
} catch (error) {
let sourceMap = null;
Copy link
Member

Choose a reason for hiding this comment

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

\n

if (inputSourceMap && utils.isSourceMap(inputSourceMap)) {
sourceMap = new SourceMapConsumer(inputSourceMap);
}
compilation.errors.push(
this.buildError(
UglifyJsPlugin.buildError(
error,
file,
inputSourceMap,
sourceMap,
requestShortener,
),
);
Expand All @@ -208,14 +196,20 @@ class UglifyJsPlugin {
const { file, input, inputSourceMap, commentsFile } = tasks[index];
const { error, map, code, warnings, extractedComments } = data;

// Create source map if needed
let sourceMap = null;
Copy link
Member

Choose a reason for hiding this comment

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

\n

if (inputSourceMap && utils.isSourceMap(inputSourceMap) && (error || (warnings && warnings.length > 0))) {
sourceMap = new SourceMapConsumer(inputSourceMap);
}

// Handling results
// Error case: add errors, and go to next file
if (error) {
compilation.errors.push(
this.buildError(
UglifyJsPlugin.buildError(
error,
file,
inputSourceMap,
sourceMap,
requestShortener,
),
);
Expand Down Expand Up @@ -275,10 +269,10 @@ class UglifyJsPlugin {
// Handling warnings
if (warnings && warnings.length > 0) {
warnings.forEach((warning) => {
const builtWarning = this.buildWarning(
const builtWarning = UglifyJsPlugin.buildWarning(
warning,
file,
inputSourceMap,
sourceMap,
Copy link
Member

@alexander-akait alexander-akait May 5, 2018

Choose a reason for hiding this comment

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

Also sourceMap can be undefined here, because warning !== error (and parsing in catch block doesn't execute)

Copy link
Member

@alexander-akait alexander-akait May 5, 2018

Choose a reason for hiding this comment

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

/cc @lojjic yep, my mistake, but if no error(s) - no source map

Copy link
Member

Choose a reason for hiding this comment

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

again mistake, sorry, very tired

Copy link
Author

Choose a reason for hiding this comment

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

I'm not following you. sourceMap can be null, if there is no valid inputSourceMap, but that's expected AFAICT.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, ok! No worries.

this.options.warningsFilter,
requestShortener,
);
Expand Down