src/com/google/javascript/jscomp/gwt/client/GwtRunner.java
/** Public compiler call. Exposed in {@link #exportCompile}. */
Public compiler call. Exposed in  #exportCompile.
Public compiler call . Exposed in #exportCompile .
@JsMethod(namespace = "jscomp")
  public static ChunkOutput compile(Flags flags, File[] inputs) throws IOException {
    phaseLogger.setLevel(Level.OFF);
    String[] unhandled = updateFlags(flags, getDefaultFlags());
    if (unhandled.length > 0) {
      throw new RuntimeException("Unhandled flag: " + unhandled[0]);
    }
    List<SourceFile> jsCode = null;
    ImmutableMap<String, SourceMapInput> sourceMaps = null;
    if (flags.jsCode != null) {
      jsCode = fromFileArray(flags.jsCode, "Input_");
      sourceMaps = buildSourceMaps(flags.jsCode, "Input_");
    }
    ImmutableMap.Builder<String, String> inputPathByWebpackId = new ImmutableMap.Builder<>();
    if (inputs != null) {
      List<SourceFile> sourceFiles = fromFileArray(inputs, "Input_");
      ImmutableMap<String, SourceMapInput> inputSourceMaps = buildSourceMaps(inputs, "Input_");
      if (jsCode == null) {
        jsCode = sourceFiles;
      } else {
        jsCode.addAll(sourceFiles);
      }
      if (sourceMaps == null) {
        sourceMaps = inputSourceMaps;
      } else {
        HashMap<String, SourceMapInput> tempMaps = new HashMap<>(sourceMaps);
        tempMaps.putAll(inputSourceMaps);
        sourceMaps = ImmutableMap.copyOf(tempMaps);
      }
      for (GwtRunner.File element : inputs) {
        if (element.webpackId != null && element.path != null) {
          inputPathByWebpackId.put(element.webpackId, element.path);
        }
      }
    }
    if (flags.js != null) {
      File[] jsFiles = getJsFiles(getStringArray(flags, "js"));
      if (jsFiles == null) {
        throw new RuntimeException(
            "Can only load files from the filesystem when running in NodeJS.");
      } else {
        jsCode.addAll(fromFileArray(jsFiles, "Input_"));
      }
    }
    Compiler compiler = new Compiler(new NodePrintStream());
    CompilerOptions options = new CompilerOptions();
    applyOptionsFromFlags(options, flags, compiler.getDiagnosticGroups());
    options.setInputSourceMaps(sourceMaps);
    List<SourceFile> externs = new ArrayList<>();
    if (flags.externs != null) {
      File[] externFiles = fromExternsFlag(getStringArray(flags, "externs"));
      if (externFiles == null) {
        throw new RuntimeException(
            "Can only load files from the filesystem when running in NodeJS.");
      }
      externs = fromFileArray(externFiles, "Extern_");
    }
    externs.addAll(createExterns(options.getEnvironment()));
    NodeErrorManager errorManager = new NodeErrorManager();
    compiler.initWebpackMap(inputPathByWebpackId.build());
    compiler.setErrorManager(errorManager);
    List<String> chunkSpecs = new ArrayList<>();
    if (flags.chunk != null) {
      Collections.addAll(chunkSpecs, flags.chunk);
    }
    List<JsModuleSpec> jsChunkSpecs = new ArrayList<>();
    for (int i = 0; i < chunkSpecs.size(); i++) {
      jsChunkSpecs.add(JsModuleSpec.create(chunkSpecs.get(i), i == 0));
    }
    ChunkOutput output;
    if (!jsChunkSpecs.isEmpty()) {
      List<JSModule> chunks = createJsModules(jsChunkSpecs, jsCode);
      compiler.compileModules(externs, chunks, options);
      output = writeChunkOutput(compiler, flags, chunks);
    } else {
      compiler.compile(externs, jsCode, options);
      output = writeOutput(compiler, flags);
    }
    output.errors = toNativeErrorArray(errorManager.errors);
    output.warnings = toNativeErrorArray(errorManager.warnings);
    return output;
  }
