|
206 | 206 | if (selector.indexOf(HOST_CONTEXT) >=0) { |
207 | 207 | hostContext = true; |
208 | 208 | } else if (selector.indexOf(HOST) >=0) { |
209 | | - // :host(...) -> scopeName... |
210 | | - selector = selector.replace(HOST_PAREN, function(m, host, paren) { |
211 | | - return (m.indexOf(hostScope) === -1 ? hostScope : '') + paren; |
212 | | - }); |
213 | | - // now normal :host |
214 | | - selector = selector.replace(HOST, hostScope); |
| 209 | + selector = this._transformHostSelector(selector, hostScope); |
215 | 210 | // replace other selectors with scoping class |
216 | 211 | } else if (jumpIndex !== 0) { |
217 | 212 | selector = scope ? this._transformSimpleSelector(selector, scope) : |
|
238 | 233 | return p$.join(PSEUDO_PREFIX); |
239 | 234 | }, |
240 | 235 |
|
| 236 | + // :host(...) -> scopeName... |
| 237 | + _transformHostSelector: function(selector, hostScope) { |
| 238 | + var m = HOST_PAREN.exec(selector); |
| 239 | + HOST_PAREN.lastIndex = 0; |
| 240 | + var paren = m && m[2].trim(); |
| 241 | + if (paren) { |
| 242 | + var selectorKind = /[[.:#*]/; |
| 243 | + if (!paren[0].match(selectorKind)) { |
| 244 | + var typeSelector = paren.split(selectorKind)[0]; |
| 245 | + if (typeSelector === hostScope) { |
| 246 | + hostScope = ''; |
| 247 | + } else { |
| 248 | + return SELECTOR_NO_MATCH; |
| 249 | + } |
| 250 | + } |
| 251 | + return selector.replace(HOST_PAREN, function(m, host, paren) { |
| 252 | + return hostScope + paren; |
| 253 | + }); |
| 254 | + } else { |
| 255 | + // now normal :host |
| 256 | + return selector.replace(HOST, hostScope); |
| 257 | + } |
| 258 | + }, |
| 259 | + |
241 | 260 | documentRule: function(rule) { |
242 | 261 | // reset selector in case this is redone. |
243 | 262 | rule.selector = rule.parsedSelector; |
|
283 | 302 | var PSEUDO_PREFIX = ':'; |
284 | 303 | var CLASS = 'class'; |
285 | 304 | var CONTENT_START = new RegExp('^(' + CONTENT + ')'); |
| 305 | + var SELECTOR_NO_MATCH = 'should_not_match'; |
286 | 306 |
|
287 | 307 | // exports |
288 | 308 | return api; |
|
0 commit comments