@@ -361,7 +361,9 @@ async function findAllScripts(buffer: string): Promise<StringMap> {
361361 } ,
362362 onLiteralValue ( value : any , _offset : number , _length : number ) {
363363 if ( script ) {
364- scripts [ script ] = value ;
364+ if ( typeof value === 'string' ) {
365+ scripts [ script ] = value ;
366+ }
365367 script = undefined ;
366368 }
367369 } ,
@@ -419,6 +421,7 @@ export function findAllScriptRanges(buffer: string): Map<string, [number, number
419421
420422export function findScriptAtPosition ( buffer : string , offset : number ) : string | undefined {
421423 let script : string | undefined = undefined ;
424+ let foundScript : string | undefined = undefined ;
422425 let inScripts = false ;
423426 let scriptStart : number | undefined ;
424427 let visitor : JSONVisitor = {
@@ -432,9 +435,10 @@ export function findScriptAtPosition(buffer: string, offset: number): string | u
432435 } ,
433436 onLiteralValue ( value : any , nodeOffset : number , nodeLength : number ) {
434437 if ( inScripts && scriptStart ) {
435- if ( offset >= scriptStart && offset < nodeOffset + nodeLength ) {
438+ if ( typeof value === 'string' && offset >= scriptStart && offset < nodeOffset + nodeLength ) {
436439 // found the script
437440 inScripts = false ;
441+ foundScript = script ;
438442 } else {
439443 script = undefined ;
440444 }
@@ -447,11 +451,13 @@ export function findScriptAtPosition(buffer: string, offset: number): string | u
447451 else if ( inScripts ) {
448452 scriptStart = nodeOffset ;
449453 script = property ;
454+ } else { // nested object which is invalid, ignore the script
455+ script = undefined ;
450456 }
451457 }
452458 } ;
453459 visit ( buffer , visitor ) ;
454- return script ;
460+ return foundScript ;
455461}
456462
457463export async function getScripts ( packageJsonUri : Uri ) : Promise < StringMap | undefined > {
0 commit comments