X Tutup
Skip to content

Commit bc64913

Browse files
tomblindPerryvw
authored andcommitted
passing nil instead of _G as context for global functions when in ES … (#271)
* passing nil instead of _G as context for global functions when in ES strict mode * fixed logic for determining strict mode * replaced hack-around when passing nil as a function context with a null keyword
1 parent c97bf17 commit bc64913

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Transpiler.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export abstract class LuaTranspiler {
7474
public namespace: string[];
7575
public importCount: number;
7676
public isModule: boolean;
77+
public isStrict: boolean;
7778
public sourceFile: ts.SourceFile;
7879
public loopStack: number[];
7980
public classStack: string[];
@@ -91,6 +92,9 @@ export abstract class LuaTranspiler {
9192
this.importCount = 0;
9293
this.sourceFile = sourceFile;
9394
this.isModule = tsHelper.isFileModule(sourceFile);
95+
this.isStrict = options.alwaysStrict
96+
|| (options.strict && options.alwaysStrict !== false)
97+
|| (this.isModule && options.target && options.target >= ts.ScriptTarget.ES2015);
9498
this.loopStack = [];
9599
this.classStack = [];
96100
this.exportStack = [];
@@ -1158,7 +1162,8 @@ export abstract class LuaTranspiler {
11581162
if (!ts.isPropertyAccessExpression(node.expression)
11591163
&& !ts.isElementAccessExpression(node.expression)
11601164
&& !tsHelper.getCustomDecorators(type, this.checker).has(DecoratorKind.NoContext)) {
1161-
params = this.transpileArguments(node.arguments, ts.createIdentifier("_G"));
1165+
const context = this.isStrict ? ts.createNull() : ts.createIdentifier("_G");
1166+
params = this.transpileArguments(node.arguments, context);
11621167
} else {
11631168
params = this.transpileArguments(node.arguments);
11641169
}
@@ -1197,7 +1202,8 @@ export abstract class LuaTranspiler {
11971202
if (!ts.isPropertyAccessExpression(node.expression)
11981203
&& !ts.isElementAccessExpression(node.expression)
11991204
&& !tsHelper.getCustomDecorators(type, this.checker).has(DecoratorKind.NoContext)) {
1200-
params = this.transpileArguments(node.arguments, ts.createIdentifier("_G"));
1205+
const context = this.isStrict ? ts.createNull() : ts.createIdentifier("_G");
1206+
params = this.transpileArguments(node.arguments, context);
12011207
} else {
12021208
params = this.transpileArguments(node.arguments);
12031209
}

0 commit comments

Comments
 (0)
X Tutup