From aa92512ac6869a575e48a94e508411ec349fa3eb Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 10 Oct 2016 09:15:15 -0700 Subject: [PATCH] fix(compiler): properly shim `:host:before` and `:host(:before)` (#12171) fixes #12165 --- modules/@angular/compiler/src/shadow_css.ts | 5 ++++- modules/@angular/compiler/test/shadow_css_spec.ts | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/@angular/compiler/src/shadow_css.ts b/modules/@angular/compiler/src/shadow_css.ts index ddc30555e3..c0c1b2c026 100644 --- a/modules/@angular/compiler/src/shadow_css.ts +++ b/modules/@angular/compiler/src/shadow_css.ts @@ -381,7 +381,10 @@ export class ShadowCss { if (_polyfillHostRe.test(selector)) { const replaceBy = this.strictStyling ? `[${hostSelector}]` : scopeSelector; - return selector.replace(_polyfillHostNoCombinatorRe, (hnc, selector) => selector + replaceBy) + return selector + .replace( + _polyfillHostNoCombinatorRe, + (hnc, selector) => selector[0] === ':' ? replaceBy + selector : selector + replaceBy) .replace(_polyfillHostRe, replaceBy + ' '); } diff --git a/modules/@angular/compiler/test/shadow_css_spec.ts b/modules/@angular/compiler/test/shadow_css_spec.ts index 6afb87de01..16de7b4657 100644 --- a/modules/@angular/compiler/test/shadow_css_spec.ts +++ b/modules/@angular/compiler/test/shadow_css_spec.ts @@ -112,10 +112,8 @@ export function main() { it('should handle no context', () => { expect(s(':host {}', 'a', 'a-host')).toEqual('[a-host] {}'); }); - it('should handle tag selector', () => { - expect(s(':host(ul) {}', 'a', 'a-host')).toEqual('ul[a-host] {}'); - - }); + it('should handle tag selector', + () => { expect(s(':host(ul) {}', 'a', 'a-host')).toEqual('ul[a-host] {}'); }); it('should handle class selector', () => { expect(s(':host(.x) {}', 'a', 'a-host')).toEqual('.x[a-host] {}'); }); @@ -141,6 +139,11 @@ export function main() { expect(s(':host([a="b"],[c=d]) {}', 'a', 'a-host')) .toEqual('[a="b"][a-host], [c="d"][a-host] {}'); }); + + it('should handle pseudo selector', () => { + expect(s(':host(:before) {}', 'a', 'a-host')).toEqual('[a-host]:before {}'); + expect(s(':host:before {}', 'a', 'a-host')).toEqual('[a-host]:before {}'); + }); }); describe((':host-context'), () => {