How to use the source-map.SourceMapGenerator.fromSourceMap 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 mendersoftware / gui / node_modules / vinyl-sourcemaps-apply / index.js View on Github external
file.sourceMap = JSON.parse(file.sourceMap);
  }

  // check source map properties
  assertProperty(sourceMap, "file");
  assertProperty(sourceMap, "mappings");
  assertProperty(sourceMap, "sources");

  // fix paths if Windows style paths
  sourceMap.file = sourceMap.file.replace(/\\/g, '/');
  sourceMap.sources = sourceMap.sources.map(function(filePath) {
    return filePath.replace(/\\/g, '/');
  });

  if (file.sourceMap && file.sourceMap.mappings !== '') {
    var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(sourceMap));
    generator.applySourceMap(new SourceMapConsumer(file.sourceMap));
    file.sourceMap = JSON.parse(generator.toString());
  } else {
    file.sourceMap = sourceMap;
  }
};
github erzu / porter / packages / porter / lib / Porter.js View on Github external
const outSourceMap = new UglifyJS.SourceMap({
    file: `${id}.js`,
    root: sourceRoot
  })

  const stream = new UglifyJS.OutputStream({
    ascii_only: true,
    screw_ie8: false,
    source_map: outSourceMap
  })
  /* eslint-enable camelcase */
  compressed.print(stream)

  const js = stream.toString()
  const map = JSON.parse(outSourceMap.toString())
  const generator = new SourceMapGenerator.fromSourceMap(new SourceMapConsumer(map))
  sourceMaps.forEach(function(sourceMap) {
    generator.applySourceMap(new SourceMapConsumer(sourceMap), sourceMap.sources[0], sourceRoot)
  })

  return {
    js,
    map: JSON.stringify(generator.toJSON(), function(k, v) {
      if (k != 'sourcesContent') return v
    })
  }
}
github huston007 / ng-annotate-loader / loader.js View on Github external
var filename = normalizePath(this.resourcePath);
  this.cacheable && this.cacheable();

  if (sourceMapEnabled && !inputSourceMap && annotateMap) {
    outputSourceMap = annotateMap;
  }

  // Using BabelJS as an example,
  //   https://github.com/babel/babel/blob/d3a73b87e9007104cb4fec343f0cfb9e1c67a4ec/packages/babel/src/transformation/file/index.js#L465
  // See also vinyl-sourcemaps-apply (used by gulp-ng-annotate) - https://github.com/floridoo/vinyl-sourcemaps-apply/blob/master/index.js
  if (sourceMapEnabled && inputSourceMap) {
    inputSourceMap.sourceRoot = '';
    inputSourceMap.sources[0] = filename;

    if (annotateMap) {
      var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(annotateMap));
      generator.applySourceMap(new SourceMapConsumer(inputSourceMap), filename);

      outputSourceMap = generator.toJSON();

      //Should be set to avoid '../../file is not in SourceMap error https://github.com/huston007/ng-annotate-loader/pull/11'
      outputSourceMap.sourceRoot = '';
      //Copy file name from incoming file because it is empty by some unknown reaon
      outputSourceMap.file = normalizePath(this.resourcePath);
    } else {
      outputSourceMap = inputSourceMap;
    }
  }

  return outputSourceMap;
}
github meteor / meteor / packages / non-core / coffeescript / plugin / compile-coffeescript.js View on Github external
if (doubleRoastedCoffee != null &&
        doubleRoastedCoffee.data != null) {
      output.js = doubleRoastedCoffee.data;

      const coffeeSourceMap = doubleRoastedCoffee.sourceMap;

      if (coffeeSourceMap) {
        // Reference the compiled CoffeeScript file so that `applySourceMap`
        // below can match it with the source map produced by the CoffeeScript
        // compiler.
        coffeeSourceMap.sources[0] = '/' + this._outputFilePath(inputFile);

        // Combine the original CoffeeScript source map with the one
        // produced by this.babelCompiler.processOneFileForTarget.
        const smg = SourceMapGenerator.fromSourceMap(
          new SourceMapConsumer(coffeeSourceMap)
        );
        smg.applySourceMap(new SourceMapConsumer(sourceMap));
        sourceMap = smg.toJSON();
      } else {
        // If the .coffee file is contained by a node_modules directory,
        // then BabelCompiler will not transpile it, and there will be
        // no sourceMap, but that's fine because the original
        // CoffeeScript sourceMap will still be valid.
      }
    }

    return addSharedHeader(output.js, sourceMap);
  }
