@@ -6,6 +6,8 @@ const svelte = require('svelte/compiler');
66
77const PREFIX = '[rollup-plugin-svelte]' ;
88
9+ const majorVersion = Number ( svelte . VERSION . split ( '.' ) [ 0 ] ) ;
10+
911const plugin_options = new Set ( [
1012 'emitCss' ,
1113 'exclude' ,
@@ -26,7 +28,7 @@ module.exports = function (options = {}) {
2628 const extensions = rest . extensions || [ '.svelte' ] ;
2729 const filter = createFilter ( rest . include , rest . exclude ) ;
2830
29- if ( svelte . VERSION [ 0 ] === '3' ) {
31+ if ( majorVersion === 3 ) {
3032 compilerOptions . format = 'esm' ;
3133 }
3234
@@ -42,8 +44,7 @@ module.exports = function (options = {}) {
4244 const { onwarn, emitCss = true } = rest ;
4345
4446 if ( emitCss ) {
45- const [ majorVer ] = svelte . VERSION . split ( '.' ) ;
46- const cssOptionValue = majorVer > 3 ? 'external' : false ;
47+ const cssOptionValue = majorVersion > 3 ? 'external' : false ;
4748 if ( compilerOptions . css ) {
4849 console . warn (
4950 `${ PREFIX } Forcing \`"compilerOptions.css": ${
@@ -129,10 +130,7 @@ module.exports = function (options = {}) {
129130 async transform ( code , id ) {
130131 if ( ! filter ( id ) ) return null ;
131132
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' ) ) ) {
136134 const compiled = svelte . compileModule ( code , {
137135 filename : id ,
138136 dev : compilerOptions . dev ,
@@ -164,9 +162,18 @@ module.exports = function (options = {}) {
164162 const compiled = svelte . compile ( code , svelte_options ) ;
165163
166164 ( 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+ }
170177 } ) ;
171178
172179 if ( emitCss && compiled . css && compiled . css . code ) {
0 commit comments