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 testChangeJsDocType_privateType3.
@Test
public void testChangeJsDocType_privateType3() {
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 MatchersTest method testEnumOfType.
@Test
public void testEnumOfType() {
String input = "/** @enum {string} */ var foo = {BAR: 'baz'};";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
Node enumNode = root.getFirstFirstChild();
assertTrue(Matchers.enumDefinitionOfType("string").matches(enumNode, new NodeMetadata(compiler)));
assertFalse(Matchers.enumDefinitionOfType("number").matches(enumNode, new NodeMetadata(compiler)));
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class MatchersTest method testPropertyAccess.
@Test
public void testPropertyAccess() {
String input = "foo.bar.method();";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
Node methodNode = root.getFirstFirstChild().getFirstChild();
Node barNode = methodNode.getFirstChild();
assertTrue(Matchers.propertyAccess().matches(methodNode, new NodeMetadata(compiler)));
assertTrue(Matchers.propertyAccess().matches(barNode, new NodeMetadata(compiler)));
assertTrue(Matchers.propertyAccess("foo.bar.method").matches(methodNode, new NodeMetadata(compiler)));
assertTrue(Matchers.propertyAccess("foo.bar").matches(barNode, new NodeMetadata(compiler)));
assertFalse(Matchers.propertyAccess("foo").matches(barNode.getFirstChild(), new NodeMetadata(compiler)));
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class MatchersTest method testPrototypeDeclarations.
@Test
public void testPrototypeDeclarations() {
String input = "" + "/** @constructor */\n" + "function Foo() {}\n" + "Foo.prototype.bar = 3;\n" + "Foo.prototype.baz = function() {};\n";
Compiler compiler = getCompiler(input);
NodeMetadata metadata = new NodeMetadata(compiler);
Node root = compileToScriptRoot(compiler);
Node prototypeVarAssign = root.getSecondChild().getFirstChild();
Node prototypeFnAssign = root.getLastChild().getFirstChild();
assertTrue(Matchers.prototypeVariableDeclaration().matches(prototypeVarAssign.getFirstChild(), metadata));
assertFalse(Matchers.prototypeMethodDeclaration().matches(prototypeVarAssign.getFirstChild(), metadata));
assertTrue(Matchers.prototypeMethodDeclaration().matches(prototypeFnAssign.getFirstChild(), metadata));
assertFalse(Matchers.prototypeVariableDeclaration().matches(prototypeFnAssign.getFirstChild(), metadata));
}
Aggregations