github MaayanLab / geo2enrichr / scripts / node_modules / grunt-contrib-concat / tasks / lib / sourcemap.js View on Github external
SourceMapConcatHelper.prototype._write = function() {
    // ensure we're using forward slashes, because these are URLs
    var file = path.relative(path.dirname(this.dest), this.files.dest);
    file = file.replace(/\\/g, '/');
    var code_map = this.node.toStringWithSourceMap({
      file: file
    });
    // Consume the new sourcemap.
    var generator = SourceMapGenerator.fromSourceMap(
      new SourceMapConsumer(code_map.map.toJSON())
    );
    // Consume sourcemaps for source files.
    this.maps.forEach(Function.apply.bind(generator.applySourceMap, generator));
    // New sourcemap.
    var newSourceMap = generator.toJSON();
    // Return a string for inline use or write the map.
    if (this.options.sourceMapStyle === 'inline') {
      grunt.log.writeln(
        'Source map for ' + chalk.cyan(this.files.dest) + ' inlined.'
      );
      return JSON.stringify(newSourceMap, null, '');
    } else {
      grunt.file.write(
        this.dest,
        JSON.stringify(newSourceMap, null, '')
github googleanalytics / autotrack / bin / build.js View on Github external
return {type, line, column, source, desc: item.description};
    };

    throw {
      errors: [
        ...closureResult.errors.map(remap('error')),
        ...closureResult.warnings.map(remap('warning')),
      ],
    };
  } else {
    // Currently, closure compiler doesn't support applying its generated
    // source map to an existing source map, so we do it manually.
    const fromMap = JSON.parse(closureResult.sourceMap);
    const toMap = rollupResult.map;

    const generator = SourceMapGenerator.fromSourceMap(
        await new SourceMapConsumer(fromMap));

    generator.applySourceMap(
        await new SourceMapConsumer(toMap), path.basename(output));

    const sourceMap = generator.toString();

    return {
      code: closureResult.compiledCode,
      map: sourceMap,
    };
  }
};
github boyarskiy / react-simple-datepicker / node_modules / webpack / node_modules / webpack-core / lib / SourceMapSource.js View on Github external
SourceMapSource.prototype.node = function(options) {
	var innerSourceMap = this._innerSourceMap;
	var sourceMap = this._sourceMap;
	if(innerSourceMap) {
		innerSourceMap = new SourceMapConsumer(innerSourceMap);
		sourceMap = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(sourceMap));
		sourceMap.setSourceContent(this._name, this._originalSource);
		sourceMap.applySourceMap(innerSourceMap, this._name);
		sourceMap = sourceMap.toJSON();
	}
	return SourceNode.fromStringWithSourceMap(this._value, new SourceMapConsumer(sourceMap));
};
github thinkjs / thinkjs / src / util / watch_compile.js View on Github external
mergeSourceMap(orginSourceMap, sourceMap){
    let {SourceMapGenerator, SourceMapConsumer} = require('source-map');
    sourceMap.file = sourceMap.file.replace(/\\/g, '/');
    sourceMap.sources = sourceMap.sources.map(filePath => {
      return filePath.replace(/\\/g, '/');
    });
    var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(sourceMap));
    generator.applySourceMap(new SourceMapConsumer(orginSourceMap));
    sourceMap = JSON.parse(generator.toString());

    return sourceMap;
  }
  /**
github RocketChat / Rocket.Chat / packages / rocketchat-postcss / build.js View on Github external
});

	if (!code) {
		return {
			code: '',
		};
	}

	const mapFilenameToFile = files.reduce((obj, file) => ({
		...obj,
		[file.getPathInBundle()]: file,
	}), {});

	map.sourcesContent = map.sources.map((filename) => mapFilenameToFile[filename].getContentsAsString());

	const newMap = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(map));

	files.filter((file) => file.getSourceMap())
		.forEach((file) => {
			newMap.applySourceMap(new SourceMapConsumer(file.getSourceMap()), file.getPathInBundle());
		});

	return {
		code,
		sourceMap: newMap.toString(),
	};
};