index.js
function processSync(filename, content, updater, format) {
  var text = String(content);

  // parse code to AST using esprima
  var ast = esprima.parse(text, {
    loc    : true,
    comment: true,
    source : filename
  });

  // sort nodes before changing the source-map
  var sorted = orderNodes(ast);

  // associate comments with nodes they annotate before changing the sort map
  associateComments(ast, sorted);

  // make sure the AST has the data from the original source map
  var converter     = convert.fromSource(text);
  var originalMap   = converter && converter.toObject();
  var sourceContent = text;
  if (originalMap) {
    sourcemapToAst(ast, originalMap);
    sourceContent = originalMap.sourcesContent[0];
  }

  // update the AST
  var updated = ((typeof updater === 'function') && updater(filename, ast)) || ast;

  // generate compressed code from the AST
  var pair = codegen.generate(updated, {
    sourceMap        : true,
    sourceMapWithCode: true,
    format           : format || {}
  });

  // ensure that the source-map has sourcesContent or browserify will not work
  //  source-map source files are posix so we have to slash them
  var posixPath = filename.replace(/\\/g, '/');
  pair.map.setSourceContent(posixPath, sourceContent);

  // convert the map to base64 embedded comment
  var mapComment = convert.fromJSON(pair.map.toString()).toComment();

  // complete
  return pair.code + mapComment;
}
function processSync(filename, content, updater, format) {
  var text = String(content);

  // parse code to AST using esprima
  var ast = esprima.parse(text, {
    loc    : true,
    comment: true,
    source : filename
  });

  // sort nodes before changing the source-map
  var sorted = orderNodes(ast);

  // associate comments with nodes they annotate before changing the sort map
  associateComments(ast, sorted);

  // make sure the AST has the data from the original source map
  var converter     = convert.fromSource(text);
  var originalMap   = converter && converter.toObject();
  var sourceContent = text;
  if (originalMap) {
    sourcemapToAst(ast, originalMap);
    sourceContent = originalMap.sourcesContent[0];
  }

  // update the AST
  var updated = ((typeof updater === 'function') && updater(filename, ast)) || ast;

  // generate compressed code from the AST
  var pair = codegen.generate(updated, {
    sourceMap        : true,
    sourceMapWithCode: true,
    format           : format || {}
  });

  // ensure that the source-map has sourcesContent or browserify will not work
  //  source-map source files are posix so we have to slash them
  var posixPath = filename.replace(/\\/g, '/');
  pair.map.setSourceContent(posixPath, sourceContent);

  // convert the map to base64 embedded comment
  var mapComment = convert.fromJSON(pair.map.toString()).toComment();

  // complete
  return pair.code + mapComment;
}
function processSync ( filename , content , updater , format ) { var text = String ( content ) ; // parse code to AST using esprima var ast = esprima . parse ( text , { loc : true , comment : true , source : filename } ) ; // sort nodes before changing the source-map var sorted = orderNodes ( ast ) ; // associate comments with nodes they annotate before changing the sort map associateComments ( ast , sorted ) ; // make sure the AST has the data from the original source map var converter = convert . fromSource ( text ) ; var originalMap = converter && converter . toObject ( ) ; var sourceContent = text ; if ( originalMap ) { sourcemapToAst ( ast , originalMap ) ; sourceContent = originalMap . sourcesContent [ 0 ] ; } // update the AST var updated = ( ( typeof updater === 'function' ) && updater ( filename , ast ) ) || ast ; // generate compressed code from the AST var pair = codegen . generate ( updated , { sourceMap : true , sourceMapWithCode : true , format : format || { } } ) ; // ensure that the source-map has sourcesContent or browserify will not work //  source-map source files are posix so we have to slash them var posixPath = filename . replace ( / \\ / g , '/' ) ; pair . map . setSourceContent ( posixPath , sourceContent ) ; // convert the map to base64 embedded comment var mapComment = convert . fromJSON ( pair . map . toString ( ) ) . toComment ( ) ; // complete return pair . code + mapComment ; }
Synchronously process the given content and apply the updater function on its AST then output with the given format.
@throws {Error} Esprima parse error or updater error
@param {string} filename The name of the file that contains the given content
@param {*} content The text content to parse
@param {function} updater A function that works on the esprima AST
@param {object} [format] An optional format for escodegen
@returns {string} The transformed content with base64 source-map comment
Synchronously process the given content and apply the updater function on its AST then output with the given format .