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));
}
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)));
}
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)));
}
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));
}
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;
}
Aggregations