@@ -6,6 +6,8 @@ const svelte = require('svelte/compiler');
6
6
7
7
const PREFIX = '[rollup-plugin-svelte]' ;
8
8
9
+ const majorVersion = Number ( svelte . VERSION . split ( '.' ) [ 0 ] ) ;
10
+
9
11
const plugin_options = new Set ( [
10
12
'emitCss' ,
11
13
'exclude' ,
@@ -26,7 +28,7 @@ module.exports = function (options = {}) {
26
28
const extensions = rest . extensions || [ '.svelte' ] ;
27
29
const filter = createFilter ( rest . include , rest . exclude ) ;
28
30
29
- if ( svelte . VERSION [ 0 ] === '3' ) {
31
+ if ( majorVersion === 3 ) {
30
32
compilerOptions . format = 'esm' ;
31
33
}
32
34
@@ -42,8 +44,7 @@ module.exports = function (options = {}) {
42
44
const { onwarn, emitCss = true } = rest ;
43
45
44
46
if ( emitCss ) {
45
- const [ majorVer ] = svelte . VERSION . split ( '.' ) ;
46
- const cssOptionValue = majorVer > 3 ? 'external' : false ;
47
+ const cssOptionValue = majorVersion > 3 ? 'external' : false ;
47
48
if ( compilerOptions . css ) {
48
49
console . warn (
49
50
`${ PREFIX } Forcing \`"compilerOptions.css": ${
@@ -129,10 +130,7 @@ module.exports = function (options = {}) {
129
130
async transform ( code , id ) {
130
131
if ( ! filter ( id ) ) return null ;
131
132
132
- if (
133
- Number ( svelte . VERSION . split ( '.' ) [ 0 ] ) >= 5 &&
134
- ( id . endsWith ( '.svelte.js' ) || id . endsWith ( '.svelte.ts' ) )
135
- ) {
133
+ if ( majorVersion > 4 && ( id . endsWith ( '.svelte.js' ) || id . endsWith ( '.svelte.ts' ) ) ) {
136
134
const compiled = svelte . compileModule ( code , {
137
135
filename : id ,
138
136
dev : compilerOptions . dev ,
@@ -164,9 +162,18 @@ module.exports = function (options = {}) {
164
162
const compiled = svelte . compile ( code , svelte_options ) ;
165
163
166
164
( compiled . warnings || [ ] ) . forEach ( ( warning ) => {
167
- if ( ! emitCss && warning . code === 'css-unused-selector' ) return ;
168
- if ( onwarn ) onwarn ( warning , this . warn ) ;
169
- else this . warn ( warning ) ;
165
+ if (
166
+ ! emitCss &&
167
+ ( warning . code === 'css-unused-selector' || warning . code === 'css_unused_selector' )
168
+ ) {
169
+ return ;
170
+ }
171
+
172
+ if ( onwarn ) {
173
+ onwarn ( warning , this . warn ) ;
174
+ } else {
175
+ this . warn ( warning ) ;
176
+ }
170
177
} ) ;
171
178
172
179
if ( emitCss && compiled . css && compiled . css . code ) {
0 commit comments