Skip to content

Commit

Permalink
Merge pull request #4841 from Polymer/exclude-style-script-bindings
Browse files Browse the repository at this point in the history
Exclude script and style tags for parsing bindings
  • Loading branch information
Steve Orvell authored Sep 21, 2017
2 parents ac16d54 + d5b6bad commit 6af12ac
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/mixins/template-stamp.html
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@
* @param {!NodeInfo} nodeInfo Node metadata for current template.
*/
static _parseTemplateChildNodes(root, templateInfo, nodeInfo) {
if (root.localName === 'script' || root.localName === 'style') {
return;
}
for (let node=root.firstChild, parentIndex=0, next; node; node=next) {
// Wrap templates
if (node.localName == 'template') {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/property-effects-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@
literal1 {{cpnd1}} literal2 {{cpnd2}}{{cpnd3.prop}} literal3 {{computeCompound(cpnd4, cpnd5, 'literalComputed')}} literal4
</div>
<span id="boundWithDash">{{objectWithDash.binding-with-dash}}</span>
<script id="scriptWithBinding">
/* eslint-disable no-unused-vars */
function foo() {
return "We have a {{binding}} here";
}
/* eslint-enable no-unused-vars */
</script>
<style id="styleWithBinding">
:host {
content: '[[binding]]'
}
</style>
</template>
<script>
let ComputingBehavior = {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,21 @@
assert.equal(el.lateBoundObserver.firstCall.args[0], 'late');
});

test('does not parse bindings inside <script>', function() {
assert.include(el.$.scriptWithBinding.textContent, "{{binding}}");
});

test('does not parse bindings inside <style>', function() {
var style = el.shadowRoot.querySelector('style');
// native shadow dom
if (style) {
assert.include(style.textContent, "[[binding]]");
// shady dom
} else {
assert.include(document.querySelector('[scope="x-basic"]').textContent, "[[binding]]");
}
});

});

suite('computed bindings with dynamic functions', function() {
Expand Down

0 comments on commit 6af12ac

Please sign in to comment.