use of com.google.javascript.rhino.SimpleSourceFile in project closure-compiler by google.
the class ParserTest method doParse.
private ParserRunner.ParseResult doParse(String string, String... warnings) {
TestErrorReporter testErrorReporter = new TestErrorReporter().expectAllWarnings(warnings);
StaticSourceFile file = new SimpleSourceFile("input", SourceKind.STRONG);
ParserRunner.ParseResult result = ParserRunner.parse(file, string, createConfig(), testErrorReporter);
// check expected features if specified
assertFS(result.features).contains(expectedFeatures);
// verifying that all warnings were seen
testErrorReporter.verifyHasEncounteredAllWarningsAndErrors();
assertSourceInfoPresent(result.ast);
return result;
}
use of com.google.javascript.rhino.SimpleSourceFile in project closure-compiler by google.
the class ParserTest method parseError.
/**
* Verify that the given code has the given parse errors.
*
* @return If in IDE mode, returns a partial tree.
*/
private Node parseError(String source, String... errors) {
TestErrorReporter testErrorReporter = new TestErrorReporter().expectAllErrors(errors);
ParseResult result = ParserRunner.parse(new SimpleSourceFile("input", SourceKind.STRONG), source, createConfig(), testErrorReporter);
Node script = result.ast;
// check expected features if specified
assertFS(result.features).contains(expectedFeatures);
// verifying that all errors were seen
testErrorReporter.verifyHasEncounteredAllWarningsAndErrors();
return script;
}
use of com.google.javascript.rhino.SimpleSourceFile in project closure-compiler by google.
the class AttachJsdocsTest method parse.
private Node parse(String source, String... warnings) {
TestErrorReporter testErrorReporter = new TestErrorReporter().expectAllWarnings(warnings);
Config config = ParserRunner.createConfig(mode, Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE, Config.RunMode.KEEP_GOING, null, true, StrictMode.SLOPPY);
Node script = ParserRunner.parse(new SimpleSourceFile("input", SourceKind.STRONG), source, config, testErrorReporter).ast;
// verifying that all warnings were seen
testErrorReporter.verifyHasEncounteredAllWarningsAndErrors();
return script;
}
use of com.google.javascript.rhino.SimpleSourceFile in project closure-compiler by google.
the class JsDocInfoParserTest method parse.
private JSDocInfo parse(String comment, JsDocParsing parseDocumentation, boolean parseFileOverview, String... warnings) {
TestErrorReporter errorReporter = new TestErrorReporter().expectAllWarnings(warnings);
Config config = Config.builder().setExtraAnnotationNames(extraAnnotations).setJsDocParsingMode(parseDocumentation).setSuppressionNames(extraSuppressions).setClosurePrimitiveNames(extraPrimitives).setLanguageMode(LanguageMode.ECMASCRIPT3).setParseInlineSourceMaps(true).setStrictMode(Config.StrictMode.SLOPPY).build();
StaticSourceFile file = new SimpleSourceFile("testcode", SourceKind.STRONG);
Node templateNode = IR.script();
templateNode.setStaticSourceFile(file);
JsDocInfoParser jsdocParser = new JsDocInfoParser(stream(comment), comment, 0, templateNode, config, errorReporter);
jsdocParser.parse();
this.prevLicense = jsdocParser.getLicenseText();
errorReporter.verifyHasEncounteredAllWarningsAndErrors();
final JSDocInfo result;
if (parseFileOverview) {
result = jsdocParser.getFileOverviewJSDocInfo();
} else {
result = jsdocParser.retrieveAndResetParsedJSDocInfo();
}
if (result != null) {
assertThat(result.getTypeNodes()).comparingElementsUsing(transforming(NodeUtil::getSourceName, "has source name that")).doesNotContain(null);
}
return result;
}
use of com.google.javascript.rhino.SimpleSourceFile in project closure-compiler by google.
the class ParserRunner method detectFeatures.
// TODO(sdh): this is less useful if we end up needing the node for library version detection
public static FeatureSet detectFeatures(String sourcePath, String sourceString) {
SourceFile file = new SourceFile(sourcePath, sourceString);
ErrorReporter reporter = IRFactory.NULL_REPORTER;
com.google.javascript.jscomp.parsing.parser.Parser.Config config = newParserConfig(IRFactory.NULL_CONFIG);
Parser p = new Parser(config, new Es6ErrorReporter(reporter, false), file);
ProgramTree tree = p.parseProgram();
StaticSourceFile simpleSourceFile = new SimpleSourceFile(sourcePath, false);
return IRFactory.detectFeatures(tree, simpleSourceFile, sourceString).union(p.getFeatures());
}
Aggregations