fixed usage of lua keywords as property names#586
Conversation
src/LuaTransformer.ts
Outdated
| parameters, | ||
| node | ||
| ); | ||
| if (this.isUnsafeName(node.expression.name.text)) { |
There was a problem hiding this comment.
It shouldn't check for builtins there
|
Some inconsistent behavior: declare var local: any;
declare var _G: any;
const a1 = { local };
const a2 = { local: local };
const b1 = { _G };
const b2 = { _G: _G };local a1 = {["local"] = ____local}
local a2 = {["local"] = local}
local b1 = {_G = _____G}
local b2 = {_G = _G}For |
|
I don't think it makes sense to declare a variable |
- not using element call for methods with lua builtin names - fixed shorthand assignment of declared lua builtins - banned lua keywords as identifier names in declare statements
src/LuaTransformer.ts
Outdated
| // Ignore declarations | ||
| if (node.modifiers && node.modifiers.some(modifier => modifier.kind === ts.SyntaxKind.DeclareKeyword)) { | ||
| return undefined; | ||
| return this.transformDeclareStatement(node); |
There was a problem hiding this comment.
These types can be declared in other file that isn't going to be transformed, so it should be handled when it's used
src/LuaTransformer.ts
Outdated
| } | ||
| } | ||
|
|
||
| public transformDeclareStatement(node: ts.Statement): StatementVisitResult { |
There was a problem hiding this comment.
IMO we shouldn't do this anymore. First, it would be quite a surprising behavior if some code would work in .d.ts files (since we don't transform them) and won't in regular. Second, it's pretty much valid to declare it, because it also may be used to augment _G type.
There was a problem hiding this comment.
I see your point about the inconsistency being confusing, but I don't see how that can be a valid declaration. Such variables could be declared as a property of _G, but this error wouldn't be triggered by that.
Also I think it would be a good idea to leave this function in (just returning undefined) as it makes sense as an api method.
There was a problem hiding this comment.
The best type for _G is typeof globalThis, which includes all globally declared symbols
No description provided.