dynakeys: `{(x), y}` now compiles correctly
This commit is contained in:
parent
863f3f6b47
commit
0d6d221568
20
lib/nodes.js
20
lib/nodes.js
|
@ -703,23 +703,27 @@
|
||||||
return this.tags.front ? "(" + obj + ")" : obj;
|
return this.tags.front ? "(" + obj + ")" : obj;
|
||||||
};
|
};
|
||||||
Obj.prototype.compileDynamic = function(o, idx) {
|
Obj.prototype.compileDynamic = function(o, idx) {
|
||||||
var _len, _ref2, _ref3, code, i, key, obj, prop, ref, sub;
|
var _len, _ref2, _ref3, acc, code, i, key, obj, prop, ref, val;
|
||||||
obj = o.scope.freeVariable('obj');
|
obj = o.scope.freeVariable('obj');
|
||||||
code = "" + obj + " = " + (new Obj(this.properties.slice(0, idx)).compile(o)) + ", ";
|
code = "" + obj + " = " + (new Obj(this.properties.slice(0, idx)).compile(o)) + ", ";
|
||||||
_ref2 = this.properties.slice(idx);
|
_ref2 = this.properties.slice(idx);
|
||||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||||
prop = _ref2[i];
|
prop = _ref2[i];
|
||||||
if (prop instanceof Assign) {
|
|
||||||
key = prop.variable.compile(o, LEVEL_PAREN);
|
|
||||||
code += "" + obj + "[" + key + "] = " + (prop.value.compile(o, LEVEL_LIST)) + ", ";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (prop instanceof Comment) {
|
if (prop instanceof Comment) {
|
||||||
code += prop.compile(o) + ' ';
|
code += prop.compile(o) + ' ';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_ref3 = prop.base.cache(o, LEVEL_LIST, ref), sub = _ref3[0], ref = _ref3[1];
|
if (prop instanceof Assign) {
|
||||||
code += "" + obj + "[" + sub + "] = " + ref + ", ";
|
acc = prop.variable.base;
|
||||||
|
key = acc.compile(o, LEVEL_PAREN);
|
||||||
|
val = prop.value.compile(o, LEVEL_LIST);
|
||||||
|
} else {
|
||||||
|
acc = prop.base;
|
||||||
|
_ref3 = acc.cache(o, LEVEL_LIST, ref), key = _ref3[0], val = _ref3[1];
|
||||||
|
ref = val;
|
||||||
|
}
|
||||||
|
key = acc instanceof Literal && IDENTIFIER.test(key) ? '.' + key : '[' + key + ']';
|
||||||
|
code += "" + obj + key + " = " + val + ", ";
|
||||||
}
|
}
|
||||||
code += obj;
|
code += obj;
|
||||||
return o.level <= LEVEL_PAREN ? code : "(" + code + ")";
|
return o.level <= LEVEL_PAREN ? code : "(" + code + ")";
|
||||||
|
|
|
@ -588,15 +588,22 @@ exports.Obj = class Obj extends Base
|
||||||
obj = o.scope.freeVariable 'obj'
|
obj = o.scope.freeVariable 'obj'
|
||||||
code = "#{obj} = #{ new Obj(@properties.slice 0, idx).compile o }, "
|
code = "#{obj} = #{ new Obj(@properties.slice 0, idx).compile o }, "
|
||||||
for prop, i in @properties.slice idx
|
for prop, i in @properties.slice idx
|
||||||
if prop instanceof Assign
|
|
||||||
key = prop.variable.compile o, LEVEL_PAREN
|
|
||||||
code += "#{obj}[#{key}] = #{ prop.value.compile o, LEVEL_LIST }, "
|
|
||||||
continue
|
|
||||||
if prop instanceof Comment
|
if prop instanceof Comment
|
||||||
code += prop.compile(o) + ' '
|
code += prop.compile(o) + ' '
|
||||||
continue
|
continue
|
||||||
[sub, ref] = prop.base.cache o, LEVEL_LIST, ref
|
if prop instanceof Assign
|
||||||
code += "#{obj}[#{sub}] = #{ref}, "
|
acc = prop.variable.base
|
||||||
|
key = acc.compile o, LEVEL_PAREN
|
||||||
|
val = prop.value.compile o, LEVEL_LIST
|
||||||
|
else
|
||||||
|
acc = prop.base
|
||||||
|
[key, val] = acc.cache o, LEVEL_LIST, ref
|
||||||
|
ref = val
|
||||||
|
key = if acc instanceof Literal and IDENTIFIER.test key
|
||||||
|
'.' + key
|
||||||
|
else
|
||||||
|
'[' + key + ']'
|
||||||
|
code += "#{obj}#{key} = #{val}, "
|
||||||
code += obj
|
code += obj
|
||||||
if o.level <= LEVEL_PAREN then code else "(#{code})"
|
if o.level <= LEVEL_PAREN then code else "(#{code})"
|
||||||
|
|
||||||
|
|
|
@ -235,12 +235,19 @@ obj = {
|
||||||
(4 * 2): 8
|
(4 * 2): 8
|
||||||
### cached shorthand ###
|
### cached shorthand ###
|
||||||
(++i)
|
(++i)
|
||||||
"#{'interpolated'}": """#{"key"}""": 123
|
### normal keys ###
|
||||||
|
key: ok
|
||||||
|
's': ok
|
||||||
|
0.0: ok
|
||||||
|
|
||||||
|
"#{'interpolated'}":
|
||||||
|
"""#{"nested"}""": 123: 456
|
||||||
### traling comment ###
|
### traling comment ###
|
||||||
}
|
}
|
||||||
eq obj.interpolated.key, 123
|
eq obj.interpolated.nested[123], 456
|
||||||
eq obj[8], 8
|
eq obj[8], 8
|
||||||
eq obj[1], 1
|
eq obj[1], 1
|
||||||
|
ok obj.key is obj.s is obj[0]
|
||||||
|
|
||||||
eq 'braceless dynamic key',
|
eq 'braceless dynamic key',
|
||||||
(key for key of """braceless #{ 0 of ((0):(0)) and 'dynamic' } key""": 0)[0]
|
(key for key of """braceless #{ 0 of ((0):(0)) and 'dynamic' } key""": 0)[0]
|
||||||
|
|
Loading…
Reference in New Issue