Search in sources :

Example 1 with SourceMapInput

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

the class GwtRunner method buildSourceMaps.

private static ImmutableMap<String, SourceMapInput> buildSourceMaps(File[] src, String unknownPrefix) {
    ImmutableMap.Builder<String, SourceMapInput> inputSourceMaps = new ImmutableMap.Builder<>();
    if (src != null) {
        for (int i = 0; i < src.length; ++i) {
            File file = src[i];
            if (isNullOrEmpty(file.sourceMap)) {
                continue;
            }
            String path = file.path;
            if (path == null) {
                path = unknownPrefix + i;
            }
            path += ".map";
            SourceFile sf = SourceFile.fromCode(path, file.sourceMap);
            inputSourceMaps.put(path, new SourceMapInput(sf));
        }
    }
    return inputSourceMaps.build();
}
Also used : SourceFile(com.google.javascript.jscomp.SourceFile) SourceMapInput(com.google.javascript.jscomp.SourceMapInput) SourceFile(com.google.javascript.jscomp.SourceFile) ImmutableMap(com.google.common.collect.ImmutableMap) EntryPoint(com.google.gwt.core.client.EntryPoint)

Example 2 with SourceMapInput

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

the class GwtRunner method compile.

/**
 * Public compiler call. Exposed in {@link #exportCompile}.
 */
public static ModuleOutput compile(Flags flags) {
    String[] unhandled = updateFlags(flags, defaultFlags);
    if (unhandled.length > 0) {
        throw new RuntimeException("Unhandled flag: " + unhandled[0]);
    }
    List<SourceFile> jsCode = fromFileArray(flags.jsCode, "Input_");
    ImmutableMap<String, SourceMapInput> sourceMaps = buildSourceMaps(flags.jsCode, "Input_");
    CompilerOptions options = new CompilerOptions();
    applyDefaultOptions(options);
    applyOptionsFromFlags(options, flags);
    options.setInputSourceMaps(sourceMaps);
    disableUnsupportedOptions(options);
    List<SourceFile> externs = fromFileArray(flags.externs, "Extern_");
    externs.addAll(createExterns(options.getEnvironment()));
    NodeErrorManager errorManager = new NodeErrorManager();
    Compiler compiler = new Compiler(new NodePrintStream());
    compiler.setErrorManager(errorManager);
    compiler.compile(externs, jsCode, options);
    ModuleOutput output = new ModuleOutput();
    output.compiledCode = writeOutput(compiler, flags.outputWrapper);
    output.errors = toNativeErrorArray(errorManager.errors);
    output.warnings = toNativeErrorArray(errorManager.warnings);
    if (flags.createSourceMap) {
        StringBuilder b = new StringBuilder();
        try {
            compiler.getSourceMap().appendTo(b, "");
        } catch (IOException e) {
        // ignore
        }
        output.sourceMap = b.toString();
    }
    return output;
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) IOException(java.io.IOException) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) SourceFile(com.google.javascript.jscomp.SourceFile) SourceMapInput(com.google.javascript.jscomp.SourceMapInput)

Aggregations

SourceFile (com.google.javascript.jscomp.SourceFile)2 SourceMapInput (com.google.javascript.jscomp.SourceMapInput)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 EntryPoint (com.google.gwt.core.client.EntryPoint)1 Compiler (com.google.javascript.jscomp.Compiler)1 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)1 IOException (java.io.IOException)1