How to use the SourceMapGenerator function from source-map

Find comprehensive JavaScript source-map.SourceMapGenerator code examples handpicked from public code repositorys.

9
10
11
12
13
14
15
16
17
18
var through = require('through');
var UglifyJS = require('uglify-js');
var UglifyCSS = require('uglifycss');

var SourceMapConsumer = sourceMap.SourceMapConsumer;
var SourceMapGenerator = sourceMap.SourceMapGenerator;
var SourceNode = sourceMap.SourceNode;


// Uglify emits ugly warnings for source maps it can't resolve.
fork icon547
star icon3
watch icon3

26
27
28
29
30
31
32
33
34
35

var validUpdateModes = ['websocket', 'ajax', 'fs', 'none'];
var updateModesNeedingUrl = ['ajax'];

function makeIdentitySourceMap(content, resourcePath) {
  var map = new sm.SourceMapGenerator();
  map.setSourceContent(resourcePath, content);
  content.split('\n').map(function(line, index) {
    map.addMapping({
      source: resourcePath,
fork icon26
star icon375
watch icon9

0
1
2
3
4
5
6
7
8
'use strict'

const sourceMap = require('source-map')
const SourceNode = sourceMap.SourceNode
const SourceMapConsumer = sourceMap.SourceMapConsumer
const SourceMapGenerator = sourceMap.SourceMapGenerator

module.exports = function(compiler, source, resourcePath, rawResult, generatedSource) {
  let rawMap = JSON.parse(compiler.$source_map())
fork icon10
star icon17
watch icon4

201
202
203
204
205
206
207
208
209
210
211
212
      "text/plain"
  };
}


function applySourceMap(generatedId, url, code, mappings) {
  const generator = new SourceMapGenerator({ file: url });
  mappings.forEach(mapping => generator.addMapping(mapping));
  generator.setSourceContent(url, code);


  const map = SourceMapConsumer(generator.toJSON());
fork icon5
star icon32
watch icon0

-3
fork icon0
star icon0
watch icon1

+ 3 other calls in file

4
5
6
7
8
9
10
11
12
13
14
 * @param {string} source The content of the source file.
 * @param {string} resourcePath The name of the source file.
 * @returns {import('source-map').RawSourceMap} The identity source map.
 */
function getIdentitySourceMap(source, resourcePath) {
  const sourceMap = new SourceMapGenerator();
  sourceMap.setSourceContent(resourcePath, source);


  source.split('\n').forEach((line, index) => {
    sourceMap.addMapping({
fork icon0
star icon0
watch icon0

2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
            }
        });
    }
    if (sourceMap$1) {
        // lazy require source-map implementation, only in non-browser builds
        context.map = new sourceMap.SourceMapGenerator();
        context.map.setSourceContent(filename, context.source);
    }
    return context;
}
fork icon0
star icon0
watch icon0

177
178
179
180
181
182
183
184
185
186
  var mapping = fis.file.wrap(pkg.dirname + '/' + pkg.filename + pkg.rExt + '.map');
  var code_map = sourceNode.toStringWithSourceMap({
    file: pkg.subpath
  });

  var generater = SourceMap.SourceMapGenerator.fromSourceMap(new SourceMap.SourceMapConsumer(code_map.map.toJSON()));
  mapping.setContent(generater.toString());
  ret.pkg[mapping.subpath] = mapping;
  content += '//# sourceMappingURL=' + mapping.getUrl();
}
fork icon0
star icon0
watch icon2

+ 3 other calls in file