How to use the convert-source-map.removeComments 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 ben-ng / minifyify / lib / minifier.js View on Github external
end = function () {
    if(self.opts.minify === false) {
      this.queue(null)
      return
    }

    var thisStream = this
      , unminCode = buffs.join('')
      , originalCode = false
      , existingMap = convertSM.fromSource(unminCode)
      , finish;

    existingMap = existingMap ? existingMap.toObject() : false;

    if(existingMap && existingMap.sourcesContent && existingMap.sourcesContent.length) {
      originalCode = convertSM.removeComments(existingMap.sourcesContent[0]);
      existingMap = JSON.stringify(existingMap);
    }
    // Only accept existing maps with sourcesContent
    else {
      existingMap = false;
    }

    finish = function (tempExistingMapFile, cleanupCallback) {
      // Don't minify JSON!
      if(file.match(/\.json$/)) {
        try {
          thisStream.queue(JSON.stringify(JSON.parse(unminCode)))
        }
        catch(e) {
          console.error('failed to parse JSON in ' + file)
          thisStream.queue(unminCode)
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;
        let lastColumn = 1;

        for (let i = 0; i < tokens.length; i++) {
            const token = tokens[i];
github browserify / static-module / index.js View on Github external
if (body.indexOf(key) !== -1) {
                    matches = true;
                    break;
                }
            }

            if (!matches) {
                // just pass it through
                output.end(buf);
                return;
            }

            if (opts.sourceMap) {
                inputMap = convertSourceMap.fromSource(body);
                if (inputMap) inputMap = inputMap.toObject();
                body = convertSourceMap.removeComments(body);
                sourcemapper = new MagicString(body);
            }

            falafel(body, parserOpts, walk);
        }
        catch (err) { return error(err) }
        finish(body);
    }), output);
github LavaMoat / lavamoat-browserify / src / sourcemaps.js View on Github external
function extractSourceMaps (sourceCode) {
  const converter = convertSourceMap.fromSource(sourceCode)
  // if (!converter) throw new Error('Unable to find original inlined sourcemap')
  const maps = converter && converter.toObject()
  const sourceContent = maps && maps.sourcesContent[0]
  const code = convertSourceMap.removeComments(sourceCode)
  return { code, maps }
}
github duojs / duo / test / cli.js View on Github external
function evaluate(js, ctx) {
  if (!ctx) ctx = { window: {}, document: {} };
  js = convert.removeComments(js);
  vm.runInNewContext('main =' + js + '(1)', ctx, 'main.vm');
  vm.runInNewContext('require =' + js + '', ctx, 'require.vm');
  return ctx;
}
github babel / babel / packages / babel-core / src / transformation / file / index.js View on Github external
parseInputSourceMap(code: string): string {
    const opts = this.opts;

    if (opts.inputSourceMap !== false) {
      const inputMap = convertSourceMap.fromSource(code);
      if (inputMap) {
        opts.inputSourceMap = inputMap.toObject();
        code = convertSourceMap.removeComments(code);
      }
    }

    return code;
  }
github shlomiassaf / ngx-chess / scripts / gulp / build.ts View on Github external
.then( () => {
            /*
             Angular compiler with 'flatModuleOutFile' turned on creates an entry JS file with a matching d.ts
             file and an aggregated metadata.json file.

             This is done by creating a corresponding TS file (to the output JS file).
             The side-effect is a source map reference to the TS file.

             Since the TS is virtual and does not exists we need to remove the comment so the source maps
             will not break.
             */
            const flatModuleJsPath = Path.join(copyInst.toSrc, `${util.getMainOutputFileName(util.currentPackage())}.js`);
            const withoutComments = convert.removeComments(fs.readFileSync(flatModuleJsPath, 'utf-8'));
            fs.writeFileSync(flatModuleJsPath, withoutComments, 'utf-8');
          });
      });
github Macil / react-hot-transform / index.js View on Github external
}, function(done) {
    var self = this;
    var source = pieces.join('');
    var inputMapCV = convert.fromSource(source);
    var inputMap;
    if (inputMapCV) {
      inputMap = inputMapCV.toObject();
      source = convert.removeComments(source);
    }
    reactHotLoader.call({
      resourcePath: file,
      callback: function(err, source, map) {
        if (err) {
          done(err);
        } else {
          if (map) {
            source = source + '\n' + convert.fromJSON(map).toComment();
          }
          self.push(source);
          done();
        }
      }
    }, source, inputMap);
  });
github forivall / tacoscript / packages / comal / src / file / index.js View on Github external
parseInputSourceMap(code): string {
    let inputMap = convertSourceMap.fromSource(code);
    if (inputMap) {
      this.inputSourceMap = inputMap.toObject();
      code = convertSourceMap.removeComments(code);
    }
    return code;
  }
github airtap / airtap / lib / builder-browserify.js View on Github external
bundler.bundle(function (err, buf) {
      if (err) {
        return cb(err)
      }

      var src = buf.toString()
      var srcmap = convert.fromSource(src)
      var map
      src = convert.removeComments(src)

      if (srcmap) {
        map = srcmap.toObject()
      }

      debug('test files took %s to bundle', humanizeDuration(Date.now() - start))
      cb(null, src, map)
    })
  }