typescript-to-lua
Version:
A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!
65 lines (64 loc) • 3.04 kB
TypeScript
import * as ts from "typescript";
import { CompilerOptions, LuaTarget } from "../../CompilerOptions";
import * as lua from "../../LuaAST";
import { ExpressionLikeNode, StatementLikeNode, VisitorMap } from "./visitors";
import { SymbolInfo } from "../utils/symbols";
import { LuaLibFeature } from "../../LuaLib";
import { Scope, ScopeType } from "../utils/scope";
export declare const tempSymbolId: lua.SymbolId;
export interface AllAccessorDeclarations {
firstAccessor: ts.AccessorDeclaration;
getAccessor: ts.GetAccessorDeclaration | undefined;
setAccessor: ts.SetAccessorDeclaration | undefined;
}
export interface EmitResolver {
isValueAliasDeclaration(node: ts.Node): boolean;
isReferencedAliasDeclaration(node: ts.Node, checkChildren?: boolean): boolean;
isTopLevelValueImportEqualsWithEntityName(node: ts.ImportEqualsDeclaration): boolean;
}
export interface TypeCheckerWithEmitResolver extends ts.TypeChecker {
getEmitResolver(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): EmitResolver;
}
export declare class TransformationContext {
program: ts.Program;
sourceFile: ts.SourceFile;
private visitorMap;
readonly diagnostics: ts.Diagnostic[];
readonly checker: TypeCheckerWithEmitResolver;
readonly resolver: EmitResolver;
readonly precedingStatementsStack: lua.Statement[][];
readonly options: CompilerOptions;
readonly luaTarget: LuaTarget;
readonly isModule: boolean;
readonly isStrict: boolean;
constructor(program: ts.Program, sourceFile: ts.SourceFile, visitorMap: VisitorMap);
private currentNodeVisitors;
private currentNodeVisitorsIndex;
private nextTempId;
transformNode(node: ts.Node): lua.Node[];
superTransformNode(node: ts.Node): lua.Node[];
private doSuperTransformNode;
transformExpression(node: ExpressionLikeNode): lua.Expression;
private assertIsExpression;
superTransformExpression(node: ExpressionLikeNode): lua.Expression;
transformStatements(node: StatementLikeNode | readonly StatementLikeNode[]): lua.Statement[];
superTransformStatements(node: StatementLikeNode | readonly StatementLikeNode[]): lua.Statement[];
pushPrecedingStatements(): void;
popPrecedingStatements(): lua.Statement[];
addPrecedingStatements(statements: lua.Statement | lua.Statement[]): void;
prependPrecedingStatements(statements: lua.Statement | lua.Statement[]): void;
createTempName(prefix?: string): string;
private getTempNameForLuaExpression;
createTempNameForLuaExpression(expression: lua.Expression): lua.Identifier;
private getTempNameForNode;
createTempNameForNode(node: ts.Node): lua.Identifier;
private lastSymbolId;
readonly symbolInfoMap: Map<lua.SymbolId, SymbolInfo>;
readonly symbolIdMaps: Map<ts.Symbol, lua.SymbolId>;
nextSymbolId(): lua.SymbolId;
readonly usedLuaLibFeatures: Set<LuaLibFeature>;
readonly scopeStack: Scope[];
private lastScopeId;
pushScope(type: ScopeType): Scope;
popScope(): Scope;
}