Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 9757c90

Browse files
committed
fix(web platform): Do not barf on attribute selectors.
See #1189
1 parent 11b1206 commit 9757c90

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

lib/core_dom/web_platform.dart

+9-3
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ class WebPlatform {
3535

3636
void shimShadowDom(dom.Element root, String selector) {
3737
if (shadowDomShimRequired) {
38-
3938
// This adds an empty attribute with the name of the component tag onto
4039
// each element in the shadow root.
41-
root.querySelectorAll("*")
42-
.forEach((n) => n.attributes[selector] = "");
40+
//
41+
// Remove the try-catch once https://github.com/angular/angular.dart/issues/1189 is
42+
// fixed.
43+
try {
44+
root.querySelectorAll("*")
45+
.forEach((n) => n.attributes[selector] = "");
46+
} catch (e, s) {
47+
print("WARNING: Failed to set up Shadow DOM shim for $selector.\n$e\n$s");
48+
}
4349
}
4450
}
4551
}

test/core_dom/web_platform_spec.dart

+27
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ main() {
1010
beforeEachModule((Module module) {
1111
module
1212
..bind(WebPlatformTestComponent)
13+
..bind(WebPlatformTestComponentWithAttribute)
1314
..bind(InnerComponent)
1415
..bind(OuterComponent)
1516
..bind(WebPlatform, toValue: new WebPlatform());
@@ -54,6 +55,24 @@ main() {
5455
}
5556
}));
5657

58+
it('should not crash with an attribute selector; but wont work either..',
59+
async((TestBed _, MockHttpBackend backend, WebPlatform platform) {
60+
61+
backend
62+
..expectGET('style.css').respond(200, 'span { background-color: red; '
63+
'}')
64+
..expectGET('template.html').respond(200, '<span>foo</span>');
65+
66+
Element element = e('<span><test-wptca a><span>ignore'
67+
'</span></test-wptca></span>');
68+
69+
_.compile(element);
70+
71+
microLeap();
72+
backend.flush();
73+
microLeap();
74+
}));
75+
5776
it('should scope :host styles to the primary element.',
5877
async((TestBed _, MockHttpBackend backend, WebPlatform platform) {
5978

@@ -176,6 +195,14 @@ main() {
176195
class WebPlatformTestComponent {
177196
}
178197

198+
@Component(
199+
selector: "test-wptca[a]",
200+
publishAs: "ctrl",
201+
templateUrl: "template.html",
202+
cssUrl: "style.css")
203+
class WebPlatformTestComponentWithAttribute {
204+
}
205+
179206
@Component(
180207
selector: "my-inner",
181208
publishAs: "ctrl",

0 commit comments

Comments
 (0)