typescript-to-lua
Advanced tools
Comparing version 0.21.1 to 0.22.0
@@ -6,7 +6,7 @@ "use strict"; | ||
const CompilerOptions_1 = require("./CompilerOptions"); | ||
const diagnostics = require("./diagnostics"); | ||
const diagnosticFactories = require("./diagnostics"); | ||
const optionDeclarations = [ | ||
{ | ||
name: "luaLibImport", | ||
describe: "Specifies how js standard features missing in lua are imported.", | ||
description: "Specifies how js standard features missing in lua are imported.", | ||
type: "enum", | ||
@@ -18,3 +18,3 @@ choices: Object.values(CompilerOptions_1.LuaLibImportKind), | ||
aliases: ["lt"], | ||
describe: "Specify Lua target version.", | ||
description: "Specify Lua target version.", | ||
type: "enum", | ||
@@ -25,3 +25,3 @@ choices: Object.values(CompilerOptions_1.LuaTarget), | ||
name: "noHeader", | ||
describe: "Specify if a header will be added to compiled files.", | ||
description: "Specify if a header will be added to compiled files.", | ||
type: "boolean", | ||
@@ -31,3 +31,3 @@ }, | ||
name: "noHoisting", | ||
describe: "Disables hoisting.", | ||
description: "Disables hoisting.", | ||
type: "boolean", | ||
@@ -37,3 +37,3 @@ }, | ||
name: "sourceMapTraceback", | ||
describe: "Applies the source map to show source TS files and lines in error tracebacks.", | ||
description: "Applies the source map to show source TS files and lines in error tracebacks.", | ||
type: "boolean", | ||
@@ -61,3 +61,3 @@ }, | ||
const spacing = " ".repeat(Math.max(1, 45 - optionString.length - valuesHint.length)); | ||
result += `\n ${optionString} <${valuesHint}>${spacing}${option.describe}\n`; | ||
result += `\n ${optionString} <${valuesHint}>${spacing}${option.description}\n`; | ||
} | ||
@@ -80,3 +80,3 @@ return result; | ||
if (hasRootLevelOptions) { | ||
parsedConfigFile.errors.push(diagnostics.tstlOptionsAreMovingToTheTstlObject(parsedConfigFile.raw.tstl)); | ||
parsedConfigFile.errors.push(diagnosticFactories.tstlOptionsAreMovingToTheTstlObject(parsedConfigFile.raw.tstl)); | ||
} | ||
@@ -86,3 +86,3 @@ for (const key in parsedConfigFile.raw.tstl) { | ||
if (!option) { | ||
parsedConfigFile.errors.push(diagnostics.unknownCompilerOption(key)); | ||
parsedConfigFile.errors.push(diagnosticFactories.unknownCompilerOption(key)); | ||
continue; | ||
@@ -144,5 +144,5 @@ } | ||
} | ||
else if (value === undefined) { | ||
if (value === undefined) { | ||
return { | ||
error: diagnostics.compilerOptionExpectsAnArgument(option.name), | ||
error: diagnosticFactories.compilerOptionExpectsAnArgument(option.name), | ||
value: undefined, | ||
@@ -162,3 +162,3 @@ increment: 0, | ||
value: undefined, | ||
error: diagnostics.compilerOptionRequiresAValueOfType(option.name, "boolean"), | ||
error: diagnosticFactories.compilerOptionRequiresAValueOfType(option.name, "boolean"), | ||
}; | ||
@@ -172,3 +172,3 @@ } | ||
value: undefined, | ||
error: diagnostics.compilerOptionRequiresAValueOfType(option.name, "string"), | ||
error: diagnosticFactories.compilerOptionRequiresAValueOfType(option.name, "string"), | ||
}; | ||
@@ -181,3 +181,3 @@ } | ||
value: undefined, | ||
error: diagnostics.argumentForOptionMustBe(`--${option.name}`, optionChoices), | ||
error: diagnosticFactories.argumentForOptionMustBe(`--${option.name}`, optionChoices), | ||
}; | ||
@@ -184,0 +184,0 @@ } |
import * as ts from "typescript"; | ||
export interface CompilerOptions extends ts.CompilerOptions { | ||
declare type KnownKeys<T> = { | ||
[K in keyof T]: string extends K ? never : number extends K ? never : K; | ||
} extends { | ||
[_ in keyof T]: infer U; | ||
} ? U : never; | ||
declare type OmitIndexSignature<T extends Record<any, any>> = Pick<T, KnownKeys<T>>; | ||
export interface TransformerImport { | ||
transform: string; | ||
import?: string; | ||
after?: boolean; | ||
afterDeclarations?: boolean; | ||
type?: "program" | "config" | "checker" | "raw" | "compilerOptions"; | ||
[option: string]: any; | ||
} | ||
export declare type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & { | ||
noHeader?: boolean; | ||
@@ -8,3 +22,5 @@ luaTarget?: LuaTarget; | ||
sourceMapTraceback?: boolean; | ||
} | ||
plugins?: Array<ts.PluginImport | TransformerImport>; | ||
[option: string]: ts.CompilerOptions[string] | Array<ts.PluginImport | TransformerImport>; | ||
}; | ||
export declare enum LuaLibImportKind { | ||
@@ -22,1 +38,2 @@ None = "none", | ||
} | ||
export {}; |
@@ -20,3 +20,5 @@ export declare class Decorator { | ||
NoSelf = "NoSelf", | ||
NoSelfInFile = "NoSelfInFile" | ||
NoSelfInFile = "NoSelfInFile", | ||
Vararg = "Vararg", | ||
ForRange = "ForRange" | ||
} |
@@ -33,2 +33,6 @@ "use strict"; | ||
return DecoratorKind.NoSelfInFile; | ||
case "vararg": | ||
return DecoratorKind.Vararg; | ||
case "forrange": | ||
return DecoratorKind.ForRange; | ||
} | ||
@@ -61,3 +65,5 @@ return undefined; | ||
DecoratorKind["NoSelfInFile"] = "NoSelfInFile"; | ||
DecoratorKind["Vararg"] = "Vararg"; | ||
DecoratorKind["ForRange"] = "ForRange"; | ||
})(DecoratorKind = exports.DecoratorKind || (exports.DecoratorKind = {})); | ||
//# sourceMappingURL=Decorator.js.map |
import * as ts from "typescript"; | ||
import { TranspileError } from "./TranspileError"; | ||
export declare const transpileError: (error: TranspileError) => { | ||
file: ts.SourceFile; | ||
start: number; | ||
length: number; | ||
category: ts.DiagnosticCategory; | ||
code: number; | ||
source: string; | ||
messageText: string; | ||
}; | ||
export declare const tstlOptionsAreMovingToTheTstlObject: (tstl: Record<string, any>) => { | ||
file: undefined; | ||
start: undefined; | ||
length: undefined; | ||
category: ts.DiagnosticCategory; | ||
code: number; | ||
source: string; | ||
messageText: string; | ||
}; | ||
export declare const transpileError: (error: TranspileError) => ts.Diagnostic; | ||
export declare const tstlOptionsAreMovingToTheTstlObject: (tstl: Record<string, any>) => ts.Diagnostic; | ||
export declare const toLoadTransformerItShouldBeTranspiled: (transform: string) => ts.Diagnostic; | ||
export declare const couldNotResolveTransformerFrom: (transform: string, base: string) => ts.Diagnostic; | ||
export declare const transformerShouldHaveAExport: (transform: string, importName: string) => ts.Diagnostic; | ||
export declare const transformerShouldBeATsTransformerFactory: (transform: string) => ts.Diagnostic; | ||
export declare const watchErrorSummary: (errorCount: number) => ts.Diagnostic; | ||
@@ -29,2 +17,3 @@ export declare const unknownCompilerOption: (name: string) => ts.Diagnostic; | ||
export declare const argumentForOptionMustBe: (name: string, values: string) => ts.Diagnostic; | ||
export declare const optionCanOnlyBeSpecifiedInTsconfigJsonFile: (name: string) => ts.Diagnostic; | ||
export declare const optionBuildMustBeFirstCommandLineArgument: () => ts.Diagnostic; |
@@ -23,2 +23,38 @@ "use strict"; | ||
}); | ||
exports.toLoadTransformerItShouldBeTranspiled = (transform) => ({ | ||
file: undefined, | ||
start: undefined, | ||
length: undefined, | ||
category: ts.DiagnosticCategory.Error, | ||
code: 0, | ||
source: "typescript-to-lua", | ||
messageText: `To load "${transform}" transformer it should be transpiled or "ts-node" should be installed`, | ||
}); | ||
exports.couldNotResolveTransformerFrom = (transform, base) => ({ | ||
file: undefined, | ||
start: undefined, | ||
length: undefined, | ||
category: ts.DiagnosticCategory.Error, | ||
code: 0, | ||
source: "typescript-to-lua", | ||
messageText: `Could not resolve "${transform}" transformer from "${base}".`, | ||
}); | ||
exports.transformerShouldHaveAExport = (transform, importName) => ({ | ||
file: undefined, | ||
start: undefined, | ||
length: undefined, | ||
category: ts.DiagnosticCategory.Error, | ||
code: 0, | ||
source: "typescript-to-lua", | ||
messageText: `"${transform}" transformer should have a "${importName}" export`, | ||
}); | ||
exports.transformerShouldBeATsTransformerFactory = (transform) => ({ | ||
file: undefined, | ||
start: undefined, | ||
length: undefined, | ||
category: ts.DiagnosticCategory.Error, | ||
code: 0, | ||
source: "typescript-to-lua", | ||
messageText: `"${transform}" transformer should be a ts.TransformerFactory or an object with ts.TransformerFactory values`, | ||
}); | ||
exports.watchErrorSummary = (errorCount) => ({ | ||
@@ -49,3 +85,4 @@ file: undefined, | ||
exports.argumentForOptionMustBe = createCommandLineError(6046, (name, values) => `Argument for '${name}' option must be: ${values}.`); | ||
exports.optionCanOnlyBeSpecifiedInTsconfigJsonFile = createCommandLineError(6064, (name) => `Option '${name}' can only be specified in 'tsconfig.json' file.`); | ||
exports.optionBuildMustBeFirstCommandLineArgument = createCommandLineError(6369, () => "Option '--build' must be the first command line argument."); | ||
//# sourceMappingURL=diagnostics.js.map |
@@ -54,3 +54,4 @@ export declare enum LuaLibFeature { | ||
Symbol = "Symbol", | ||
SymbolRegistry = "SymbolRegistry" | ||
SymbolRegistry = "SymbolRegistry", | ||
TypeOf = "TypeOf" | ||
} | ||
@@ -57,0 +58,0 @@ export declare class LuaLib { |
@@ -60,2 +60,3 @@ "use strict"; | ||
LuaLibFeature["SymbolRegistry"] = "SymbolRegistry"; | ||
LuaLibFeature["TypeOf"] = "TypeOf"; | ||
})(LuaLibFeature = exports.LuaLibFeature || (exports.LuaLibFeature = {})); | ||
@@ -62,0 +63,0 @@ const luaLibDependencies = { |
import * as ts from "typescript"; | ||
import { CompilerOptions } from "./CompilerOptions"; | ||
import { CompilerOptions, LuaTarget } from "./CompilerOptions"; | ||
import * as tstl from "./LuaAST"; | ||
@@ -15,4 +15,8 @@ import { LuaLibFeature } from "./LuaLib"; | ||
} | ||
interface SymbolInfo { | ||
symbol: ts.Symbol; | ||
firstSeenAtPos: number; | ||
} | ||
interface FunctionDefinitionInfo { | ||
referencedSymbols: Set<tstl.SymbolId>; | ||
referencedSymbols: Map<tstl.SymbolId, ts.Node[]>; | ||
definition?: tstl.VariableDeclarationStatement | tstl.AssignmentStatement; | ||
@@ -23,3 +27,3 @@ } | ||
id: number; | ||
referencedSymbols?: Set<tstl.SymbolId>; | ||
referencedSymbols?: Map<tstl.SymbolId, ts.Node[]>; | ||
variableDeclarations?: tstl.VariableDeclarationStatement[]; | ||
@@ -41,24 +45,24 @@ functionDefinitions?: Map<tstl.SymbolId, FunctionDefinitionInfo>; | ||
protected program: ts.Program; | ||
private isStrict; | ||
private luaTarget; | ||
private checker; | ||
protected isStrict: boolean; | ||
protected luaTarget: LuaTarget; | ||
protected checker: DiagnosticsProducingTypeChecker; | ||
protected options: CompilerOptions; | ||
private resolver; | ||
private isModule; | ||
private currentSourceFile?; | ||
private currentNamespace; | ||
private classStack; | ||
private scopeStack; | ||
private genVarCounter; | ||
private luaLibFeatureSet; | ||
private symbolInfo; | ||
private symbolIds; | ||
private genSymbolIdCounter; | ||
private readonly typeValidationCache; | ||
protected resolver: EmitResolver; | ||
protected isModule: boolean; | ||
protected currentSourceFile?: ts.SourceFile; | ||
protected currentNamespace: ts.ModuleDeclaration | undefined; | ||
protected classStack: ts.ClassLikeDeclaration[]; | ||
protected scopeStack: Scope[]; | ||
protected genVarCounter: number; | ||
protected luaLibFeatureSet: Set<LuaLibFeature>; | ||
protected symbolInfo: Map<number, SymbolInfo>; | ||
protected symbolIds: Map<ts.Symbol, number>; | ||
protected genSymbolIdCounter: number; | ||
protected readonly typeValidationCache: Map<ts.Type, Set<ts.Type>>; | ||
constructor(program: ts.Program); | ||
private setupState; | ||
protected setupState(): void; | ||
transformSourceFile(node: ts.SourceFile): [tstl.Block, Set<LuaLibFeature>]; | ||
transformStatement(node: ts.Statement): StatementVisitResult; | ||
/** Converts an array of ts.Statements into an array of tstl.Statements */ | ||
private transformStatements; | ||
protected transformStatements(statements: readonly ts.Statement[]): tstl.Statement[]; | ||
transformBlock(block: ts.Block): tstl.Block; | ||
@@ -68,19 +72,20 @@ transformBlockAsDoStatement(block: ts.Block): StatementVisitResult; | ||
transformImportDeclaration(statement: ts.ImportDeclaration): StatementVisitResult; | ||
private createModuleRequire; | ||
private validateClassElement; | ||
protected createModuleRequire(moduleSpecifier: ts.StringLiteral, resolveModule?: boolean): tstl.CallExpression; | ||
protected validateClassElement(element: ts.ClassElement): void; | ||
transformImportEqualsDeclaration(declaration: ts.ImportEqualsDeclaration): StatementVisitResult; | ||
transformExternalModuleReference(externalModuleReference: ts.ExternalModuleReference): ExpressionVisitResult; | ||
private transformEntityName; | ||
protected transformEntityName(entityName: ts.EntityName): ExpressionVisitResult; | ||
transformQualifiedName(qualifiedName: ts.QualifiedName): ExpressionVisitResult; | ||
transformClassDeclaration(statement: ts.ClassLikeDeclaration, nameOverride?: tstl.Identifier): StatementVisitResult; | ||
private createClassCreationMethods; | ||
private transformClassInstanceFields; | ||
private createConstructorName; | ||
private transformConstructorDeclaration; | ||
protected createClassCreationMethods(statement: ts.ClassLikeDeclarationBase, className: tstl.Identifier, localClassName: tstl.Identifier, classNameText: string, extendsType?: ts.Type): tstl.Statement[]; | ||
protected transformClassInstanceFields(classDeclaration: ts.ClassLikeDeclaration, instanceFields: ts.PropertyDeclaration[]): tstl.Statement[]; | ||
protected createConstructorName(className: tstl.Identifier): tstl.TableIndexExpression; | ||
protected transformConstructorDeclaration(statement: ts.ConstructorDeclaration, className: tstl.Identifier, instanceFields: ts.PropertyDeclaration[], classDeclaration: ts.ClassLikeDeclaration): StatementVisitResult; | ||
transformGetAccessorDeclaration(getAccessor: ts.GetAccessorDeclaration, className: tstl.Identifier): StatementVisitResult; | ||
transformSetAccessorDeclaration(setAccessor: ts.SetAccessorDeclaration, className: tstl.Identifier): StatementVisitResult; | ||
transformMethodDeclaration(node: ts.MethodDeclaration, className: tstl.Identifier, noPrototype: boolean): StatementVisitResult; | ||
private transformParameters; | ||
private transformFunctionBody; | ||
private transformParameterDefaultValueDeclaration; | ||
protected transformParameters(parameters: ts.NodeArray<ts.ParameterDeclaration>, context?: tstl.Identifier): [tstl.Identifier[], tstl.DotsLiteral | undefined, tstl.Identifier | undefined]; | ||
protected isRestParameterReferenced(identifier: tstl.Identifier, scope: Scope): boolean; | ||
protected transformFunctionBody(parameters: ts.NodeArray<ts.ParameterDeclaration>, body: ts.Block, spreadIdentifier?: tstl.Identifier): [tstl.Statement[], Scope]; | ||
protected transformParameterDefaultValueDeclaration(parameterName: tstl.Identifier, value?: ts.Expression, tsOriginal?: ts.Node): tstl.Statement; | ||
transformBindingPattern(pattern: ts.BindingPattern, table: tstl.Identifier, propertyAccessStack?: ts.PropertyName[]): StatementVisitResult; | ||
@@ -95,3 +100,3 @@ protected createModuleLocalNameIdentifier(declaration: ts.ModuleDeclaration): tstl.Identifier; | ||
}>; | ||
private transformGeneratorFunction; | ||
protected transformGeneratorFunction(parameters: ts.NodeArray<ts.ParameterDeclaration>, body: ts.Block, spreadIdentifier?: tstl.Identifier): [tstl.Statement[], Scope]; | ||
transformFunctionDeclaration(functionDeclaration: ts.FunctionDeclaration): StatementVisitResult; | ||
@@ -109,8 +114,9 @@ transformTypeAliasDeclaration(_statement: ts.TypeAliasDeclaration): StatementVisitResult; | ||
transformForStatement(statement: ts.ForStatement): StatementVisitResult; | ||
private transformForOfInitializer; | ||
protected transformForOfInitializer(initializer: ts.ForInitializer, expression: tstl.Expression): tstl.Statement; | ||
protected transformLoopBody(loop: ts.WhileStatement | ts.DoStatement | ts.ForStatement | ts.ForOfStatement | ts.ForInOrOfStatement): tstl.Statement[]; | ||
private transformBlockOrStatement; | ||
private transformForOfArrayStatement; | ||
private transformForOfLuaIteratorStatement; | ||
private transformForOfIteratorStatement; | ||
protected transformBlockOrStatement(statement: ts.Statement): tstl.Statement[]; | ||
protected transformForOfArrayStatement(statement: ts.ForOfStatement, block: tstl.Block): StatementVisitResult; | ||
protected transformForOfLuaIteratorStatement(statement: ts.ForOfStatement, block: tstl.Block): StatementVisitResult; | ||
protected transformForOfIteratorStatement(statement: ts.ForOfStatement, block: tstl.Block): StatementVisitResult; | ||
protected transformForRangeStatement(statement: ts.ForOfStatement, body: tstl.Block): StatementVisitResult; | ||
transformForOfStatement(statement: ts.ForOfStatement): StatementVisitResult; | ||
@@ -126,15 +132,17 @@ transformForInStatement(statement: ts.ForInStatement): StatementVisitResult; | ||
protected transformBinaryOperation(left: tstl.Expression, right: tstl.Expression, operator: ts.BinaryOperator, tsOriginal: ts.Node): ExpressionVisitResult; | ||
protected transformTypeOfLiteralComparison(typeOfExpression: ts.TypeOfExpression, comparedExpression: tstl.StringLiteral, operator: ts.BinaryOperator, tsOriginal: ts.Node): ExpressionVisitResult; | ||
protected transformComparisonExpression(expression: ts.BinaryExpression): ExpressionVisitResult; | ||
transformBinaryExpression(expression: ts.BinaryExpression): ExpressionVisitResult; | ||
private transformAssignment; | ||
private transformAssignmentStatement; | ||
private transformAssignmentExpression; | ||
private transformCompoundAssignmentExpression; | ||
protected transformAssignment(lhs: ts.Expression, right?: tstl.Expression): tstl.Statement; | ||
protected transformAssignmentStatement(expression: ts.BinaryExpression): StatementVisitResult; | ||
protected transformAssignmentExpression(expression: ts.BinaryExpression): tstl.CallExpression | tstl.MethodCallExpression; | ||
protected transformCompoundAssignmentExpression(expression: ts.Expression, lhs: ts.Expression, rhs: ts.Expression, replacementOperator: ts.BinaryOperator, isPostfix: boolean): tstl.CallExpression; | ||
transformBinaryOperator(operator: ts.BinaryOperator, node: ts.Node): tstl.BinaryOperator; | ||
transformClassExpression(expression: ts.ClassExpression): ExpressionVisitResult; | ||
private transformCompoundAssignmentStatement; | ||
private transformUnaryBitLibOperation; | ||
private transformUnaryBitOperation; | ||
private transformBinaryBitLibOperation; | ||
private transformBinaryBitOperation; | ||
private transformProtectedConditionalExpression; | ||
protected transformCompoundAssignmentStatement(node: ts.Node, lhs: ts.Expression, rhs: ts.Expression, replacementOperator: ts.BinaryOperator): tstl.Statement; | ||
protected transformUnaryBitLibOperation(node: ts.Node, expression: tstl.Expression, operator: tstl.UnaryBitwiseOperator, lib: string): ExpressionVisitResult; | ||
protected transformUnaryBitOperation(node: ts.Node, expression: tstl.Expression, operator: tstl.UnaryBitwiseOperator): ExpressionVisitResult; | ||
protected transformBinaryBitLibOperation(node: ts.Node, left: tstl.Expression, right: tstl.Expression, operator: ts.BinaryOperator, lib: string): ExpressionVisitResult; | ||
protected transformBinaryBitOperation(node: ts.Node, left: tstl.Expression, right: tstl.Expression, operator: ts.BinaryOperator): ExpressionVisitResult; | ||
protected transformProtectedConditionalExpression(expression: ts.ConditionalExpression): tstl.CallExpression; | ||
transformConditionalExpression(expression: ts.ConditionalExpression): ExpressionVisitResult; | ||
@@ -151,27 +159,37 @@ transformPostfixUnaryExpression(expression: ts.PostfixUnaryExpression): ExpressionVisitResult; | ||
transformCallExpression(expression: ts.CallExpression): ExpressionVisitResult; | ||
private transformGlobalFunctionCall; | ||
protected transformGlobalFunctionCall(node: ts.CallExpression): tstl.Expression | undefined; | ||
transformPropertyCall(node: ts.CallExpression): ExpressionVisitResult; | ||
transformElementCall(node: ts.CallExpression): ExpressionVisitResult; | ||
private transformArguments; | ||
protected transformArguments<T extends ts.Expression>(params: ts.NodeArray<ts.Expression> | ts.Expression[], sig?: ts.Signature, context?: T): tstl.Expression[]; | ||
transformPropertyAccessExpression(expression: ts.PropertyAccessExpression): ExpressionVisitResult; | ||
private transformMathExpression; | ||
private transformMathCallExpression; | ||
private transformStringProperty; | ||
private transformArrayProperty; | ||
private transformLuaTableProperty; | ||
protected transformMathExpression(identifier: ts.Identifier): tstl.Expression; | ||
protected transformMathCallExpression(node: ts.CallExpression): tstl.Expression; | ||
protected transformStringProperty(node: ts.PropertyAccessExpression): tstl.UnaryExpression; | ||
protected transformArrayProperty(node: ts.PropertyAccessExpression): tstl.UnaryExpression | undefined; | ||
protected transformLuaTableProperty(node: ts.PropertyAccessExpression): tstl.UnaryExpression; | ||
transformElementAccessExpression(expression: ts.ElementAccessExpression): ExpressionVisitResult; | ||
private transformConstEnumValue; | ||
private transformStringCallExpression; | ||
private createStringCall; | ||
private transformStringExpression; | ||
private transformObjectCallExpression; | ||
private transformConsoleCallExpression; | ||
private isStringFormatTemplate; | ||
private transformSymbolCallExpression; | ||
private transformNumberCallExpression; | ||
private validateLuaTableCall; | ||
private transformLuaTableExpressionStatement; | ||
private transformLuaTableCallExpression; | ||
private transformArrayCallExpression; | ||
private transformFunctionCallExpression; | ||
private tryGetConstEnumValue; | ||
protected transformStringCallExpression(node: ts.CallExpression): tstl.Expression; | ||
protected createStringCall(methodName: string, tsOriginal: ts.Node, ...params: tstl.Expression[]): tstl.CallExpression; | ||
protected transformStringExpression(identifier: ts.Identifier): ExpressionVisitResult; | ||
protected transformObjectCallExpression(expression: ts.CallExpression): ExpressionVisitResult; | ||
protected transformConsoleCallExpression(expression: ts.CallExpression): ExpressionVisitResult; | ||
protected isStringFormatTemplate(expression: ts.Expression): boolean; | ||
protected transformSymbolCallExpression(expression: ts.CallExpression): tstl.CallExpression; | ||
protected transformNumberCallExpression(expression: ts.CallExpression): tstl.CallExpression; | ||
protected validateLuaTableCall(expression: ts.CallExpression & { | ||
expression: ts.PropertyAccessExpression; | ||
}, isWithinExpressionStatement: boolean): void; | ||
protected transformLuaTableExpressionStatement(node: ts.ExpressionStatement & { | ||
expression: ts.CallExpression; | ||
} & { | ||
expression: { | ||
expression: ts.PropertyAccessExpression; | ||
}; | ||
}): tstl.VariableDeclarationStatement | tstl.AssignmentStatement; | ||
protected transformLuaTableCallExpression(expression: ts.CallExpression & { | ||
expression: ts.PropertyAccessExpression; | ||
}): tstl.Expression; | ||
protected transformArrayCallExpression(node: ts.CallExpression): tstl.CallExpression; | ||
protected transformFunctionCallExpression(node: ts.CallExpression): tstl.CallExpression; | ||
transformArrayBindingElement(name: ts.ArrayBindingElement): ExpressionVisitResult; | ||
@@ -191,3 +209,3 @@ transformAssertionExpression(expression: ts.AssertionExpression): ExpressionVisitResult; | ||
transformIdentifier(identifier: ts.Identifier): tstl.Identifier; | ||
private transformIdentifierExpression; | ||
protected transformIdentifierExpression(expression: ts.Identifier): tstl.Expression; | ||
protected getSymbolFromIdentifier(identifier: tstl.Identifier): ts.Symbol | undefined; | ||
@@ -226,3 +244,3 @@ protected getIdentifierExportScope(identifier: tstl.Identifier): ts.SourceFile | ts.ModuleDeclaration | undefined; | ||
protected pushScope(scopeType: ScopeType): void; | ||
private shouldHoist; | ||
protected shouldHoist(symbolId: tstl.SymbolId, scope: Scope): boolean; | ||
protected replaceStatementInParent(oldNode: tstl.Statement, newNode?: tstl.Statement): void; | ||
@@ -238,4 +256,4 @@ protected hoistImportStatements(scope: Scope, statements: tstl.Statement[]): tstl.Statement[]; | ||
protected filterUndefinedAndCast<TOriginal, TCast extends TOriginal>(items: Array<TOriginal | undefined>, cast: (item: TOriginal) => item is TCast): TCast[]; | ||
private createConstructorDecorationStatement; | ||
protected createConstructorDecorationStatement(declaration: ts.ClassLikeDeclaration): tstl.AssignmentStatement | undefined; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ts = require("typescript"); | ||
const diagnostics_1 = require("./diagnostics"); | ||
const diagnosticFactories = require("./diagnostics"); | ||
const LuaPrinter_1 = require("./LuaPrinter"); | ||
const LuaTransformer_1 = require("./LuaTransformer"); | ||
const TranspileError_1 = require("./TranspileError"); | ||
function getCustomTransformers(_program, customTransformers, onSourceFile) { | ||
// TODO: https://github.com/Microsoft/TypeScript/issues/28310 | ||
const forEachSourceFile = (node, callback) => ts.isBundle(node) | ||
? ts.updateBundle(node, node.sourceFiles.map(callback)) | ||
: callback(node); | ||
const luaTransformer = () => node => forEachSourceFile(node, sourceFile => { | ||
onSourceFile(sourceFile); | ||
return ts.createSourceFile(sourceFile.fileName, "", ts.ScriptTarget.ESNext); | ||
}); | ||
return { | ||
afterDeclarations: customTransformers.afterDeclarations, | ||
before: [...(customTransformers.before || []), ...(customTransformers.after || []), luaTransformer], | ||
}; | ||
} | ||
const TSTransformers_1 = require("./TSTransformers"); | ||
function transpile({ program, sourceFiles: targetSourceFiles, customTransformers = {}, transformer = new LuaTransformer_1.LuaTransformer(program), printer = new LuaPrinter_1.LuaPrinter(program.getCompilerOptions()), }) { | ||
@@ -65,3 +52,3 @@ const options = program.getCompilerOptions(); | ||
throw err; | ||
diagnostics.push(diagnostics_1.transpileError(err)); | ||
diagnostics.push(diagnosticFactories.transpileError(err)); | ||
updateTranspiledFile(sourceFile.fileName, { | ||
@@ -73,3 +60,3 @@ lua: `error(${JSON.stringify(err.message)})\n`, | ||
}; | ||
const transformers = getCustomTransformers(program, customTransformers, processSourceFile); | ||
const transformers = TSTransformers_1.getCustomTransformers(program, diagnostics, customTransformers, processSourceFile); | ||
const writeFile = (fileName, data, _bom, _onError, sourceFiles = []) => { | ||
@@ -76,0 +63,0 @@ for (const sourceFile of sourceFiles) { |
@@ -27,2 +27,5 @@ import * as ts from "typescript"; | ||
static isLuaIteratorType(node: ts.Node, checker: ts.TypeChecker): boolean; | ||
static isRestParameter(node: ts.Node, checker: ts.TypeChecker): boolean; | ||
static isVarArgType(node: ts.Node, checker: ts.TypeChecker): boolean; | ||
static isForRangeType(node: ts.Node, checker: ts.TypeChecker): boolean; | ||
static isTupleReturnCall(node: ts.Node, checker: ts.TypeChecker): boolean; | ||
@@ -29,0 +32,0 @@ static isInTupleReturnFunction(node: ts.Node, checker: ts.TypeChecker): boolean; |
@@ -149,2 +149,21 @@ "use strict"; | ||
} | ||
static isRestParameter(node, checker) { | ||
const symbol = checker.getSymbolAtLocation(node); | ||
if (!symbol) { | ||
return false; | ||
} | ||
const declarations = symbol.getDeclarations(); | ||
if (!declarations) { | ||
return false; | ||
} | ||
return declarations.some(d => ts.isParameter(d) && d.dotDotDotToken !== undefined); | ||
} | ||
static isVarArgType(node, checker) { | ||
const type = checker.getTypeAtLocation(node); | ||
return type !== undefined && TSHelper.getCustomDecorators(type, checker).has(Decorator_1.DecoratorKind.Vararg); | ||
} | ||
static isForRangeType(node, checker) { | ||
const type = checker.getTypeAtLocation(node); | ||
return TSHelper.getCustomDecorators(type, checker).has(Decorator_1.DecoratorKind.ForRange); | ||
} | ||
static isTupleReturnCall(node, checker) { | ||
@@ -151,0 +170,0 @@ if (ts.isCallExpression(node)) { |
@@ -8,3 +8,3 @@ #!/usr/bin/env node | ||
const CommandLineParser = require("./CommandLineParser"); | ||
const cliDiagnostics = require("./diagnostics"); | ||
const diagnosticFactories = require("./diagnostics"); | ||
function createWatchStatusReporter(options) { | ||
@@ -32,3 +32,3 @@ return ts.createWatchStatusReporter(ts.sys, shouldBePretty(options)); | ||
if (commandLine.fileNames.length !== 0) { | ||
reportDiagnostic(cliDiagnostics.optionProjectCannotBeMixedWithSourceFilesOnACommandLine()); | ||
reportDiagnostic(diagnosticFactories.optionProjectCannotBeMixedWithSourceFilesOnACommandLine()); | ||
ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); | ||
@@ -47,3 +47,3 @@ return; | ||
else { | ||
reportDiagnostic(cliDiagnostics.cannotFindATsconfigJsonAtTheSpecifiedDirectory(project)); | ||
reportDiagnostic(diagnosticFactories.cannotFindATsconfigJsonAtTheSpecifiedDirectory(project)); | ||
ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); | ||
@@ -57,3 +57,3 @@ } | ||
else { | ||
reportDiagnostic(cliDiagnostics.theSpecifiedPathDoesNotExist(project)); | ||
reportDiagnostic(diagnosticFactories.theSpecifiedPathDoesNotExist(project)); | ||
ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); | ||
@@ -72,3 +72,3 @@ } | ||
if (commandLine.options.build) { | ||
reportDiagnostic(cliDiagnostics.optionBuildMustBeFirstCommandLineArgument()); | ||
reportDiagnostic(diagnosticFactories.optionBuildMustBeFirstCommandLineArgument()); | ||
return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); | ||
@@ -197,3 +197,3 @@ } | ||
fullRecompile = errors.length > 0; | ||
host.onWatchStatusChange(cliDiagnostics.watchErrorSummary(errors.length), host.getNewLine(), options); | ||
host.onWatchStatusChange(diagnosticFactories.watchErrorSummary(errors.length), host.getNewLine(), options); | ||
}; | ||
@@ -200,0 +200,0 @@ } |
@@ -6,3 +6,2 @@ import * as ts from "typescript"; | ||
static CouldNotCast: (castName: string) => Error; | ||
static CouldNotFindEnumMember: (enumDeclaration: ts.EnumDeclaration, enumMember: string, node: ts.Node) => TranspileError; | ||
static DefaultImportsNotSupported: (node: ts.Node) => TranspileError; | ||
@@ -53,2 +52,3 @@ static ForbiddenEllipsisDestruction: (node: ts.Node) => TranspileError; | ||
static InvalidAmbientIdentifierName: (node: ts.Identifier) => TranspileError; | ||
static InvalidForRangeCall: (node: ts.Node, message: string) => TranspileError; | ||
} |
@@ -10,3 +10,2 @@ "use strict"; | ||
TSTLErrors.CouldNotCast = (castName) => new Error(`Failed to cast all elements to expected type using ${castName}.`); | ||
TSTLErrors.CouldNotFindEnumMember = (enumDeclaration, enumMember, node) => new TranspileError_1.TranspileError(`Could not find ${enumMember} in ${enumDeclaration.name.text}`, node); | ||
TSTLErrors.DefaultImportsNotSupported = (node) => new TranspileError_1.TranspileError(`Default Imports are not supported, please use named imports instead!`, node); | ||
@@ -98,3 +97,6 @@ TSTLErrors.ForbiddenEllipsisDestruction = (node) => new TranspileError_1.TranspileError(`Ellipsis destruction is not allowed.`, node); | ||
}; | ||
TSTLErrors.InvalidForRangeCall = (node, message) => { | ||
return new TranspileError_1.TranspileError(`Invalid @forRange call: ${message}`, node); | ||
}; | ||
exports.TSTLErrors = TSTLErrors; | ||
//# sourceMappingURL=TSTLErrors.js.map |
{ | ||
"name": "typescript-to-lua", | ||
"version": "0.21.1", | ||
"version": "0.22.0", | ||
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!", | ||
@@ -42,2 +42,3 @@ "repository": "https://github.com/TypeScriptToLua/TypeScriptToLua", | ||
"dependencies": { | ||
"resolve": "^1.10.1", | ||
"source-map": "^0.7.3", | ||
@@ -50,2 +51,3 @@ "typescript": "^3.4.5" | ||
"@types/node": "^11.13.0", | ||
"@types/resolve": "0.0.8", | ||
"fengari": "^0.1.4", | ||
@@ -52,0 +54,0 @@ "jest": "^24.8.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
494693
93
7905
3
11
5
+ Addedresolve@^1.10.1
+ Addedfunction-bind@1.1.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)