How to use the SourceMapConsumer function from source-map
Find comprehensive JavaScript source-map.SourceMapConsumer code examples handpicked from public code repositorys.
GitHub: PoeticMediaLab/annotator
8 9 10 11 12 13 14 15 16
var sourceMap = require('source-map'); 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;
547
3
3
221 222 223 224 225 226 227 228 229
* `mappings`: A string of base64 VLQs which contain the actual mappings. * `file`: Optional. The generated filename this source map is associated with. ```js var consumer = new sourceMap.SourceMapConsumer(rawSourceMapJsonData); ``` #### SourceMapConsumer.prototype.computeColumnSpans()
357
73
2
14 15 16 17 18 19 20 21 22
## Use on the Web <script src="https://unpkg.com/source-map@0.7.2/dist/source-map.js"></script> <script> sourceMap.SourceMapConsumer.initialize({ "lib/mappings.wasm": "https://unpkg.com/source-map@0.7.2/lib/mappings.wasm" }); </script>
20
25
2
+ 27 other calls in file
GitHub: brunch/brunch
14 15 16 17 18 19 20 21 22 23
return new SourceNode(1, 0, null, lines); }; const prepSourceMap = (code, sourceMap) => { const consumer = new SourceMapConsumer(typeof sourceMap === 'string' ? JSON.parse(sourceMap) : sourceMap ); return SourceNode.fromStringWithSourceMap(code, consumer);
474
0
135
+ 13 other calls in file
68 69 70 71 72 73 74 75 76 77
// 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); node.prepend(inject);
16
87
0
GitHub: gaearon/react-hot-loader
65 66 67 68 69 70 71 72 73 74
} if (!map) { map = makeIdentitySourceMap(source, resourcePath); // eslint-disable-line no-param-reassign } const sourceMapConsumer = new SourceMapConsumer(map); const onSourceMapReady = consumedMap => { const node = new SourceNode(null, null, null, [ SourceNode.fromStringWithSourceMap(source, consumedMap),
837
0
0
55 56 57 58 59 60 61 62 63 64
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(); return this.callback(null, result.code, result.map.toString());
16
33
3
+ 8 other calls in file
10 11 12 13 14 15 16 17 18 19
let map if (this.sourceMap) { const ssSourceMap = JSON.parse(sst.toSourceMap()) if (prevMap) { const destConsumer = new SourceMapConsumer(ssSourceMap) const srcConsumer = new SourceMapConsumer(prevMap) Promise.all([destConsumer, srcConsumer]) .then(([destConsumer, srcConsumer]) => { const gen = SourceMapGenerator.fromSourceMap(destConsumer) gen.applySourceMap(srcConsumer, this.resourcePath)
9
47
5
GitHub: roytam1/UXP
205 206 207 208 209 210 211 212 213 214 215 216
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()); sourceMapRequests.set(generatedId, Promise.resolve(map)); } const publicInterface = {
5
32
0
5 6 7 8 9 10 11 12 13 14
if (result && result.code) { if (result.map) { node.add( SourceNode.fromStringWithSourceMap( result.code, new SourceMapConsumer(result.map) ) ) } else { node.add(result.code)
2
0
0
GitHub: wozien/fe-note
118 119 120 121 122 123 124 125 126 127
// source-map const options = loaderUtils.getOptions(this) || {}; if(options.sourceMap && sourceMap) { const currentRequest = loaderUtils.getCurrentRequest(); const node = SourceNode.fromStringWithSourceMap(content, new SourceMapConsumer(sourceMap)); node.prepend(useStrictPrefix); const result = node.toStringWithSourceMap({ file: currentRequest }); const callback = this.async(); callback(null, result.code, result.map.toJSON());
1
10
2
10 11 12 13 14 15 16 17 18 19
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', ]).toStringWithSourceMap(); return {code: out.code, map: out.map.toString()}; };
0
0
2
+ 5 other calls in file
GitHub: mcamac/tarp
80 81 82 83 84 85 86 87 88 89
}) } 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')));
0
0
2
+ 19 other calls in file
156 157 158 159 160 161 162 163 164 165
var mapFile = getMapFile(file); if (mapFile) { var json = JSON.parse(mapFile.getContent()); var smc = new SourceMap.SourceMapConsumer(json); sourceNode.add(SourceMap.SourceNode.fromStringWithSourceMap(message.content, smc)); // mapFile.release = false; } else {
0
0
2
+ 3 other calls in file
source-map.SourceMapConsumer is the most popular function in source-map (130 examples)