How to use the convert-source-map.fromMapFileSource 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 istanbuljs / v8-to-istanbul / lib / v8-to-istanbul.js View on Github external
async load () {
    const rawSource = this.sources.source || await readFile(this.path, 'utf8')
    const rawSourceMap = this.sources.sourceMap ||
      // if we find a source-map (either inline, or a .map file) we load
      // both the transpiled and original source, both of which are used during
      // the backflips we perform to remap absolute to relative positions.
      convertSourceMap.fromSource(rawSource) || convertSourceMap.fromMapFileSource(rawSource, dirname(this.path))

    if (rawSourceMap) {
      if (rawSourceMap.sourcemap.sources.length > 1) {
        console.warn('v8-to-istanbul: source-mappings from one to many files not yet supported')
        this.source = new CovSource(rawSource, this.wrapperLength)
      } else {
        this._rewritePath(rawSourceMap)
        this.sourceMap = await new SourceMapConsumer(rawSourceMap.sourcemap)

        let originalRawSource
        if (this.sources.originalSource) {
          originalRawSource = this.sources.originalSource
        } else {
          originalRawSource = await readFile(this.path, 'utf8')
        }
github Jam3 / devtool / lib / require-hook.js View on Github external
script = debugExpr + script;
    }

    // bail early if we don't have a path
    if (!currentWrapFile || !useSourceMaps) return moduleWrap(script);

    var sourceFile = path.relative(basedir, currentWrapFile).replace(/\\/g, '/');
    var sourceFileName = path.basename(sourceFile);
    var sourceFileDir = path.dirname(sourceFile);
    var hasComment = convertSourceMap.commentRegex.test(script);
    var hasMapFile = convertSourceMap.mapFileCommentRegex.test(script);

    // if we have a map pointing to a file, inline it as base64
    if (!hasComment && hasMapFile) {
      try {
        var sm = convertSourceMap.fromMapFileSource(original, sourceFileDir);
        script = [
          combineSourceMap.removeComments(script),
          convertSourceMap.fromObject(sm.sourcemap).toComment()
        ].join('\n');
        hasComment = true; // now we have base64 comment
      } catch (err) {
        // Don't attempt to handle source maps for this file,
        // it is most likely a comment about source maps and not
        // a *real* source map comment!
      }
    }

    var wrapScript = moduleWrap(script);

    // do not make any more alterations to the source maps
    if (hasComment || hasMapFile) return wrapScript;
github avajs / ava / lib / snapshot-manager.js View on Github external
function resolveSourceFile(file) {
	const testDir = path.dirname(file);
	const buffer = tryRead(file);
	if (!buffer) {
		return file; // Assume the file is stubbed in our test suite.
	}

	const source = buffer.toString();
	const converter = convertSourceMap.fromSource(source) || convertSourceMap.fromMapFileSource(source, testDir);
	if (converter) {
		const map = converter.toObject();
		const firstSource = `${map.sourceRoot || ''}${map.sources[0]}`;
		return path.resolve(testDir, firstSource);
	}

	return file;
}
github aurelia / cli / lib / build / bundle.js View on Github external
try {
            let base64SourceMap = Convert.fromSource(file.contents.toString());

            if (base64SourceMap) {
              return null;
            }
          } catch (error) {
            // we don't want the build to fail when a sourcemap file can't be parsed
            return null;
          }

          let converter;

          try {
            converter = Convert.fromMapFileSource(file.contents.toString(), parsedPath.dir);
          } catch (e) {
            logger.error(e);
            return null;
          }

          sourceMap = converter
            ? converter.sourcemap
            : null;

          return sourceMap;
        }
github istanbuljs / nyc / test / src / source-map-cache.js View on Github external
_.forOwn(covered, function (fixture) {
  var source = fixture.contentSync()
  var sourceMap = convertSourceMap.fromSource(source) || convertSourceMap.fromMapFileSource(source, fixture.absPath)
  if (sourceMap) {
    sourceMapCache.addMap(fixture.absPath, sourceMap.sourcemap)
  }
})
github KnisterPeter / Smaller / bundles / typescript / src / main / resources / typescript.js View on Github external
fs.readFile(target, {encoding:'utf8'}, function(e, data) {
        if (e) throw e;
        js = data;
        var sourceMap = convert.fromMapFileSource(js, command.outdir);
        sourceMap.setProperty('sources', [rel]);
        js = convert.removeMapFileComments(js);
        js += '\n' + sourceMap.toComment() + '\n';
        
        fs.writeFile(target, js, function() {
          queue = queue.slice(1);
          if (queue.length == 0) done();
        });
      });
    });
github avajs / ava / lib / babel-pipeline.js View on Github external
function getSourceMap(filePath, code) {
	let sourceMap = convertSourceMap.fromSource(code);

	if (!sourceMap) {
		const dirPath = path.dirname(filePath);
		sourceMap = convertSourceMap.fromMapFileSource(code, dirPath);
	}

	return sourceMap ? sourceMap.toObject() : undefined;
}
github dumberjs / dumber / lib / shared.js View on Github external
const sourceMap = (() => {
    try {
      let converter = convert.fromSource(contents);
      if (converter) return converter.sourcemap;

      if (filePath) {
        converter = convert.fromMapFileSource(contents, dir);
        if (converter) return converter.sourcemap;
      }
    } catch (err) {
      return;
    }
  })();
github avajs / ava / lib / caching-precompiler.js View on Github external
function getSourceMap(filePath, code) {
	let sourceMap = convertSourceMap.fromSource(code);

	if (!sourceMap) {
		const dirPath = path.dirname(filePath);
		sourceMap = convertSourceMap.fromMapFileSource(code, dirPath);
	}

	return sourceMap ? sourceMap.toObject() : undefined;
}
github power-assert-js / grunt-espower / tasks / espower.js View on Github external
function espowerSource(grunt, jsCode, filepath, dest, options) {
    var jsAst, espowerOptions, modifiedAst, escodegenOutput, resolved;

    jsAst = esprima.parse(jsCode, {
        tolerant: true,
        loc: true,
        raw: true,
        source: filepath
    });
    var inMap = convert.fromSource(jsCode) || convert.fromMapFileSource(jsCode, path.dirname(filepath));
    espowerOptions = extend(espower.defaultOptions(), options, {
        destructive: true,
        path: filepath,
        sourceMap: inMap ? inMap.sourcemap : void 0
    });
    modifiedAst = estraverse.replace(jsAst, mergeVisitors([
        {
            enter: empowerAssert.enter
        },
        espower.createVisitor(jsAst, espowerOptions)
    ]));
    escodegenOutput = escodegen.generate(modifiedAst, {
        sourceMap: true,
        sourceMapWithCode: true
    });
    var outMap = convert.fromJSON(escodegenOutput.map.toString());