How to use the source-map.SourceMapGenerator function in source-map

To help you get started, we’ve selected a few source-map examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuejs / vueify / lib / compiler.js View on Github external
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
github wiledal / gulp-include / index.js View on Github external
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: {
github sidorares / pugify / index.js View on Github external
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, "/");
github liferay / liferay-plugins / hooks / rtl-hook / docroot / WEB-INF / src / com / liferay / rtl / hook / filter / dynamiccss / dependencies / r2.js View on Github external
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];
}
github joewalker / devtools.html / server / actors / script.js View on Github external
_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);
github facebook / emitter / vendor / fbtransform / lib / transform.js View on Github external
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;
}
github microsoft / vscode-nls-dev / src / lib.ts View on Github external
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 }
github fitak / fitak / node_modules / postcss / lib / map-generator.js View on Github external
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: {
github aui / art-template / lib / precompile.js View on Github external
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();
};
github fuse-box / fuse-box / src / transform / fastTransform.ts View on Github external
}
          : 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 };
}