How to use the convert-source-map.fromSource 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 thlorenz / mold-source-map / test / transform-sources.js View on Github external
.on('end', function () {
      var sm = convert.fromSource(bundle);
      var sources = sm.getProperty('sources')
        .filter(function(source) {
          // exclude browserify's prelude
          return !/_prelude\.js$/.test(source);
        });

      t.equal(sources.length, 3, 'molds 3 sources')
      t.ok(~sources.indexOf('js/main.js'), 'molds main.js relative to root')
      t.ok(~sources.indexOf('js/foo.js'), 'molds foo.js relative to root')
      t.ok(~sources.indexOf('js/wunder/bar.js'), 'molds wunder/bar.js relative to root')
    });
});
github javascript-studio / studio-cli / lib / studio.js View on Github external
setSource(source) {
    if (!source) {
      this.fail('No sources received on stdin');
      return;
    }
    this.source = source;
    this.source_map = convert_source_map.fromSource(source);
    if (!this.source_map) {
      try {
        this.source_map = convert_source_map.fromMapFileComment(source,
          this.working_dir);
      } catch (ignore) {
        // It throws if there are no source maps
      }
    }
    if (this.source_map) {
      this.source_map = this.source_map.toObject();
      this.source = convert_source_map.removeComments(source);
    }
    gzip(source, (err, buffer) => {
      if (err) {
        this.fail('gzip failure', err);
      } else {
github fand / glslify-lite / src / glslify-bundle.ts View on Github external
private async preprocess(dep: DepsInfo): Promise {
        // Get sourcemaps created by pretransform
        const rawMap = convert.fromSource(dep.source);
        const consumer = rawMap
            ? await new sourceMap.SourceMapConsumer(rawMap.toObject())
            : null;
        if (consumer) {
            dep.source = convert.removeComments(dep.source); // eslint-disable-line
        }

        const tokens = tokenize(dep.source);
        const imports = [];
        let exports = null;

        depth(tokens);
        scope(tokens);

        // Note: tokens must be sorted by position
        let lastLine = 1;
github duojs / duo / test / cli.js View on Github external
it('should include inline source-maps', function* () {
      var out = yield exec('--development index.js', 'simple');
      if (out.error) throw out.error;
      var entry = yield fs.readFile(path('simple/build/index.js'), 'utf8');
      var map = convert.fromSource(entry).toObject();
      var src = map.sourcesContent[map.sources.indexOf('/two.js')];
      assert.equal(src.trim(), 'module.exports = \'two\';');
    });
  });
github KnisterPeter / Smaller / bundles / browserify / src / main / resources / browserify.js View on Github external
function() {
        if (withSourceMaps) {
          var sourceMap = convert.fromSource(min);
          sourceMap.setProperty('sources', sourceMap.getProperty('sources').map(
            function(source) { return path.relative(command.indir, source); }));
          min = convert.removeComments(min);
          min += '\n' + sourceMap.toComment() + '\n';
        }
        fs.writeFile(path.join(command.outdir, 'output.js'), min, function(e) {
          if (e) {
            console.log(e);
            done();
          } else {
            console.log('Written result to ' + path.join(command.outdir, 'output.js'));
            done('output.js');
          }
        });
      }));
}
github linkedin / css-blocks / packages / webpack-plugin / src / CssAssets.ts View on Github external
function assetAsSource(contents: string, filename: string): Source {
    let sourcemap: convertSourceMap.SourceMapConverter | undefined;
    if (/sourceMappingURL/.test(contents)) {
        sourcemap = convertSourceMap.fromSource(contents) ||
            convertSourceMap.fromMapFileComment(contents, path.dirname(filename));
    }
    if (sourcemap) {
        let sm: RawSourceMap = sourcemap.toObject();
        contents = convertSourceMap.removeComments(contents);
        contents = convertSourceMap.removeMapFileComments(contents);
        return new SourceMapSource(contents, filename, sm);
    } else {
        return new RawSource(contents);
    }
}
github download-online-video / chrome-avgle-helper / build / build.js View on Github external
function afterBundle(isFirstBundle, error, buffer) {
					if (error) {
						if (isFirstBundle) onFatal(`browserify bundle "${fromName}" failed!`, error);
						return log.error(`browserify bundle "${fromName}" failed!`, error);
					}
					let code = String(buffer);
					let map = JSON.parse(sourceMapConvert.fromSource(code).toJSON());
					code = sourceMapConvert.removeMapFileComments(code);

					let babelResult = pipeToBabel(code, map);
					if (babelResult.error) {
						if (isFirstBundle) return onFatal(`build "${fromName}" failed!`, error);
						return log.error(`build "${fromName}" failed!`, error);
					}
					code = babelResult.code;
					map = babelResult.map;
					writeTextFile(to, code);
					writeTextFile(to, code)
						.then(() => writeTextFile(sourceMapTo, JSON.stringify(map, null, '\t')))
						.then(() => log.info(`build "${fromName}" to "${toName}"`))
						.catch(onFatal)
						.then(() => isFirstBundle ? resolve() : null);
				}
github jamesshore / lets_code_javascript / node_modules / combine-source-map / index.js View on Github external
function resolveMap(source) {
  var gen = convert.fromSource(source);
  return gen ? gen.toObject() : null;
}
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;
}