Skip to content

Commit 743912a

Browse files
committed
Flag var statements as static if no module exists
1 parent c62259e commit 743912a

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/TransformHelper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ export class TransformHelper {
44
// Helper to create simple lua variable statement;
55
public static createLuaVariableStatement(identifier: ts.Identifier,
66
expression?: ts.Expression,
7-
typeNode?: ts.TypeNode): ts.VariableStatement {
7+
typeNode?: ts.TypeNode,
8+
modifiers: ReadonlyArray<ts.Modifier> = []): ts.VariableStatement {
89
const declaration = ts.createVariableDeclaration(identifier, typeNode, expression);
9-
const statement = ts.createVariableStatement([], ts.createVariableDeclarationList([declaration]));
10+
const statement = ts.createVariableStatement(modifiers, ts.createVariableDeclarationList([declaration]));
1011
return statement;
1112
}
1213

src/Transformer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ export class LuaTransformer {
304304
return undefined;
305305
}
306306
public visitVariableStatement(node: ts.VariableStatement): ts.VisitResult<ts.VariableStatement> {
307+
// TODO maybe flag as gglobal/local here somehow?
308+
if (!this.isModule && !this.currentNamespace) {
309+
return ts.updateVariableStatement(
310+
node, [ts.createModifier(ts.SyntaxKind.StaticKeyword)], node.declarationList);
311+
}
307312
return node;
308313
}
309314
public visitExpressionStatement(node: ts.ExpressionStatement): ts.VisitResult<ts.ExpressionStatement> {

test/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fs.copyFileSync(
2323
testRunner.outputStream
2424
// this will use alsatian's default output if you remove this
2525
// you'll get TAP or you can add your favourite TAP reporter in it's place
26-
// .pipe(TapBark.create().getPipeable())
26+
.pipe(TapBark.create().getPipeable())
2727
// pipe to the console
2828
.pipe(process.stdout);
2929

0 commit comments

Comments
 (0)