我们正在构建一个 Ember/Java 应用程序,并在我们的 maven 构建期间使用 Rhino 来预编译我们的 Handlebars 模板。直到今天我们还在使用 Handlebars RC3 和 Ember RC3,生活还不错。今天我们尝试更新到 Ember RC6 和 Handlebars 1.0.0,现在我们的 Rhino 预编译器给出了这个:
js: "src/main/js/third-party/handlebars-1.0.0.js", line 2024: uncaught JavaScript runtime
exception: TypeError: Cannot call method "replace" of undefined
at src/main/js/third-party/handlebars-1.0.0.js:2024
at src/main/js/third-party/handlebars-1.0.0.js:2038
at src/main/js/third-party/handlebars-1.0.0.js:1747
at src/main/js/third-party/handlebars-1.0.0.js:1368
at src/main/js/third-party/handlebars-1.0.0.js:1860
at src/main/js/third-party/handlebars-1.0.0.js:1356
at src/main/js/third-party/handlebars-1.0.0.js:1860
at src/main/js/third-party/handlebars-1.0.0.js:1356
at src/main/js/rhino-handlebars-precompiler.js:75 (precompile)
at src/main/js/rhino-handlebars-precompiler.js:89 (init)
at src/main/js/rhino-handlebars-precompiler.js:93
at src/main/js/rhino-handlebars-precompiler.js:15
我们已经尝试了我们自己的 Rhino 编译器和这里找到的那个:https ://github.com/locnguyen/ember-rhino-precompiler 。
更新
在深入研究 Handlebars 之后,似乎 Handlebars-1.0.0 产生的操作码与 Handlebars RC3 略有不同,特别是它缺少对 _triageMustache 帮助器的调用。对于这个车把片段:
{{#if enableLinks}}<a href="/foo?userId={{unbound loginAsAdminId}}&userAsId={{unbound legacyUserId}}" id="logoutAsLink">Return to {{loginAsAdminName}}</a>{{/if}}
使用 RC3,我们得到:
in compile appendContent "<a href="/userportal/returnToAdmin?userId="
getContext 0
pushStringParam "loginAsAdminId" "ID"
pushProgram
pushProgram
emptyHash
invokeKnownHelper 1 "unbound"
appendEscaped
appendContent "&userAsId="
getContext 0
pushStringParam "legacyUserId" "ID"
pushProgram
pushProgram
emptyHash
invokeKnownHelper 1 "unbound"
appendEscaped
appendContent "" id="logoutAsLink">Return to "
getContext 0
pushStringParam "loginAsAdminName" "ID"
pushProgram
pushProgram
emptyHash
invokeKnownHelper 1 "_triageMustache"
appendEscaped
appendContent "</a>"
使用 1.0.0,我们得到:
in compile appendContent "<a href="/userportal/returnToAdmin?userId="
getContext 0
pushStringParam "loginAsAdminId" "ID"
pushProgram
pushProgram
emptyHash
invokeKnownHelper 1 "unbound"
appendEscaped
appendContent "&userAsId="
getContext 0
pushStringParam "legacyUserId" "ID"
pushProgram
pushProgram
emptyHash
invokeKnownHelper 1 "unbound"
appendEscaped
appendContent "" id="logoutAsLink">Return to "
getContext 0
pushStringParam "loginAsAdminName" "ID"
pushProgram
pushProgram
emptyHash
invokeHelper 1
appendEscaped
appendContent "</a>"
请注意,最后一次调用 invokeHelper 缺少帮助程序名称。那就是事情正在下降的地方。我对车把的了解还不够深入,无法弄清楚为什么它会丢失。
谢谢,斯科特