use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class PolymerIntegrationTest method testPolymerExportPolicyExportAllClassBased.
@Test
public void testPolymerExportPolicyExportAllClassBased() {
CompilerOptions options = createCompilerOptions();
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setPolymerVersion(2);
options.setWarningLevel(DiagnosticGroups.CHECK_TYPES, CheckLevel.ERROR);
addPolymerExterns();
options.setRenamingPolicy(VariableRenamingPolicy.ALL, PropertyRenamingPolicy.ALL_UNQUOTED);
options.setRemoveUnusedPrototypeProperties(true);
options.setPolymerExportPolicy(PolymerExportPolicy.EXPORT_ALL);
options.setGenerateExports(true);
options.setExportLocalPropertyDefinitions(true);
Compiler compiler = compile(options, lines(EXPORT_PROPERTY_DEF, "class FooElement extends PolymerElement {", " static get properties() {", " return {", " longUnusedProperty: String,", " }", " }", " longUnusedMethod() {", " return this.longUnusedProperty;", " }", "}"));
String source = compiler.toSource();
// If we see these identifiers anywhere in the output source, we know that we successfully
// protected it against removal and renaming.
assertThat(source).contains("longUnusedProperty");
assertThat(source).contains("longUnusedMethod");
assertThat(compiler.getErrors()).isEmpty();
assertThat(compiler.getWarnings()).isEmpty();
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class PolymerIntegrationTest method testPolymerElementImportedFromEsModule.
@Test
public void testPolymerElementImportedFromEsModule() {
CompilerOptions options = createCompilerOptions();
options.setPolymerVersion(2);
options.setWarningLevel(DiagnosticGroups.CHECK_TYPES, CheckLevel.ERROR);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
addPolymerExterns();
Compiler compiler = compile(options, new String[] { lines("export class PolymerElement {};"), lines("import {PolymerElement} from './i0.js';", "class Foo extends PolymerElement {", " get is() { return 'foo-element'; }", " static get properties() { return { fooProp: String }; }", "}", "const foo = new Foo();", // had successfully parsed the element definition.
"foo.fooProp;") });
assertThat(compiler.getErrors()).isEmpty();
assertThat(compiler.getWarnings()).isEmpty();
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class ProductionCoverageInstrumentationPassIntegrationTest method testInstrumentationMappingIsCreated.
@Test
public void testInstrumentationMappingIsCreated() {
CompilerOptions options = createCompilerOptions();
declareIstArrExtern();
String source = lines(//
"function foo() { ", " console.log('Hello');", "}");
Compiler compiledSourceCode = compile(options, source);
VariableMap variableParamMap = compiledSourceCode.getInstrumentationMapping();
ImmutableMap<String, String> paramMap = variableParamMap.getOriginalNameToNewNameMap();
assertThat(paramMap).hasSize(4);
assertWithMessage("FunctionNames in the parameter mapping are not properly set").that(paramMap.get(" FunctionNames")).isEqualTo("[\"foo\"]");
assertWithMessage("FileNames in the parameter mapping are not properly set").that(paramMap.get(" FileNames")).isEqualTo("[\"i0.js\"]");
assertWithMessage("Types in the parameter mapping are not properly set").that(paramMap.get(" Types")).isEqualTo("[\"FUNCTION\"]");
assertWithMessage("Array index encoding is not performed properly").that(paramMap.get("C")).isEqualTo("AAACA");
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class IntegrationTestCase method test.
/**
* Asserts that when compiling with the given compiler options, there is an error or warning.
*/
protected void test(CompilerOptions options, String[] original, String[] compiled, DiagnosticGroup warnings) {
Compiler compiler = compile(options, original);
checkUnexpectedErrorsOrWarnings(compiler, 1);
if (compiled != null) {
Node root = compiler.getRoot().getLastChild();
Node expectedRoot = parseExpectedCode(compiled, options);
assertNode(root).usingSerializer(compiler::toSource).isEqualTo(expectedRoot);
}
DiagnosticType diagnostic;
if (compiler.getErrorCount() == 1) {
diagnostic = compiler.getErrors().get(0).getType();
} else {
diagnostic = compiler.getWarnings().get(0).getType();
}
assertWithMessage("Error not in expected diagnostic group. Error: " + diagnostic.key + "\nExpected group: " + warnings).that(warnings.matches(diagnostic)).isTrue();
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class IntegrationTestCase method testParseError.
/**
* Asserts that there is at least one parse error.
*/
protected void testParseError(CompilerOptions options, String original, String compiled) {
Compiler compiler = compile(options, original);
for (JSError error : compiler.getErrors()) {
if (!DiagnosticGroups.PARSING.matches(error)) {
assertWithMessage("Found unexpected error type " + error.getType() + ":\n" + error).fail();
}
}
assertWithMessage("Unexpected warnings: " + Joiner.on("\n").join(compiler.getWarnings())).that(compiler.getWarnings().size()).isEqualTo(0);
if (compiled != null) {
Node root = compiler.getRoot().getLastChild();
Node expectedRoot = parseExpectedCode(new String[] { compiled }, options);
assertNode(root).usingSerializer(compiler::toSource).isEqualTo(expectedRoot);
}
}
Aggregations