diff --git a/lib/mixins/element-mixin.html b/lib/mixins/element-mixin.html index cf8962062d..c4489cbef2 100644 --- a/lib/mixins/element-mixin.html +++ b/lib/mixins/element-mixin.html @@ -416,8 +416,8 @@ function finalizeTemplate(proto, template, baseURI, is, ext) { // support `include="module-name"` let cssText = - Polymer.StyleGather.cssFromTemplate(template, baseURI) + - Polymer.StyleGather.cssFromModuleImports(is); + Polymer.StyleGather.cssFromModuleImports(is) + + Polymer.StyleGather.cssFromTemplate(template, baseURI); if (cssText) { let style = document.createElement('style'); style.textContent = cssText; diff --git a/lib/utils/style-gather.html b/lib/utils/style-gather.html index cc58c7cbb0..7a2bb37c50 100644 --- a/lib/utils/style-gather.html +++ b/lib/utils/style-gather.html @@ -70,14 +70,13 @@ cssFromModule(moduleId) { let m = importModule(moduleId); if (m && m._cssText === undefined) { - let cssText = ''; + // module imports: + let cssText = this._cssFromModuleImports(m); // include css from the first template in the module let t = m.querySelector('template'); if (t) { - cssText += this.cssFromTemplate(t, /** @type {templateWithAssetPath }*/(m).assetpath); + cssText += this.cssFromTemplate(t, /** @type {templateWithAssetPath} */(m).assetpath); } - // module imports: - cssText += this.cssFromModuleImports(moduleId); m._cssText = cssText || null; } if (!m) { @@ -126,12 +125,18 @@ * @this {StyleGather} */ cssFromModuleImports(moduleId) { - let cssText = ''; let m = importModule(moduleId); - if (!m) { - return cssText; - } - let p$ = m.querySelectorAll(MODULE_STYLE_LINK_SELECTOR); + return m ? this._cssFromModuleImports(m) : ''; + }, + /** + * @memberof Polymer.StyleGather + * @this {StyleGather} + * @param {!HTMLElement} module dom-module element that could contain `` styles + * @return {string} Concatenated CSS content from links in the dom-module + */ + _cssFromModuleImports(module) { + let cssText = ''; + let p$ = module.querySelectorAll(MODULE_STYLE_LINK_SELECTOR); for (let i=0; i < p$.length; i++) { let p = p$[i]; if (p.import) { diff --git a/test/unit/styling-import.html b/test/unit/styling-import.html index 9b6a18117a..3b1673dc37 100644 --- a/test/unit/styling-import.html +++ b/test/unit/styling-import.html @@ -52,6 +52,23 @@ + + + + + +