typescript-to-lua
Advanced tools
Comparing version 1.13.1 to 1.13.2
@@ -58,2 +58,3 @@ "use strict"; | ||
function transformArrayPrototypeCall(context, node, calledMethod) { | ||
var _a, _b, _c; | ||
const signature = context.checker.getResolvedSignature(node); | ||
@@ -69,5 +70,5 @@ const [caller, params] = (0, call_1.transformCallAndArguments)(context, calledMethod.expression, node.arguments, signature); | ||
if (node.arguments.length === 1) { | ||
const param = params[0]; | ||
const param = (_a = params[0]) !== null && _a !== void 0 ? _a : lua.createNilLiteral(); | ||
if ((0, lua_ast_1.isUnpackCall)(param)) { | ||
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayPushArray, node, caller, param.params[0]); | ||
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayPushArray, node, caller, (_b = param.params[0]) !== null && _b !== void 0 ? _b : lua.createNilLiteral()); | ||
} | ||
@@ -121,3 +122,3 @@ if (!lua.isDotsLiteral(param)) { | ||
const defaultSeparatorLiteral = lua.createStringLiteral(","); | ||
const param = params[0]; | ||
const param = (_c = params[0]) !== null && _c !== void 0 ? _c : lua.createNilLiteral(); | ||
const parameters = [ | ||
@@ -124,0 +125,0 @@ caller, |
@@ -30,2 +30,3 @@ "use strict"; | ||
function transformMathCall(context, node, calledMethod) { | ||
var _a, _b, _c, _d; | ||
const signature = context.checker.getResolvedSignature(node); | ||
@@ -57,3 +58,3 @@ const params = (0, call_1.transformArguments)(context, node.arguments, signature); | ||
const one = lua.createNumericLiteral(1); | ||
const add = lua.createBinaryExpression(one, params[0], lua.SyntaxKind.AdditionOperator); | ||
const add = lua.createBinaryExpression(one, (_a = params[0]) !== null && _a !== void 0 ? _a : lua.createNilLiteral(), lua.SyntaxKind.AdditionOperator); | ||
return lua.createCallExpression(lua.createTableIndexExpression(math, log), [add], node); | ||
@@ -63,3 +64,3 @@ } | ||
// Translate to base ^ power | ||
return lua.createBinaryExpression(params[0], params[1], lua.SyntaxKind.PowerOperator, node); | ||
return lua.createBinaryExpression((_b = params[0]) !== null && _b !== void 0 ? _b : lua.createNilLiteral(), (_c = params[1]) !== null && _c !== void 0 ? _c : lua.createNilLiteral(), lua.SyntaxKind.PowerOperator, node); | ||
} | ||
@@ -70,3 +71,3 @@ // math.floor(x + 0.5) | ||
const half = lua.createNumericLiteral(0.5); | ||
const add = lua.createBinaryExpression(params[0], half, lua.SyntaxKind.AdditionOperator); | ||
const add = lua.createBinaryExpression((_d = params[0]) !== null && _d !== void 0 ? _d : lua.createNilLiteral(), half, lua.SyntaxKind.AdditionOperator); | ||
return lua.createCallExpression(lua.createTableIndexExpression(math, floor), [add], node); | ||
@@ -73,0 +74,0 @@ } |
@@ -15,2 +15,3 @@ "use strict"; | ||
function transformStringPrototypeCall(context, node, calledMethod) { | ||
var _a, _b, _c, _d; | ||
const signature = context.checker.getResolvedSignature(node); | ||
@@ -27,3 +28,3 @@ const [caller, params] = (0, call_1.transformCallAndArguments)(context, calledMethod.expression, node.arguments, signature); | ||
case "indexOf": { | ||
const stringExpression = createStringCall("find", node, caller, params[0], params[1] | ||
const stringExpression = createStringCall("find", node, caller, (_a = params[0]) !== null && _a !== void 0 ? _a : lua.createNilLiteral(), params[1] | ||
? // string.find handles negative indexes by making it relative to string end, but for indexOf it's the same as 0 | ||
@@ -78,3 +79,3 @@ lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("math"), lua.createStringLiteral("max")), [(0, lua_ast_1.addToNumericExpression)(params[1], 1), lua.createNumericLiteral(1)]) | ||
if (literalValue !== undefined && literalValue >= 0) { | ||
const firstParamPlusOne = (0, lua_ast_1.addToNumericExpression)(params[0], 1); | ||
const firstParamPlusOne = (0, lua_ast_1.addToNumericExpression)((_b = params[0]) !== null && _b !== void 0 ? _b : lua.createNilLiteral(), 1); | ||
return createStringCall("sub", node, caller, firstParamPlusOne, firstParamPlusOne); | ||
@@ -88,3 +89,3 @@ } | ||
if (literalValue !== undefined && literalValue >= 0) { | ||
return lua.createBinaryExpression(createStringCall("byte", node, caller, (0, lua_ast_1.addToNumericExpression)(params[0], 1)), (0, lua_ast_1.createNaN)(), lua.SyntaxKind.OrOperator); | ||
return lua.createBinaryExpression(createStringCall("byte", node, caller, (0, lua_ast_1.addToNumericExpression)((_c = params[0]) !== null && _c !== void 0 ? _c : lua.createNilLiteral(), 1)), (0, lua_ast_1.createNaN)(), lua.SyntaxKind.OrOperator); | ||
} | ||
@@ -102,3 +103,5 @@ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringCharCodeAt, node, caller, ...params); | ||
const floor = lua.createStringLiteral("floor"); | ||
const parameter = lua.createCallExpression(lua.createTableIndexExpression(math, floor), [params[0]]); | ||
const parameter = lua.createCallExpression(lua.createTableIndexExpression(math, floor), [ | ||
(_d = params[0]) !== null && _d !== void 0 ? _d : lua.createNilLiteral(), | ||
]); | ||
return createStringCall("rep", node, caller, parameter); | ||
@@ -105,0 +108,0 @@ case "padStart": |
import * as ts from "typescript"; | ||
import * as lua from "../../LuaAST"; | ||
import { LuaTarget, TypeScriptToLuaOptions } from "../../CompilerOptions"; | ||
@@ -100,1 +101,4 @@ import { AnnotationKind } from "./annotations"; | ||
}; | ||
export declare const cannotAssignToNodeOfKind: ((node: ts.Node, kind: lua.SyntaxKind) => ts.Diagnostic) & { | ||
code: number; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.invalidSpreadInCallExtension = exports.invalidMethodCallExtensionUse = exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0; | ||
exports.cannotAssignToNodeOfKind = exports.invalidSpreadInCallExtension = exports.invalidMethodCallExtensionUse = exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0; | ||
const ts = require("typescript"); | ||
const lua = require("../../LuaAST"); | ||
const CompilerOptions_1 = require("../../CompilerOptions"); | ||
@@ -64,2 +65,3 @@ const utils_1 = require("../../utils"); | ||
exports.invalidSpreadInCallExtension = createErrorDiagnosticFactory("Spread elements are not supported in call extensions."); | ||
exports.cannotAssignToNodeOfKind = createErrorDiagnosticFactory((kind) => `Cannot create assignment assigning to a node of type ${lua.SyntaxKind[kind]}.`); | ||
//# sourceMappingURL=diagnostics.js.map |
@@ -254,11 +254,13 @@ "use strict"; | ||
// Thus, need to add a hyphen to the first line. | ||
const firstLine = lines[0]; | ||
if (firstLine.startsWith(" @")) { | ||
lines.unshift("-"); | ||
if (lines.length > 0) { | ||
const firstLine = lines[0]; | ||
if (firstLine.startsWith(" @")) { | ||
lines.unshift("-"); | ||
} | ||
else { | ||
lines.shift(); | ||
lines.unshift("-" + firstLine); | ||
} | ||
return lines; | ||
} | ||
else { | ||
lines.shift(); | ||
lines.unshift("-" + firstLine); | ||
} | ||
return lines; | ||
} | ||
@@ -265,0 +267,0 @@ const createNaN = (tsOriginal) => lua.createBinaryExpression(lua.createNumericLiteral(0), lua.createNumericLiteral(0), lua.SyntaxKind.DivisionOperator, tsOriginal); |
@@ -6,3 +6,2 @@ "use strict"; | ||
const lua = require("../../../LuaAST"); | ||
const utils_1 = require("../../../utils"); | ||
const assignment_validation_1 = require("../../utils/assignment-validation"); | ||
@@ -36,5 +35,12 @@ const export_1 = require("../../utils/export"); | ||
const left = context.transformExpression(node); | ||
return lua.isIdentifier(left) && symbol && (0, export_1.isSymbolExported)(context, symbol) | ||
? (0, export_1.createExportedIdentifier)(context, left) | ||
: (0, utils_1.cast)(left, lua.isAssignmentLeftHandSideExpression); | ||
if (lua.isIdentifier(left) && symbol && (0, export_1.isSymbolExported)(context, symbol)) { | ||
return (0, export_1.createExportedIdentifier)(context, left); | ||
} | ||
if (lua.isAssignmentLeftHandSideExpression(left)) { | ||
return left; | ||
} | ||
else { | ||
context.diagnostics.push((0, diagnostics_1.cannotAssignToNodeOfKind)(node, left.kind)); | ||
return lua.createAnonymousIdentifier(); | ||
} | ||
} | ||
@@ -41,0 +47,0 @@ exports.transformAssignmentLeftHandSideExpression = transformAssignmentLeftHandSideExpression; |
@@ -53,22 +53,23 @@ "use strict"; | ||
} | ||
const parent = (0, typescript_1.findFirstNonOuterParent)(node); | ||
// Variable declaration with destructuring | ||
if (ts.isVariableDeclaration(node.parent) && ts.isArrayBindingPattern(node.parent.name)) { | ||
if (ts.isVariableDeclaration(parent) && ts.isArrayBindingPattern(parent.name)) { | ||
return false; | ||
} | ||
// Variable assignment with destructuring | ||
if (ts.isBinaryExpression(node.parent) && | ||
node.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && | ||
ts.isArrayLiteralExpression(node.parent.left)) { | ||
if (ts.isBinaryExpression(parent) && | ||
parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && | ||
ts.isArrayLiteralExpression(parent.left)) { | ||
return false; | ||
} | ||
// Spread operator | ||
if (ts.isSpreadElement(node.parent)) { | ||
if (ts.isSpreadElement(parent)) { | ||
return false; | ||
} | ||
// Stand-alone expression | ||
if (ts.isExpressionStatement(node.parent)) { | ||
if (ts.isExpressionStatement(parent)) { | ||
return false; | ||
} | ||
// Forwarded multi-return call | ||
if ((ts.isReturnStatement(node.parent) || ts.isArrowFunction(node.parent)) && // Body-less arrow func | ||
if ((ts.isReturnStatement(parent) || ts.isArrowFunction(parent)) && // Body-less arrow func | ||
isInMultiReturnFunction(context, node)) { | ||
@@ -78,7 +79,7 @@ return false; | ||
// Element access expression 'foo()[0]' will be optimized using 'select' | ||
if (ts.isElementAccessExpression(node.parent)) { | ||
if (ts.isElementAccessExpression(parent)) { | ||
return false; | ||
} | ||
// LuaIterable in for...of | ||
if (ts.isForOfStatement(node.parent) && | ||
if (ts.isForOfStatement(parent) && | ||
(0, language_extensions_1.getIterableExtensionKindForNode)(context, node) === language_extensions_1.IterableExtensionKind.Iterable) { | ||
@@ -85,0 +86,0 @@ return false; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const lua = require("../../LuaAST"); | ||
const utils_1 = require("../../utils"); | ||
const language_extensions_1 = require("../utils/language-extensions"); | ||
@@ -67,6 +68,20 @@ const lua_ast_1 = require("../utils/lua-ast"); | ||
return innerExpression; | ||
const iterableExtensionType = (0, language_extensions_1.getIterableExtensionKindForNode)(context, node.expression); | ||
if (iterableExtensionType) { | ||
if (iterableExtensionType === language_extensions_1.IterableExtensionKind.Iterable) { | ||
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.LuaIteratorSpread, node, innerExpression); | ||
} | ||
else if (iterableExtensionType === language_extensions_1.IterableExtensionKind.Pairs) { | ||
const objectEntries = (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ObjectEntries, node, innerExpression); | ||
return (0, lua_ast_1.createUnpackCall)(context, objectEntries, node); | ||
} | ||
else if (iterableExtensionType === language_extensions_1.IterableExtensionKind.PairsKey) { | ||
const objectKeys = (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ObjectKeys, node, innerExpression); | ||
return (0, lua_ast_1.createUnpackCall)(context, objectKeys, node); | ||
} | ||
else { | ||
(0, utils_1.assertNever)(iterableExtensionType); | ||
} | ||
} | ||
const type = context.checker.getTypeAtLocation(node.expression); // not ts-inner expression, in case of casts | ||
if ((0, language_extensions_1.isLuaIterable)(context, type)) { | ||
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.LuaIteratorSpread, node, innerExpression); | ||
} | ||
if ((0, typescript_1.isArrayType)(context, type)) { | ||
@@ -73,0 +88,0 @@ return (0, lua_ast_1.createUnpackCall)(context, innerExpression, node); |
{ | ||
"name": "typescript-to-lua", | ||
"version": "1.13.1", | ||
"version": "1.13.2", | ||
"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
1036520
14812