@@ -3,15 +3,9 @@ import * as lua from "../../LuaAST";
33import { assertNever } from "../../utils" ;
44import { FunctionVisitor , TransformationContext , Visitors } from "../context" ;
55import { unsupportedAccessorInObjectLiteral } from "../utils/diagnostics" ;
6- import { InvalidAmbientIdentifierName } from "../utils/errors" ;
76import { createExportedIdentifier , getSymbolExportScope } from "../utils/export" ;
87import { LuaLibFeature , transformLuaLibFunction } from "../utils/lualib" ;
9- import {
10- createSafeName ,
11- hasUnsafeIdentifierName ,
12- hasUnsafeSymbolName ,
13- isValidLuaIdentifier ,
14- } from "../utils/safe-names" ;
8+ import { createSafeName , hasUnsafeIdentifierName , hasUnsafeSymbolName } from "../utils/safe-names" ;
159import { getSymbolIdOfSymbol , trackSymbolReference } from "../utils/symbols" ;
1610import { isArrayType } from "../utils/typescript" ;
1711import { transformFunctionLikeDeclaration } from "./function" ;
@@ -32,20 +26,13 @@ export function createShorthandIdentifier(
3226 valueSymbol : ts . Symbol | undefined ,
3327 propertyIdentifier : ts . Identifier
3428) : lua . Expression {
35- let name : string ;
36- if ( valueSymbol !== undefined ) {
37- name = hasUnsafeSymbolName ( context , valueSymbol , propertyIdentifier )
38- ? createSafeName ( valueSymbol . name )
39- : valueSymbol . name ;
40- } else {
41- const propertyName = propertyIdentifier . text ;
42- if ( ! isValidLuaIdentifier ( propertyName ) ) {
43- // Catch ambient declarations of identifiers with bad names
44- throw InvalidAmbientIdentifierName ( propertyIdentifier ) ;
45- }
29+ const propertyName = propertyIdentifier . text ;
4630
47- name = hasUnsafeIdentifierName ( context , propertyIdentifier ) ? createSafeName ( propertyName ) : propertyName ;
48- }
31+ const isUnsafeName = valueSymbol
32+ ? hasUnsafeSymbolName ( context , valueSymbol , propertyIdentifier )
33+ : hasUnsafeIdentifierName ( context , propertyIdentifier , false ) ;
34+
35+ const name = isUnsafeName ? createSafeName ( propertyName ) : propertyName ;
4936
5037 let identifier = context . transformExpression ( ts . createIdentifier ( name ) ) ;
5138 lua . setNodeOriginal ( identifier , propertyIdentifier ) ;
0 commit comments