How to use the SourceNode function from source-map
Find comprehensive JavaScript source-map.SourceNode code examples handpicked from public code repositorys.
GitHub: PoeticMediaLab/annotator
![PoeticMediaLab profile picture](/PoeticMediaLab.png?size=40)
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.
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();
+ 17 other calls in file
GitHub: gaearon/react-hot-loader
![gaearon profile picture](/gaearon.png?size=40)
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); };
+ 3 other calls in file
GitHub: brunch/brunch
![brunch profile picture](/brunch.png?size=40)
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' ?
+ 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);
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)
GitHub: nivoc/meteor
![nivoc profile picture](/nivoc.png?size=40)
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
+ 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',
+ 5 other calls in file
GitHub: mcamac/tarp
![mcamac profile picture](/mcamac.png?size=40)
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;
+ 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) {
+ 3 other calls in file
source-map.SourceMapConsumer is the most popular function in source-map (130 examples)