Skip to content

Commit a482c44

Browse files
authored
Transformer v1 (#294)
* Addded NS Transformer * Added block transformation * Fixed manual block visit not being flattened * Flag var statements as static if no module exists * Revert "Merge branch 'master' into transformer-namespace" This reverts commit 773afae, reversing changes made to 743912a. * Removed statement static mod * Added a lot of transformers for expressions and statements * Added remaining implementations for transforms Transfrom & Transpile works now but there are still soem feature missing Many tests (especially translation) will fail aswell. * Fixed bug with default values for constructor parameters * Lualib omit when unused (#280) * lualib inline omit header when no features are used * Tests to enforce no lualib text when unused, unless using always * Fixed wrong version (git fail) * Updated alsatian * Improved empty block handling * Added empty lines between functions
1 parent 227aa60 commit a482c44

File tree

11 files changed

+535
-246
lines changed

11 files changed

+535
-246
lines changed

package-lock.json

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@types/glob": "^5.0.35",
5151
"@types/node": "^9.6.23",
5252
"@types/yargs": "^11.1.1",
53-
"alsatian": "^2.2.1",
53+
"alsatian": "^2.3.0",
5454
"circular-json": "^0.5.5",
5555
"codecov": "3.0.2",
5656
"deep-equal": "^1.0.1",

src/LuaLibFeature.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export enum LuaLibFeature {
2+
ArrayConcat = "ArrayConcat",
3+
ArrayEvery = "ArrayEvery",
4+
ArrayFilter = "ArrayFilter",
5+
ArrayForEach = "ArrayForEach",
6+
ArrayIndexOf = "ArrayIndexOf",
7+
ArrayMap = "ArrayMap",
8+
ArrayPush = "ArrayPush",
9+
ArrayReverse = "ArrayReverse",
10+
ArrayShift = "ArrayShift",
11+
ArrayUnshift = "ArrayUnshift",
12+
ArraySort = "ArraySort",
13+
ArraySlice = "ArraySlice",
14+
ArraySome = "ArraySome",
15+
ArraySplice = "ArraySplice",
16+
InstanceOf = "InstanceOf",
17+
Map = "Map",
18+
Set = "Set",
19+
StringReplace = "StringReplace",
20+
StringSplit = "StringSplit",
21+
Ternary = "Ternary",
22+
}

src/TSHelper.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ export class TSHelper {
5656
return false;
5757
}
5858

59+
public static isIdentifierExported(
60+
identifier: ts.Identifier, scope: ts.ModuleDeclaration | ts.SourceFile, checker: ts.TypeChecker): boolean {
61+
const identifierSymbol = checker.getTypeAtLocation(scope).getSymbol();
62+
if (identifierSymbol.exports) {
63+
return identifierSymbol.exports.has(identifier.escapedText);
64+
}
65+
66+
return false;
67+
}
68+
5969
public static isInDestructingAssignment(node: ts.Node): boolean {
6070
return node.parent && ((ts.isVariableDeclaration(node.parent) && ts.isArrayBindingPattern(node.parent.name))
6171
|| (ts.isBinaryExpression(node.parent) && ts.isArrayLiteralExpression(node.parent.left)));

src/TransformHelper.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import * as ts from "typescript";
22

33
export class TransformHelper {
44
// Helper to create simple lua variable statement;
5-
public static createLuaVariableStatement(
6-
identifier: ts.Identifier,
7-
expression: ts.Expression,
8-
typeNode?: ts.TypeNode
9-
): ts.VariableStatement {
5+
public static createLuaVariableStatement(identifier: ts.Identifier,
6+
expression?: ts.Expression,
7+
typeNode?: ts.TypeNode,
8+
modifiers: ReadonlyArray<ts.Modifier> = []): ts.VariableStatement {
109
const declaration = ts.createVariableDeclaration(identifier, typeNode, expression);
11-
const statement = ts.createVariableStatement([], ts.createVariableDeclarationList([declaration]));
10+
const statement = ts.createVariableStatement(modifiers, ts.createVariableDeclarationList([declaration]));
1211
return statement;
1312
}
1413

@@ -18,4 +17,9 @@ export class TransformHelper {
1817
ts.createCall(requireIdentifier, [ts.createLiteralTypeNode(moduleSpecifier)], [moduleSpecifier]);
1918
return this.createLuaVariableStatement(identifier, requireCall);
2019
}
20+
21+
public static flatten<T>(arr: T[]): T[] {
22+
const flat = [].concat(...arr);
23+
return flat.some(Array.isArray) ? this.flatten(flat) : flat;
24+
}
2125
}

0 commit comments

Comments
 (0)