[FIX] implementation of t-call's 0-index in qweb-js

Had expected regularity, had not noticed the Python version is really an
ignoble hack where the string "0" (exactly) is interpreted in a specific
manner when used in t-raw and format strings, *and nowhere else*.

Had special-cased the expression everywhere which broke e.g.
<t-set="xxx" t-value="0"/>. Reproduce Python behavior more closely,
and strongly consider swapping out both for something different e.g.
[[content]] or something like that, which doesn't cause problems in
Python but doesn't have to be so specially cased either.
This commit is contained in:
Xavier Morel 2014-10-14 16:17:04 +02:00
parent 94e7dc6050
commit b9fdb93bec
1 changed files with 9 additions and 8 deletions

View File

@ -26,12 +26,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// TODO: templates orverwritten could be called by t-call="__super__" ?
// TODO: t-set + t-value + children node == scoped variable ?
var QWeb2 = {
expressions_cache: {
// special case for template bodies, __content__ doesn't work in
// Python impl because safe_eval -> assert_no_dunder_name so use
// Python impl's magical 0 variable instead
'0': 'dict[0]',
},
expressions_cache: { },
RESERVED_WORDS: 'true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,this,typeof,eval,void,Math,RegExp,Array,Object,Date'.split(','),
ACTIONS_PRECEDENCE: 'foreach,if,call,set,esc,raw,js,debug,log'.split(','),
WORD_REPLACEMENT: {
@ -594,6 +589,12 @@ QWeb2.Element = (function() {
QWeb2.expressions_cache[e] = r;
return r;
},
format_str: function (e) {
if (e == '0') {
return 'dict[0]';
}
return this.format_expression(e);
},
string_interpolation : function(s) {
var _this = this;
if (!s) {
@ -608,7 +609,7 @@ QWeb2.Element = (function() {
// extract literal string between previous and current match
append_literal(s.slice(start, re.lastIndex - m[0].length));
// extract matched expression
r.push('(' + this.format_expression(m[2] || m[1]) + ')');
r.push('(' + this.format_str(m[2] || m[1]) + ')');
// update position of new matching
start = re.lastIndex;
}
@ -737,7 +738,7 @@ QWeb2.Element = (function() {
+ "));");
},
compile_action_raw : function(value) {
this.top("r.push(" + (this.format_expression(value)) + ");");
this.top("r.push(" + (this.format_str(value)) + ");");
},
compile_action_js : function(value) {
this.top("(function(" + value + ") {");