Search in sources :

Example 56 with Compiler

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);
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Node(com.google.javascript.rhino.Node) Test(org.junit.Test)

Example 57 with Compiler

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);
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Node(com.google.javascript.rhino.Node) Test(org.junit.Test)

Example 58 with Compiler

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);
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Node(com.google.javascript.rhino.Node) Test(org.junit.Test)

Example 59 with Compiler

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);
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Node(com.google.javascript.rhino.Node) Test(org.junit.Test)

Example 60 with Compiler

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);
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Node(com.google.javascript.rhino.Node) Test(org.junit.Test)

Aggregations

Compiler (com.google.javascript.jscomp.Compiler)172 Test (org.junit.Test)132 Node (com.google.javascript.rhino.Node)116 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)50 SourceFile (com.google.javascript.jscomp.SourceFile)22 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)16 NoninjectingCompiler (com.google.javascript.jscomp.testing.NoninjectingCompiler)9 TestExternsBuilder (com.google.javascript.jscomp.testing.TestExternsBuilder)8 Result (com.google.javascript.jscomp.Result)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 File (java.io.File)4 BlackHoleErrorManager (com.google.javascript.jscomp.BlackHoleErrorManager)3 JSError (com.google.javascript.jscomp.JSError)3 InputId (com.google.javascript.rhino.InputId)3 GwtIncompatible (com.google.common.annotations.GwtIncompatible)2 AbstractCompiler (com.google.javascript.jscomp.AbstractCompiler)2 CompilerInput (com.google.javascript.jscomp.CompilerInput)2 JSChunk (com.google.javascript.jscomp.JSChunk)2 JSModule (com.google.javascript.jscomp.JSModule)2