Search in sources :

Example 1 with LazyParsedDependencyInfo

use of com.google.javascript.jscomp.LazyParsedDependencyInfo in project closure-compiler by google.

the class DepsGenerator method parseSources.

/**
 * Parses all source files for dependency information.
 * @param preparsedFiles A set of closure-relative paths.
 *     Files in this set are not parsed if they are encountered in srcs.
 * @return Returns a map of closure-relative paths -> DependencyInfo for the
 *     newly parsed files.
 * @throws IOException Occurs upon an IO error.
 */
private Map<String, DependencyInfo> parseSources(Set<String> preparsedFiles) throws IOException {
    Map<String, DependencyInfo> parsedFiles = new LinkedHashMap<>();
    JsFileParser jsParser = new JsFileParser(errorManager).setModuleLoader(loader);
    Compiler compiler = new Compiler();
    compiler.init(ImmutableList.of(), ImmutableList.of(), new CompilerOptions());
    for (SourceFile file : srcs) {
        String closureRelativePath = PathUtil.makeRelative(closurePathAbs, PathUtil.makeAbsolute(file.getName()));
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Closure-relative path: " + closureRelativePath);
        }
        if (InclusionStrategy.WHEN_IN_SRCS == mergeStrategy || !preparsedFiles.contains(closureRelativePath)) {
            DependencyInfo depInfo = jsParser.parseFile(file.getName(), closureRelativePath, file.getCode());
            depInfo = new LazyParsedDependencyInfo(depInfo, new JsAst(file), compiler);
            // Kick the source out of memory.
            file.clearCachedSource();
            parsedFiles.put(closureRelativePath, depInfo);
        }
    }
    return parsedFiles;
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) JsAst(com.google.javascript.jscomp.JsAst) LazyParsedDependencyInfo(com.google.javascript.jscomp.LazyParsedDependencyInfo) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) SourceFile(com.google.javascript.jscomp.SourceFile) LazyParsedDependencyInfo(com.google.javascript.jscomp.LazyParsedDependencyInfo) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Compiler (com.google.javascript.jscomp.Compiler)1 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)1 JsAst (com.google.javascript.jscomp.JsAst)1 LazyParsedDependencyInfo (com.google.javascript.jscomp.LazyParsedDependencyInfo)1 SourceFile (com.google.javascript.jscomp.SourceFile)1 LinkedHashMap (java.util.LinkedHashMap)1