How to use the SourceNode function from source-map

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

10
11
12
13
14
15
16
17
18
19
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.
// It cannot map our license preamble or the browserify wrappers.
fork icon547
star icon3
watch icon3

54
55
56
57
58
59
60
61
62

  logger(message, 'info');
}

const node = new SourceNode(null, null, null, [
  new SourceNode(null, null, this.resourcePath, prependText),
  SourceNode.fromStringWithSourceMap(processedSource, new SourceMapConsumer(map))
]).join(separator);
const result = node.toStringWithSourceMap();
fork icon16
star icon33
watch icon3

+ 17 other calls in file

70
71
72
73
74
75
76
77
78
79
const sourceMapConsumer = new SourceMapConsumer(map);

const onSourceMapReady = consumedMap => {
  const node = new SourceNode(null, null, null, [
    SourceNode.fromStringWithSourceMap(source, consumedMap),
    new SourceNode(null, null, resourcePath, appendText),
  ]).join(separator);
  const result = node.toStringWithSourceMap();
  callback(null, result.code, result.map.toJSON() || undefined);
};
fork icon837
star icon0
watch icon0

+ 3 other calls in file

10
11
12
13
14
15
16
17
18
19
const identityNode = (code, path) => {
  const lines = code.split('\n').map((line, index) => {
    return new SourceNode(index + 1, 0, path, `${line}\n`);
  });

  return new SourceNode(1, 0, null, lines);
};

const prepSourceMap = (code, sourceMap) => {
  const consumer = new SourceMapConsumer(typeof sourceMap === 'string' ?
fork icon474
star icon0
watch icon135

+ 27 other calls in file

67
68
69
70
71
72
73
74
75
// https://github.com/mozilla/source-map#sourcenode
// https://github.com/webpack/imports-loader/blob/master/index.js#L34-L44
// https://webpack.github.io/docs/loaders.html#writing-a-loader
if (sourceMap) {
    var currentRequest = loaderUtils.getCurrentRequest(this);
    var SourceNode = SourceMap.SourceNode;
    var SourceMapConsumer = SourceMap.SourceMapConsumer;
    var sourceMapConsumer = new SourceMapConsumer(sourceMap);
    var node = SourceNode.fromStringWithSourceMap(source, sourceMapConsumer);
fork icon16
star icon87
watch icon0

21
22
23
24
25
26
27
28
29
  scriptSetupResult,
  templateResult,
  filename,
  stylesResult
) {
  var node = new SourceNode(null, null, null)
  addToSourceMap(node, scriptResult)
  addToSourceMap(node, scriptSetupResult)
  addToSourceMap(node, templateResult)
fork icon2
star icon0
watch icon0

136
137
138
139
140
141
142
143
144
145
    sourceWidth: sourceWidth,
    noLineNumbers: self.noLineNumbers
  }));
});

var node = new sourcemap.SourceNode(null, null, null, chunks);

var results = node.toStringWithSourceMap({
  file: self.combinedServePath
}); // results has 'code' and 'map' attributes
fork icon0
star icon2
watch icon2

+ 4 other calls in file

7
8
9
10
11
12
13
14
15
16
const Handlebars = require('handlebars/dist/cjs/handlebars.js');
const {SourceMapConsumer, SourceNode} = require('source-map');

exports.process = (code, filename) => {
  const pc = Handlebars.precompile(code, {srcName: filename});
  const out = new SourceNode(null, null, null, [
    'const Handlebars = require("handlebars/dist/cjs/handlebars.runtime.js");\n',
    'module.exports = Handlebars.template(',
    SourceNode.fromStringWithSourceMap(pc.code, new SourceMapConsumer(pc.map)),
    ');\n',
fork icon0
star icon0
watch icon2

+ 5 other calls in file

82
83
84
85
86
87
88
89
90
91

if (transformedModule.map) {
  return SourceNode.fromStringWithSourceMap(
    codeWithTarpRequires, new SourceMapConsumer(transformedModule.map));
} else {
  var sn = new SourceNode(null, null, depModule.path);
  codeWithTarpRequires.split('\n')
    .forEach((line, i) => sn.add(new SourceNode(i + 1, 0, depModule.path, line + '\n')));
  sn.setSourceContent(depModule.path, depModule.code);
  return sn;
fork icon0
star icon0
watch icon2

+ 39 other calls in file

128
129
130
131
132
133
134
135
136
137
var pkg = fis.file(root, filepath);
var has = [];

var sourceNode;
if (sourceMap) {
  sourceNode = new SourceMap.SourceNode();
}

var content = '';
unpacked.forEach(function(item) {
fork icon0
star icon0
watch icon2

+ 3 other calls in file