Skip to content

Commit 7dcb47f

Browse files
committed
Simplification, fix for BC breaks, reverting modified tests, more tests added
1 parent e3798e1 commit 7dcb47f

File tree

4 files changed

+55
-29
lines changed

4 files changed

+55
-29
lines changed

src/lib/css-parse.html

+3-25
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,7 @@
126126
// emit rule if there is cssText
127127
if (cssText) {
128128
if (node.selector) {
129-
text += node.selector;
130-
if (!Polymer.Settings.useNativeShadow && !node.parent.type) {
131-
var selector = node.selector.split(' ');
132-
var styleProperties = Polymer.StyleProperties;
133-
// `styleProperties.XSCOPE_NAME` just to increase specificity
134-
if (this._rx.tagName.test(node.selector)) {
135-
if (!this._rx.scopedSelector.test(selector[0])) {
136-
selector[0] += '.' + styleProperties.XSCOPE_NAME;
137-
text += ', ' + selector.join(' ');
138-
}
139-
} else if (
140-
selector[0].indexOf(this.HOST) === -1 &&
141-
selector[0].indexOf(styleProperties.XSCOPE_NAME) === -1
142-
) {
143-
selector[0] = '.' + styleProperties.XSCOPE_NAME + ' ' + selector[0];
144-
text += ', ' + selector.join(' ');
145-
}
146-
}
147-
text += ' ' + this.OPEN_BRACE + '\n';
129+
text += node.selector + ' ' + this.OPEN_BRACE + '\n';
148130
}
149131
text += cssText;
150132
if (node.selector) {
@@ -194,16 +176,12 @@
194176
mixinApply: /@apply[\s]*\([^)]*?\)[\s]*(?:[;\n]|$)?/gim,
195177
varApply: /[^;:]*?:[^;]*?var\([^;]*\)(?:[;\n]|$)?/gim,
196178
keyframesRule: /^@[^\s]*keyframes/,
197-
multipleSpaces: /\s+/g,
198-
tagName: /^[a-z]/i,
199-
scopedSelector: /^([a-z\-]+)\.\1/i
179+
multipleSpaces: /\s+/g
200180
},
201181

202182
VAR_START: '--',
203183
MEDIA_START: '@media',
204-
AT_START: '@',
205-
206-
HOST: ':host'
184+
AT_START: '@'
207185

208186
};
209187

test/unit/css-parse.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
});
144144

145145
test('rules stringify', function() {
146-
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; } }');
146+
var orig = sanitizeCss(s.textContent);
147147
var result = sanitizeCss(css.stringify(tree));
148148
assert.equal(result, orig, 'unexpected stringified output');
149149
});
@@ -154,7 +154,7 @@
154154
assert.equal(t.rules[0].selector, '.stuff', 'unexpected rule selector');
155155
assert.equal(t.rules[0].cssText, 'background: red;', 'unexpected rule cssText');
156156
var result = sanitizeCss(css.stringify(t));
157-
assert.equal(result, '.stuff, .x-scope .stuff { background: red; }', 'unexpected stringified output');
157+
assert.equal(result, '.stuff { background: red; }', 'unexpected stringified output');
158158
});
159159

160160
test('short escape sequences', function() {
@@ -166,7 +166,8 @@
166166
assert.equal(t.rules[3].selector, '.\\0c3333d-model');
167167
assert.equal(t.rules[4].selector, '.\\d33333d-model');
168168
assert.equal(t.rules[5].selector, '.\\e33333d-model');
169-
});
169+
});
170+
170171
test('multiple consequent spaces in CSS selector', function() {
171172
var s4 = document.querySelector('#multiple-spaces');
172173
var t = css.parse(s4.textContent);

test/unit/styling-scoped-elements.html

+40
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,53 @@
303303
</script>
304304
</dom-module>
305305

306+
<style is="custom-style">
307+
:root {
308+
--x-specificity-parent : {
309+
border: 10px solid blue;
310+
};
311+
--x-specificity-nested : {
312+
border: 3px solid red;
313+
};
314+
}
315+
</style>
316+
317+
<dom-module id="x-specificity-parent">
318+
<template>
319+
<style>
320+
/* TODO remove `:host` when https://github.com/Polymer/polymer/pull/2419 merged */
321+
:host ::content > :not(template) {
322+
@apply(--x-specificity-parent);
323+
}
324+
</style>
325+
<content></content>
326+
</template>
327+
<script>
328+
Polymer({is: 'x-specificity-parent', extends: 'div'});
329+
</script>
330+
</dom-module>
331+
332+
<dom-module id="x-specificity-nested">
333+
<template>
334+
<style>
335+
:host {
336+
@apply(--x-specificity-nested);
337+
}
338+
</style>
339+
</template>
340+
<script>
341+
Polymer({is: 'x-specificity-nested', extends: 'div'});
342+
</script>
343+
</dom-module>
344+
306345
<style is="custom-style">
307346
:root {
308347
--x-overriding : {
309348
border-top: 1px solid red;
310349
}
311350
}
312351
</style>
352+
313353
<dom-module id="x-overriding">
314354
<template>
315355
<style>

test/unit/styling-scoped.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545

4646
<x-specificity></x-specificity>
4747
<x-specificity class="bar"></x-specificity>
48+
<div is="x-specificity-parent">
49+
<div is="x-specificity-nested"></div>
50+
</div>
4851
<x-overriding></x-overriding>
4952

5053
<script>
@@ -205,7 +208,7 @@
205208
var s$ = document.head.querySelectorAll('style[scope]');
206209
var expected = ['x-gchild', 'x-child2', 'x-styled', 'x-button', 'x-mixed-case',
207210
'x-mixed-case-button', 'x-dynamic-scope', 'x-specificity', 'x-overriding',
208-
'x-overriding-0'];
211+
'x-overriding-0', 'x-specificity-parent-0', 'x-specificity-nested-0'];
209212
var actual = [];
210213
for (var i=0; i<s$.length; i++) {
211214
actual.push(s$[i].getAttribute('scope'));
@@ -253,6 +256,10 @@
253256
assertComputed(document.querySelector('x-specificity.bar'), '2px');
254257
});
255258

259+
test('specificity of ::content > :not(template) selector', function() {
260+
assertComputed(document.querySelector('[is=x-specificity-nested]'), '10px');
261+
});
262+
256263
test('overwriting mixin properties', function() {
257264
var root = document.querySelector('x-overriding');
258265
assertComputed(root.querySelector('.red'), '1px');

0 commit comments

Comments
 (0)