我们正在构建一个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时缺少帮助程序名称。这就是事情正在发生的地方。我不知道车把还不知道为什么它会丢失。
谢谢, 斯科特
答案 0 :(得分:1)
在这里回答我自己的问题:显然Ember RC6与Handlebars 1.0.0不兼容。看到这个帖子(我知道它引用了RC5,但RC6中仍然存在问题):http://discuss.emberjs.com/t/ember-rc-5-is-not-working-properly-with-handlebars-1-0-0/1391
我通过樱桃选择此提交来修复它:https://github.com/emberjs/ember.js/commit/4023186ea157a8687ac611181e2ca49e5fc891d5