Skip to content

Commit d22da21

Browse files
TheLartiansPerryvw
authored andcommitted
Fix lua identifier (#358)
* fix-lua-identifier * added test
1 parent 544247e commit d22da21

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/TSHelper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ export class TSHelper {
514514
}
515515

516516
public static isValidLuaIdentifier(str: string): boolean {
517-
return str.match(/[a-zA-Z_][a-zA-Z0-9_]*/) !== null;
517+
const match = str.match(/[a-zA-Z_][a-zA-Z0-9_]*/);
518+
return match && match[0] === str;
518519
}
519520

520521
public static isFalsible(type: ts.Type, strictNullChecks: boolean): boolean {

test/unit/assignments.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,4 +803,14 @@ export class AssignmentTests {
803803
"Unsupported assignment of mixed function/method overload. "
804804
+ "Overloads should either be all functions or all methods, but not both.");
805805
}
806+
807+
@Test("String table access")
808+
public stringTableAccess(assignType: string): void {
809+
const code = `const dict : {[key:string]:any} = {};
810+
dict["a b"] = 3;
811+
return dict["a b"];`;
812+
const result = util.transpileAndExecute(code);
813+
Expect(result).toBe(3);
814+
}
815+
806816
}

0 commit comments

Comments
 (0)