use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testDeleteArgumentWithPrefixComment.
@Test
public void testDeleteArgumentWithPrefixComment() {
String originalCode = "f(a, /** @type {number} */ (b), c);";
String expectedCode = "f(a, c);";
Compiler compiler = getCompiler(originalCode);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().deleteArgument(root.getFirstFirstChild(), 1).build();
assertChanges(fix, "", originalCode, expectedCode);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testRenameFunction_justFunctionName.
@Test
public void testRenameFunction_justFunctionName() {
String input = "obj.fnCall();";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().rename(root.getFirstFirstChild(), "renamedFnCall").build();
CodeReplacement replacement = CodeReplacement.create(4, "fnCall".length(), "renamedFnCall");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testReplace_samePrecedence.
@Test
public void testReplace_samePrecedence() {
String before = "5 - ";
String after = "1";
Compiler compiler = getCompiler(before + after + ";\n");
Node root = compileToScriptRoot(compiler);
Node newNode = IR.exprResult(IR.sub(IR.number(3), IR.number(2)));
Node toReplace = root.getOnlyChild().getOnlyChild().getLastChild();
SuggestedFix fix = new SuggestedFix.Builder().replace(toReplace, newNode, compiler).build();
CodeReplacement replacement = CodeReplacement.create(before.length(), after.length(), "(3 - 2)");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testDeleteArgumentFirstWithLineComment.
@Test
public void testDeleteArgumentFirstWithLineComment() {
String originalCode = "f(// blah \n a, b, c);";
String expectedCode = "f(b, c);";
Compiler compiler = getCompiler(originalCode);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().deleteArgument(root.getFirstFirstChild(), 0).build();
assertChanges(fix, "", originalCode, expectedCode);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testRenameTaggedTemplate_entireName.
@Test
public void testRenameTaggedTemplate_entireName() {
String fnName = "goog.dom.classes.oldTaggedTemp";
String newFnName = "goog.dom.classesList.newTaggedTemp";
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);
}
Aggregations