diff --git a/src/lib/apply-shim.html b/src/lib/apply-shim.html
index 60c075e9e4..43cdc1a34a 100644
--- a/src/lib/apply-shim.html
+++ b/src/lib/apply-shim.html
@@ -289,12 +289,20 @@
_separator: MIXIN_VAR_SEP,
transform: function(styles, elementProto) {
this.__currentElementProto = elementProto;
- styleUtil.forRulesInStyles(styles, this._boundTransformRule);
- elementProto.__applyShimInvalid = false;
+ styleUtil.forRulesInStyles(styles, this._boundFindDefinitions);
+ styleUtil.forRulesInStyles(styles, this._boundFindApplications)
+ if (elementProto) {
+ elementProto.__applyShimInvalid = false;
+ }
this.__currentElementProto = null;
},
- transformRule: function(rule) {
- rule.cssText = this.transformCssText(rule.parsedCssText);
+ _findDefinitions: function(rule) {
+ var cssText = rule.parsedCssText;
+ // fix shim variables
+ cssText = cssText.replace(BAD_VAR, fixVars);
+ // produce variables
+ cssText = cssText.replace(VAR_ASSIGN, produceCssProperties);
+ rule.cssText = cssText;
// :root was only used for variable assignment in property shim,
// but generates invalid selectors with real properties.
// replace with `:host > *`, which serves the same effect
@@ -302,13 +310,13 @@
rule.selector = ':host > *';
}
},
- transformCssText: function(cssText) {
- // fix shim variables
- cssText = cssText.replace(BAD_VAR, fixVars);
- // produce variables
- cssText = cssText.replace(VAR_ASSIGN, produceCssProperties);
+ _findApplications: function(rule) {
// consume mixins
- return consumeCssProperties(cssText);
+ rule.cssText = consumeCssProperties(rule.cssText);
+ },
+ transformRule: function(rule) {
+ this._findDefinitions(rule);
+ this._findApplications(rule);
},
_getInitialValueForProperty: function(property) {
if (!this._measureElement) {
@@ -321,6 +329,8 @@
};
ApplyShim._boundTransformRule = ApplyShim.transformRule.bind(ApplyShim);
+ ApplyShim._boundFindDefinitions = ApplyShim._findDefinitions.bind(ApplyShim);
+ ApplyShim._boundFindApplications = ApplyShim._findApplications.bind(ApplyShim);
return ApplyShim;
})();
diff --git a/src/lib/custom-style.html b/src/lib/custom-style.html
index 3ffb0d2296..c8c0aea751 100644
--- a/src/lib/custom-style.html
+++ b/src/lib/custom-style.html
@@ -213,12 +213,12 @@
function(rule) {
// shim the selector for current runtime settings
styleTransformer.documentRule(rule);
- // run the apply shim if unbuilt and using native css custom properties
- if (settings.useNativeCSSProperties && !buildType) {
- applyShim.transformRule(rule);
- }
}
);
+ // run the apply shim if unbuilt and using native css custom properties
+ if (settings.useNativeCSSProperties && !buildType) {
+ applyShim.transform([e]);
+ }
}
// custom properties shimming
// (if we use native custom properties, no need to apply any property shimming)
diff --git a/test/unit/styling-cross-scope-apply.html b/test/unit/styling-cross-scope-apply.html
index 9468d69fca..58070d8b86 100644
--- a/test/unit/styling-cross-scope-apply.html
+++ b/test/unit/styling-cross-scope-apply.html
@@ -687,6 +687,34 @@
+
+
+
+
+
+
+