@@ -55,6 +55,19 @@ const luaBuiltins: ReadonlySet<string> = new Set([
5555
5656export const isUnsafeName = ( name : string ) => ! isValidLuaIdentifier ( name ) || luaBuiltins . has ( name ) ;
5757
58+ function checkName ( context : TransformationContext , name : string , node : ts . Node ) : boolean {
59+ const isInvalid = ! isValidLuaIdentifier ( name ) ;
60+
61+ if ( isInvalid ) {
62+ // Empty identifier is a TypeScript error
63+ if ( name !== "" ) {
64+ context . diagnostics . push ( invalidAmbientIdentifierName ( node , name ) ) ;
65+ }
66+ }
67+
68+ return isInvalid ;
69+ }
70+
5871export function hasUnsafeSymbolName (
5972 context : TransformationContext ,
6073 symbol : ts . Symbol ,
@@ -63,8 +76,7 @@ export function hasUnsafeSymbolName(
6376 const isAmbient = symbol . declarations && symbol . declarations . some ( d => isAmbientNode ( d ) ) ;
6477
6578 // Catch ambient declarations of identifiers with bad names
66- if ( ! isValidLuaIdentifier ( symbol . name ) && isAmbient ) {
67- context . diagnostics . push ( invalidAmbientIdentifierName ( tsOriginal , symbol . name ) ) ;
79+ if ( isAmbient && checkName ( context , symbol . name , tsOriginal ) ) {
6880 return true ;
6981 }
7082
@@ -84,12 +96,7 @@ export function hasUnsafeIdentifierName(
8496 }
8597 }
8698
87- if ( ! isValidLuaIdentifier ( identifier . text ) ) {
88- context . diagnostics . push ( invalidAmbientIdentifierName ( identifier , identifier . text ) ) ;
89- return true ;
90- }
91-
92- return false ;
99+ return checkName ( context , identifier . text , identifier ) ;
93100}
94101
95102const fixInvalidLuaIdentifier = ( name : string ) =>
0 commit comments