You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							33 lines
						
					
					
						
							1.0 KiB
						
					
					
				
			
		
		
	
	
							33 lines
						
					
					
						
							1.0 KiB
						
					
					
				const path = require('path') | 
						|
const sourceMap = require('source-map') | 
						|
const splitRE = /\r?\n/g | 
						|
 | 
						|
module.exports = function generateSourceMap (script, output, filePath, content, inputMap) { | 
						|
  var hashedFilename = path.basename(filePath) | 
						|
  var map = new sourceMap.SourceMapGenerator() | 
						|
  map.setSourceContent(hashedFilename, content) | 
						|
  // check input source map from babel/coffee etc | 
						|
  var inputMapConsumer = inputMap && new sourceMap.SourceMapConsumer(inputMap) | 
						|
  var generatedOffset = (output ? output.split(splitRE).length : 0) + 1 | 
						|
  script.split(splitRE).forEach(function (line, index) { | 
						|
    var ln = index + 1 | 
						|
    var originalLine = inputMapConsumer | 
						|
      ? inputMapConsumer.originalPositionFor({ line: ln, column: 0 }).line | 
						|
      : ln | 
						|
    if (originalLine) { | 
						|
      map.addMapping({ | 
						|
        source: hashedFilename, | 
						|
        generated: { | 
						|
          line: ln + generatedOffset, | 
						|
          column: 0 | 
						|
        }, | 
						|
        original: { | 
						|
          line: originalLine, | 
						|
          column: 0 | 
						|
        } | 
						|
      }) | 
						|
    } | 
						|
  }) | 
						|
  map._hashedFilename = hashedFilename | 
						|
  return map | 
						|
}
 | 
						|
 |