Search in sources :

Example 11 with Compiler

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

the class MatchersTest method testGoogModule.

@Test
public void testGoogModule() {
    String input = "goog.module('testcase');";
    Compiler compiler = getCompiler(input);
    Node root = compileToScriptRoot(compiler);
    Node fnCall = root.getFirstFirstChild();
    NodeMetadata metadata = new NodeMetadata(compiler);
    assertTrue(Matchers.googModule().matches(fnCall, metadata));
    assertTrue(Matchers.googModuleOrProvide().matches(fnCall, metadata));
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Node(com.google.javascript.rhino.Node) Test(org.junit.Test)

Example 12 with Compiler

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

the class MatchersTest method testIsPrivate.

@Test
public void testIsPrivate() {
    String externs = "";
    String input = "" + "/** @private */\n" + "var foo = 3;";
    Compiler compiler = getCompiler(externs, input);
    Node root = compileToScriptRoot(compiler);
    Node node = root.getFirstChild();
    assertTrue(Matchers.isPrivate().matches(node, new NodeMetadata(compiler)));
    input = "" + "/** @package */\n" + "var foo = 3;";
    compiler = getCompiler(externs, input);
    root = compileToScriptRoot(compiler);
    node = root.getFirstChild();
    assertFalse(Matchers.isPrivate().matches(node, new NodeMetadata(compiler)));
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Node(com.google.javascript.rhino.Node) Test(org.junit.Test)

Example 13 with Compiler

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

the class MatchersTest method testJsDocTypeNoMatch1.

@Test
public void testJsDocTypeNoMatch1() {
    String input = "/** @const */ var foo = 1;";
    Compiler compiler = getCompiler(input);
    Node root = compileToScriptRoot(compiler);
    Node node = root.getFirstFirstChild();
    assertFalse(Matchers.jsDocType("number").matches(node, new NodeMetadata(compiler)));
    assertFalse(Matchers.jsDocType("string").matches(node, new NodeMetadata(compiler)));
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Node(com.google.javascript.rhino.Node) Test(org.junit.Test)

Example 14 with Compiler

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

the class MatchersTest method testNewClass_specificClass.

@Test
public void testNewClass_specificClass() {
    String externs = "" + "/** @constructor */\n" + "function Foo() {};\n" + "/** @constructor */\n" + "function Bar() {};";
    String input = "var foo = new Foo();";
    Compiler compiler = getCompiler(externs, input);
    NodeMetadata metadata = new NodeMetadata(compiler);
    Node root = compileToScriptRoot(compiler);
    Node varNode = root.getFirstChild();
    Node newNode = varNode.getFirstFirstChild();
    assertTrue(newNode.isNew());
    assertTrue(Matchers.newClass("Foo").matches(newNode, metadata));
    assertFalse(Matchers.newClass("Bar").matches(newNode, metadata));
    assertFalse(Matchers.newClass("Foo").matches(newNode.getFirstChild(), metadata));
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Node(com.google.javascript.rhino.Node) Test(org.junit.Test)

Example 15 with Compiler

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

the class JsfileParser method parse.

/**
 * Internal implementation to produce the {@link FileInfo} object.
 */
private static FileInfo parse(String code, String filename, @Nullable Reporter reporter) {
    ErrorReporter errorReporter = new DelegatingReporter(reporter);
    Compiler compiler = new Compiler();
    compiler.init(ImmutableList.<SourceFile>of(), ImmutableList.<SourceFile>of(), new CompilerOptions());
    Config config = ParserRunner.createConfig(// TODO(sdh): ES8 STRICT, with a non-strict fallback - then give warnings.
    Config.LanguageMode.ECMASCRIPT8, Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE, Config.RunMode.KEEP_GOING, /* extraAnnotationNames */
    ImmutableSet.<String>of(), /* parseInlineSourceMaps */
    true, Config.StrictMode.SLOPPY);
    SourceFile source = SourceFile.fromCode(filename, code);
    FileInfo info = new FileInfo(errorReporter);
    ParserRunner.ParseResult parsed = ParserRunner.parse(source, code, config, errorReporter);
    parsed.ast.setInputId(new InputId(filename));
    String version = parsed.features.version();
    if (!version.equals("es3")) {
        info.loadFlags.add(JsArray.of("lang", version));
    }
    for (Comment comment : parsed.comments) {
        if (comment.type == Comment.Type.JSDOC) {
            parseComment(comment, info);
        }
    }
    NodeTraversal.traverseEs6(compiler, parsed.ast, new Traverser(info));
    return info;
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Comment(com.google.javascript.jscomp.parsing.parser.trees.Comment) ParserRunner(com.google.javascript.jscomp.parsing.ParserRunner) Config(com.google.javascript.jscomp.parsing.Config) ErrorReporter(com.google.javascript.rhino.ErrorReporter) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) InputId(com.google.javascript.rhino.InputId) SourceFile(com.google.javascript.jscomp.SourceFile)

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