保誠-保戶業務員媒合平台
Tomas
2022-05-19 957a1f10a06fdbb76f1a0ba94fe44126c613fee3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
}