-
-
Notifications
You must be signed in to change notification settings - Fork 179
perf(src/index): regression caused by parsing source maps individually #287
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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]; | ||
|
@@ -187,11 +171,15 @@ class UglifyJsPlugin { | |
|
||
tasks.push(task); | ||
} catch (error) { | ||
let sourceMap = null; | ||
if (inputSourceMap && utils.isSourceMap(inputSourceMap)) { | ||
sourceMap = new SourceMapConsumer(inputSourceMap); | ||
} | ||
compilation.errors.push( | ||
this.buildError( | ||
UglifyJsPlugin.buildError( | ||
error, | ||
file, | ||
inputSourceMap, | ||
sourceMap, | ||
requestShortener, | ||
), | ||
); | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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, | ||
), | ||
); | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again mistake, sorry, very tired There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not following you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, ok! No worries. |
||
this.options.warningsFilter, | ||
requestShortener, | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n