我最近从 GitHub 中提取了一个项目,该项目在其 build.xml 中包含了一个 compile-soy 任务。该任务使用 SoyToJsSrcCompiler.jar 将几个大豆文件编译成 javascript。该项目包含目标目录,因此我可以看到编译后的文件包含如下代码:
jive.fbldr.soy.attachments = function(opt_data, opt_sb) {
var output = opt_sb || new soy.StringBuilder();
output.append('<div class="fbldr-attachments"><div class="fbldr-attach-head"><p>Use the following form to upload file attachments and, optionally, include a variable to reference the uploaded file in the form\'s HTML source.</p><p>Multiple files may be attached, but only one at a time. Click "Finished" when all files have been attached.</p></div><div class="fbldr-attach-field"><label>Link to HTML Variable (optional) : </label></div><div class="fbldr-attach-field"><select id="fbldr-attach-link"><option value="" selected="selected">Select HTML variable...</option>');
var optionList34 = opt_data.variables;
var optionListLen34 = optionList34.length;
当我在没有任何代码更改的情况下运行相同的任务时,生成的编译结果会不断用 opt_ignored 替换 opt_sb 并删除对 soy.StringBuilder 的所有引用。我手动运行“java -jar lib/SoyToJsSrcCompiler.jar --outputPathFormat target/soy2/fbldr.soy templates/fbldr.soy”,而不是使用build.xml。我得到相同的结果。
jive.fbldr.soy.attachments = function(opt_data, opt_ignored) {
var output = '<div class="fbldr-attachments"><div class="fbldr-attach-head"><p>Use the following form to upload file attachments and, optionally, include a variable to reference the uploaded file in the form\'s HTML source.</p><p>Multiple files may be attached, but only one at a time. Click "Finished" when all files have been attached.</p></div><div class="fbldr-attach-field"><label>Link to HTML Variable (optional) : </label></div><div class="fbldr-attach-field"><select id="fbldr-attach-link"><option value="" selected="selected">Select HTML variable...</option>';
var optionList4 = opt_data.variables;
var optionListLen4 = optionList4.length;
从我读过的所有闭包模板文档中,预计输出将使用 StringBuilder。我无法弄清楚为什么我的调用不断生成忽略 StringBuilder 的输出。有人会碰巧知道是什么原因造成的吗?