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

Exclude script and style tags for parsing bindings #4841

Merged
merged 3 commits into from
Sep 21, 2017
Merged
Show file tree
Hide file tree
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
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