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 48b329c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/standard/effectBuilder.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,26 @@
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()) {
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 48b329c

Please sign in to comment.