@@ -11,7 +11,7 @@ import Stylesheet from './css/Stylesheet';
11
11
import { test } from '../config' ;
12
12
import Fragment from './nodes/Fragment' ;
13
13
import internal_exports from './internal-exports' ;
14
- import { Node , Ast , CompileOptions , Var } from '../interfaces' ;
14
+ import { Node , Ast , CompileOptions , Var , Warning } from '../interfaces' ;
15
15
import error from '../utils/error' ;
16
16
import getCodeFrame from '../utils/getCodeFrame' ;
17
17
import flattenReference from '../utils/flattenReference' ;
@@ -40,6 +40,7 @@ childKeys.ExportNamedDeclaration = ['declaration', 'specifiers'];
40
40
41
41
export default class Component {
42
42
stats : Stats ;
43
+ warnings : Warning [ ] ;
43
44
44
45
ast : Ast ;
45
46
source : string ;
@@ -93,11 +94,13 @@ export default class Component {
93
94
source : string ,
94
95
name : string ,
95
96
compileOptions : CompileOptions ,
96
- stats : Stats
97
+ stats : Stats ,
98
+ warnings : Warning [ ]
97
99
) {
98
100
this . name = name ;
99
101
100
102
this . stats = stats ;
103
+ this . warnings = warnings ;
101
104
this . ast = ast ;
102
105
this . source = source ;
103
106
this . compileOptions = compileOptions ;
@@ -161,7 +164,7 @@ export default class Component {
161
164
162
165
if ( ! compileOptions . customElement ) this . stylesheet . reify ( ) ;
163
166
164
- this . stylesheet . warnOnUnusedSelectors ( stats ) ;
167
+ this . stylesheet . warnOnUnusedSelectors ( this ) ;
165
168
}
166
169
167
170
add_var ( variable : Var ) {
@@ -214,105 +217,121 @@ export default class Component {
214
217
}
215
218
216
219
generate ( result : string ) {
217
- const { compileOptions , name } = this ;
218
- const { format = 'esm' } = compileOptions ;
220
+ let js = null ;
221
+ let css = null ;
219
222
220
- const banner = `/* ${ this . file ? `${ this . file } ` : `` } generated by Svelte v${ "__VERSION__" } */` ;
223
+ if ( result ) {
224
+ const { compileOptions, name } = this ;
225
+ const { format = 'esm' } = compileOptions ;
221
226
222
- // TODO use same regex for both
223
- result = result . replace ( compileOptions . generate === 'ssr' ? / ( @ + | # + ) ( \w * (?: - \w * ) ? ) / g : / ( @ + ) ( \w * (?: - \w * ) ? ) / g, ( match : string , sigil : string , name : string ) => {
224
- if ( sigil === '@' ) {
225
- if ( internal_exports . has ( name ) ) {
226
- if ( compileOptions . dev && internal_exports . has ( `${ name } Dev` ) ) name = `${ name } Dev` ;
227
- this . helpers . add ( name ) ;
228
- }
227
+ const banner = `/* ${ this . file ? `${ this . file } ` : `` } generated by Svelte v${ "__VERSION__" } */` ;
229
228
230
- return this . alias ( name ) ;
231
- }
229
+ // TODO use same regex for both
230
+ result = result . replace ( compileOptions . generate === 'ssr' ? / ( @ + | # + ) ( \w * (?: - \w * ) ? ) / g : / ( @ + ) ( \w * (?: - \w * ) ? ) / g, ( match : string , sigil : string , name : string ) => {
231
+ if ( sigil === '@' ) {
232
+ if ( internal_exports . has ( name ) ) {
233
+ if ( compileOptions . dev && internal_exports . has ( `${ name } Dev` ) ) name = `${ name } Dev` ;
234
+ this . helpers . add ( name ) ;
235
+ }
232
236
233
- return sigil . slice ( 1 ) + name ;
234
- } ) ;
237
+ return this . alias ( name ) ;
238
+ }
235
239
236
- const importedHelpers = Array . from ( this . helpers )
237
- . sort ( )
238
- . map ( name => {
239
- const alias = this . alias ( name ) ;
240
- return { name, alias } ;
240
+ return sigil . slice ( 1 ) + name ;
241
241
} ) ;
242
242
243
- const module = wrapModule (
244
- result ,
245
- format ,
246
- name ,
247
- compileOptions ,
248
- banner ,
249
- compileOptions . sveltePath ,
250
- importedHelpers ,
251
- this . imports ,
252
- this . vars . filter ( variable => variable . module && variable . export_name ) . map ( variable => ( {
253
- name : variable . name ,
254
- as : variable . export_name
255
- } ) ) ,
256
- this . source
257
- ) ;
243
+ const importedHelpers = Array . from ( this . helpers )
244
+ . sort ( )
245
+ . map ( name => {
246
+ const alias = this . alias ( name ) ;
247
+ return { name, alias } ;
248
+ } ) ;
249
+
250
+ const module = wrapModule (
251
+ result ,
252
+ format ,
253
+ name ,
254
+ compileOptions ,
255
+ banner ,
256
+ compileOptions . sveltePath ,
257
+ importedHelpers ,
258
+ this . imports ,
259
+ this . vars . filter ( variable => variable . module && variable . export_name ) . map ( variable => ( {
260
+ name : variable . name ,
261
+ as : variable . export_name
262
+ } ) ) ,
263
+ this . source
264
+ ) ;
258
265
259
- const parts = module . split ( '✂]' ) ;
260
- const finalChunk = parts . pop ( ) ;
266
+ const parts = module . split ( '✂]' ) ;
267
+ const finalChunk = parts . pop ( ) ;
261
268
262
- const compiled = new Bundle ( { separator : '' } ) ;
269
+ const compiled = new Bundle ( { separator : '' } ) ;
263
270
264
- function addString ( str : string ) {
265
- compiled . addSource ( {
266
- content : new MagicString ( str ) ,
267
- } ) ;
268
- }
271
+ function addString ( str : string ) {
272
+ compiled . addSource ( {
273
+ content : new MagicString ( str ) ,
274
+ } ) ;
275
+ }
269
276
270
- const { filename } = compileOptions ;
277
+ const { filename } = compileOptions ;
271
278
272
- // special case — the source file doesn't actually get used anywhere. we need
273
- // to add an empty file to populate map.sources and map.sourcesContent
274
- if ( ! parts . length ) {
275
- compiled . addSource ( {
276
- filename,
277
- content : new MagicString ( this . source ) . remove ( 0 , this . source . length ) ,
278
- } ) ;
279
- }
279
+ // special case — the source file doesn't actually get used anywhere. we need
280
+ // to add an empty file to populate map.sources and map.sourcesContent
281
+ if ( ! parts . length ) {
282
+ compiled . addSource ( {
283
+ filename,
284
+ content : new MagicString ( this . source ) . remove ( 0 , this . source . length ) ,
285
+ } ) ;
286
+ }
280
287
281
- const pattern = / \[ ✂ ( \d + ) - ( \d + ) $ / ;
288
+ const pattern = / \[ ✂ ( \d + ) - ( \d + ) $ / ;
282
289
283
- parts . forEach ( ( str : string ) => {
284
- const chunk = str . replace ( pattern , '' ) ;
285
- if ( chunk ) addString ( chunk ) ;
290
+ parts . forEach ( ( str : string ) => {
291
+ const chunk = str . replace ( pattern , '' ) ;
292
+ if ( chunk ) addString ( chunk ) ;
286
293
287
- const match = pattern . exec ( str ) ;
294
+ const match = pattern . exec ( str ) ;
288
295
289
- const snippet = this . code . snip ( + match [ 1 ] , + match [ 2 ] ) ;
296
+ const snippet = this . code . snip ( + match [ 1 ] , + match [ 2 ] ) ;
290
297
291
- compiled . addSource ( {
292
- filename,
293
- content : snippet ,
298
+ compiled . addSource ( {
299
+ filename,
300
+ content : snippet ,
301
+ } ) ;
294
302
} ) ;
295
- } ) ;
296
303
297
- addString ( finalChunk ) ;
304
+ addString ( finalChunk ) ;
298
305
299
- const css = compileOptions . customElement ?
300
- { code : null , map : null } :
301
- this . stylesheet . render ( compileOptions . cssOutputFilename , true ) ;
306
+ css = compileOptions . customElement ?
307
+ { code : null , map : null } :
308
+ this . stylesheet . render ( compileOptions . cssOutputFilename , true ) ;
302
309
303
- const js = {
304
- code : compiled . toString ( ) ,
305
- map : compiled . generateMap ( {
306
- includeContent : true ,
307
- file : compileOptions . outputFilename ,
308
- } )
309
- } ;
310
+ js = {
311
+ code : compiled . toString ( ) ,
312
+ map : compiled . generateMap ( {
313
+ includeContent : true ,
314
+ file : compileOptions . outputFilename ,
315
+ } )
316
+ } ;
317
+ }
310
318
311
319
return {
312
- ast : this . ast ,
313
320
js,
314
321
css,
315
- stats : this . stats . render ( this )
322
+ ast : this . ast ,
323
+ warnings : this . warnings ,
324
+ vars : this . vars . filter ( v => ! v . global && ! v . implicit && ! v . internal ) . map ( v => ( {
325
+ name : v . name ,
326
+ export_name : v . export_name || null ,
327
+ injected : v . injected || false ,
328
+ module : v . module || false ,
329
+ mutated : v . mutated || false ,
330
+ reassigned : v . reassigned || false ,
331
+ referenced : v . referenced || false ,
332
+ writable : v . writable || false
333
+ } ) ) ,
334
+ stats : this . stats . render ( )
316
335
} ;
317
336
}
318
337
@@ -393,7 +412,7 @@ export default class Component {
393
412
394
413
const frame = getCodeFrame ( this . source , start . line - 1 , start . column ) ;
395
414
396
- this . stats . warn ( {
415
+ this . warnings . push ( {
397
416
code : warning . code ,
398
417
message : warning . message ,
399
418
frame,
0 commit comments