Skip to content

Commit

Permalink
Accept no-arg computed fns as static. Fixes #1516.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed May 22, 2015
1 parent 42eaedd commit c001344
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/standard/effectBuilder.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,27 @@
_parseMethod: function(expression) {
var m = expression.match(/(\w*)\((.*)\)/);
if (m) {
// replace escaped commas with comma entity, split on un-escaped commas
var args = m[2].replace(/\\,/g, ',').split(',');
return this._parseArgs(args, { method: m[1], static: true });
var sig = { method: m[1], static: true };
if (m[2].trim()) {
// replace escaped commas with comma entity, split on un-escaped commas
var args = m[2].replace(/\\,/g, ',').split(',');
return this._parseArgs(args, sig);
} else {
sig.args = Polymer.nar;
return sig;
}
}
},

_parseArgs: function(argList, effect) {
effect.args = argList.map(function(rawArg) {
_parseArgs: function(argList, sig) {
sig.args = argList.map(function(rawArg) {
var arg = this._parseArg(rawArg);
if (!arg.literal) {
effect.static = false;
sig.static = false;
}
return arg;
}, this);
return effect;
return sig;
},

_parseArg: function(rawArg) {
Expand Down
4 changes: 4 additions & 0 deletions test/unit/bind-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
computed-from-pure-literals='{{computeFromLiterals( 3, "foo")}}'
computed-from-tricky-literals="{{computeFromTrickyLiterals(3, 'tricky\,\'zot\'')}}"
computed-from-tricky-literals2='{{computeFromTrickyLiterals(3,"tricky\,\'zot\'" )}}'
computed-from-no-args="{{computeFromNoArgs( )}}"
>
Test
</div>
Expand Down Expand Up @@ -198,6 +199,9 @@
},
computeFromTrickyLiterals: function(a, b) {
return a + b;
},
computeFromNoArgs: function() {
return 'no args!';
}
});
</script>
Expand Down
4 changes: 4 additions & 0 deletions test/unit/bind.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@
assert.equal(el.$.computedContent.textContent, '3tricky,\'zot\'', 'Wrong textContent from tricky literal arg computation');
});

test('computed annotation with no args', function() {
assert.equal(el.$.boundChild.computedFromNoArgs, 'no args!', 'Wrong content when computed has no args');
});

test('no read-only observer called with assignment', function() {
el.readolyvalue = 46;
assert.equal(el.observerCounts.readonlyvalueChanged, 0, 'observer should not be called for readOnly prop assignment');
Expand Down

0 comments on commit c001344

Please sign in to comment.