How to use the convert-source-map.mapFileCommentRegex function in convert-source-map

To help you get started, we’ve selected a few convert-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 sony / cdp-js / packages / master-tasks / tasks / srcmap.js View on Github external
function convertCode2Script(code) {
    // clean source code comment
    return code
        .replace(/\/\/\/ 
github danvk / source-map-explorer / src / explore.ts View on Github external
consumer = await new SourceMapConsumer(converter.toJSON());
  }

  if (!consumer) {
    throw new AppError({ code: 'NoSourceMap' });
  }

  return {
    consumer,
    codeFileContent,
  };
}

const COMMENT_REGEX = convert.commentRegex;
const MAP_FILE_COMMENT_REGEX = convert.mapFileCommentRegex;

/** Extract either source map comment from file content */
function getSourceMapComment(fileContent: string): string {
  const sourceMapComment =
    getFirstRegexMatch(COMMENT_REGEX, fileContent) ||
    getFirstRegexMatch(MAP_FILE_COMMENT_REGEX, fileContent) ||
    '';

  // Remove trailing EOLs
  return sourceMapComment.trim();
}

const LF = '\n';
const CR_LF = '\r\n';

function detectEOL(content: string): string {
github gulpjs / vinyl-sourcemap / lib / helpers.js View on Github external
function loadSourceMap(file, state, callback) {
  // Try to read inline source map
  state.map = convert.fromSource(state.content);

  if (state.map) {
    state.map = state.map.toObject();
    // Sources in map are relative to the source file
    state.path = file.dirname;
    state.content = convert.removeComments(state.content);
    // Remove source map comment from source
    file.contents = new Buffer(state.content, 'utf8');
    return callback();
  }

  // Look for source map comment referencing a source map file
  var mapComment = convert.mapFileCommentRegex.exec(state.content);

  var mapFile;
  if (mapComment) {
    mapFile = path.resolve(file.dirname, mapComment[1] || mapComment[2]);
    state.content = convert.removeMapFileComments(state.content);
    // Remove source map comment from source
    file.contents = new Buffer(state.content, 'utf8');
  } else {
    // If no comment try map file with same name as source file
    mapFile = file.path + '.map';
  }

  // Sources in external map are relative to map file
  state.path = path.dirname(mapFile);

  fs.readFile(mapFile, onRead);
github frankwallis / plugin-typescript / lib / incremental-compiler.js View on Github external
let output = this._services.getEmitOutput(this._files[filename].tsname);
			if (output.emitSkipped)
				throw new Error("Typescript emit error");

			let jsname = tsToJs(this._files[filename].tsname);
			let jstext = output.outputFiles
				.filter((file) => (file.name == jsname))[0].text;

			let mapname = tsToJsMap(this._files[filename].tsname);
			let mapfile = output.outputFiles
				.filter((file) => (file.name == mapname))[0]

			if (mapfile) {
				// replace the source map url with the actual source map
				let sourcemap = convert.fromJSON(mapfile.text);
				jstext = jstext.replace(convert.mapFileCommentRegex, sourcemap.toComment());
			}

			return {
				failure: false,
				errors: [],
				js: jstext
			}
		} else {
			return {
				failure: true,
				errors: diagnostics,
				js: undefined
			}
		}
	}
github stolksdorf / vitreum / node_modules / gulp-sourcemaps / index.js View on Github external
var fileContent = file.contents.toString();
    var sourceMap;

    if (options && options.loadMaps) {
      var sourcePath = ''; //root path for the sources in the map

      // Try to read inline source map
      sourceMap = convert.fromSource(fileContent);
      if (sourceMap) {
        sourceMap = sourceMap.toObject();
        // sources in map are relative to the source file
        sourcePath = path.dirname(file.path);
        fileContent = convert.removeComments(fileContent);
      } else {
        // look for source map comment referencing a source map file
        var mapComment = convert.mapFileCommentRegex.exec(fileContent);

        var mapFile;
        if (mapComment) {
          mapFile = path.resolve(path.dirname(file.path), mapComment[1] || mapComment[2]);
          fileContent = convert.removeMapFileComments(fileContent);
        // if no comment try map file with same name as source file
        } else {
          mapFile = file.path + '.map';
        }

        // sources in external map are relative to map file
        sourcePath = path.dirname(mapFile);

        try {
          sourceMap = JSON.parse(stripBom(fs.readFileSync(mapFile, 'utf8')));
        } catch(e) {}
github jamesshore / lets_code_javascript / node_modules / combine-source-map / index.js View on Github external
exports.removeComments = function (src) {
  if (!src.replace) return src;
  return src.replace(convert.commentRegex, '').replace(convert.mapFileCommentRegex, '');
};
github monounity / karma-typescript / src / bundler / source-map.ts View on Github external
public loadFileFromComment(bundleItem: BundleItem) {

        let commentMatch = convertSourceMap.mapFileCommentRegex.exec(bundleItem.source);

        if (commentMatch && commentMatch[1]) {

            let map: convertSourceMap.SourceMapConverter;
            let dirname = path.dirname(bundleItem.filename);

            if (!commentMatch[1].startsWith("data:")) {
                let mapFilename = path.join(dirname, commentMatch[1]);
                try {
                    let mapJson = fs.readFileSync(mapFilename, "utf-8");
                    map = convertSourceMap.fromJSON(mapJson);
                }
                catch (error) {
                    this.log.debug("Source map %s doesn't exist", mapFilename);
                }
            }