use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testRemoveGoogRequire_doesNotExist.
@Test
public void testRemoveGoogRequire_doesNotExist() {
String input = "goog.require('abc.def');\n" + "\n" + "/** @private */\n" + "function foo_() {};\n";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
Match match = new Match(root.getFirstChild(), new NodeMetadata(compiler));
SuggestedFix fix = new SuggestedFix.Builder().removeGoogRequire(match, "fakefake").build();
SetMultimap<String, CodeReplacement> replacementMap = fix.getReplacements();
assertThat(replacementMap).isEmpty();
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testChangeJsDocType2.
@Test
public void testChangeJsDocType2() {
String code = "/** @type {Foo} */\nvar foo = new Foo()";
Compiler compiler = getCompiler(code);
Node root = compileToScriptRoot(compiler);
Node varNode = root.getFirstChild();
Node jsdocRoot = Iterables.getOnlyElement(varNode.getJSDocInfo().getTypeNodes());
SuggestedFix fix = new SuggestedFix.Builder().insertBefore(jsdocRoot, "!").build();
CodeReplacement replacement = CodeReplacement.create("/** @type {".length(), 0, "!");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testRemoveCast_return.
@Test
public void testRemoveCast_return() {
String input = Joiner.on('\n').join("function f() {", " return /** @type {string} */ (", " 'I am obviously a string. Why are you casting me?');", "}");
String expectedCode = Joiner.on('\n').join("function f() {", " return 'I am obviously a string. Why are you casting me?';", "}");
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
Node castNode = root.getFirstChild().getLastChild().getFirstChild().getLastChild();
assertTrue(castNode.isCast());
SuggestedFix fix = new SuggestedFix.Builder().removeCast(castNode, compiler).build();
assertChanges(fix, "", input, expectedCode);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testRenameFunction_entireName.
@Test
public void testRenameFunction_entireName() {
String fnName = "goog.dom.classes.add";
String newFnName = "goog.dom.classlist.add";
String input = fnName + "(foo, bar);";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().rename(root.getFirstFirstChild(), newFnName, true).build();
CodeReplacement replacement = CodeReplacement.create(0, fnName.length(), newFnName);
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testAddGoogRequire_alreadyExists.
@Test
public void testAddGoogRequire_alreadyExists() {
String input = "goog.provide('js.Foo');\n" + "goog.require('abc.def');\n" + "\n" + "/** @private */\n" + "function foo_() {};\n";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
Match match = new Match(root.getFirstChild(), new NodeMetadata(compiler));
SuggestedFix fix = new SuggestedFix.Builder().addGoogRequire(match, "abc.def").build();
SetMultimap<String, CodeReplacement> replacementMap = fix.getReplacements();
assertThat(replacementMap).isEmpty();
}
Aggregations