Skip to content

Commit e6daa5f

Browse files
authored
Add bit and bit32 as lua keywords (#1617)
If code uses bitwise operations, it will import `bit32` (for lua 5.2 target) or `bit` (for luajit target). Add these to the keywords list in safe-names.ts to make sure that they are not overwritten by a variable with the same name. Closes #1615
1 parent 04f2ceb commit e6daa5f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/transformation/utils/safe-names.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export const isValidLuaIdentifier = (name: string, options: CompilerOptions) =>
1616

1717
export const luaKeywords: ReadonlySet<string> = new Set([
1818
"and",
19+
"bit",
20+
"bit32",
1921
"break",
2022
"do",
2123
"else",

test/unit/identifiers.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,15 @@ describe("lua keyword as identifier doesn't interfere with lua's value", () => {
577577
expect(luaResult).toBe("foobar");
578578
});
579579

580+
test("variable (bit32)", () => {
581+
util.testFunction`
582+
const bit32 = 1;
583+
return bit32 << 1;
584+
`
585+
.setOptions({ luaTarget: LuaTarget.Lua52 })
586+
.expectToMatchJsResult();
587+
});
588+
580589
test("variable (_G)", () => {
581590
util.testFunction`
582591
const _G = "bar";

0 commit comments

Comments
 (0)