use of com.google.javascript.jscomp.Compiler in project kontraktor by RuedigerMoeller.
the class ClojureJSPostProcessor method postProcess.
@Override
public String postProcess(String currentJS, JSPostProcessorContext context) {
try {
Compiler compiler = new Compiler();
CompilerOptions options = new CompilerOptions();
options.setLanguageOut(CompilerOptions.LanguageMode.ECMASCRIPT5);
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
// To get the complete set of externs, the logic in
// CompilerRunner.getDefaultExterns() should be used here.
SourceFile extern = SourceFile.fromCode("xxxx.js", "");
// The dummy input name "input.js" is used here so that any warnings or
// errors will cite line numbers in terms of input.js.
SourceFile input = SourceFile.fromCode("input.js", currentJS);
ArrayList in = new ArrayList();
in.add(input);
// compile() returns a Result, but it is not needed here.
Result compile = compiler.compile(CommandLineRunner.getBuiltinExterns(CompilerOptions.Environment.BROWSER), in, options);
// System.out.println(compile);
// The compiler is responsible for generating the compiled code; it is not
// accessible via the Result.
String s = compiler.toSource();
// System.out.println(s);
return s;
} catch (Exception e) {
Log.Warn(this, e);
}
return currentJS;
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class TypeSyntaxTest method parse.
private Node parse(String source, String expected, LanguageMode languageIn) {
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(languageIn);
options.setLanguageOut(LanguageMode.ECMASCRIPT6_TYPED);
options.setPreserveTypeAnnotations(true);
options.setPrettyPrint(true);
options.setLineLengthThreshold(80);
options.setPreferSingleQuotes(true);
Compiler compiler = new Compiler();
compiler.setErrorManager(testErrorManager);
compiler.initOptions(options);
Node script = compiler.parse(SourceFile.fromCode("[test]", source));
// Verifying that all warnings were seen
assertTrue("Missing an error", testErrorManager.hasEncounteredAllErrors());
assertTrue("Missing a warning", testErrorManager.hasEncounteredAllWarnings());
if (script != null && testErrorManager.getErrorCount() == 0) {
// if it can be parsed, it should round trip.
String actual = new CodePrinter.Builder(script).setCompilerOptions(options).setTypeRegistry(compiler.getTypeIRegistry()).build().trim();
assertThat(actual).isEqualTo(expected);
}
return script;
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class RefasterJsScannerTest method testInitialize_emptyBeforeTemplates.
@Test
public void testInitialize_emptyBeforeTemplates() throws Exception {
try {
Compiler compiler = createCompiler();
compileTestCode(compiler, "", "");
createScanner(compiler, "function before_foo() {}; function after_foo() {};");
fail("RefasterJS templates are not allowed to be empty!.");
} catch (IllegalStateException expected) {
}
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class RefasterJsScannerTest method testInitialize_missingAfterTemplate.
@Test
public void testInitialize_missingAfterTemplate() throws Exception {
try {
Compiler compiler = createCompiler();
compileTestCode(compiler, "", "");
createScanner(compiler, "function before_foo() {'bar'};");
fail("An exception should have been thrown for missing the after template.");
} catch (IllegalStateException expected) {
}
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class RefasterJsScannerTest method testInitialize_success.
@Test
public void testInitialize_success() throws Exception {
Compiler compiler = createCompiler();
compileTestCode(compiler, "", "");
createScanner(compiler, "function before_foo() {'str';}; function after_foo() {};");
}
Aggregations