@@ -11,8 +11,8 @@ import ts from 'typescript';
1111 * static get style() { return "styles"; }
1212 * }
1313 */
14- export const addStaticStyleGetterWithinClass = ( classMembers : ts . ClassElement [ ] , cmp : d . ComponentCompilerMeta ) => {
15- const styleLiteral = getStyleLiteral ( cmp ) ;
14+ export const addStaticStyleGetterWithinClass = ( classMembers : ts . ClassElement [ ] , cmp : d . ComponentCompilerMeta , commentOriginalSelector : boolean ) => {
15+ const styleLiteral = getStyleLiteral ( cmp , commentOriginalSelector ) ;
1616 if ( styleLiteral ) {
1717 classMembers . push ( createStaticGetter ( 'style' , styleLiteral ) ) ;
1818 }
@@ -23,35 +23,35 @@ export const addStaticStyleGetterWithinClass = (classMembers: ts.ClassElement[],
2323 * const MyComponent = class {}
2424 * MyComponent.style = "styles";
2525 */
26- export const addStaticStylePropertyToClass = ( styleStatements : ts . Statement [ ] , cmp : d . ComponentCompilerMeta ) => {
27- const styleLiteral = getStyleLiteral ( cmp ) ;
26+ export const addStaticStylePropertyToClass = ( styleStatements : ts . Statement [ ] , cmp : d . ComponentCompilerMeta , commentOriginalSelector : boolean ) => {
27+ const styleLiteral = getStyleLiteral ( cmp , commentOriginalSelector ) ;
2828 if ( styleLiteral ) {
2929 const statement = ts . createStatement ( ts . createAssignment ( ts . createPropertyAccess ( ts . createIdentifier ( cmp . componentClassName ) , 'style' ) , styleLiteral ) ) ;
3030 styleStatements . push ( statement ) ;
3131 }
3232} ;
3333
34- const getStyleLiteral = ( cmp : d . ComponentCompilerMeta ) => {
34+ const getStyleLiteral = ( cmp : d . ComponentCompilerMeta , commentOriginalSelector : boolean ) => {
3535 if ( Array . isArray ( cmp . styles ) && cmp . styles . length > 0 ) {
3636 if ( cmp . styles . length > 1 || ( cmp . styles . length === 1 && cmp . styles [ 0 ] . modeName !== DEFAULT_STYLE_MODE ) ) {
3737 // multiple style modes
38- return getMultipleModeStyle ( cmp , cmp . styles ) ;
38+ return getMultipleModeStyle ( cmp , cmp . styles , commentOriginalSelector ) ;
3939 } else {
4040 // single style
41- return getSingleStyle ( cmp , cmp . styles [ 0 ] ) ;
41+ return getSingleStyle ( cmp , cmp . styles [ 0 ] , commentOriginalSelector ) ;
4242 }
4343 }
4444 return null ;
4545} ;
4646
47- const getMultipleModeStyle = ( cmp : d . ComponentCompilerMeta , styles : d . StyleCompiler [ ] ) => {
47+ const getMultipleModeStyle = ( cmp : d . ComponentCompilerMeta , styles : d . StyleCompiler [ ] , commentOriginalSelector : boolean ) => {
4848 const styleModes : ts . ObjectLiteralElementLike [ ] = [ ] ;
4949
5050 styles . forEach ( style => {
5151 if ( typeof style . styleStr === 'string' ) {
5252 // inline the style string
5353 // static get style() { return { ios: "string" }; }
54- const styleLiteral = createStyleLiteral ( cmp , style ) ;
54+ const styleLiteral = createStyleLiteral ( cmp , style , commentOriginalSelector ) ;
5555 const propStr = createPropertyAssignment ( style . modeName , styleLiteral ) ;
5656 styleModes . push ( propStr ) ;
5757 } else if ( typeof style . styleIdentifier === 'string' ) {
@@ -79,11 +79,11 @@ const createPropertyAssignment = (mode: string, initializer: ts.Expression) => {
7979 return node ;
8080} ;
8181
82- const getSingleStyle = ( cmp : d . ComponentCompilerMeta , style : d . StyleCompiler ) => {
82+ const getSingleStyle = ( cmp : d . ComponentCompilerMeta , style : d . StyleCompiler , commentOriginalSelector : boolean ) => {
8383 if ( typeof style . styleStr === 'string' ) {
8484 // inline the style string
8585 // static get style() { return "string"; }
86- return createStyleLiteral ( cmp , style ) ;
86+ return createStyleLiteral ( cmp , style , commentOriginalSelector ) ;
8787 }
8888
8989 if ( typeof style . styleIdentifier === 'string' ) {
@@ -103,11 +103,11 @@ const getSingleStyle = (cmp: d.ComponentCompilerMeta, style: d.StyleCompiler) =>
103103 return null ;
104104} ;
105105
106- const createStyleLiteral = ( cmp : d . ComponentCompilerMeta , style : d . StyleCompiler ) => {
107- if ( cmp . encapsulation === 'scoped' ) {
106+ const createStyleLiteral = ( cmp : d . ComponentCompilerMeta , style : d . StyleCompiler , commentOriginalSelector : boolean ) => {
107+ if ( cmp . encapsulation === 'scoped' || ( commentOriginalSelector && cmp . encapsulation === 'shadow' ) ) {
108108 // scope the css first
109109 const scopeId = getScopeId ( cmp . tagName , style . modeName ) ;
110- return ts . createStringLiteral ( scopeCss ( style . styleStr , scopeId , false ) ) ;
110+ return ts . createStringLiteral ( scopeCss ( style . styleStr , scopeId , commentOriginalSelector ) ) ;
111111 }
112112
113113 return ts . createStringLiteral ( style . styleStr ) ;
0 commit comments