@@ -246,13 +246,15 @@ export class ReplStore implements Store {
246
246
}
247
247
248
248
addFile ( fileOrFilename : string | File ) : void {
249
- const file =
250
- typeof fileOrFilename === 'string'
251
- ? new File (
252
- fileOrFilename ,
253
- fileOrFilename . endsWith ( '.vue' ) ? newSFCCode : ''
254
- )
255
- : fileOrFilename
249
+ let file : File
250
+ if ( typeof fileOrFilename === 'string' ) {
251
+ file = new File (
252
+ fileOrFilename ,
253
+ fileOrFilename . endsWith ( '.vue' ) ? newSFCCode : ''
254
+ )
255
+ } else {
256
+ file = fileOrFilename
257
+ }
256
258
this . state . files [ file . filename ] = file
257
259
if ( ! file . hidden ) this . setActive ( file . filename )
258
260
}
@@ -342,14 +344,15 @@ export class ReplStore implements Store {
342
344
for ( const filename in newFiles ) {
343
345
setFile ( files , filename , newFiles [ filename ] )
344
346
}
345
- this . state . errors = [ ]
347
+ const errors = [ ]
346
348
for ( const file in files ) {
347
- this . state . errors . push ( ...( await compileFile ( this , files [ file ] ) ) )
349
+ errors . push ( ...( await compileFile ( this , files [ file ] ) ) )
348
350
}
349
- this . state . mainFile = mainFile
351
+ this . state . errors = errors
352
+ this . state . mainFile = addSrcPrefix ( mainFile )
350
353
this . state . files = files
351
354
this . initImportMap ( )
352
- this . setActive ( mainFile )
355
+ this . setActive ( this . state . mainFile )
353
356
this . forceSandboxReset ( )
354
357
}
355
358
@@ -470,15 +473,18 @@ function setFile(
470
473
) {
471
474
// prefix user files with src/
472
475
// for cleaner Volar path completion when using Monaco editor
473
- const normalized =
474
- filename !== importMapFile &&
475
- filename !== tsconfigFile &&
476
- ! filename . startsWith ( 'src/' )
477
- ? `src/${ filename } `
478
- : filename
476
+ const normalized = addSrcPrefix ( filename )
479
477
files [ normalized ] = new File ( normalized , content )
480
478
}
481
479
480
+ function addSrcPrefix ( file : string ) {
481
+ return file === importMapFile ||
482
+ file === tsconfigFile ||
483
+ file . startsWith ( 'src/' )
484
+ ? file
485
+ : `src/${ file } `
486
+ }
487
+
482
488
function fixURL ( url : string ) {
483
489
return url . replace ( 'https://sfc.vuejs' , 'https://play.vuejs' )
484
490
}
0 commit comments