tools/clusterfuzz/js_fuzzer/source_helpers.js
/**
 * Read file path into an AST.
 *
 * Post-processes the AST by replacing V8 natives and removing disallowed
 * natives, as well as removing load expressions and adding the paths-to-load
 * as meta data.
 */
Read file path into an AST.
Post-processes the AST by replacing V8 natives and removing disallowed
natives, as well as removing load expressions and adding the paths-to-load
as meta data.
Read file path into an AST . Post - processes the AST by replacing V8 natives and removing disallowed natives as well as removing load expressions and adding the paths - to - load as meta data .
function loadSource(baseDir, relPath, parseStrict=false) {
  const absPath = fsPath.resolve(fsPath.join(baseDir, relPath));
  const data = fs.readFileSync(absPath, 'utf-8');
  if (guessType(data) !== SCRIPT) {
    return null;
  }
  const preprocessed = maybeUseStict(replaceV8Builtins(data), parseStrict);
  const ast = babylon.parse(preprocessed, BABYLON_OPTIONS);
  removeComments(ast);
  cleanAsserts(ast);
  annotateWithOriginalPath(ast, relPath);
  const flags = loadFlags(data);
  const dependentPaths = resolveLoads(absPath, ast);
  return new ParsedSource(ast, baseDir, relPath, flags, dependentPaths);
}
function loadSource ( baseDir , relPath , parseStrict = false ) { const absPath = fsPath . resolve ( fsPath . join ( baseDir , relPath ) ) ; const data = fs . readFileSync ( absPath , 'utf-8' ) ; if ( guessType ( data ) !== SCRIPT ) { return null ; } const preprocessed = maybeUseStict ( replaceV8Builtins ( data ) , parseStrict ) ; const ast = babylon . parse ( preprocessed , BABYLON_OPTIONS ) ; removeComments ( ast ) ; cleanAsserts ( ast ) ; annotateWithOriginalPath ( ast , relPath ) ; const flags = loadFlags ( data ) ; const dependentPaths = resolveLoads ( absPath , ast ) ; return new ParsedSource ( ast , baseDir , relPath , flags , dependentPaths ) ; }
Read file path into an AST.
Read file path into an AST .