Search in sources :

Example 36 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 37 with Compiler

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

Example 38 with Compiler

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

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

Example 40 with 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));
}
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