use of com.google.template.soy.msgs.internal.InsertMsgsVisitor in project closure-templates by google.
the class JsSrcMain method genJsSrc.
/**
* Generates JS source code given a Soy parse tree, an options object, and an optional bundle of
* translated messages.
*
* @param soyTree The Soy parse tree to generate JS source code for.
* @param templateRegistry The template registry that contains all the template information.
* @param jsSrcOptions The compilation options relevant to this backend.
* @param msgBundle The bundle of translated messages, or null to use the messages from the Soy
* source.
* @param errorReporter The Soy error reporter that collects errors during code generation.
* @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.
*/
public List<String> genJsSrc(SoyFileSetNode soyTree, TemplateRegistry templateRegistry, SoyJsSrcOptions jsSrcOptions, @Nullable SoyMsgBundle msgBundle, ErrorReporter errorReporter) {
// VeLogInstrumentationVisitor add html attributes for {velog} commands and also run desugaring
// pass since code generator does not understand html nodes (yet).
new VeLogInstrumentationVisitor(templateRegistry).exec(soyTree);
try (GuiceSimpleScope.InScope inScope = apiCallScope.enter()) {
// Seed the scoped parameters.
BidiGlobalDir bidiGlobalDir = SoyBidiUtils.decodeBidiGlobalDirFromJsOptions(jsSrcOptions.getBidiGlobalDir(), jsSrcOptions.getUseGoogIsRtlForBidiGlobalDir());
ApiCallScopeUtils.seedSharedParams(inScope, msgBundle, bidiGlobalDir);
// Replace MsgNodes.
if (jsSrcOptions.shouldGenerateGoogMsgDefs()) {
Preconditions.checkState(bidiGlobalDir != null, "If enabling shouldGenerateGoogMsgDefs, must also set bidi global directionality.");
} else {
Preconditions.checkState(bidiGlobalDir == null || bidiGlobalDir.isStaticValue(), "If using bidiGlobalIsRtlCodeSnippet, must also enable shouldGenerateGoogMsgDefs.");
new InsertMsgsVisitor(msgBundle, errorReporter).insertMsgs(soyTree);
}
// Combine raw text nodes before codegen.
new CombineConsecutiveRawTextNodesPass().run(soyTree);
return createVisitor(jsSrcOptions, typeRegistry).gen(soyTree, templateRegistry, errorReporter);
}
}
Aggregations