Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Commit 787ca6c

Browse files
committed
Merge pull request #245 from vicb/0313-deepc
Add support for the >>> selector in ShadowCSS
2 parents 3edbe7f + 878d628 commit 787ca6c

File tree

5 files changed

+50
-25
lines changed

5 files changed

+50
-25
lines changed

src/ShadowCSS/ShadowCSS.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,15 @@ var selectorRe = /([^{]*)({[\s\S]*?})/gim,
578578
polyfillHostRe = new RegExp(polyfillHost, 'gim'),
579579
polyfillHostContextRe = new RegExp(polyfillHostContext, 'gim'),
580580
shadowDOMSelectorsRe = [
581-
/\^\^/g,
582-
/\^/g,
583-
/\/shadow\//g,
584-
/\/shadow-deep\//g,
581+
/>>>/g,
585582
/::shadow/g,
586-
/\/deep\//g,
587-
/::content/g
583+
/::content/g,
584+
// Deprecated selectors
585+
/\/deep\//g, // former >>>
586+
/\/shadow\//g, // former ::shadow
587+
/\/shadow-deep\//g, // former /deep/
588+
/\^\^/g, // former /shadow/
589+
/\^/g // former /shadow-deep/
588590
];
589591

590592
function stylesToCssText(styles, preserveComments) {

src/ShadowDOM/querySelector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
}
5050

5151
function shimSelector(selector) {
52-
return String(selector).replace(/\/deep\/|::shadow/g, ' ');
52+
return String(selector).replace(/\/deep\/|::shadow|>>>/g, ' ');
5353
}
5454

5555
function shimMatchesSelector(selector) {
@@ -71,7 +71,7 @@
7171
)
7272
// From ShadowCSS, will be replaced by space
7373
.replace(
74-
/\^|\/shadow\/|\/shadow-deep\/|::shadow|\/deep\/|::content/g,
74+
/\^|\/shadow\/|\/shadow-deep\/|::shadow|\/deep\/|::content|>>>/g,
7575
' '
7676
);
7777
}

tests/ShadowCSS/html/combinators-shadow.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
x-bar /deep/ .zot {
4141
color: white;
4242
}
43+
44+
x-bar >>> .zot-2 {
45+
color: white;
46+
}
4347
</style>
4448
<div class="foo">orange</div>
4549
<div class="foo2">green</div>
@@ -58,6 +62,7 @@
5862

5963
<template id="x-zot">
6064
<div class="zot">Zot</div>
65+
<div class="zot-2">Zot</div>
6166
<div class="zot-inner">inner</div>
6267
</template>
6368

@@ -84,11 +89,18 @@
8489
var xZot = foo.shadowRoot.querySelector('x-bar').shadowRoot
8590
.querySelector('x-zot');
8691
var zot = xZot.shadowRoot.querySelector('.zot');
92+
var zot2 = xZot.shadowRoot.querySelector('.zot-2');
8793

8894
chai.assert.equal(getComputedStyle(zot).backgroundColor, 'rgb(0, 128, 0)',
89-
'^ styles are applied (backgroundColor)');
95+
'::shadow styles are applied (backgroundColor)');
9096
chai.assert.equal(getComputedStyle(zot).color, 'rgb(255, 255, 255)',
91-
'^^ styles are applied (color)');
97+
'/deep/ styles are applied (color)');
98+
99+
// TODO(vicb): remove the if when >>> get supported by browsers
100+
if (window.ShadowDOMPolyfill) {
101+
chai.assert.equal(getComputedStyle(zot2).color, 'rgb(255, 255, 255)',
102+
'>>> styles are applied (color)');
103+
}
92104

93105
// NOTE: native import styles not shimmed under SD polyfill
94106
var unsupported = window.ShadowDOMPolyfill && HTMLImports.useNative;

tests/ShadowDOM/js/Document.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ htmlSuite('Document', function() {
216216

217217
assert.equal(aa1, document.querySelector('div /deep/ aa'));
218218
assert.equal(bb, document.querySelector('div /deep/ bb'));
219+
220+
assert.equal(aa1, document.querySelector('div >>> aa'));
221+
assert.equal(bb, document.querySelector('div >>> bb'));
219222
});
220223

221224
test('querySelectorAll deep', function() {
@@ -230,14 +233,18 @@ htmlSuite('Document', function() {
230233

231234
div.offsetHeight;
232235

233-
var list = document.querySelectorAll('div /deep/ aa');
234-
assert.equal(2, list.length);
235-
assert.equal(aa1, list[0]);
236-
assert.equal(aa2, list[1]);
236+
['div /deep/ aa', 'div >>> aa'].forEach(function(selector) {
237+
var list = div.querySelectorAll(selector);
238+
assert.equal(2, list.length);
239+
assert.equal(aa1, list[0]);
240+
assert.equal(aa2, list[1]);
241+
});
237242

238-
list = document.querySelectorAll('div /deep/ bb');
239-
assert.equal(1, list.length);
240-
assert.equal(bb, list[0]);
243+
['div /deep/ bb', 'div >>> bb'].forEach(function(selector) {
244+
var list = div.querySelectorAll(selector);
245+
assert.equal(1, list.length);
246+
assert.equal(bb, list[0]);
247+
});
241248
});
242249

243250
test('addEventListener', function() {

tests/ShadowDOM/js/Element.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,18 @@ suite('Element', function() {
128128

129129
div.offsetHeight;
130130

131-
var list = div.querySelectorAll('div /deep/ aa');
132-
assert.equal(2, list.length);
133-
assert.equal(aa1, list[0]);
134-
assert.equal(aa2, list[1]);
135-
136-
list = div.querySelectorAll('div /deep/ bb');
137-
assert.equal(1, list.length);
138-
assert.equal(bb, list[0]);
131+
['div /deep/ aa', 'div >>> aa'].forEach(function(selector) {
132+
var list = div.querySelectorAll(selector);
133+
assert.equal(2, list.length);
134+
assert.equal(aa1, list[0]);
135+
assert.equal(aa2, list[1]);
136+
});
137+
138+
['div /deep/ bb', 'div >>> bb'].forEach(function(selector) {
139+
var list = div.querySelectorAll(selector);
140+
assert.equal(1, list.length);
141+
assert.equal(bb, list[0]);
142+
});
139143
});
140144

141145
test('querySelectorAll ::shadow', function() {

0 commit comments

Comments
 (0)