22import { Except , SetOptional } from 'type-fest'
33import * as semver from 'semver'
44import type { MatchParentsType } from './utilTypes'
5+ import isVueFileName from './utils/vue/isVueFileName'
56
67export function findChildContainingPosition ( typescript : typeof ts , sourceFile : ts . SourceFile , position : number ) : ts . Node | undefined {
78 function find ( node : ts . Node ) : ts . Node | undefined {
@@ -354,7 +355,7 @@ export const isValidInitializerForDestructure = (match: ts.Expression) => {
354355
355356 return true
356357}
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 ) => {
358359 const checker = getFullTypeChecker ( typeChecker )
359360 let hasCollision : boolean | undefined
360361
@@ -366,7 +367,6 @@ export const isNameUniqueAtLocation = (name: string, location: ts.Node | undefin
366367 childNode . forEachChild ( checkCollision )
367368 }
368369 }
369- if ( ! location ) return
370370
371371 if ( ts . isSourceFile ( location ) ) {
372372 hasCollision = createUniqueName ( name , location as any ) !== name
@@ -385,6 +385,8 @@ const getClosestParentScope = (node: ts.Node) => {
385385}
386386export const isNameUniqueAtNodeClosestScope = ( name : string , node : ts . Node , typeChecker : ts . TypeChecker ) => {
387387 const closestScope = getClosestParentScope ( node )
388+ if ( ! closestScope ) return
389+
388390 return isNameUniqueAtLocation ( name , closestScope , typeChecker )
389391}
390392
@@ -423,6 +425,9 @@ const createUniqueName = (name: string, sourceFile: ts.SourceFile) => {
423425 return ( parent as ts . ImportSpecifier ) . propertyName !== node
424426 case ts . SyntaxKind . PropertyAssignment :
425427 return ( parent as ts . PropertyAssignment ) . name !== node
428+ // Skip identifiers in vue template
429+ case ts . SyntaxKind . ArrayLiteralExpression :
430+ return ! isVueFileName ( sourceFile . fileName )
426431 default :
427432 return true
428433 }
@@ -437,6 +442,7 @@ const createUniqueName = (name: string, sourceFile: ts.SourceFile) => {
437442 while ( identifiers . includes ( name ) ) {
438443 name = `_${ name } `
439444 }
445+
440446 return name
441447}
442448
0 commit comments