Skip to content

Commit

Permalink
Fix strip-whitespace for nested templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Jan 20, 2017
1 parent 345e2c5 commit a3b75eb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/lib/annotations/annotations.html
Expand Up @@ -72,11 +72,11 @@
// construct and return a list of annotation records
// by scanning `template`'s content
//
parseAnnotations: function(template) {
parseAnnotations: function(template, stripWhiteSpace) {
var list = [];
var content = template._content || template.content;
this._parseNodeAnnotations(content, list,
template.hasAttribute('strip-whitespace'));
stripWhiteSpace || template.hasAttribute('strip-whitespace'));
return list;
},

Expand Down Expand Up @@ -231,7 +231,7 @@
var next = node.nextSibling;
if (node.localName === 'template' &&
!node.hasAttribute('preserve-content')) {
this._parseTemplate(node, i, list, annote);
this._parseTemplate(node, i, list, annote, stripWhiteSpace);
}
if (node.localName == 'slot') {
node = this._replaceSlotWithContent(node);
Expand Down Expand Up @@ -295,11 +295,11 @@
// (this is both an optimization to avoid re-stamping nested template
// children and avoids a bug in Chrome where nested template children
// upgrade)
_parseTemplate: function(node, index, list, parent) {
_parseTemplate: function(node, index, list, parent, stripWhiteSpace) {
// TODO(sjmiles): simply altering the .content reference didn't
// work (there was some confusion, might need verification)
var content = document.createDocumentFragment();
content._notes = this.parseAnnotations(node);
content._notes = this.parseAnnotations(node, stripWhiteSpace);
content.appendChild(node.content);
// TODO(sjmiles): using `nar` to avoid unnecessary allocation;
// in general the handling of these arrays needs some cleanup
Expand Down
48 changes: 40 additions & 8 deletions test/unit/template-whitespace.html
Expand Up @@ -40,13 +40,13 @@
<div>A</div>
<div>B</div>
</template>

<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'no-whitespace'
});
});
});
</script>

</dom-module>
Expand All @@ -55,7 +55,7 @@

<dom-module id="no-whitespace-style">

<template strip-whitespace>
<template strip-whitespace>
<style>
:host {
display: block;
Expand All @@ -70,14 +70,14 @@
Polymer({
is: 'no-whitespace-style'
});
});
});
</script>

</dom-module>

<dom-module id="no-whitespace-nested">

<template strip-whitespace>
<template strip-whitespace>
<div>
<div>A</div>
</div>
Expand All @@ -91,14 +91,14 @@
Polymer({
is: 'no-whitespace-nested'
});
});
});
</script>

</dom-module>

<dom-module id="no-whitespace-binding">

<template strip-whitespace>
<template strip-whitespace>

<div id="text">{{text}}</div>
<div id="attr" attr$="{{attr}}">
Expand All @@ -121,7 +121,32 @@
},
is: 'no-whitespace-binding'
});
});
});
</script>

</dom-module>

<dom-module id="no-whitespace-repeat">

<template strip-whitespace>

<template is="dom-repeat" items="[[items]]">
<div></div>
</template>

</template>

<script>
HTMLImports.whenReady(function() {
Polymer({
properties: {
items: {
value: function() { return [1, 2, 3]}
}
},
is: 'no-whitespace-repeat'
});
});
</script>

</dom-module>
Expand Down Expand Up @@ -169,6 +194,13 @@
assert.equal(el.$.compound.textContent, ' a b ');
});

test('template with dom-repeat stamped without whitespace when strip-template is used', function() {
var el = document.createElement('no-whitespace-repeat');
document.body.appendChild(el);
Polymer.dom.flush();
assert.equal(Polymer.dom(el.root).childNodes.length, 4);
});

});

</script>
Expand Down

0 comments on commit a3b75eb

Please sign in to comment.