typescript-to-lua
Advanced tools
Comparing version 1.16.1 to 1.16.2
@@ -12,4 +12,5 @@ import * as ts from "typescript"; | ||
export declare function isArrayType(context: TransformationContext, type: ts.Type): boolean; | ||
export declare function isAlwaysArrayType(context: TransformationContext, type: ts.Type): boolean; | ||
export declare function isFunctionType(type: ts.Type): boolean; | ||
export declare function canBeFalsy(context: TransformationContext, type: ts.Type): boolean; | ||
export declare function canBeFalsyWhenNotNull(context: TransformationContext, type: ts.Type): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.canBeFalsyWhenNotNull = exports.canBeFalsy = exports.isFunctionType = exports.isArrayType = exports.forTypeOrAnySupertype = exports.isNumberType = exports.isStringType = exports.typeCanHaveSomeOfFlags = exports.typeAlwaysHasSomeOfFlags = void 0; | ||
exports.canBeFalsyWhenNotNull = exports.canBeFalsy = exports.isFunctionType = exports.isAlwaysArrayType = exports.isArrayType = exports.forTypeOrAnySupertype = exports.isNumberType = exports.isStringType = exports.typeCanHaveSomeOfFlags = exports.typeAlwaysHasSomeOfFlags = void 0; | ||
const ts = require("typescript"); | ||
@@ -66,2 +66,16 @@ function typeAlwaysHasSomeOfFlags(context, type, flags) { | ||
} | ||
function isAlwaysExplicitArrayType(context, type) { | ||
if (context.checker.isArrayType(type) || context.checker.isTupleType(type)) | ||
return true; | ||
if (type.symbol) { | ||
const baseConstraint = context.checker.getBaseConstraintOfType(type); | ||
if (baseConstraint && baseConstraint !== type) { | ||
return isAlwaysExplicitArrayType(context, baseConstraint); | ||
} | ||
} | ||
if (type.isUnionOrIntersection()) { | ||
return type.types.every(t => isAlwaysExplicitArrayType(context, t)); | ||
} | ||
return false; | ||
} | ||
/** | ||
@@ -87,2 +101,6 @@ * Iterate over a type and its bases until the callback returns true. | ||
exports.isArrayType = isArrayType; | ||
function isAlwaysArrayType(context, type) { | ||
return forTypeOrAnySupertype(context, type, t => isAlwaysExplicitArrayType(context, t)); | ||
} | ||
exports.isAlwaysArrayType = isAlwaysArrayType; | ||
function isFunctionType(type) { | ||
@@ -89,0 +107,0 @@ return type.getCallSignatures().length > 0; |
@@ -105,3 +105,12 @@ "use strict"; | ||
// Transform class members | ||
// First transform the methods, in case the static properties call them | ||
for (const member of classDeclaration.members) { | ||
if (ts.isMethodDeclaration(member)) { | ||
// Methods | ||
const statements = (0, method_1.transformMethodDeclaration)(context, member, localClassName); | ||
result.push(...statements); | ||
} | ||
} | ||
// Then transform the rest | ||
for (const member of classDeclaration.members) { | ||
if (ts.isAccessor(member)) { | ||
@@ -117,7 +126,2 @@ // Accessors | ||
} | ||
else if (ts.isMethodDeclaration(member)) { | ||
// Methods | ||
const statements = (0, method_1.transformMethodDeclaration)(context, member, localClassName); | ||
result.push(...statements); | ||
} | ||
else if (ts.isPropertyDeclaration(member)) { | ||
@@ -124,0 +128,0 @@ // Properties |
@@ -86,3 +86,4 @@ "use strict"; | ||
const type = context.checker.getTypeAtLocation(node.expression); // not ts-inner expression, in case of casts | ||
if ((0, typescript_1.isArrayType)(context, type)) { | ||
if ((0, typescript_1.isAlwaysArrayType)(context, type)) { | ||
// All union members must be arrays to be able to shortcut to unpack call | ||
return (0, lua_ast_1.createUnpackCall)(context, innerExpression, node); | ||
@@ -89,0 +90,0 @@ } |
{ | ||
"name": "typescript-to-lua", | ||
"version": "1.16.1", | ||
"version": "1.16.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", |
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
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
1055488
15097