Search in sources :

Example 1 with MessageFormatter

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

the class TranspilationException method format.

private static String format(SourceExcerptProvider source, JSError[] errors, JSError[] warnings) {
    StringBuilder sb = new StringBuilder().append("Transpilation failed:\n");
    MessageFormatter formatter = source != null ? ErrorFormat.SINGLELINE.toFormatter(source, false) : ErrorFormat.SOURCELESS.toFormatter(source, false);
    for (JSError error : errors) {
        sb.append("\n").append(formatter.formatError(error));
    }
    for (JSError warning : warnings) {
        sb.append("\n").append(formatter.formatError(warning));
    }
    return sb.toString();
}
Also used : MessageFormatter(com.google.javascript.jscomp.MessageFormatter) JSError(com.google.javascript.jscomp.JSError)

Example 2 with MessageFormatter

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

the class CompileTask method createCompiler.

private Compiler createCompiler(CompilerOptions options) {
    Compiler compiler = new Compiler();
    MessageFormatter formatter = options.getErrorFormat().toFormatter(compiler, false);
    AntErrorManager errorManager = new AntErrorManager(formatter, this);
    compiler.setErrorManager(errorManager);
    return compiler;
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) MessageFormatter(com.google.javascript.jscomp.MessageFormatter)

Example 3 with MessageFormatter

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

the class CompilerBasedTransformer method transform.

@Override
public Source transform(Source input) {
    CompileResult result = compilerSupplier.compile(input.path(), input.code());
    if (result.errors.length > 0) {
        // TODO(sdh): how to handle this?  Currently we throw an ISE with the message,
        // but this may not be the most appropriate option.  It might make sense to
        // add console.log() statements to any JS that comes out, particularly for
        // warnings.
        MessageFormatter formatter = ErrorFormat.SOURCELESS.toFormatter(null, false);
        StringBuilder message = new StringBuilder().append(getTranformationName()).append(" failed.\n");
        for (JSError error : result.errors) {
            message.append(formatter.formatError(error));
        }
        throw new IllegalStateException(message.toString());
    }
    if (!result.transformed) {
        return input;
    }
    Source.Builder builder = input.toBuilder().setCode(result.source).setSourceMap(result.sourceMap);
    if (getRuntime().isPresent()) {
        builder.addRuntime(compilerSupplier.runtime(getRuntime().get()));
    }
    return builder.build();
}
Also used : MessageFormatter(com.google.javascript.jscomp.MessageFormatter) JSError(com.google.javascript.jscomp.JSError)

Aggregations

MessageFormatter (com.google.javascript.jscomp.MessageFormatter)3 JSError (com.google.javascript.jscomp.JSError)2 Compiler (com.google.javascript.jscomp.Compiler)1