typescript-to-lua
Advanced tools
Comparing version 1.20.1 to 1.21.0
@@ -7,2 +7,3 @@ import * as ts from "typescript"; | ||
NoSelf = "noSelf", | ||
CustomName = "customName", | ||
NoSelfInFile = "noSelfInFile" | ||
@@ -9,0 +10,0 @@ } |
@@ -11,2 +11,3 @@ "use strict"; | ||
AnnotationKind["NoSelf"] = "noSelf"; | ||
AnnotationKind["CustomName"] = "customName"; | ||
AnnotationKind["NoSelfInFile"] = "noSelfInFile"; | ||
@@ -13,0 +14,0 @@ })(AnnotationKind || (exports.AnnotationKind = AnnotationKind = {})); |
@@ -19,2 +19,6 @@ import * as ts from "typescript"; | ||
} | ||
export declare enum LoopContinued { | ||
WithGoto = 0, | ||
WithRepeatBreak = 1 | ||
} | ||
export interface Scope { | ||
@@ -28,3 +32,3 @@ type: ScopeType; | ||
importStatements?: lua.Statement[]; | ||
loopContinued?: boolean; | ||
loopContinued?: LoopContinued; | ||
functionReturned?: boolean; | ||
@@ -31,0 +35,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.performHoisting = exports.separateHoistedStatements = exports.isFunctionScopeWithDefinition = exports.hasReferencedSymbol = exports.hasReferencedUndefinedLocalFunction = exports.addScopeVariableDeclaration = exports.findScope = exports.peekScope = exports.markSymbolAsReferencedInCurrentScopes = exports.walkScopesUp = exports.ScopeType = void 0; | ||
exports.performHoisting = exports.separateHoistedStatements = exports.isFunctionScopeWithDefinition = exports.hasReferencedSymbol = exports.hasReferencedUndefinedLocalFunction = exports.addScopeVariableDeclaration = exports.findScope = exports.peekScope = exports.markSymbolAsReferencedInCurrentScopes = exports.walkScopesUp = exports.LoopContinued = exports.ScopeType = void 0; | ||
const ts = require("typescript"); | ||
@@ -21,2 +21,7 @@ const lua = require("../../LuaAST"); | ||
})(ScopeType || (exports.ScopeType = ScopeType = {})); | ||
var LoopContinued; | ||
(function (LoopContinued) { | ||
LoopContinued[LoopContinued["WithGoto"] = 0] = "WithGoto"; | ||
LoopContinued[LoopContinued["WithRepeatBreak"] = 1] = "WithRepeatBreak"; | ||
})(LoopContinued || (exports.LoopContinued = LoopContinued = {})); | ||
function* walkScopesUp(context) { | ||
@@ -23,0 +28,0 @@ const scopeStack = context.scopeStack; |
@@ -6,3 +6,2 @@ "use strict"; | ||
const lua = require("../../LuaAST"); | ||
const diagnostics_1 = require("../utils/diagnostics"); | ||
const scope_1 = require("../utils/scope"); | ||
@@ -16,14 +15,23 @@ const transformBreakStatement = (breakStatement, context) => { | ||
var _a; | ||
if (context.luaTarget === CompilerOptions_1.LuaTarget.Universal || | ||
const scope = (0, scope_1.findScope)(context, scope_1.ScopeType.Loop); | ||
const continuedWith = context.luaTarget === CompilerOptions_1.LuaTarget.Universal || | ||
context.luaTarget === CompilerOptions_1.LuaTarget.Lua50 || | ||
context.luaTarget === CompilerOptions_1.LuaTarget.Lua51) { | ||
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(statement, "Continue statement", context.luaTarget)); | ||
} | ||
const scope = (0, scope_1.findScope)(context, scope_1.ScopeType.Loop); | ||
context.luaTarget === CompilerOptions_1.LuaTarget.Lua51 | ||
? scope_1.LoopContinued.WithRepeatBreak | ||
: scope_1.LoopContinued.WithGoto; | ||
if (scope) { | ||
scope.loopContinued = true; | ||
scope.loopContinued = continuedWith; | ||
} | ||
return lua.createGotoStatement(`__continue${(_a = scope === null || scope === void 0 ? void 0 : scope.id) !== null && _a !== void 0 ? _a : ""}`, statement); | ||
const label = `__continue${(_a = scope === null || scope === void 0 ? void 0 : scope.id) !== null && _a !== void 0 ? _a : ""}`; | ||
switch (continuedWith) { | ||
case scope_1.LoopContinued.WithGoto: | ||
return lua.createGotoStatement(label, statement); | ||
case scope_1.LoopContinued.WithRepeatBreak: | ||
return [ | ||
lua.createAssignmentStatement(lua.createIdentifier(label), lua.createBooleanLiteral(true), statement), | ||
lua.createBreakStatement(statement), | ||
]; | ||
} | ||
}; | ||
exports.transformContinueStatement = transformContinueStatement; | ||
//# sourceMappingURL=break-continue.js.map |
@@ -20,2 +20,3 @@ "use strict"; | ||
const call_extension_1 = require("./language-extensions/call-extension"); | ||
const identifier_1 = require("./identifier"); | ||
function validateArguments(context, params, signature) { | ||
@@ -93,3 +94,9 @@ if (!signature || signature.parameters.length < params.length) { | ||
const table = context.transformExpression(left.expression); | ||
return lua.createMethodCallExpression(table, lua.createIdentifier(left.name.text, left.name), transformedArguments, node); | ||
let name = left.name.text; | ||
const symbol = context.checker.getSymbolAtLocation(left); | ||
const customName = (0, identifier_1.getCustomNameFromSymbol)(symbol); | ||
if (customName) { | ||
name = customName; | ||
} | ||
return lua.createMethodCallExpression(table, lua.createIdentifier(name, left.name), transformedArguments, node); | ||
} | ||
@@ -96,0 +103,0 @@ else if (ts.isElementAccessExpression(left) || ts.isPropertyAccessExpression(left)) { |
@@ -20,2 +20,3 @@ "use strict"; | ||
const decorators_2 = require("./decorators"); | ||
const typescript_1 = require("../../utils/typescript"); | ||
const transformClassDeclaration = (declaration, context) => { | ||
@@ -184,5 +185,12 @@ // If declaration is a default export, transform to export variable assignment instead | ||
} | ||
return lua.createTableIndexExpression(baseClassName, lua.createStringLiteral("prototype")); | ||
const f = (0, typescript_1.findFirstNodeAbove)(expression, ts.isFunctionLike); | ||
if (f && ts.canHaveModifiers(f) && (0, utils_1.isStaticNode)(f)) { | ||
// In static method, don't add prototype to super call | ||
return baseClassName; | ||
} | ||
else { | ||
return lua.createTableIndexExpression(baseClassName, lua.createStringLiteral("prototype")); | ||
} | ||
}; | ||
exports.transformSuperExpression = transformSuperExpression; | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,4 @@ import * as ts from "typescript"; | ||
export declare function transformIdentifier(context: TransformationContext, identifier: ts.Identifier): lua.Identifier; | ||
export declare function getCustomNameFromSymbol(symbol?: ts.Symbol): undefined | string; | ||
export declare function transformIdentifierWithSymbol(context: TransformationContext, node: ts.Identifier, symbol: ts.Symbol | undefined): lua.Expression; | ||
export declare const transformIdentifierExpression: FunctionVisitor<ts.Identifier>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transformIdentifierExpression = exports.transformIdentifierWithSymbol = exports.transformIdentifier = void 0; | ||
exports.transformIdentifierExpression = exports.transformIdentifierWithSymbol = exports.getCustomNameFromSymbol = exports.transformIdentifier = void 0; | ||
const ts = require("typescript"); | ||
@@ -18,2 +18,3 @@ const lua = require("../../LuaAST"); | ||
const identifier_1 = require("./language-extensions/identifier"); | ||
const annotations_1 = require("../utils/annotations"); | ||
function transformIdentifier(context, identifier) { | ||
@@ -23,2 +24,24 @@ return transformNonValueIdentifier(context, identifier, context.checker.getSymbolAtLocation(identifier)); | ||
exports.transformIdentifier = transformIdentifier; | ||
function getCustomNameFromSymbol(symbol) { | ||
let retVal; | ||
if (symbol) { | ||
const declarations = symbol.getDeclarations(); | ||
if (declarations) { | ||
let customNameAnnotation = undefined; | ||
for (const declaration of declarations) { | ||
const nodeAnnotations = (0, annotations_1.getNodeAnnotations)(declaration); | ||
const foundAnnotation = nodeAnnotations.get(annotations_1.AnnotationKind.CustomName); | ||
if (foundAnnotation) { | ||
customNameAnnotation = foundAnnotation; | ||
break; | ||
} | ||
} | ||
if (customNameAnnotation) { | ||
retVal = customNameAnnotation.args[0]; | ||
} | ||
} | ||
} | ||
return retVal; | ||
} | ||
exports.getCustomNameFromSymbol = getCustomNameFromSymbol; | ||
function transformNonValueIdentifier(context, identifier, symbol) { | ||
@@ -53,5 +76,6 @@ if ((0, optional_chaining_1.isOptionalContinuation)(identifier)) { | ||
} | ||
const text = (0, safe_names_1.hasUnsafeIdentifierName)(context, identifier, symbol) | ||
? (0, safe_names_1.createSafeName)(identifier.text) | ||
: identifier.text; | ||
let text = (0, safe_names_1.hasUnsafeIdentifierName)(context, identifier, symbol) ? (0, safe_names_1.createSafeName)(identifier.text) : identifier.text; | ||
const customName = getCustomNameFromSymbol(symbol); | ||
if (customName) | ||
text = customName; | ||
const symbolId = (0, symbols_1.getIdentifierSymbolId)(context, identifier, symbol); | ||
@@ -58,0 +82,0 @@ return lua.createIdentifier(text, identifier, symbolId, identifier.text); |
@@ -19,9 +19,18 @@ "use strict"; | ||
const scopeId = scope.id; | ||
if (!scope.loopContinued) { | ||
return body; | ||
switch (scope.loopContinued) { | ||
case undefined: | ||
return body; | ||
case scope_1.LoopContinued.WithGoto: | ||
return [lua.createDoStatement(body), lua.createLabelStatement(`__continue${scopeId}`)]; | ||
case scope_1.LoopContinued.WithRepeatBreak: | ||
const identifier = lua.createIdentifier(`__continue${scopeId}`); | ||
const literalTrue = lua.createBooleanLiteral(true); | ||
return [ | ||
lua.createDoStatement([ | ||
lua.createVariableDeclarationStatement(identifier), | ||
lua.createRepeatStatement(lua.createBlock([...body, lua.createAssignmentStatement(identifier, literalTrue)]), literalTrue), | ||
lua.createIfStatement(lua.createUnaryExpression(identifier, lua.SyntaxKind.NotOperator), lua.createBlock([lua.createBreakStatement()])), | ||
]), | ||
]; | ||
} | ||
const baseResult = [lua.createDoStatement(body)]; | ||
const continueLabel = lua.createLabelStatement(`__continue${scopeId}`); | ||
baseResult.push(continueLabel); | ||
return baseResult; | ||
} | ||
@@ -28,0 +37,0 @@ exports.transformLoopBody = transformLoopBody; |
{ | ||
"name": "typescript-to-lua", | ||
"version": "1.20.1", | ||
"version": "1.21.0", | ||
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/TypeScriptToLua/TypeScriptToLua", |
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
1088365
15517