use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class SoyFileSet method compileForServerRendering.
/**
* Runs common compiler logic shared by tofu and jbcsrc backends.
*/
private ServerCompilationPrimitives compileForServerRendering() {
ParseResult result = parse(SyntaxVersion.V2_0);
throwIfErrorsPresent();
SoyFileSetNode soyTree = result.fileSet();
TemplateRegistry registry = result.registry();
// which case it is pointless.
if (cache == null) {
new ClearSoyDocStringsVisitor().exec(soyTree);
}
throwIfErrorsPresent();
return new ServerCompilationPrimitives(registry, soyTree);
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class SoyFileSet method compileToJsSrc.
/**
* Compiles this Soy file set into JS source code files and returns these JS files as a list of
* strings, one per file.
*
* @param jsSrcOptions The compilation options for the JS Src output target.
* @param msgBundle The bundle of translated messages, or null to use the messages from the Soy
* source.
* @return A list of strings where each string represents the JS source code that belongs in one
* JS file. The generated JS files correspond one-to-one to the original Soy source files.
* @throws SoyCompilationException If compilation fails.
*/
@SuppressWarnings("deprecation")
public List<String> compileToJsSrc(SoyJsSrcOptions jsSrcOptions, @Nullable SoyMsgBundle msgBundle) {
ParseResult result = preprocessJsSrcResults(jsSrcOptions);
TemplateRegistry registry = result.registry();
SoyFileSetNode fileSet = result.fileSet();
List<String> generatedSrcs = new JsSrcMain(apiCallScopeProvider, typeRegistry).genJsSrc(fileSet, registry, jsSrcOptions, msgBundle, errorReporter);
throwIfErrorsPresent();
reportWarnings();
return generatedSrcs;
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class FindTransitiveDepTemplatesVisitorTest method testTwoPathsToSameRecursiveCycle.
@Test
public void testTwoPathsToSameRecursiveCycle() {
// aaa -> {bbb, ccc}, bbb -> ddd, ccc -> ddd, ddd -> bbb.
String fileContent = "" + "{namespace ns}\n" + "\n" + "/***/\n" + "{template .aaa}\n" + " {$ij.boo} {$ij.foo} {call .bbb /} {call .ccc /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .bbb}\n" + " {$ij.boo} {$ij.goo} {call .ddd /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .ccc}\n" + " {$ij.boo} {$ij.moo} {call .ddd /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .ddd}\n" + " {$ij.boo} {$ij.too} {call .bbb /}\n" + "{/template}\n";
ParseResult result = SoyFileSetParserBuilder.forFileContents(fileContent).errorReporter(FAIL).parse();
TemplateRegistry templateRegistry = result.registry();
SoyFileSetNode soyTree = result.fileSet();
TemplateNode aaa = soyTree.getChild(0).getChild(0);
TemplateNode bbb = soyTree.getChild(0).getChild(1);
TemplateNode ccc = soyTree.getChild(0).getChild(2);
TemplateNode ddd = soyTree.getChild(0).getChild(3);
// Test with exec(aaa).
// Exercises: processCalleeHelper case 4 with incorporateCalleeVisitInfo case 4 (ccc -> ddd).
FindTransitiveDepTemplatesVisitor visitor = new FindTransitiveDepTemplatesVisitor(templateRegistry);
Map<TemplateNode, TransitiveDepTemplatesInfo> memoizedInfoMap = visitor.templateToFinishedInfoMap;
visitor.exec(aaa);
assertThat(memoizedInfoMap).hasSize(4);
assertThat(memoizedInfoMap.get(bbb).depTemplateSet).isEqualTo(ImmutableSet.of(bbb, ddd));
assertThat(memoizedInfoMap.get(ddd).depTemplateSet).isEqualTo(ImmutableSet.of(ddd, bbb));
assertThat(memoizedInfoMap.get(ccc).depTemplateSet).isEqualTo(ImmutableSet.of(ccc, ddd, bbb));
assertThat(memoizedInfoMap.get(aaa).depTemplateSet).isEqualTo(ImmutableSet.of(aaa, bbb, ccc, ddd));
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class FindTransitiveDepTemplatesVisitorTest method testSimpleRecursion.
@Test
public void testSimpleRecursion() {
// Tests direct recursion (cycle of 1) and indirect recursion with a cycle of 2.
// aaa -> bbb, bbb -> {bbb, ccc}, ccc -> bbb.
String fileContent = "" + "{namespace ns}\n" + "\n" + "/***/\n" + "{template .aaa}\n" + " {call .bbb /} {$ij.boo} {$ij.foo}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .bbb}\n" + " {$ij.boo} {$ij.goo} {call .bbb /} {call .ccc /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .ccc}\n" + " {$ij.boo} {call .bbb /} {$ij.moo}\n" + "{/template}\n";
ParseResult result = SoyFileSetParserBuilder.forFileContents(fileContent).errorReporter(FAIL).parse();
TemplateRegistry templateRegistry = result.registry();
SoyFileSetNode soyTree = result.fileSet();
TemplateNode aaa = soyTree.getChild(0).getChild(0);
TemplateNode bbb = soyTree.getChild(0).getChild(1);
TemplateNode ccc = soyTree.getChild(0).getChild(2);
// Test with exec(aaa).
// Exercises: processCalleeHelper case 2 (bbb -> bbb).
// Exercises: processCalleeHelper case 3 (ccc -> bbb).
// Exercises: processCalleeHelper case 5 with incorporateCalleeVisitInfo case 2 (bbb -> ccc).
FindTransitiveDepTemplatesVisitor visitor = new FindTransitiveDepTemplatesVisitor(templateRegistry);
Map<TemplateNode, TransitiveDepTemplatesInfo> memoizedInfoMap = visitor.templateToFinishedInfoMap;
visitor.exec(aaa);
assertThat(memoizedInfoMap).hasSize(3);
assertThat(memoizedInfoMap.get(ccc).depTemplateSet).isEqualTo(ImmutableSet.of(ccc, bbb));
assertThat(memoizedInfoMap.get(bbb).depTemplateSet).isEqualTo(ImmutableSet.of(bbb, ccc));
assertThat(memoizedInfoMap.get(aaa).depTemplateSet).isEqualTo(ImmutableSet.of(aaa, bbb, ccc));
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class ResolveExpressionTypesVisitorTest method testLegacyObjectMapLiteralWithStringKeysAsMap.
@Test
public void testLegacyObjectMapLiteralWithStringKeysAsMap() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{@param v1: int}", "{@param v2: string}", "{@param k1: string}", "{let $map: [$k1: $v1, 'b': $v2] /}", "{assertType('legacy_object_map<string,int|string>', $map)}")).declaredSyntaxVersion(SyntaxVersion.V2_0).typeRegistry(TYPE_REGISTRY).addSoyFunction(ASSERT_TYPE_FUNCTION).parse().fileSet();
assertTypes(soyTree);
}
Aggregations