File tree 5 files changed +26
-11
lines changed
test/css/samples/custom-scope-class
5 files changed +26
-11
lines changed Original file line number Diff line number Diff line change @@ -131,8 +131,9 @@ export default class Component {
131
131
this . stylesheet = new Stylesheet ( {
132
132
source,
133
133
ast,
134
- filename : compile_options . filename ,
135
134
options : {
135
+ filename : compile_options . filename ,
136
+ component_name : name ,
136
137
dev : compile_options . dev ,
137
138
scope_class_getter : compile_options . scopeClass
138
139
}
Original file line number Diff line number Diff line change @@ -298,13 +298,18 @@ export default class Stylesheet {
298
298
constructor ( {
299
299
source,
300
300
ast,
301
- filename,
302
- options : { dev, scope_class_getter = getDefaultScopeClass } ,
301
+ options : {
302
+ component_name,
303
+ filename,
304
+ dev,
305
+ scope_class_getter = getDefaultScopeClass ,
306
+ } ,
303
307
} : {
304
308
source : string ;
305
309
ast : Ast ;
306
- filename : string ;
307
310
options : {
311
+ filename : string | undefined ;
312
+ component_name : string | undefined ;
308
313
dev : boolean ;
309
314
scope_class_getter : CssScopeClassGetter ;
310
315
} ;
@@ -315,7 +320,11 @@ export default class Stylesheet {
315
320
this . dev = dev ;
316
321
317
322
if ( ast . css && ast . css . children . length ) {
318
- this . id = scope_class_getter ( { filename, hash : hash ( ast . css . content . styles ) } ) ;
323
+ this . id = scope_class_getter ( {
324
+ filename,
325
+ name : component_name ,
326
+ hash : hash ( ast . css . content . styles ) ,
327
+ } ) ;
319
328
320
329
this . has_styles = true ;
321
330
Original file line number Diff line number Diff line change @@ -104,9 +104,9 @@ export interface Warning {
104
104
105
105
export type ModuleFormat = 'esm' | 'cjs' ;
106
106
107
-
108
107
export type CssScopeClassGetter = ( args : {
109
- filename : string ;
108
+ name : string | undefined ;
109
+ filename : string | undefined ;
110
110
hash : string ;
111
111
} ) => string ;
112
112
Original file line number Diff line number Diff line change 1
1
export default {
2
2
compileOptions : {
3
- scopeClass ( { hash } ) {
4
- return `sv-${ hash } ` ;
5
- }
3
+ filename : 'src/components/FooSwitcher.svelte' ,
4
+ scopeClass ( { hash, name, filename } ) {
5
+ const minFilename = filename
6
+ . split ( '/' )
7
+ . map ( i => i . charAt ( 0 ) . toLowerCase ( ) )
8
+ . join ( '' ) ;
9
+ return `sv-${ name } -${ minFilename } -${ hash } ` ;
10
+ } ,
6
11
} ,
7
12
} ;
Original file line number Diff line number Diff line change 1
- div .sv-bzh57p {color : red}
1
+ div .sv-FooSwitcher-scf- bzh57p {color : red}
You can’t perform that action at this time.
0 commit comments