Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't trap id for marshalling if it's a binding directive + test #1474

Merged
merged 1 commit into from
May 1, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
don't trap id for marshalling if it's a binding directive + test
  • Loading branch information
Scott J Miles committed May 1, 2015
commit 12513df2e19b457e25167750893cc379d5dab7dd
25 changes: 17 additions & 8 deletions src/lib/annotations/annotations.html
Original file line number Diff line number Diff line change
@@ -89,10 +89,18 @@
this._parseElementAnnotations(node, list);
},

_testEscape: function(value) {
var escape = value.slice(0, 2);
if (escape === '{{' || escape === '[[') {
return escape;
}
},

// add annotations gleaned from TextNode `node` to `list`
_parseTextNodeAnnotation: function(node, list) {
var v = node.textContent, escape = v.slice(0, 2);
if (escape === '{{' || escape === '[[') {
var v = node.textContent;
var escape = this._testEscape(v);
if (escape) {
// NOTE: use a space here so the textNode remains; some browsers
// (IE) evacipate an empty textNode.
node.textContent = ' ';
@@ -242,8 +250,8 @@
_parseNodeAttributeAnnotations: function(node, annotation) {
for (var i=node.attributes.length-1, a; (a=node.attributes[i]); i--) {
var n = a.name, v = a.value;
// id
if (n === 'id') {
// id (unless actually an escaped binding annotation)
if (n === 'id' && !this._testEscape(v)) {
annotation.id = v;
}
// events (on-*)
@@ -266,10 +274,12 @@

// construct annotation data from a generic attribute, or undefined
_parseNodeAttributeAnnotation: function(node, n, v) {
var mode = '', escape = v.slice(0, 2), name = n;
if (escape === '{{' || escape === '[[') {
var escape = this._testEscape(v);
if (escape) {
// Cache name (`n` will be mangled)
var name = n;
// Mode (one-way or two)
mode = escape[0];
var mode = escape[0];
v = v.slice(2, -2);
// Negate
var not = false;
@@ -327,5 +337,4 @@

};


</script>
9 changes: 7 additions & 2 deletions test/unit/bind-elements.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div id="boundChild"
<div id="boundChild"
value="{{value}}"
negvalue="{{!bool}}"
attrvalue$="{{attrvalue}}"
@@ -15,6 +15,7 @@
custom-event-object-value="{{customEventObject.value::change}}">
Test
</div>
<span id="{{boundId}}"></span>
</template>
<script>
Polymer({
@@ -72,6 +73,10 @@
customEventObject: {
type: Object,
value: function() { return {}; }
},
boundId: {
type: String,
value: 'span'
}
},
observers: [
@@ -182,7 +187,7 @@
</script>

<template>
<x-basic id="basic1"
<x-basic id="basic1"
value="{{boundvalue}}"
notifyingvalue="{{boundnotifyingvalue}}"
camel-notifying-value="{{boundnotifyingvalue}}"
13 changes: 7 additions & 6 deletions test/unit/bind.html
Original file line number Diff line number Diff line change
@@ -32,6 +32,10 @@
document.body.removeChild(el);
});

test('id is bindable', function() {
assert.equal(Polymer.dom(el.root).querySelector('span').id, 'span', 'id bound to <span> not found');
});

test('camel-case binding updates', function() {
el.value = 41;
assert.equal(el.$.boundChild.camelCase, 41, 'Value not propagated to camelCase property');
@@ -171,12 +175,9 @@
});

test('annotated dataset attribute binding', function() {
// IE10, sigh
if (el.dataset) {
el.dataSetId = 'yeah';
assert.equal(el.$.boundChild.dataset.id, 'yeah', 'dataset.id dataset property not set correctly');
assert.equal(el.$.boundChild.getAttribute('data-id'), 'yeah', 'data-id attribute not set correctly');
}
el.dataSetId = 'yeah';
assert.equal(el.$.boundChild.dataset.id, 'yeah', 'dataset.id dataset property not set correctly');
assert.equal(el.$.boundChild.getAttribute('data-id'), 'yeah', 'data-id attribute not set correctly');
});

test('custom notification event to property', function() {