Search in sources :

Example 31 with Compiler

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

Example 32 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)

Example 33 with Compiler

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

Example 34 with Compiler

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

Example 35 with Compiler

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);
}
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)107 Test (org.junit.Test)83 Node (com.google.javascript.rhino.Node)80 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)15 SourceFile (com.google.javascript.jscomp.SourceFile)11 IOException (java.io.IOException)6 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Result (com.google.javascript.jscomp.Result)3 AbstractCompiler (com.google.javascript.jscomp.AbstractCompiler)2 BlackHoleErrorManager (com.google.javascript.jscomp.BlackHoleErrorManager)2 CompilerInput (com.google.javascript.jscomp.CompilerInput)2 JSModule (com.google.javascript.jscomp.JSModule)2 JSSourceFile (com.google.javascript.jscomp.JSSourceFile)2 CircularDependencyException (com.google.javascript.jscomp.deps.SortedDependencies.CircularDependencyException)2 AbstractJSProject (net.vtst.ow.closure.compiler.deps.AbstractJSProject)2 JSProject (net.vtst.ow.closure.compiler.deps.JSProject)2 ErrorManager (com.google.javascript.jscomp.ErrorManager)1 JsAst (com.google.javascript.jscomp.JsAst)1 LazyParsedDependencyInfo (com.google.javascript.jscomp.LazyParsedDependencyInfo)1