Skip to content

Commit 92f5317

Browse files
committed
use sourceAndMap is available
1 parent 76a2fef commit 92f5317

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

lib/EvalSourceMapDevToolModuleTemplatePlugin.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ EvalSourceMapDevToolModuleTemplatePlugin.prototype.apply = function(moduleTempla
1717
moduleTemplate.plugin("module", function(source, module, chunk) {
1818
if(source.__EvalSourceMapDevTool_Data)
1919
return source.__EvalSourceMapDevTool_Data;
20-
var content = source.source();
2120

22-
var sourceMap = source.map();
21+
if(source.sourceAndMap) {
22+
var sourceAndMap = source.sourceAndMap();
23+
var sourceMap = sourceAndMap.map;
24+
var content = sourceAndMap.source;
25+
} else {
26+
var sourceMap = source.map();
27+
var content = source.source();
28+
}
2329
if(!sourceMap) {
2430
return source;
2531
}

lib/SourceMapDevToolPlugin.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,22 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
6363
}
6464
return;
6565
}
66-
var sourceMap = asset.map();
66+
if(asset.sourceAndMap) {
67+
var sourceAndMap = asset.sourceAndMap();
68+
var sourceMap = sourceAndMap.map;
69+
var source = sourceAndMap.source;
70+
} else {
71+
var sourceMap = asset.map();
72+
var source = asset.source();
73+
}
74+
if(!sourceMap.sources)
75+
console.log(asset, sourceMap, asset.constructor);
6776
if(sourceMap) {
6877
return {
6978
chunk: chunk,
7079
file: file,
7180
asset: asset,
81+
source: source,
7282
sourceMap: sourceMap
7383
}
7484
}
@@ -112,6 +122,7 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
112122
var file = task.file;
113123
var asset = task.asset;
114124
var sourceMap = task.sourceMap;
125+
var source = task.source;
115126
var moduleFilenames = task.moduleFilenames;
116127
var modules = task.modules;
117128
sourceMap.sources = moduleFilenames;
@@ -144,12 +155,12 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
144155
});
145156
var sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
146157
if(currentSourceMappingURLComment !== false) {
147-
asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(asset, currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
158+
asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
148159
}
149160
asset.__SourceMapDevTool_Data[sourceMapFile] = this.assets[sourceMapFile] = new RawSource(JSON.stringify(sourceMap));
150161
chunk.files.push(sourceMapFile);
151162
} else {
152-
asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(asset, currentSourceMappingURLComment
163+
asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment
153164
.replace(/\[map\]/g, function() {
154165
return JSON.stringify(sourceMap);
155166
})

lib/dependencies/LoaderPlugin.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@ LoaderPlugin.prototype.apply = function(compiler) {
3232

3333
if(dep.module.error) return callback(dep.module.error);
3434
if(!dep.module._source) throw new Error("The module created for a LoaderDependency must have a property _source");
35-
var map = dep.module._source.map();
36-
var source = dep.module._source.source();
35+
var moduleSource = dep.module._source;
36+
if(moduleSource.sourceAndMap) {
37+
var sourceAndMap = moduleSource.sourceAndMap();
38+
var map = sourceAndMap.map;
39+
var source = sourceAndMap.source;
40+
} else {
41+
var map = moduleSource.map();
42+
var source = moduleSource.source();
43+
}
3744
if(dep.module.fileDependencies) {
3845
dep.module.fileDependencies.forEach(function(dep) {
3946
loaderContext.addDependency(dep);
@@ -50,4 +57,4 @@ LoaderPlugin.prototype.apply = function(compiler) {
5057
};
5158
});
5259
});
53-
};
60+
};

lib/optimize/UglifyJsPlugin.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,19 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
4646
var warnings = [];
4747
try {
4848
var asset = compilation.assets[file];
49-
var input = asset.source();
5049
if(asset.__UglifyJsPlugin) {
5150
compilation.assets[file] = asset.__UglifyJsPlugin;
5251
return;
5352
}
5453
if(options.sourceMap !== false) {
55-
var inputSourceMap = asset.map();
54+
if(asset.sourceAndMap) {
55+
var sourceAndMap = asset.sourceAndMap();
56+
var inputSourceMap = sourceAndMap.map;
57+
var input = sourceAndMap.source;
58+
} else {
59+
var inputSourceMap = asset.map();
60+
var input = asset.source();
61+
}
5662
var sourceMap = new SourceMapConsumer(inputSourceMap);
5763
uglify.AST_Node.warn_function = function(warning) {
5864
var match = /\[.+:([0-9]+),([0-9]+)\]/.exec(warning);
@@ -67,6 +73,7 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
6773
"[" + requestShortener.shorten(original.source) + ":" + original.line + "," + original.column + "]");
6874
};
6975
} else {
76+
var input = asset.source();
7077
uglify.AST_Node.warn_function = function(warning) {
7178
warnings.push(warning);
7279
};
@@ -102,7 +109,7 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
102109
if(map) map = map + "";
103110
stream = stream + "";
104111
asset.__UglifyJsPlugin = compilation.assets[file] = (map ?
105-
new SourceMapSource(stream, file, map, input, inputSourceMap) :
112+
new SourceMapSource(stream, file, JSON.parse(map), input, inputSourceMap) :
106113
new RawSource(stream));
107114
if(warnings.length > 0) {
108115
compilation.warnings.push(new Error(file + " from UglifyJs\n" + warnings.join("\n")));

0 commit comments

Comments
 (0)