Search in sources :

Example 26 with Compiler

use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.

the class SuggestedFixTest method testRemoveGoogRequire_doesNotExist.

@Test
public void testRemoveGoogRequire_doesNotExist() {
    String input = "goog.require('abc.def');\n" + "\n" + "/** @private */\n" + "function foo_() {};\n";
    Compiler compiler = getCompiler(input);
    Node root = compileToScriptRoot(compiler);
    Match match = new Match(root.getFirstChild(), new NodeMetadata(compiler));
    SuggestedFix fix = new SuggestedFix.Builder().removeGoogRequire(match, "fakefake").build();
    SetMultimap<String, CodeReplacement> replacementMap = fix.getReplacements();
    assertThat(replacementMap).isEmpty();
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Node(com.google.javascript.rhino.Node) Test(org.junit.Test)

Example 27 with Compiler

use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.

the class SuggestedFixTest method testChangeJsDocType2.

@Test
public void testChangeJsDocType2() {
    String code = "/** @type {Foo} */\nvar foo = new Foo()";
    Compiler compiler = getCompiler(code);
    Node root = compileToScriptRoot(compiler);
    Node varNode = root.getFirstChild();
    Node jsdocRoot = Iterables.getOnlyElement(varNode.getJSDocInfo().getTypeNodes());
    SuggestedFix fix = new SuggestedFix.Builder().insertBefore(jsdocRoot, "!").build();
    CodeReplacement replacement = CodeReplacement.create("/** @type {".length(), 0, "!");
    assertReplacement(fix, replacement);
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Node(com.google.javascript.rhino.Node) Test(org.junit.Test)

Example 28 with Compiler

use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.

the class SuggestedFixTest method testRemoveCast_return.

@Test
public void testRemoveCast_return() {
    String input = Joiner.on('\n').join("function f() {", "  return /** @type {string} */ (", "      'I am obviously a string. Why are you casting me?');", "}");
    String expectedCode = Joiner.on('\n').join("function f() {", "  return 'I am obviously a string. Why are you casting me?';", "}");
    Compiler compiler = getCompiler(input);
    Node root = compileToScriptRoot(compiler);
    Node castNode = root.getFirstChild().getLastChild().getFirstChild().getLastChild();
    assertTrue(castNode.isCast());
    SuggestedFix fix = new SuggestedFix.Builder().removeCast(castNode, compiler).build();
    assertChanges(fix, "", input, expectedCode);
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Node(com.google.javascript.rhino.Node) Test(org.junit.Test)

Example 29 with Compiler

use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.

the class SuggestedFixTest method testRenameFunction_entireName.

@Test
public void testRenameFunction_entireName() {
    String fnName = "goog.dom.classes.add";
    String newFnName = "goog.dom.classlist.add";
    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 30 with Compiler

use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.

the class SuggestedFixTest method testAddGoogRequire_alreadyExists.

@Test
public void testAddGoogRequire_alreadyExists() {
    String input = "goog.provide('js.Foo');\n" + "goog.require('abc.def');\n" + "\n" + "/** @private */\n" + "function foo_() {};\n";
    Compiler compiler = getCompiler(input);
    Node root = compileToScriptRoot(compiler);
    Match match = new Match(root.getFirstChild(), new NodeMetadata(compiler));
    SuggestedFix fix = new SuggestedFix.Builder().addGoogRequire(match, "abc.def").build();
    SetMultimap<String, CodeReplacement> replacementMap = fix.getReplacements();
    assertThat(replacementMap).isEmpty();
}
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