use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testChangeJsDocType_privateType2.
@Test
public void testChangeJsDocType_privateType2() {
String before = "/** @private ";
String after = "@const {Foo} */\nvar foo = new Foo()";
Compiler compiler = getCompiler(before + after);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().changeJsDocType(root.getFirstChild(), compiler, "Object").build();
CodeReplacement replacement = CodeReplacement.create(before.length(), "@const {Foo}".length(), "@const {Object}");
assertReplacement(fix, replacement);
}
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);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testReplace_leftHandSideAssignment.
@Test
public void testReplace_leftHandSideAssignment() {
String before = "var MyClass = function() {};\n";
String after = "MyClass.prototype.foo = function() {};\n";
Compiler compiler = getCompiler(before + after);
Node root = compileToScriptRoot(compiler);
Node newNode = IR.getprop(IR.getprop(IR.name("MyClass"), IR.string("prototype")), IR.string("bar"));
SuggestedFix fix = new SuggestedFix.Builder().replace(root.getLastChild().getFirstFirstChild(), newNode, compiler).build();
CodeReplacement replacement = CodeReplacement.create(before.length(), "MyClass.prototype.foo".length(), "MyClass.prototype.bar");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testInsertArguments_lastArgument.
@Test
public void testInsertArguments_lastArgument() {
String before = "goog.dom.classes.add(foo, bar";
String after = ");";
Compiler compiler = getCompiler(before + after);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().insertArguments(root.getFirstFirstChild(), 2, "baz").build();
CodeReplacement replacement = CodeReplacement.create(before.length(), 0, ", baz");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testDelete_multipleVarDeclaration.
@Test
public void testDelete_multipleVarDeclaration() {
String input = "var foo = 3, bar, baz;";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
// Delete the 1st variable on the line. Make sure the deletion includes the assignment and the
// trailing comma.
SuggestedFix fix = new SuggestedFix.Builder().delete(root.getFirstFirstChild()).build();
CodeReplacement replacement = CodeReplacement.create(4, "foo = 3, ".length(), "");
assertReplacement(fix, replacement);
// Delete the 2nd variable.
fix = new SuggestedFix.Builder().delete(root.getFirstChild().getSecondChild()).build();
replacement = CodeReplacement.create(13, "bar, ".length(), "");
assertReplacement(fix, replacement);
// Delete the last variable. Make sure it removes the leading comma.
fix = new SuggestedFix.Builder().delete(root.getFirstChild().getLastChild()).build();
replacement = CodeReplacement.create(16, ", baz".length(), "");
assertReplacement(fix, replacement);
}
Aggregations