2
2
import { Except , SetOptional } from 'type-fest'
3
3
import * as semver from 'semver'
4
4
import type { MatchParentsType } from './utilTypes'
5
+ import isVueFileName from './utils/vue/isVueFileName'
5
6
6
7
export function findChildContainingPosition ( typescript : typeof ts , sourceFile : ts . SourceFile , position : number ) : ts . Node | undefined {
7
8
function find ( node : ts . Node ) : ts . Node | undefined {
@@ -354,7 +355,7 @@ export const isValidInitializerForDestructure = (match: ts.Expression) => {
354
355
355
356
return true
356
357
}
357
- export const isNameUniqueAtLocation = ( name : string , location : ts . Node | undefined , typeChecker : ts . TypeChecker ) => {
358
+ export const isNameUniqueAtLocation = ( name : string , location : ts . Node , typeChecker : ts . TypeChecker ) => {
358
359
const checker = getFullTypeChecker ( typeChecker )
359
360
let hasCollision : boolean | undefined
360
361
@@ -366,7 +367,6 @@ export const isNameUniqueAtLocation = (name: string, location: ts.Node | undefin
366
367
childNode . forEachChild ( checkCollision )
367
368
}
368
369
}
369
- if ( ! location ) return
370
370
371
371
if ( ts . isSourceFile ( location ) ) {
372
372
hasCollision = createUniqueName ( name , location as any ) !== name
@@ -385,6 +385,8 @@ const getClosestParentScope = (node: ts.Node) => {
385
385
}
386
386
export const isNameUniqueAtNodeClosestScope = ( name : string , node : ts . Node , typeChecker : ts . TypeChecker ) => {
387
387
const closestScope = getClosestParentScope ( node )
388
+ if ( ! closestScope ) return
389
+
388
390
return isNameUniqueAtLocation ( name , closestScope , typeChecker )
389
391
}
390
392
@@ -423,6 +425,9 @@ const createUniqueName = (name: string, sourceFile: ts.SourceFile) => {
423
425
return ( parent as ts . ImportSpecifier ) . propertyName !== node
424
426
case ts . SyntaxKind . PropertyAssignment :
425
427
return ( parent as ts . PropertyAssignment ) . name !== node
428
+ // Skip identifiers in vue template
429
+ case ts . SyntaxKind . ArrayLiteralExpression :
430
+ return ! isVueFileName ( sourceFile . fileName )
426
431
default :
427
432
return true
428
433
}
@@ -437,6 +442,7 @@ const createUniqueName = (name: string, sourceFile: ts.SourceFile) => {
437
442
while ( identifiers . includes ( name ) ) {
438
443
name = `_${ name } `
439
444
}
445
+
440
446
return name
441
447
}
442
448
0 commit comments