From d24dfd908c1f9e17cc48bf2fb2bf9c00e76fa35a Mon Sep 17 00:00:00 2001 From: Steve Orvell Date: Thu, 23 Jan 2014 15:58:53 -0800 Subject: [PATCH] =?UTF-8?q?add=20support=20for=20:ancestor(.foo)=20{=20?= =?UTF-8?q?=E2=80=A6=20}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ShadowCSS.js | 53 ++++++++++++++++++++++++------- test/html/styling/colon-host.html | 7 ++-- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/ShadowCSS.js b/src/ShadowCSS.js index f55a02a..4bc5254 100644 --- a/src/ShadowCSS.js +++ b/src/ShadowCSS.js @@ -382,7 +382,10 @@ var ShadowCSS = { var cssText = stylesToCssText(styles).replace(hostRuleRe, ''); cssText = this.insertPolyfillHostInCssText(cssText); cssText = this.convertColonHost(cssText); + cssText = this.convertColonAncestor(cssText); + // TODO(sorvell): deprecated, remove cssText = this.convertPseudos(cssText); + // TODO(sorvell): deprecated, remove cssText = this.convertParts(cssText); cssText = this.convertCombinators(cssText); var rules = cssToRules(cssText); @@ -402,29 +405,40 @@ var ShadowCSS = { * * to * + * scopeName.foo > .bar + */ + convertColonHost: function(cssText) { + return this.convertColonRule(cssText, cssColonHostRe, + this.colonHostPartReplacer); + }, + /* + * convert a rule like :ancestor(.foo) > .bar { } + * + * to + * * scopeName.foo > .bar, .foo scopeName > .bar { } * * and * - * :host(.foo:host) .bar { ... } + * :ancestor(.foo:host) .bar { ... } * * to * * scopeName.foo .bar { ... } */ - convertColonHost: function(cssText) { + convertColonAncestor: function(cssText) { + return this.convertColonRule(cssText, cssColonAncestorRe, + this.colonAncestorPartReplacer); + }, + convertColonRule: function(cssText, regExp, partReplacer) { // p1 = :host, p2 = contents of (), p3 rest of rule - return cssText.replace(cssColonHostRe, function(m, p1, p2, p3) { + return cssText.replace(regExp, function(m, p1, p2, p3) { p1 = polyfillHostNoCombinator; if (p2) { var parts = p2.split(','), r = []; for (var i=0, l=parts.length, p; (i -