@@ -11,7 +11,7 @@ export default function loader(source, map) {
11
11
const parseResult = parse ( source ) ;
12
12
13
13
let replacer ;
14
- if ( options . sourceMap ) {
14
+ if ( options . sourceMap ) {
15
15
replacer = new ReplaceSource (
16
16
map ? new SourceMapSource ( source , remainingRequest , map ) : new OriginalSource ( source , remainingRequest ) ,
17
17
remainingRequest ) ;
@@ -23,7 +23,7 @@ export default function loader(source, map) {
23
23
const includedStylesheetsMediaQuery = new Map ( ) ;
24
24
25
25
parseResult . atImports . forEach ( ( imp ) => {
26
- if ( loaderUtils . isUrlRequest ( imp . url , options . root ) ) {
26
+ if ( loaderUtils . isUrlRequest ( imp . url , options . root ) ) {
27
27
const request = loaderUtils . urlToRequest ( imp . url , options . root ) ;
28
28
replacer . replace ( imp . start , imp . end , '' ) ;
29
29
includedStylesheets . add ( request ) ;
@@ -42,21 +42,21 @@ export default function loader(source, map) {
42
42
const importReplacements = new Map ( ) ;
43
43
44
44
let id = 0 ;
45
- for ( const pair of importedNames ) {
45
+ for ( const pair of importedNames ) {
46
46
const internalName = `cssLoaderImport${ id } _${ pair [ 1 ] . importName } ` ;
47
47
id += 1 ;
48
48
importReplacements . set ( pair [ 0 ] , internalName ) ;
49
49
declarations . push ( `import { ${ pair [ 1 ] . importName } as ${ internalName } } from ${ JSON . stringify ( pair [ 1 ] . from ) } ;` ) ;
50
50
includedStylesheets . add ( pair [ 1 ] . from ) ;
51
51
}
52
52
53
- for ( const pair of importReplacements ) {
53
+ for ( const pair of importReplacements ) {
54
54
const identifier = parseResult . identifiers . get ( pair [ 0 ] ) ;
55
- if ( identifier ) {
55
+ if ( identifier ) {
56
56
columns = false ;
57
- const length = identifier . name . length ;
57
+ const offset = identifier . name . length - 1 ;
58
58
identifier . locations . forEach ( ( loc ) => {
59
- replacer . replace ( loc , loc + length - 1 , `$CSS$LOADER$\{${ pair [ 1 ] } }` ) ;
59
+ replacer . replace ( loc , loc + offset , `$CSS$LOADER$\{${ pair [ 1 ] } }` ) ;
60
60
} ) ;
61
61
}
62
62
}
@@ -66,21 +66,21 @@ export default function loader(source, map) {
66
66
} ) ;
67
67
68
68
const includedStylesheetsArray = [ ] ;
69
- for ( const include of includedStylesheets ) {
69
+ for ( const include of includedStylesheets ) {
70
70
const internalName = `cssLoaderImport${ id } ` ;
71
71
id += 1 ;
72
72
declarations . push ( `import ${ internalName } from ${ loaderUtils . stringifyRequest ( this , include ) } ;` ) ;
73
73
includedStylesheetsArray . push ( {
74
74
name : internalName ,
75
- mediaQuery : includedStylesheetsMediaQuery . get ( include ) || ''
75
+ mediaQuery : includedStylesheetsMediaQuery . get ( include ) || '' ,
76
76
} ) ;
77
77
}
78
78
79
79
let css ;
80
80
let sourceMap ;
81
- if ( options . sourceMap ) {
81
+ if ( options . sourceMap ) {
82
82
const sourceAndMap = replacer . sourceAndMap ( typeof options . sourceMap === 'object' ? options . sourceMap : {
83
- columns : columns
83
+ columns,
84
84
} ) ;
85
85
css = sourceAndMap . code ;
86
86
sourceMap = sourceAndMap . map ;
@@ -93,22 +93,20 @@ export default function loader(source, map) {
93
93
94
94
return [
95
95
'// css runtime' ,
96
- `import * as runtime from ${ loaderUtils . stringifyRequest ( this , require . resolve ( " ../runtime" ) ) } ;` ,
96
+ `import * as runtime from ${ loaderUtils . stringifyRequest ( this , require . resolve ( ' ../runtime' ) ) } ;` ,
97
97
'' ,
98
98
'// declarations' ,
99
99
declarations . join ( '\n' ) ,
100
100
'' ,
101
101
'// CSS' ,
102
- 'export default runtime.create([' ,
102
+ 'export default /*#__PURE__*/ runtime.create([' ,
103
103
] . concat (
104
104
includedStylesheetsArray . map ( ( include ) => {
105
- if ( ! include . mediaQuery ) return ` ${ include . name } ,` ;
105
+ if ( ! include . mediaQuery ) return ` ${ include . name } ,` ;
106
106
return ` runtime.importStylesheet(${ include . name } , ${ JSON . stringify ( include . mediaQuery ) } ,` ;
107
- } )
107
+ } ) ,
108
108
) . concat ( [
109
- sourceMap ?
110
- ` runtime.moduleWithSourceMap(module.id, ${ cssJs } , ${ sourceMap } )` :
111
- ` runtime.moduleWithoutSourceMap(module.id, ${ cssJs } )` ,
112
- ']);'
109
+ ` runtime.${ sourceMap ? 'moduleWithSourceMap' : 'moduleWithoutSourceMap' } (module.id, ${ cssJs } ${ sourceMap ? `, ${ sourceMap } ` : '' } )` ,
110
+ ']);' ,
113
111
] ) . join ( '\n' ) ;
114
112
}
0 commit comments