How to use the convert-source-map.fromJSON 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 mattdesl / canvas-sketch-cli / src / index.js View on Github external
}
    }

    // strip any subsequently added source maps
    code = SourceMapUtil.removeComments(code);
    code = SourceMapUtil.removeMapFileComments(code);

    // now add them back in as per our options
    if (sourceMapOption && sourceMapJSON && debug) {
      let relSrcMapFile = path.relative(dir, sourceMapFile);
      // if (!path.isAbsolute(relSrcMapFile)) {
      //   relSrcMapFile = `./${encodeURIComponent(relSrcMapFile)}`;
      // }
      const isInline = sourceMapOption === 'inline';
      const comment = isInline
        ? SourceMapUtil.fromJSON(sourceMapJSON).toComment()
        : SourceMapUtil.generateMapFileComment(relSrcMapFile);
      if (!code.endsWith('\n')) code += '\n';
      code += comment + '\n';
    }

    // In --stdout mode, just output the code
    if (opt.stdout) {
      throw new Error('--stdout is not yet supported');
    } else {
      // A util to log the output of a file
      const logFile = (type, file, data) => {
        const bytes = chalk.dim(`(${prettyBytes(data.length)})`);
        logger.log(`${type}${chalk.bold(path.relative(cwd, file))} ${bytes}`, { leadingSpace: false });
      };

      // Read the templated HTML, transform it and write it out
github frankwallis / plugin-typescript / lib / incremental-compiler.js View on Github external
if (diagnostics.length == 0) {
			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 power-assert-js / gulp-espower / index.js View on Github external
sourceMap: file.relative,
            // do not set sourceMapRoot to keep paths relative until the end of chain
            // sourceMapRoot: file.base,
            sourceMapWithCode: true
        });
    }
    var modifiedAst = estraverse.replace(jsAst, mergeVisitors([
        {
            enter: empowerAssert.enter
        },
        espower.createVisitor(jsAst, espowerOptions)
    ]));
    var escodegenOutput = escodegen.generate(modifiedAst, escodegenOptions);
    if (inMap) {
        file.contents = new Buffer(escodegenOutput.code);
        var outMap = convert.fromJSON(escodegenOutput.map.toString());
        outMap.setProperty('sources', inMap.sources);
        outMap.setProperty('sourcesContent', inMap.sourcesContent);

        var reMap;
        if (inMap.mappings === '') {
            applySourceMap(file, outMap.toJSON());
            reMap = convert.fromObject(file.sourceMap);
        } else {
            reMap = convert.fromObject(mergeSourceMap(inMap, outMap.toJSON()));
        }
        reMap.setProperty('sources', inMap.sources);
        reMap.setProperty('sourcesContent', inMap.sourcesContent);
        // do not set sourceMapRoot to keep paths relative until the end of chain
        // reMap.setProperty('sourceRoot', file.base);

        file.sourceMap = reMap.toObject();
github hughsk / uglifyify / test / index.js View on Github external
test('uglifyify: sourcemaps', function(t) {
  t.plan(10)

  var src  = path.join(__dirname, 'fixture.js')
  var json = path.join(__dirname, 'fixture.json')
  var orig = fs.readFileSync(src, 'utf8')
  var min  = uglify.minify(orig, {
    sourceMap: {
      url: 'out.js.map'
    }
  })

  var map = convert.fromJSON(min.map)
  map.setProperty('sources', [src])
  map.setProperty('sourcesContent', [orig])

  var mapped = [orig, map.toComment()].join('\n')

  from2([mapped])
    .pipe(uglifyify(json))
    .pipe(bl(doneWithMap))

  from2([orig])
    .pipe(uglifyify(json))
    .pipe(bl(doneWithoutMap))

  browserify({ entries: [src], debug: true })
    .transform(uglifyify)
    .bundle()
github sidorares / pugify / index.js View on Github external
while (!found && line < compiledLines.length) {
        var lnDebug = compiledLines[line];
        if (re.test(lnDebug)) {
            found = true;
            compiledLines[line] = lnDebug.replace(re, '');
        }
        line++;
    }
    if (found) {
        var ln = compiledLines.length;
        compiledLines[ln - 1] = compiledLines[ln - 1].replace(/\} catch \(err\)[^}]*};/, '');
    }

    generator.setSourceContent(name, src);

    var map = convert.fromJSON(generator.toString());
    compiledLines.push(map.toComment());
    return compiledLines.join('\n');
}
github andreypopp / sweetify / index.js View on Github external
var r;

        modules.unshift(eliminateIncludeMacros);

        try {
          r = sweet.compile(buffer, {
            modules: modules,
            sourceMap: true,
            filename: filename
          });
        } catch(e) {
          return stream.emit('error', e);
        }

        var map = sourceMap.fromJSON(r.sourceMap);
        map.sourcemap.sourcesContent = [buffer];

        stream.queue(r.code + '\n' + map.toComment());
        stream.queue(null);
      });
    });
github fand / glslify-lite / src / glslify-import.ts View on Github external
output += l.content + "\n";
        map.addMapping({
            source: l.source,
            original: {
                line: l.line,
                column: 1
            },
            generated: {
                line: i + 1,
                column: 1
            }
        });
    });

    const mapJSON = map.toString();
    const mapComment = convert.fromJSON(mapJSON).toComment();

    return output + "\n" + mapComment;
};
github monounity / karma-typescript / src / bundler / source-map.ts View on Github external
public getSourceMap(queued: Queued): convertSourceMap.SourceMapConverter {
        if (queued.emitOutput.sourceMapText) {

            let map = convertSourceMap.fromJSON(queued.emitOutput.sourceMapText);
            if (!map.getProperty("sourcesContent")) {
                map.addProperty("sourcesContent", [queued.emitOutput.sourceFile.text]);
            }

            return map;
        }

        return undefined;
    }
github chemzqm / wept / lib / wxss.js View on Github external
p.done(err => {
      if (err) return reject(err)
      let res = results.join('\n')
      res = res + convert.fromJSON(generator.toString()).toComment({
        multiline: true
      })
      resolve(res)
    })
  })