use of com.google.javascript.rhino.InputId in project closure-compiler by google.
the class TypeCheckTest method testNameNode.
/**
* Type checks a NAME node and retrieve its type.
*/
private JSType testNameNode(String name) {
Node node = Node.newString(Token.NAME, name);
Node parent = new Node(Token.SCRIPT, node);
parent.setInputId(new InputId("code"));
Node externs = new Node(Token.SCRIPT);
externs.setInputId(new InputId("externs"));
IR.root(externs, parent);
makeTypeCheck().processForTesting(null, parent);
return node.getJSType();
}
use of com.google.javascript.rhino.InputId in project closure-compiler by google.
the class TypedScopeCreatorTest method createEmptyRoot.
private static Node createEmptyRoot() {
Node root = new Node(Token.ROOT, new Node(Token.SCRIPT));
root.getFirstChild().setInputId(new InputId("input"));
return root;
}
use of com.google.javascript.rhino.InputId 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;
}
use of com.google.javascript.rhino.InputId in project closure-compiler by google.
the class CompilerTest method testNormalInputs.
public void testNormalInputs() {
CompilerOptions options = new CompilerOptions();
Compiler compiler = new Compiler();
List<SourceFile> inputs = ImmutableList.of(SourceFile.fromCode("in1", ""), SourceFile.fromCode("in2", ""));
compiler.compile(EMPTY_EXTERNS, inputs, options);
assertTrue(compiler.getInput(new InputId("externs")).isExtern());
assertFalse(compiler.getInput(new InputId("in1")).isExtern());
assertFalse(compiler.getInput(new InputId("in2")).isExtern());
}
use of com.google.javascript.rhino.InputId in project closure-compiler by google.
the class SimpleReplaceScriptTest method testInferWithModules.
public void testInferWithModules() {
CompilerOptions options = getOptions();
Compiler compiler = new Compiler();
List<SourceFile> inputs = ImmutableList.of(SourceFile.fromCode("in", ""));
Result result = compiler.compile(EXTVAR_EXTERNS, inputs, options);
assertTrue(result.success);
CompilerInput oldInput = compiler.getInput(new InputId("in"));
JSModule myModule = oldInput.getModule();
assertThat(myModule.getInputs()).hasSize(1);
SourceFile newSource = SourceFile.fromCode("in", "var x;");
JsAst ast = new JsAst(newSource);
compiler.replaceScript(ast);
assertThat(myModule.getInputs()).hasSize(1);
assertThat(myModule.getInputs()).doesNotContain(oldInput);
assertThat(myModule.getInputs()).containsExactly(compiler.getInput(new InputId("in")));
}
Aggregations