typescript-to-lua
Advanced tools
Comparing version 0.23.0 to 0.24.0
# Changelog | ||
## 0.23.0 | ||
- Added support for OmittedExpression in array literals and array binding patterns. | ||
- Added support for [tagged template literals](https://basarat.gitbooks.io/typescript/docs/template-strings.html#tagged-templates). | ||
- Changed output lua formatting to be more debugger-friendly. | ||
- Various improvements to source maps. | ||
- Fixed an issue with the interaction of super calls and exported classes. | ||
- Fixed `@noResolution` not working on named modules. | ||
- Fixed namespace merging not working due to an earlier change. | ||
- Some refactoring and plumbing for the website. | ||
## 0.22.0 | ||
@@ -4,0 +17,0 @@ |
export declare class Decorator { | ||
args: string[]; | ||
static isValid(decoratorKindString: string): boolean; | ||
static getDecoratorKind(decoratorKindString: string): DecoratorKind | undefined; | ||
kind: DecoratorKind; | ||
args: string[]; | ||
constructor(name: string, args: string[]); | ||
@@ -7,0 +7,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class Decorator { | ||
static isValid(decoratorKindString) { | ||
return this.getDecoratorKind(decoratorKindString) !== undefined; | ||
} | ||
static getDecoratorKind(decoratorKindString) { | ||
switch (decoratorKindString.toLowerCase()) { | ||
case "extension": | ||
return DecoratorKind.Extension; | ||
case "metaextension": | ||
return DecoratorKind.MetaExtension; | ||
case "customconstructor": | ||
return DecoratorKind.CustomConstructor; | ||
case "compilemembersonly": | ||
return DecoratorKind.CompileMembersOnly; | ||
case "noresolution": | ||
return DecoratorKind.NoResolution; | ||
case "pureabstract": | ||
return DecoratorKind.PureAbstract; | ||
case "phantom": | ||
return DecoratorKind.Phantom; | ||
case "tuplereturn": | ||
return DecoratorKind.TupleReturn; | ||
case "luaiterator": | ||
return DecoratorKind.LuaIterator; | ||
case "luatable": | ||
return DecoratorKind.LuaTable; | ||
case "noself": | ||
return DecoratorKind.NoSelf; | ||
case "noselfinfile": | ||
return DecoratorKind.NoSelfInFile; | ||
case "vararg": | ||
return DecoratorKind.Vararg; | ||
case "forrange": | ||
return DecoratorKind.ForRange; | ||
} | ||
return undefined; | ||
} | ||
constructor(name, args) { | ||
this.args = args; | ||
const kind = Decorator.getDecoratorKind(name); | ||
@@ -46,4 +11,9 @@ if (kind === undefined) { | ||
this.kind = kind; | ||
this.args = args; | ||
} | ||
static isValid(decoratorKindString) { | ||
return this.getDecoratorKind(decoratorKindString) !== undefined; | ||
} | ||
static getDecoratorKind(decoratorKindString) { | ||
return Object.values(DecoratorKind).find(decoratorKind => decoratorKind.toLowerCase() === decoratorKindString.toLowerCase()); | ||
} | ||
} | ||
@@ -50,0 +20,0 @@ exports.Decorator = Decorator; |
@@ -207,3 +207,3 @@ import * as ts from "typescript"; | ||
export declare function isStringLiteral(node: Node): node is StringLiteral; | ||
export declare function createStringLiteral(value: string | ts.__String, tsOriginal?: ts.Node, parent?: Node): StringLiteral; | ||
export declare function createStringLiteral(value: string, tsOriginal?: ts.Node, parent?: Node): StringLiteral; | ||
export declare enum FunctionExpressionFlags { | ||
@@ -233,3 +233,3 @@ None = 0, | ||
kind: SyntaxKind.TableExpression; | ||
fields?: TableFieldExpression[]; | ||
fields: TableFieldExpression[]; | ||
} | ||
@@ -281,3 +281,3 @@ export declare function isTableExpression(node: Node): node is TableExpression; | ||
export declare function isIdentifier(node: Node): node is Identifier; | ||
export declare function createIdentifier(text: string | ts.__String, tsOriginal?: ts.Node, symbolId?: SymbolId, originalName?: string, parent?: Node): Identifier; | ||
export declare function createIdentifier(text: string, tsOriginal?: ts.Node, symbolId?: SymbolId, originalName?: string, parent?: Node): Identifier; | ||
export declare function cloneIdentifier(identifier: Identifier, tsOriginal?: ts.Node): Identifier; | ||
@@ -284,0 +284,0 @@ export declare function createAnonymousIdentifier(tsOriginal?: ts.Node, parent?: Node): Identifier; |
@@ -425,3 +425,3 @@ "use strict"; | ||
exports.isTableExpression = isTableExpression; | ||
function createTableExpression(fields, tsOriginal, parent) { | ||
function createTableExpression(fields = [], tsOriginal, parent) { | ||
const expression = createNode(SyntaxKind.TableExpression, tsOriginal, parent); | ||
@@ -428,0 +428,0 @@ setParent(fields, expression); |
@@ -58,4 +58,2 @@ import { EmitHost } from "./Transpile"; | ||
} | ||
export declare class LuaLib { | ||
static loadFeatures(features: Iterable<LuaLibFeature>, emitHost: EmitHost): string; | ||
} | ||
export declare function loadLuaLibFeatures(features: Iterable<LuaLibFeature>, emitHost: EmitHost): string; |
@@ -74,30 +74,28 @@ "use strict"; | ||
}; | ||
class LuaLib { | ||
static loadFeatures(features, emitHost) { | ||
let result = ""; | ||
const loadedFeatures = new Set(); | ||
function load(feature) { | ||
if (!loadedFeatures.has(feature)) { | ||
loadedFeatures.add(feature); | ||
const dependencies = luaLibDependencies[feature]; | ||
if (dependencies) { | ||
dependencies.forEach(load); | ||
} | ||
const featureFile = path.resolve(__dirname, `../dist/lualib/${feature}.lua`); | ||
const luaLibFeature = emitHost.readFile(featureFile); | ||
if (luaLibFeature !== undefined) { | ||
result += luaLibFeature.toString() + "\n"; | ||
} | ||
else { | ||
throw new Error(`Could not read lualib feature ../dist/lualib/${feature}.lua`); | ||
} | ||
} | ||
function loadLuaLibFeatures(features, emitHost) { | ||
let result = ""; | ||
const loadedFeatures = new Set(); | ||
function load(feature) { | ||
if (loadedFeatures.has(feature)) | ||
return; | ||
loadedFeatures.add(feature); | ||
const dependencies = luaLibDependencies[feature]; | ||
if (dependencies) { | ||
dependencies.forEach(load); | ||
} | ||
for (const feature of features) { | ||
load(feature); | ||
const featureFile = path.resolve(__dirname, `../dist/lualib/${feature}.lua`); | ||
const luaLibFeature = emitHost.readFile(featureFile); | ||
if (luaLibFeature !== undefined) { | ||
result += luaLibFeature + "\n"; | ||
} | ||
return result; | ||
else { | ||
throw new Error(`Could not read lualib feature ../dist/lualib/${feature}.lua`); | ||
} | ||
} | ||
for (const feature of features) { | ||
load(feature); | ||
} | ||
return result; | ||
} | ||
exports.LuaLib = LuaLib; | ||
exports.loadLuaLibFeatures = loadLuaLibFeatures; | ||
//# sourceMappingURL=LuaLib.js.map |
@@ -8,5 +8,5 @@ import { SourceNode } from "source-map"; | ||
export declare class LuaPrinter { | ||
private static operatorMap; | ||
private options; | ||
private emitHost; | ||
private static operatorMap; | ||
private currentIndent; | ||
@@ -13,0 +13,0 @@ private sourceFile; |
@@ -12,6 +12,6 @@ "use strict"; | ||
constructor(options, emitHost) { | ||
this.sourceFile = ""; | ||
this.options = options; | ||
this.emitHost = emitHost; | ||
this.currentIndent = ""; | ||
this.sourceFile = ""; | ||
} | ||
@@ -81,3 +81,3 @@ print(block, luaLibFeatures, sourceFile = "") { | ||
header += "-- Lua Library inline imports\n"; | ||
header += LuaLib_1.LuaLib.loadFeatures(luaLibFeatures, this.emitHost); | ||
header += LuaLib_1.loadLuaLibFeatures(luaLibFeatures, this.emitHost); | ||
} | ||
@@ -432,9 +432,3 @@ } | ||
printTableExpression(expression) { | ||
const chunks = []; | ||
chunks.push("{"); | ||
if (expression.fields) { | ||
chunks.push(...this.printExpressionList(expression.fields)); | ||
} | ||
chunks.push("}"); | ||
return this.createSourceNode(expression, chunks); | ||
return this.createSourceNode(expression, ["{", ...this.printExpressionList(expression.fields), "}"]); | ||
} | ||
@@ -441,0 +435,0 @@ printUnaryExpression(expression) { |
@@ -13,3 +13,5 @@ import * as ts from "typescript"; | ||
Conditional = 16, | ||
Block = 32 | ||
Block = 32, | ||
Try = 64, | ||
Catch = 128 | ||
} | ||
@@ -32,2 +34,3 @@ interface SymbolInfo { | ||
loopContinued?: boolean; | ||
functionReturned?: boolean; | ||
} | ||
@@ -45,21 +48,21 @@ export interface EmitResolver { | ||
protected program: ts.Program; | ||
protected isStrict: boolean; | ||
protected luaTarget: LuaTarget; | ||
protected readonly typeValidationCache: Map<ts.Type, Set<ts.Type>>; | ||
protected currentNamespace?: ts.ModuleDeclaration; | ||
protected checker: DiagnosticsProducingTypeChecker; | ||
protected options: CompilerOptions; | ||
protected resolver: EmitResolver; | ||
protected isModule: boolean; | ||
protected currentSourceFile?: ts.SourceFile; | ||
protected currentNamespace: ts.ModuleDeclaration | undefined; | ||
protected classStack: ts.ClassLikeDeclaration[]; | ||
protected scopeStack: Scope[]; | ||
protected luaTarget: LuaTarget; | ||
protected isStrict: boolean; | ||
constructor(program: ts.Program); | ||
protected genVarCounter: number; | ||
protected luaLibFeatureSet: Set<LuaLibFeature>; | ||
protected symbolInfo: Map<number, SymbolInfo>; | ||
protected symbolIds: Map<ts.Symbol, number>; | ||
protected scopeStack: Scope[]; | ||
protected classStack: ts.ClassLikeDeclaration[]; | ||
protected symbolInfo: Map<tstl.SymbolId, SymbolInfo>; | ||
protected symbolIds: Map<ts.Symbol, tstl.SymbolId>; | ||
protected genSymbolIdCounter: number; | ||
protected readonly typeValidationCache: Map<ts.Type, Set<ts.Type>>; | ||
constructor(program: ts.Program); | ||
protected setupState(): void; | ||
transformSourceFile(node: ts.SourceFile): [tstl.Block, Set<LuaLibFeature>]; | ||
private setupState; | ||
protected currentSourceFile: ts.SourceFile; | ||
protected isModule: boolean; | ||
protected resolver: EmitResolver; | ||
transformSourceFile(sourceFile: ts.SourceFile): tstl.Block; | ||
transformStatement(node: ts.Statement): StatementVisitResult; | ||
@@ -112,3 +115,3 @@ /** Converts an array of ts.Statements into an array of tstl.Statements */ | ||
transformForStatement(statement: ts.ForStatement): StatementVisitResult; | ||
protected transformForOfInitializer(initializer: ts.ForInitializer, expression: tstl.Expression): tstl.Statement; | ||
protected transformForOfInitializer(initializer: ts.ForInitializer, expression: tstl.Expression): tstl.Statement | undefined; | ||
protected transformLoopBody(loop: ts.WhileStatement | ts.DoStatement | ts.ForStatement | ts.ForOfStatement | ts.ForInOrOfStatement): tstl.Statement[]; | ||
@@ -124,2 +127,3 @@ protected transformBlockOrStatement(statement: ts.Statement): tstl.Statement[]; | ||
transformBreakStatement(breakStatement: ts.BreakStatement): StatementVisitResult; | ||
protected transformScopeBlock(block: ts.Block, scopeType: ScopeType): [tstl.Block, Scope]; | ||
transformTryStatement(statement: ts.TryStatement): StatementVisitResult; | ||
@@ -169,2 +173,3 @@ transformThrowStatement(statement: ts.ThrowStatement): StatementVisitResult; | ||
protected transformLuaTableProperty(node: ts.PropertyAccessExpression): tstl.UnaryExpression; | ||
protected transformElementAccessArgument(expression: ts.ElementAccessExpression): tstl.Expression; | ||
transformElementAccessExpression(expression: ts.ElementAccessExpression): ExpressionVisitResult; | ||
@@ -195,4 +200,3 @@ private tryGetConstEnumValue; | ||
protected transformFunctionCallExpression(node: ts.CallExpression): tstl.CallExpression; | ||
transformArrayBindingElement(name: ts.ArrayBindingElement): ExpressionVisitResult; | ||
transformArrayBindingExpression(name: ts.Expression): ExpressionVisitResult; | ||
transformArrayBindingElement(name: ts.ArrayBindingElement | ts.Expression): ExpressionVisitResult; | ||
transformAssertionExpression(expression: ts.AssertionExpression): ExpressionVisitResult; | ||
@@ -210,3 +214,2 @@ transformTypeOfExpression(expression: ts.TypeOfExpression): ExpressionVisitResult; | ||
transformPropertyName(propertyName: ts.PropertyName): ExpressionVisitResult; | ||
protected getIdentifierText(identifier: ts.Identifier): string; | ||
transformIdentifier(identifier: ts.Identifier): tstl.Identifier; | ||
@@ -225,3 +228,3 @@ protected transformIdentifierExpression(expression: ts.Identifier): tstl.Expression; | ||
protected createImmediatelyInvokedFunctionExpression(statements: tstl.Statement[], result: tstl.Expression | tstl.Expression[], tsOriginal: ts.Node): tstl.CallExpression; | ||
protected createUnpackCall(expression: tstl.Expression | undefined, tsOriginal: ts.Node): tstl.Expression; | ||
protected createUnpackCall(expression: tstl.Expression | undefined, tsOriginal?: ts.Node): tstl.Expression; | ||
protected getAbsoluteImportPath(relativePath: string): string; | ||
@@ -232,3 +235,3 @@ protected getImportPath(relativePath: string, node: ts.Node): string; | ||
protected createExportsIdentifier(): tstl.Identifier; | ||
protected createLocalOrExportedOrGlobalDeclaration(lhs: tstl.Identifier | tstl.Identifier[], rhs?: tstl.Expression | tstl.Expression[], tsOriginal?: ts.Node, parent?: tstl.Node): tstl.Statement[]; | ||
protected createLocalOrExportedOrGlobalDeclaration(lhs: tstl.Identifier | tstl.Identifier[], rhs?: tstl.Expression | tstl.Expression[], tsOriginal?: ts.Node, parent?: tstl.Node, overrideExportScope?: ts.SourceFile | ts.ModuleDeclaration): tstl.Statement[]; | ||
protected validateFunctionAssignment(node: ts.Node, fromType: ts.Type, toType: ts.Type, toName?: string): void; | ||
@@ -235,0 +238,0 @@ protected validatePropertyAssignment(node: ts.Node): void; |
@@ -43,3 +43,3 @@ "use strict"; | ||
try { | ||
const [luaAst, lualibFeatureSet] = transformer.transformSourceFile(sourceFile); | ||
const [luaAst, lualibFeatureSet] = transformer.transform(sourceFile); | ||
if (!options.noEmit && !options.emitDeclarationOnly) { | ||
@@ -46,0 +46,0 @@ const [lua, sourceMap] = printer.print(luaAst, lualibFeatureSet, sourceFile.fileName); |
@@ -61,5 +61,5 @@ import * as ts from "typescript"; | ||
export declare function isFalsible(type: ts.Type, strictNullChecks: boolean): boolean; | ||
export declare function getFirstDeclaration(symbol: ts.Symbol, sourceFile?: ts.SourceFile): ts.Declaration | undefined; | ||
export declare function getFirstDeclaration(symbol: ts.Symbol, sourceFile: ts.SourceFile): ts.Declaration | undefined; | ||
export declare function getRawLiteral(node: ts.LiteralLikeNode): string; | ||
export declare function isFirstDeclaration(node: ts.VariableDeclaration, checker: ts.TypeChecker): boolean; | ||
export declare function isFirstDeclaration(node: ts.VariableDeclaration, checker: ts.TypeChecker, sourceFile: ts.SourceFile): boolean; | ||
export declare function isStandardLibraryDeclaration(declaration: ts.Declaration, program: ts.Program): boolean; | ||
@@ -66,0 +66,0 @@ export declare function isStandardLibraryType(type: ts.Type, name: string | undefined, program: ts.Program): boolean; |
@@ -637,5 +637,3 @@ "use strict"; | ||
} | ||
if (sourceFile) { | ||
declarations = declarations.filter(d => findFirstNodeAbove(d, ts.isSourceFile) === sourceFile); | ||
} | ||
declarations = declarations.filter(d => findFirstNodeAbove(d, ts.isSourceFile) === sourceFile); | ||
return declarations.length > 0 ? declarations.reduce((p, c) => (p.pos < c.pos ? p : c)) : undefined; | ||
@@ -652,3 +650,3 @@ } | ||
exports.getRawLiteral = getRawLiteral; | ||
function isFirstDeclaration(node, checker) { | ||
function isFirstDeclaration(node, checker, sourceFile) { | ||
const symbol = checker.getSymbolAtLocation(node.name); | ||
@@ -658,3 +656,3 @@ if (!symbol) { | ||
} | ||
const firstDeclaration = getFirstDeclaration(symbol); | ||
const firstDeclaration = getFirstDeclaration(symbol, sourceFile); | ||
return firstDeclaration === node; | ||
@@ -758,3 +756,3 @@ } | ||
const tableExpression = expression; | ||
return !tableExpression.fields || tableExpression.fields.every(e => isSimpleExpression(e)); | ||
return tableExpression.fields.every(e => isSimpleExpression(e)); | ||
case tstl.SyntaxKind.TableFieldExpression: | ||
@@ -761,0 +759,0 @@ const fieldExpression = expression; |
@@ -31,3 +31,2 @@ import * as ts from "typescript"; | ||
export declare const MissingMetaExtension: (node: ts.Node) => TranspileError; | ||
export declare const MissingSourceFile: () => Error; | ||
export declare const UndefinedFunctionDefinition: (functionSymbolId: number) => Error; | ||
@@ -34,0 +33,0 @@ export declare const UndefinedScope: () => Error; |
@@ -35,3 +35,2 @@ "use strict"; | ||
exports.MissingMetaExtension = (node) => new TranspileError_1.TranspileError(`@metaExtension requires the extension of the metatable class.`, node); | ||
exports.MissingSourceFile = () => new Error("Expected transformer.sourceFile to be set, but it isn't."); | ||
exports.UndefinedFunctionDefinition = (functionSymbolId) => new Error(`Function definition for function symbol ${functionSymbolId} is undefined.`); | ||
@@ -38,0 +37,0 @@ exports.UndefinedScope = () => new Error("Expected to pop a scope, but found undefined."); |
@@ -19,10 +19,6 @@ "use strict"; | ||
function getCustomTransformers(program, diagnostics, 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 => { | ||
const luaTransformer = () => sourceFile => { | ||
onSourceFile(sourceFile); | ||
return ts.createSourceFile(sourceFile.fileName, "", ts.ScriptTarget.ESNext); | ||
}); | ||
}; | ||
const transformersFromOptions = loadTransformersFromOptions(program, diagnostics); | ||
@@ -29,0 +25,0 @@ return { |
{ | ||
"name": "typescript-to-lua", | ||
"version": "0.23.0", | ||
"version": "0.24.0", | ||
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!", | ||
@@ -26,5 +26,5 @@ "repository": "https://github.com/TypeScriptToLua/TypeScriptToLua", | ||
"lint": "npm run lint:tslint && npm run lint:prettier", | ||
"lint:prettier": "prettier --check **/*.{js,ts,yml,json,md} || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)", | ||
"lint:prettier": "prettier --check \"**/*.{js,ts,yml,json,md}\" || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)", | ||
"lint:tslint": "tslint -p . && tslint -p test && tslint -p src/lualib", | ||
"fix:prettier": "prettier --check --write **/*.{js,ts,yml,json,md}", | ||
"fix:prettier": "prettier --check --write \"**/*.{js,ts,yml,json,md}\"", | ||
"release-major": "npm version major", | ||
@@ -31,0 +31,0 @@ "release-minor": "npm version minor", |
@@ -68,12 +68,2 @@ <div align="center"> | ||
## Building & Tests | ||
`npm run build` to build the project. | ||
`npm run test` to run tests. | ||
`npm run test-threaded` runs test in parallel, faster but less detailed output. | ||
`npm run coverage` or `npm run coverage-html` to generate a coverage report. | ||
## Sublime Text integration | ||
@@ -80,0 +70,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 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
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
508675
8197
86