Skip to content

Commit

Permalink
Fix normalizeRootSelector
Browse files Browse the repository at this point in the history
Remove crazy `runtime` switch in `whenHostOrRootRules`

Fix tests with takeRecords
  • Loading branch information
dfreedm committed Sep 23, 2016
1 parent dd786fd commit c2278a0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
14 changes: 5 additions & 9 deletions src/lib/style-properties.html
Expand Up @@ -35,7 +35,7 @@
self.decorateRule(rule);
// mark in-order position of ast rule in styles block, used for cache key
rule.index = ruleIndex++;
self.whenHostOrRootRule(scope, rule, style, false, function(info) {
self.whenHostOrRootRule(scope, rule, style, function(info) {
// we can't cache styles with :host and :root props in @media rules
if (rule.parent.type === styleUtil.ruleTypes.MEDIA_RULE) {
scope.__notStyleScopeCacheable = true;
Expand Down Expand Up @@ -285,19 +285,15 @@
return {properties: props, key: o};
},

whenHostOrRootRule: function(scope, rule, style, runtime, callback) {
whenHostOrRootRule: function(scope, rule, style, callback) {
if (!rule.propertyInfo) {
self.decorateRule(rule);
}
if (!rule.propertyInfo.properties) {
return;
}
var checkRoot = function(hostScope, selector) {
if (runtime) {
return selector.indexOf(':root') === 0 || (hostScope === 'html' && parsedSelector.indexOf('html') === 0);
} else {
return selector === ':root' || selector === 'html';
}
return selector.indexOf(':root') === 0 || (hostScope === 'html' && selector.indexOf('html') === 0);
};
var hostScope = scope.is ?
styleTransformer._calcHostScope(scope.is, scope.extends) :
Expand Down Expand Up @@ -338,7 +334,7 @@
// parsedSelector fallback for 'shady' css build
selectorToMatch = rule.transformedSelector || rule.parsedSelector;
}
if (isRoot && runtime && hostScope === 'html') {
if (isRoot && hostScope === 'html') {
selectorToMatch = rule.transformedSelector || rule.parsedSelector;
}
callback({
Expand All @@ -353,7 +349,7 @@
// note: active rules excludes non-matching @media rules
styleUtil.forActiveRulesInStyles(scope._styles, function(rule, style) {
// if scope is StyleDefaults, use _element for matchesSelector
self.whenHostOrRootRule(scope, rule, style, true, function(info) {
self.whenHostOrRootRule(scope, rule, style, function(info) {
var element = scope._element || scope;
if (matchesSelector.call(element, info.selector)) {
if (info.isHost) {
Expand Down
4 changes: 1 addition & 3 deletions src/lib/style-transformer.html
Expand Up @@ -289,9 +289,7 @@
},

normalizeRootSelector: function(rule) {
if (rule.selector === ROOT) {
rule.selector = 'html';
}
rule.selector = rule.selector.replace(ROOT, 'html');
},

_transformDocumentSelector: function(selector) {
Expand Down
2 changes: 2 additions & 0 deletions test/unit/custom-style.html
Expand Up @@ -571,6 +571,7 @@
var el;
function activateSelectors() {
document.documentElement.setAttribute('foo', 'bar');
CustomElements.takeRecords();
Polymer.updateStyles();
}
suiteSetup(function() {
Expand All @@ -579,6 +580,7 @@
});
teardown(function() {
document.documentElement.removeAttribute('foo');
CustomElements.takeRecords();
Polymer.updateStyles();
});
test(':root...', function() {
Expand Down

0 comments on commit c2278a0

Please sign in to comment.