How to use the convert-source-map.fromComment 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 fand / glslify-lite / test / source-map.ts View on Github external
test("Import npm packages", async t => {
    const output = await file(path.resolve(__dirname, "fixtures/test01.frag"));

    // Test sourcemaps
    const lastLine = output.split("\n").pop();
    t.assert(
        /\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,/.test(
            lastLine
        ),
        "contains sourceMaps of the file"
    );

    const sm = convert.fromComment(lastLine).toObject();
    const consumer = await new sourceMap.SourceMapConsumer(sm);
    const hasPos = (
        line: number,
        column: number,
        expLine: number,
        expCol: number
    ) => {
        const op = gOP(output, { line, column }, consumer);
        // console.log(line, column, op.line, op.column);
        t.deepEqual(
            { line: op.line, column: op.column },
            { line: expLine, column: expCol }
        );
    };

    // Line 12
github babel / babel / packages / babel-core / src / transformation / normalize-file.js View on Github external
ast = parser(pluginPasses, options, code);
  }

  let inputMap = null;
  if (options.inputSourceMap !== false) {
    // If an explicit object is passed in, it overrides the processing of
    // source maps that may be in the file itself.
    if (typeof options.inputSourceMap === "object") {
      inputMap = convertSourceMap.fromObject(options.inputSourceMap);
    }

    if (!inputMap) {
      const lastComment = extractComments(INLINE_SOURCEMAP_REGEX, ast);
      if (lastComment) {
        try {
          inputMap = convertSourceMap.fromComment(lastComment);
        } catch (err) {
          debug("discarding unknown inline input sourcemap", err);
        }
      }
    }

    if (!inputMap) {
      const lastComment = extractComments(EXTERNAL_SOURCEMAP_REGEX, ast);
      if (typeof options.filename === "string" && lastComment) {
        try {
          // when `lastComment` is non-null, EXTERNAL_SOURCEMAP_REGEX must have matches
          const match: [string, string] = (EXTERNAL_SOURCEMAP_REGEX.exec(
            lastComment,
          ): any);
          const inputMapContent: Buffer = fs.readFileSync(
            path.resolve(path.dirname(options.filename), match[1]),
github defunctzombie / node-enchilada / index.js View on Github external
if (watch) {
                    watchFiles(bundle, dependencies, req_path);
                }
                if (err) {
                    return callback(err);
                }
                if (otherError) {
                    return callback(otherError);
                }

                var srcmap = undefined;
                var map_path = undefined;
                if (debug_opt) {
                    // output sourcemap
                    srcmap = convert.fromComment(src);
                    src = convert.removeComments(src);
                    srcmap.setProperty('file', req_path);
                    map_path = req_path.replace(/.js$/, '.map.json');
                }

                if (compress) {
                    var ugly_opt = {};
                    if (typeof compress == 'object') {
                        ugly_opt = compress
                    }

                    ugly_opt.fromString = true;

                    if (srcmap) {
                        ugly_opt.inSourceMap = srcmap.toObject(),
                        ugly_opt.outSourceMap = req_path
github sony / cdp-js / packages / master-tasks / tasks / srcmap.js View on Github external
function getNodeFromCode(code) {
    if (convert.mapFileCommentRegex.test(code)) {
        try {
            return SourceNode.fromStringWithSourceMap(
                convertCode2Script(code),
                new SourceMapConsumer(convert.fromComment(code).toObject())
            );
        } catch (error) {
            console.error('getNodeFromCode() error: ' + error);
            const node = new SourceNode();
            node.add(convertCode2Script(code));
            return node;
        }
    } else {
        const node = new SourceNode();
        node.add(convertCode2Script(code));
        return node;
    }
}
github nikku / karma-browserify / lib / bro.js View on Github external
function extractSourceMap(bundleContents) {
  var start = bundleContents.lastIndexOf('//# sourceMappingURL');
  var sourceMapComment = start !== -1 ? bundleContents.substring(start) : '';

  return sourceMapComment && convert.fromComment(sourceMapComment);
}
github monounity / karma-typescript / dist / bundler / source-map.js View on Github external
SourceMap.prototype.loadFileFromComment = function (bundleItem) {
        var commentMatch = convertSourceMap.mapFileCommentRegex.exec(bundleItem.source);
        if (commentMatch && commentMatch[1]) {
            var map = void 0;
            var dirname_1 = path.dirname(bundleItem.filename);
            if (!commentMatch[1].startsWith("data:")) {
                var mapFilename = path.join(dirname_1, commentMatch[1]);
                var mapJson = fs.readFileSync(mapFilename, "utf-8");
                map = convertSourceMap.fromJSON(mapJson);
            }
            else {
                map = convertSourceMap.fromComment(commentMatch[0]);
            }
            if (!map.getProperty("sourcesContent")) {
                var sourcesContent_1 = [];
                map.getProperty("sources").forEach(function (source) {
                    var sourceFilename = path.join(dirname_1, source);
                    var sourceContent = fs.readFileSync(sourceFilename, "utf-8");
                    sourcesContent_1.push(sourceContent);
                });
                map.addProperty("sourcesContent", sourcesContent_1);
            }
            this.cleanupSources(map);
            bundleItem.source = combineSourceMap.removeComments(bundleItem.source) + map.toComment();
        }
    };
    SourceMap.prototype.cleanupSources = function (map) {
github TypeStrong / tsify / lib / Tsifier.js View on Github external
Tsifier.prototype.setSourcePathInSourcemap = function (output, inputFile) {
		var self = this;
		var normalized = ts.normalizePath(path.relative(
			self.bopts.basedir || currentDirectory,
			inputFile
		));

		var sourcemap = convert.fromComment(output);
		sourcemap.setProperty('sources', [normalized]);
		return output.replace(convert.commentRegex, sourcemap.toComment());
	}
github monounity / karma-typescript / src / bundler / source-map.ts View on Github external
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);
                }
            }
            else {
                map = convertSourceMap.fromComment(commentMatch[0]);
            }

            if (!map) {
                this.log.debug("Unable to resolve source map for %s", bundleItem.filename);
                return;
            }

            if (!map.getProperty("sourcesContent")) {

                let sourcesContent: string[] = [];
                map.getProperty("sources").forEach((source: string) => {
                    let sourceFilename = path.join(dirname, source);
                    try {
                        let sourceContent = fs.readFileSync(sourceFilename, "utf-8");
                        sourcesContent.push(sourceContent);
                    }