File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3232 this . _prepConstructor ( ) ;
3333 // template
3434 this . _prepTemplate ( ) ;
35- // styles
35+ // styles and style properties
3636 this . _prepStyles ( ) ;
37- // style properties
38- this . _prepStyleProperties ( ) ;
3937 // template markup
4038 this . _prepAnnotations ( ) ;
4139 // accessors
Original file line number Diff line number Diff line change 4545 // calculate shimmed styles (we must always do this as it
4646 // stores shimmed style data in the css rules for later use)
4747 var cssText = styleTransformer . elementStyles ( this ) ;
48- // do we really need to output shimmed styles
49- var needsStatic = this . _needsStaticStyles ( this . _styles ) ;
48+ // prepare to shim style properties.
49+ this . _prepStyleProperties ( ) ;
50+ // do we really need to output static shimmed styles?
51+ // only if no custom properties are used since otherwise
52+ // styles are applied via property shimming.
53+ var needsStatic = this . _styles . length &&
54+ ! this . _needsStyleProperties ( ) ;
5055 // under shady dom we always output a shimmed style (which may be
5156 // empty) so that other dynamic stylesheets can always be placed
5257 // after the element's main stylesheet.
Original file line number Diff line number Diff line change 2626
2727 Polymer . Base . _addFeature ( {
2828
29- // Skip applying CSS if there are some mixins or variables used
30- // since styles with mixins and variables will be added on later stages anyway,
31- // and will include styles applied here, no need to do this twice
32- _needsStaticStyles : function ( styles ) {
33- var needsStatic ;
34- for ( var i = 0 , l = styles . length , css ; i < l ; i ++ ) {
35- css = styleUtil . parser . _clean ( styles [ i ] . textContent ) ;
36- css = propertyUtils . collectConsumingCssText ( css ) ;
37- needsStatic = needsStatic || Boolean ( css ) ;
38- if ( css . match ( propertyUtils . rx . MIXIN_MATCH ) ||
39- css . match ( propertyUtils . rx . VAR_MATCH ) ) {
40- return false ;
41- }
42- }
43- return needsStatic ;
44- } ,
45-
4629 _prepStyleProperties : function ( ) {
4730 // note: an element should produce an x-scope stylesheet
4831 // if it has any _stylePropertyNames
49- this . _ownStylePropertyNames = this . _styles ?
32+ this . _ownStylePropertyNames = this . _styles && this . _styles . length ?
5033 propertyUtils . decorateStyles ( this . _styles ) :
5134 null ;
5235 } ,
Original file line number Diff line number Diff line change 389389 assertComputed ( d , '10px' ) ;
390390 } ) ;
391391
392+ test ( 'producing a var that consumes results in static and not dynamic stylesheet' , function ( ) {
393+ var d = document . createElement ( 'x-var-produce-via-consume' ) ;
394+ document . body . appendChild ( d ) ;
395+ CustomElements . takeRecords ( ) ;
396+ var styleRoot = d . shadowRoot ? d . shadowRoot : document . head ;
397+ var staticStyle = styleRoot . querySelector ( 'style[scope=x-var-produce-via-consume]' ) ;
398+ assert . ok ( staticStyle ) ;
399+ assert . match ( staticStyle . textContent , / d i s p l a y / , 'static style does not contain style content' ) ;
400+ assert . equal ( styleRoot . querySelectorAll ( 'style[scope~=x-var-produce-via-consume]' ) . length , 1 ) ;
401+ } ) ;
402+
392403 // TODO(sorvell): fix for #1761 was reverted; include test once this issue is addressed
393404 test ( 'mixin values can be overridden by subsequent concrete properties' , function ( ) {
394405 assertComputed ( styled . $ . override , '19px' ) ;
Original file line number Diff line number Diff line change 890890 assertComputed ( d , '10px' ) ;
891891 } ) ;
892892
893+ test ( 'producing a var that consumes results in static and not dynamic stylesheet' , function ( ) {
894+ var d = document . createElement ( 'x-var-produce-via-consume' ) ;
895+ document . body . appendChild ( d ) ;
896+ CustomElements . takeRecords ( ) ;
897+ var styleRoot = d . shadowRoot ? d . shadowRoot : document . head ;
898+ var staticStyle = styleRoot . querySelector ( 'style[scope=x-var-produce-via-consume]' ) ;
899+ assert . ok ( staticStyle ) ;
900+ assert . match ( staticStyle . textContent , / d i s p l a y / , 'static style does not contain style content' ) ;
901+ assert . equal ( styleRoot . querySelectorAll ( 'style[scope~=x-var-produce-via-consume]' ) . length , 1 ) ;
902+ } ) ;
903+
893904} ) ;
894905
895906</ script >
You can’t perform that action at this time.
0 commit comments