File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -429,4 +429,23 @@ describe('SFC style preprocessors', () => {
429429
430430 expect ( res . errors . length ) . toBe ( 0 )
431431 } )
432+
433+ test ( 'should mount scope on correct selector when have universal selector' , ( ) => {
434+ expect ( compileScoped ( `* { color: red; }` ) ) . toMatchInlineSnapshot ( `
435+ "[data-v-test] { color: red;
436+ }"
437+ ` )
438+ expect ( compileScoped ( '* .foo { color: red; }' ) ) . toMatchInlineSnapshot ( `
439+ ".foo[data-v-test] { color: red;
440+ }"
441+ ` )
442+ expect ( compileScoped ( `*.foo { color: red; }` ) ) . toMatchInlineSnapshot ( `
443+ ".foo[data-v-test] { color: red;
444+ }"
445+ ` )
446+ expect ( compileScoped ( `.foo * { color: red; }` ) ) . toMatchInlineSnapshot ( `
447+ ".foo[data-v-test] * { color: red;
448+ }"
449+ ` )
450+ } )
432451} )
Original file line number Diff line number Diff line change @@ -170,6 +170,32 @@ function rewriteSelector(
170170 }
171171 }
172172
173+ if ( n . type === 'universal' ) {
174+ const prev = selector . at ( selector . index ( n ) - 1 )
175+ const next = selector . at ( selector . index ( n ) + 1 )
176+ // * ... {}
177+ if ( ! prev ) {
178+ // * .foo {} -> .foo[xxxxxxx] {}
179+ if ( next ) {
180+ if ( next . type === 'combinator' && next . value === ' ' ) {
181+ selector . removeChild ( next )
182+ }
183+ selector . removeChild ( n )
184+ return
185+ } else {
186+ // * {} -> [xxxxxxx] {}
187+ node = selectorParser . combinator ( {
188+ value : '' ,
189+ } )
190+ selector . insertBefore ( n , node )
191+ selector . removeChild ( n )
192+ return false
193+ }
194+ }
195+ // .foo * -> .foo[xxxxxxx] *
196+ if ( node ) return
197+ }
198+
173199 if (
174200 ( n . type !== 'pseudo' && n . type !== 'combinator' ) ||
175201 ( n . type === 'pseudo' &&
You can’t perform that action at this time.
0 commit comments