@ JsMethod ( namespace = "jscomp" ) public static ChunkOutput compile ( Flags flags , File [ ] inputs ) throws IOException { phaseLogger . setLevel ( Level . OFF ) ; String [ ] unhandled = updateFlags ( flags , getDefaultFlags ( ) ) ; if ( unhandled . length > 0 ) { throw new RuntimeException ( "Unhandled flag: " + unhandled [ 0 ] ) ; } List < SourceFile > jsCode = null ; ImmutableMap < String , SourceMapInput > sourceMaps = null ; if ( flags . jsCode != null ) { jsCode = fromFileArray ( flags . jsCode , "Input_" ) ; sourceMaps = buildSourceMaps ( flags . jsCode , "Input_" ) ; } ImmutableMap . Builder < String , String > inputPathByWebpackId = new ImmutableMap . Builder < > ( ) ; if ( inputs != null ) { List < SourceFile > sourceFiles = fromFileArray ( inputs , "Input_" ) ; ImmutableMap < String , SourceMapInput > inputSourceMaps = buildSourceMaps ( inputs , "Input_" ) ; if ( jsCode == null ) { jsCode = sourceFiles ; } else { jsCode . addAll ( sourceFiles ) ; } if ( sourceMaps == null ) { sourceMaps = inputSourceMaps ; } else { HashMap < String , SourceMapInput > tempMaps = new HashMap < > ( sourceMaps ) ; tempMaps . putAll ( inputSourceMaps ) ; sourceMaps = ImmutableMap . copyOf ( tempMaps ) ; } for ( GwtRunner . File element : inputs ) { if ( element . webpackId != null && element . path != null ) { inputPathByWebpackId . put ( element . webpackId , element . path ) ; } } } if ( flags . js != null ) { File [ ] jsFiles = getJsFiles ( getStringArray ( flags , "js" ) ) ; if ( jsFiles == null ) { throw new RuntimeException ( "Can only load files from the filesystem when running in NodeJS." ) ; } else { jsCode . addAll ( fromFileArray ( jsFiles , "Input_" ) ) ; } } Compiler compiler = new Compiler ( new NodePrintStream ( ) ) ; CompilerOptions options = new CompilerOptions ( ) ; applyOptionsFromFlags ( options , flags , compiler . getDiagnosticGroups ( ) ) ; options . setInputSourceMaps ( sourceMaps ) ; List < SourceFile > externs = new ArrayList < > ( ) ; if ( flags . externs != null ) { File [ ] externFiles = fromExternsFlag ( getStringArray ( flags , "externs" ) ) ; if ( externFiles == null ) { throw new RuntimeException ( "Can only load files from the filesystem when running in NodeJS." ) ; } externs = fromFileArray ( externFiles , "Extern_" ) ; } externs . addAll ( createExterns ( options . getEnvironment ( ) ) ) ; NodeErrorManager errorManager = new NodeErrorManager ( ) ; compiler . initWebpackMap ( inputPathByWebpackId . build ( ) ) ; compiler . setErrorManager ( errorManager ) ; List < String > chunkSpecs = new ArrayList < > ( ) ; if ( flags . chunk != null ) { Collections . addAll ( chunkSpecs , flags . chunk ) ; } List < JsModuleSpec > jsChunkSpecs = new ArrayList < > ( ) ; for ( int i = 0 ; i < chunkSpecs . size ( ) ; i ++ ) { jsChunkSpecs . add ( JsModuleSpec . create ( chunkSpecs . get ( i ) , i == 0 ) ) ; } ChunkOutput output ; if ( ! jsChunkSpecs . isEmpty ( ) ) { List < JSModule > chunks = createJsModules ( jsChunkSpecs , jsCode ) ; compiler . compileModules ( externs , chunks , options ) ; output = writeChunkOutput ( compiler , flags , chunks ) ; } else { compiler . compile ( externs , jsCode , options ) ; output = writeOutput ( compiler , flags ) ; } output . errors = toNativeErrorArray ( errorManager . errors ) ; output . warnings = toNativeErrorArray ( errorManager . warnings ) ; return output ; }
Public compiler call.
Public compiler call .
// The PhaseOptimizer logs skipped pass warnings that interfere with capturing // output and errors in the open source runners.