Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function generateSourceMap (script, output) {
// hot-reload source map busting
var hashedFilename = path.basename(filePath) + '?' + hash(filePath + content)
var map = new sourceMap.SourceMapGenerator()
map.setSourceContent(hashedFilename, content)
// check input source map from babel/coffee etc
var inMap = resolvedParts.map
var inMapConsumer = inMap && new sourceMap.SourceMapConsumer(inMap)
var generatedOffset = (output ? output.split(splitRE).length : 0) + 1
script.split(splitRE).forEach(function (line, index) {
var ln = index + 1
var originalLine = inMapConsumer
? inMapConsumer.originalPositionFor({ line: ln, column: 0 }).line
: ln
if (originalLine) {
map.addMapping({
source: hashedFilename,
generated: {
line: ln + generatedOffset,
column: 0
function processInclude(content, filePath, sourceMap, includedFiles) {
var matches = content.match(/^(\s+)?(\/\/|\/\*|\#|\<\!\-\-)(\s+)?=(\s+)?(include|require)(.+$)/mg);
var relativeBasePath = path.dirname(filePath);
if (!matches) return {
content: content,
map: null
};
// Apply sourcemaps
var map = null,
mapSelf, lastMappedLine, currentPos, insertedLines;
if (sourceMap) {
map = new SourceMapGenerator({
file: unixStylePath(filePath)
});
lastMappedLine = 1;
currentPos = 0;
insertedLines = 0;
mapSelf = function (currentLine) { // maps current file between matches and after all matches
var currentOrigLine = currentLine - insertedLines;
for (var q = (currentLine - lastMappedLine); q > 0; q--) {
map.addMapping({
generated: {
line: currentLine - q,
column: 0
},
original: {
function withSourceMap(src, compiled, name) {
var compiledLines = compiled.split('\n');
var generator = new SourceMapGenerator({ file: name + '.js' });
compiledLines.forEach(function (l, lineno) {
var oldFormat = false;
var generatedLine;
var linesMatched = {};
linesMatched[name] = {};
var m = l.match(/;pug_debug_line = ([0-9]+);/);
if (m) {
var originalLine = Number(m[1]);
if (originalLine > 0) {
var fname = "";
m = l.match(/;pug_debug_filename = \"(.*)\";/);
if (m) {
fname = m[1].replace(/\\u002F/g, "/");
function mixin(compiler) {
var file = compiler.options.filename || 'generated.css';
compiler.map = new SourceMap({ file: file });
compiler.position = { line: 1, column: 1 };
for (var k in exports) compiler[k] = exports[k];
}
_invertSourceMap: function ({ code, mappings }) {
const generator = new SourceMapGenerator({ file: this.url });
return DevToolsUtils.yieldingEach(mappings._array, m => {
let mapping = {
generated: {
line: m.originalLine,
column: m.originalColumn
}
};
if (m.source) {
mapping.source = m.source;
mapping.original = {
line: m.generatedLine,
column: m.generatedColumn
};
mapping.name = m.name;
}
generator.addMapping(mapping);
function runPass(source, visitors, options) {
var ast = esprima.parse(source, { comment: true, loc: true, range: true });
var state = createState(source, options);
state.g.originalProgramAST = ast;
state.g.visitors = visitors;
if (options.sourceMap) {
var SourceMapGenerator = require('source-map').SourceMapGenerator;
state.g.sourceMap = new SourceMapGenerator({ file: 'transformed.js' });
}
traverse(ast, [], state);
catchup(source.length, state);
return state;
}
public generateSourceMap(): string {
if (!this.rawSourceMap) {
return undefined;
}
let sourceMapGenerator = new SourceMapGenerator({ sourceRoot: this.rawSourceMap.sourceRoot });
let lineDelta = 0;
this.lines.forEach(line => {
let mappings = line.mappings;
let columnDelta = 0;
if (mappings) {
mappings.forEach(mapping => {
lineDelta = (mapping.lineDelta || 0) + lineDelta;
columnDelta = (mapping.columnDelta || 0) + columnDelta;
if (mapping.delete) {
return;
}
sourceMapGenerator.addMapping({
source: mapping.source,
name: mapping.name,
original: { line: mapping.originalLine, column: mapping.originalColumn },
generated: { line: mapping.generatedLine + lineDelta, column: mapping.generatedColumn + columnDelta }
proto$0.stringify = function() {var this$0 = this;
this.css = '';
this.map = new mozilla.SourceMapGenerator({ file: this.outputFile() });
var line = 1;
var column = 1;
var lines, last;
var builder = function(str, node, type) {
this$0.css += str;
if ( node && node.source && node.source.start && type != 'end' ) {
this$0.map.addMapping({
source: this$0.sourcePath(node),
original: {
line: node.source.start.line,
column: node.source.start.column - 1
},
generated: {
var getOldSourceMap = function getOldSourceMap(mappings, _ref) {
var sourceRoot = _ref.sourceRoot,
source = _ref.source,
file = _ref.file;
var oldSourceMap = new sourceMap.SourceMapGenerator({
file: file,
sourceRoot: sourceRoot
});
mappings.forEach(function (mapping) {
mapping.source = source;
oldSourceMap.addMapping(mapping);
});
return oldSourceMap.toJSON();
};
}
: item.local,
),
);
});
toBeRemoved.forEach(item => {
const index = item.arr.indexOf(item.node);
if (index > -1) {
item.arr.splice(index, 1);
}
});
let map;
if (opts.sourceMaps) {
map = new sourceMapModule.SourceMapGenerator({
file: 'script.js',
});
}
const code = generate(ast, { ecmaVersion: 7, sourceMap: map });
let jsonSourceMaps;
if (opts.sourceMaps) {
jsonSourceMaps = map.toJSON();
if (!jsonSourceMaps.sourcesContent) {
delete jsonSourceMaps.file;
jsonSourceMaps.sourcesContent = [opts.input];
}
}
return { code, sourceMap: jsonSourceMaps };
}