From 092a9d01e516e6d8545474b850403a841020663a Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Thu, 29 Oct 2015 23:51:30 +0100 Subject: [PATCH] Fix for overriding mixin properties, fixes #1873 --- src/lib/css-parse.html | 25 ++++++++++------ test/unit/css-parse.html | 4 +-- test/unit/styling-scoped-elements.html | 40 ++++++++++++++++++++++++++ test/unit/styling-scoped.html | 12 +++++++- 4 files changed, 69 insertions(+), 12 deletions(-) diff --git a/src/lib/css-parse.html b/src/lib/css-parse.html index 866d5f219a..b47228f8c7 100644 --- a/src/lib/css-parse.html +++ b/src/lib/css-parse.html @@ -113,15 +113,20 @@ if (cssText) { if (node.selector) { text += node.selector; - if ( - !Polymer.Settings.useNativeShadow && - !node.parent.type && - this._rx.tagName.test(node.selector) - ) { + if (!Polymer.Settings.useNativeShadow && !node.parent.type) { var selector = node.selector.split(' '); - // `Polymer.StyleProperties.XSCOPE_NAME` just to increase specificity - selector[0] += '.' + Polymer.StyleProperties.XSCOPE_NAME; - text += ', ' + selector.join(' '); + var styleProperties = Polymer.StyleProperties; + // `styleProperties.XSCOPE_NAME` just to increase specificity + if (this._rx.tagName.test(node.selector)) { + selector[0] += '.' + styleProperties.XSCOPE_NAME; + text += ', ' + selector.join(' '); + } else if ( + selector[0].indexOf(this.HOST) === -1 && + selector[0].indexOf(styleProperties.XSCOPE_NAME) === -1 + ) { + selector[0] = '.' + styleProperties.XSCOPE_NAME + ' ' + selector[0]; + text += ', ' + selector.join(' '); + } } text += ' ' + this.OPEN_BRACE + '\n'; } @@ -178,7 +183,9 @@ VAR_START: '--', MEDIA_START: '@media', - AT_START: '@' + AT_START: '@', + + HOST: ':host' }; diff --git a/test/unit/css-parse.html b/test/unit/css-parse.html index 36172ae7ef..7b5856044d 100644 --- a/test/unit/css-parse.html +++ b/test/unit/css-parse.html @@ -105,7 +105,7 @@ }); test('rules stringify', function() { - var orig = sanitizeCss(s.textContent); + var orig = sanitizeCss(':host { background: red; } .foo .bar .baz, zonk[happy]:focus, .x-scope .foo .bar .baz, zonk[happy]:focus { font-family: sans-serif; font-size: 15px; } @-webkit-keyframes fill-unfill-rotate, .x-scope @-webkit-keyframes fill-unfill-rotate { 12.5% { transform: rotate(135deg); } 25% { transform: rotate(270deg); } 37.5% { transform: rotate(405deg); } 50% { transform: rotate(540deg); } 62.5% { transform: rotate(675deg); } 75% { transform: rotate(810deg); } 87.5% { transform: rotate(945deg); } to { transform: rotate(1080deg); } } @media (max-width: 400px), .x-scope @media (max-width: 400px) { div { margin-left: 0 !important; } }'); var result = sanitizeCss(css.stringify(tree)); assert.equal(result, orig, 'unexpected stringified output'); }); @@ -116,7 +116,7 @@ assert.equal(t.rules[0].selector, '.stuff', 'unexpected rule selector'); assert.equal(t.rules[0].cssText, 'background: red;', 'unexpected rule cssText'); var result = sanitizeCss(css.stringify(t)); - assert.equal(result, '.stuff { background: red; }', 'unexpected stringified output'); + assert.equal(result, '.stuff, .x-scope .stuff { background: red; }', 'unexpected stringified output'); }); }); diff --git a/test/unit/styling-scoped-elements.html b/test/unit/styling-scoped-elements.html index 9b74bfa0b6..aaba1e4753 100644 --- a/test/unit/styling-scoped-elements.html +++ b/test/unit/styling-scoped-elements.html @@ -302,3 +302,43 @@ Polymer({is: 'x-specificity'}); + + + + + + + diff --git a/test/unit/styling-scoped.html b/test/unit/styling-scoped.html index 32a321ccbf..f2a99ee12d 100644 --- a/test/unit/styling-scoped.html +++ b/test/unit/styling-scoped.html @@ -45,6 +45,7 @@ +