Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4290749
initial hoisting implementation (needs tests)
tomblind Jan 25, 2019
968b12a
fixed issues with switch and loop continue
tomblind Jan 25, 2019
73929f9
Merge remote-tracking branch 'origin/ts-to-lua-ast' into hoisting
tomblind Jan 26, 2019
86c7bd4
dealing with hoisting of imports and exports
tomblind Jan 26, 2019
5bc6764
Merge remote-tracking branch 'origin/ts-to-lua-ast' into hoisting
tomblind Jan 26, 2019
e2374c5
hoisting tests
tomblind Jan 27, 2019
7833a65
fixed namespace hoisting and added more tests
tomblind Jan 27, 2019
f378a01
Merge remote-tracking branch 'origin/master' into hoisting
tomblind Jan 27, 2019
23cde6a
rebuilt translation tests with hoisting
tomblind Jan 28, 2019
5fff23c
fixed tests
tomblind Jan 28, 2019
fbf7072
Merge remote-tracking branch 'origin/master' into hoisting
tomblind Jan 28, 2019
4927c88
More Hoisting Adjustments
tomblind Jan 28, 2019
77303dc
reverting accidentally changed test files
tomblind Jan 28, 2019
e167812
renamed some things for clarity
tomblind Jan 28, 2019
3000e3b
working on possible smart-hoisting detection
tomblind Jan 31, 2019
8592d4a
Merge remote-tracking branch 'origin/master' into hoisting
tomblind Jan 31, 2019
b4157b3
addressed comments
tomblind Jan 31, 2019
086465f
Merge remote-tracking branch 'origin/hoisting' into hoisting-v2
tomblind Jan 31, 2019
27bb3b5
smart-hoisting working
tomblind Jan 31, 2019
58b5237
fixed tests
tomblind Jan 31, 2019
6fabe14
refactored hoisting detection and added command line options to contr…
tomblind Feb 1, 2019
baf226e
Another full refactor
tomblind Feb 1, 2019
67c44b6
change ScopeType to bitfields
tomblind Feb 1, 2019
cd47351
Merge remote-tracking branch 'origin/master' into hoisting
tomblind Feb 1, 2019
31c6890
rewrote hoisting to defer all logic to popScope, so that there's no n…
tomblind Feb 3, 2019
1a846b8
reworked hoisting to avoid printer hacks
tomblind Feb 4, 2019
798bb27
removing unnecessary symbol lookups
tomblind Feb 4, 2019
eadfa75
Merge remote-tracking branch 'origin/master' into hoisting
tomblind Feb 4, 2019
c9c564b
removing accidentally added import
tomblind Feb 4, 2019
d6e83e2
replaced ts.Symbol stored in identifiers with generic ids
tomblind Feb 5, 2019
922380f
split out stuff to separate functions
tomblind Feb 5, 2019
9edd0bc
Merge remote-tracking branch 'origin/master' into hoisting
tomblind Feb 6, 2019
01191da
reverted bad logic which broke referencing exports inside functions
tomblind Feb 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/CommandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export const optionDeclarations: YargsOptions = {
describe: "Specify if a header will be added to compiled files.",
type: "boolean",
},
noHoisting: {
default: false,
describe: "Disables hoisting.",
type: "boolean",
},
};

class CLIError extends Error {}
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ export function transpileString(
const result = transpiler.transpileSourceFile(program.getSourceFile("file.ts"));

return result.trim();
}
}
1 change: 1 addition & 0 deletions src/CompilerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface CompilerOptions extends ts.CompilerOptions {
noHeader?: boolean;
luaTarget?: LuaTarget;
luaLibImport?: LuaLibImportKind;
noHoisting?: boolean;
}

export enum LuaLibImportKind {
Expand Down
12 changes: 11 additions & 1 deletion src/LuaAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export type BinaryOperator =

export type Operator = UnaryOperator | BinaryOperator;

export type SymbolId = number;

// TODO For future sourcemap support?
export interface TextRange {
pos: number;
Expand Down Expand Up @@ -791,15 +793,23 @@ export function createMethodCallExpression(
export interface Identifier extends Expression {
kind: SyntaxKind.Identifier;
text: string;
symbolId?: SymbolId;
}

export function isIdentifier(node: Node): node is Identifier {
return node.kind === SyntaxKind.Identifier;
}

export function createIdentifier(text: string | ts.__String, tsOriginal?: ts.Node, parent?: Node): Identifier {
export function createIdentifier(
text: string | ts.__String,
tsOriginal?: ts.Node,
symbolId?: SymbolId,
parent?: Node
): Identifier
{
const expression = createNode(SyntaxKind.Identifier, tsOriginal, parent) as Identifier;
expression.text = text as string;
expression.symbolId = symbolId;
return expression;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again is it possible to avoid having ts types in the Lua AST?
Sorry I haven't elaborated on why I don't think TS stuff should be in an Lua AST.

Main reason, it's a design choice: Having no TS nodes in the AST clearly separates the transform and print step. Allowing them to run independent of each other. Not having any TS nodes in the AST allows us to easily create Lua ASTs from the ground up (with no TS used to generate the AST).

I think a good compromise would be do just save the symbolID on the AST node, since that would just be a number and not a ts type. And as far as I can tell you only save the symbol to keep track on what should be hoisted? I think the ID could be enough for that purpose.
Or maybe map the tstl.Identifier to the Symbol somewhere else? For example in a Map<> in the Transformer, that way we wouldn't have to store the information on the node itself. Since you don't need that info in there print step there is no reason to save it on the node tbh.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for the explanation - that makes sense to me. All I need here is a way to differentiate unique symbols, so an ID system like you suggest should work.


Expand Down
Loading