use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class MatchersTest method testJsDocType2.
@Test
public void testJsDocType2() {
String input = "/** @type {number} */ let foo = 1;";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
Node node = root.getFirstFirstChild();
assertTrue(Matchers.jsDocType("number").matches(node, new NodeMetadata(compiler)));
assertFalse(Matchers.jsDocType("string").matches(node, new NodeMetadata(compiler)));
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testDeleteArgumentLast.
@Test
public void testDeleteArgumentLast() {
String originalCode = "f(a, b, c);";
String expectedCode = "f(a, b);";
Compiler compiler = getCompiler(originalCode);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().deleteArgument(root.getFirstFirstChild(), 2).build();
assertChanges(fix, "", originalCode, expectedCode);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testReplace_lowerPrecedence.
@Test
public void testReplace_lowerPrecedence() {
String before = "2 * ";
String after = "3";
Compiler compiler = getCompiler(before + after + ";\n");
Node root = compileToScriptRoot(compiler);
Node newNode = IR.exprResult(IR.sub(IR.number(4), IR.number(1)));
Node toReplace = root.getOnlyChild().getOnlyChild().getLastChild();
SuggestedFix fix = new SuggestedFix.Builder().replace(toReplace, newNode, compiler).build();
CodeReplacement replacement = CodeReplacement.create(before.length(), after.length(), "(4 - 1)");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testDelete_multipleConstDeclaration.
@Test
public void testDelete_multipleConstDeclaration() {
String input = "const foo = 3, bar = 4, baz = 5;";
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(6, "foo = 3, ".length(), "");
assertReplacement(fix, replacement);
// Delete the 2nd variable.
fix = new SuggestedFix.Builder().delete(root.getFirstChild().getSecondChild()).build();
replacement = CodeReplacement.create(15, "bar = 4, ".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(22, ", baz = 5".length(), "");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method assertAddGoogRequire.
private static void assertAddGoogRequire(String before, String after, String namespace) {
Compiler compiler = getCompiler(before + after);
Node root = compileToScriptRoot(compiler);
Match match = new Match(root.getFirstChild(), new NodeMetadata(compiler));
SuggestedFix fix = new SuggestedFix.Builder().addGoogRequire(match, namespace).build();
CodeReplacement replacement = CodeReplacement.create(before.length(), 0, "goog.require('" + namespace + "');\n", namespace);
assertReplacement(fix, replacement);
}
Aggregations