mirror of https://github.com/webpack/webpack.git
				
				
				
			use sourceAndMap is available
This commit is contained in:
		
							parent
							
								
									76a2fef32a
								
							
						
					
					
						commit
						92f53176a2
					
				|  | @ -17,9 +17,15 @@ EvalSourceMapDevToolModuleTemplatePlugin.prototype.apply = function(moduleTempla | ||||||
| 	moduleTemplate.plugin("module", function(source, module, chunk) { | 	moduleTemplate.plugin("module", function(source, module, chunk) { | ||||||
| 		if(source.__EvalSourceMapDevTool_Data) | 		if(source.__EvalSourceMapDevTool_Data) | ||||||
| 			return source.__EvalSourceMapDevTool_Data; | 			return source.__EvalSourceMapDevTool_Data; | ||||||
| 		var content = source.source(); |  | ||||||
| 
 | 
 | ||||||
|  | 		if(source.sourceAndMap) { | ||||||
|  | 			var sourceAndMap = source.sourceAndMap(); | ||||||
|  | 			var sourceMap = sourceAndMap.map; | ||||||
|  | 			var content = sourceAndMap.source; | ||||||
|  | 		} else { | ||||||
| 			var sourceMap = source.map(); | 			var sourceMap = source.map(); | ||||||
|  | 			var content = source.source(); | ||||||
|  | 		} | ||||||
| 		if(!sourceMap) { | 		if(!sourceMap) { | ||||||
| 			return source; | 			return source; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -63,12 +63,22 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) { | ||||||
| 						} | 						} | ||||||
| 						return; | 						return; | ||||||
| 					} | 					} | ||||||
|  | 					if(asset.sourceAndMap) { | ||||||
|  | 						var sourceAndMap = asset.sourceAndMap(); | ||||||
|  | 						var sourceMap = sourceAndMap.map; | ||||||
|  | 						var source = sourceAndMap.source; | ||||||
|  | 					} else { | ||||||
| 						var sourceMap = asset.map(); | 						var sourceMap = asset.map(); | ||||||
|  | 						var source = asset.source(); | ||||||
|  | 					} | ||||||
|  | 					if(!sourceMap.sources) | ||||||
|  | 						console.log(asset, sourceMap, asset.constructor); | ||||||
| 					if(sourceMap) { | 					if(sourceMap) { | ||||||
| 						return { | 						return { | ||||||
| 							chunk: chunk, | 							chunk: chunk, | ||||||
| 							file: file, | 							file: file, | ||||||
| 							asset: asset, | 							asset: asset, | ||||||
|  | 							source: source, | ||||||
| 							sourceMap: sourceMap | 							sourceMap: sourceMap | ||||||
| 						} | 						} | ||||||
| 					} | 					} | ||||||
|  | @ -112,6 +122,7 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) { | ||||||
| 				var file = task.file; | 				var file = task.file; | ||||||
| 				var asset = task.asset; | 				var asset = task.asset; | ||||||
| 				var sourceMap = task.sourceMap; | 				var sourceMap = task.sourceMap; | ||||||
|  | 				var source = task.source; | ||||||
| 				var moduleFilenames = task.moduleFilenames; | 				var moduleFilenames = task.moduleFilenames; | ||||||
| 				var modules = task.modules; | 				var modules = task.modules; | ||||||
| 				sourceMap.sources = moduleFilenames; | 				sourceMap.sources = moduleFilenames; | ||||||
|  | @ -144,12 +155,12 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) { | ||||||
| 					}); | 					}); | ||||||
| 					var sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/"); | 					var sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/"); | ||||||
| 					if(currentSourceMappingURLComment !== false) { | 					if(currentSourceMappingURLComment !== false) { | ||||||
| 						asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(asset, currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl)); | 						asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl)); | ||||||
| 					} | 					} | ||||||
| 					asset.__SourceMapDevTool_Data[sourceMapFile] = this.assets[sourceMapFile] = new RawSource(JSON.stringify(sourceMap)); | 					asset.__SourceMapDevTool_Data[sourceMapFile] = this.assets[sourceMapFile] = new RawSource(JSON.stringify(sourceMap)); | ||||||
| 					chunk.files.push(sourceMapFile); | 					chunk.files.push(sourceMapFile); | ||||||
| 				} else { | 				} else { | ||||||
| 					asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(asset, currentSourceMappingURLComment | 					asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment | ||||||
| 						.replace(/\[map\]/g, function() { | 						.replace(/\[map\]/g, function() { | ||||||
| 							return JSON.stringify(sourceMap); | 							return JSON.stringify(sourceMap); | ||||||
| 						}) | 						}) | ||||||
|  |  | ||||||
|  | @ -32,8 +32,15 @@ LoaderPlugin.prototype.apply = function(compiler) { | ||||||
| 
 | 
 | ||||||
| 						if(dep.module.error) return callback(dep.module.error); | 						if(dep.module.error) return callback(dep.module.error); | ||||||
| 						if(!dep.module._source) throw new Error("The module created for a LoaderDependency must have a property _source"); | 						if(!dep.module._source) throw new Error("The module created for a LoaderDependency must have a property _source"); | ||||||
| 						var map = dep.module._source.map(); | 						var moduleSource = dep.module._source; | ||||||
| 						var source = dep.module._source.source(); | 						if(moduleSource.sourceAndMap) { | ||||||
|  | 							var sourceAndMap = moduleSource.sourceAndMap(); | ||||||
|  | 							var map = sourceAndMap.map; | ||||||
|  | 							var source = sourceAndMap.source; | ||||||
|  | 						} else { | ||||||
|  | 							var map = moduleSource.map(); | ||||||
|  | 							var source = moduleSource.source(); | ||||||
|  | 						} | ||||||
| 						if(dep.module.fileDependencies) { | 						if(dep.module.fileDependencies) { | ||||||
| 							dep.module.fileDependencies.forEach(function(dep) { | 							dep.module.fileDependencies.forEach(function(dep) { | ||||||
| 								loaderContext.addDependency(dep); | 								loaderContext.addDependency(dep); | ||||||
|  |  | ||||||
|  | @ -46,13 +46,19 @@ UglifyJsPlugin.prototype.apply = function(compiler) { | ||||||
| 				var warnings = []; | 				var warnings = []; | ||||||
| 				try { | 				try { | ||||||
| 					var asset = compilation.assets[file]; | 					var asset = compilation.assets[file]; | ||||||
| 					var input = asset.source(); |  | ||||||
| 					if(asset.__UglifyJsPlugin) { | 					if(asset.__UglifyJsPlugin) { | ||||||
| 						compilation.assets[file] = asset.__UglifyJsPlugin; | 						compilation.assets[file] = asset.__UglifyJsPlugin; | ||||||
| 						return; | 						return; | ||||||
| 					} | 					} | ||||||
| 					if(options.sourceMap !== false) { | 					if(options.sourceMap !== false) { | ||||||
|  | 						if(asset.sourceAndMap) { | ||||||
|  | 							var sourceAndMap = asset.sourceAndMap(); | ||||||
|  | 							var inputSourceMap = sourceAndMap.map; | ||||||
|  | 							var input = sourceAndMap.source; | ||||||
|  | 						} else { | ||||||
| 							var inputSourceMap = asset.map(); | 							var inputSourceMap = asset.map(); | ||||||
|  | 							var input = asset.source(); | ||||||
|  | 						} | ||||||
| 						var sourceMap = new SourceMapConsumer(inputSourceMap); | 						var sourceMap = new SourceMapConsumer(inputSourceMap); | ||||||
| 						uglify.AST_Node.warn_function = function(warning) { | 						uglify.AST_Node.warn_function = function(warning) { | ||||||
| 							var match = /\[.+:([0-9]+),([0-9]+)\]/.exec(warning); | 							var match = /\[.+:([0-9]+),([0-9]+)\]/.exec(warning); | ||||||
|  | @ -67,6 +73,7 @@ UglifyJsPlugin.prototype.apply = function(compiler) { | ||||||
| 								"[" + requestShortener.shorten(original.source) + ":" + original.line + "," + original.column + "]"); | 								"[" + requestShortener.shorten(original.source) + ":" + original.line + "," + original.column + "]"); | ||||||
| 						}; | 						}; | ||||||
| 					} else { | 					} else { | ||||||
|  | 						var input = asset.source(); | ||||||
| 						uglify.AST_Node.warn_function = function(warning) { | 						uglify.AST_Node.warn_function = function(warning) { | ||||||
| 							warnings.push(warning); | 							warnings.push(warning); | ||||||
| 						}; | 						}; | ||||||
|  | @ -102,7 +109,7 @@ UglifyJsPlugin.prototype.apply = function(compiler) { | ||||||
| 					if(map) map = map + ""; | 					if(map) map = map + ""; | ||||||
| 					stream = stream + ""; | 					stream = stream + ""; | ||||||
| 					asset.__UglifyJsPlugin = compilation.assets[file] = (map ? | 					asset.__UglifyJsPlugin = compilation.assets[file] = (map ? | ||||||
| 						new SourceMapSource(stream, file, map, input, inputSourceMap) : | 						new SourceMapSource(stream, file, JSON.parse(map), input, inputSourceMap) : | ||||||
| 						new RawSource(stream)); | 						new RawSource(stream)); | ||||||
| 					if(warnings.length > 0) { | 					if(warnings.length > 0) { | ||||||
| 						compilation.warnings.push(new Error(file + " from UglifyJs\n" + warnings.join("\n"))); | 						compilation.warnings.push(new Error(file + " from UglifyJs\n" + warnings.join("\n"))); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue