Socket
Socket
Sign inDemoInstall

typescript-to-lua

Package Overview
Dependencies
Maintainers
2
Versions
157
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-to-lua - npm Package Compare versions

Comparing version 1.3.4 to 1.4.0

dist/lualib-build/plugin.d.ts

5

dist/cli/parse.js

@@ -15,2 +15,7 @@ "use strict";

{
name: "extension",
description: 'File extension for the resulting Lua files. Defaults to ".lua"',
type: "string",
},
{
name: "luaBundle",

@@ -17,0 +22,0 @@ description: "The name of the lua file to bundle output lua to. Requires luaBundleEntry.",

2

dist/CompilerOptions.d.ts

@@ -20,2 +20,3 @@ import * as ts from "typescript";

buildMode?: BuildMode;
extension?: string;
luaBundle?: string;

@@ -36,3 +37,2 @@ luaBundleEntry?: string;

None = "none",
Always = "always",
Inline = "inline",

@@ -39,0 +39,0 @@ Require = "require"

@@ -9,3 +9,2 @@ "use strict";

LuaLibImportKind["None"] = "none";
LuaLibImportKind["Always"] = "always";
LuaLibImportKind["Inline"] = "inline";

@@ -12,0 +11,0 @@ LuaLibImportKind["Require"] = "require";

@@ -11,1 +11,2 @@ export { version } from "./cli/information";

export * from "./transpilation";
export { ProcessedFile } from "./transpilation/utils";
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

import { EmitHost } from "./transpilation";
import * as lua from "./LuaAST";
export declare enum LuaLibFeature {

@@ -99,3 +100,13 @@ ArrayConcat = "ArrayConcat",

}
export declare function loadLuaLibFeatures(features: Iterable<LuaLibFeature>, emitHost: EmitHost): string;
export interface LuaLibFeatureInfo {
dependencies?: LuaLibFeature[];
exports: string[];
}
export declare type LuaLibModulesInfo = Record<LuaLibFeature, LuaLibFeatureInfo>;
export declare const luaLibModulesInfoFileName = "lualib_module_info.json";
export declare function getLuaLibModulesInfo(emitHost: EmitHost): LuaLibModulesInfo;
export declare function readLuaLibFeature(feature: LuaLibFeature, emitHost: EmitHost): string;
export declare function resolveRecursiveLualibFeatures(features: Iterable<LuaLibFeature>, emitHost: EmitHost, luaLibModulesInfo?: LuaLibModulesInfo): LuaLibFeature[];
export declare function loadInlineLualibFeatures(features: Iterable<LuaLibFeature>, emitHost: EmitHost): string;
export declare function loadImportedLualibFeatures(features: Iterable<LuaLibFeature>, emitHost: EmitHost): lua.Statement[];
export declare function getLuaLibBundle(emitHost: EmitHost): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLuaLibBundle = exports.loadLuaLibFeatures = exports.LuaLibFeature = void 0;
exports.getLuaLibBundle = exports.loadImportedLualibFeatures = exports.loadInlineLualibFeatures = exports.resolveRecursiveLualibFeatures = exports.readLuaLibFeature = exports.getLuaLibModulesInfo = exports.luaLibModulesInfoFileName = exports.LuaLibFeature = void 0;
const path = require("path");
const lua = require("./LuaAST");
var LuaLibFeature;

@@ -103,73 +104,40 @@ (function (LuaLibFeature) {

})(LuaLibFeature = exports.LuaLibFeature || (exports.LuaLibFeature = {}));
/* eslint-disable @typescript-eslint/naming-convention */
const luaLibDependencies = {
ArrayConcat: [LuaLibFeature.ArrayIsArray],
ArrayFlat: [LuaLibFeature.ArrayConcat, LuaLibFeature.ArrayIsArray],
ArrayFlatMap: [LuaLibFeature.ArrayConcat, LuaLibFeature.ArrayIsArray],
Await: [LuaLibFeature.InstanceOf, LuaLibFeature.New, LuaLibFeature.Promise],
Decorate: [LuaLibFeature.ObjectGetOwnPropertyDescriptor, LuaLibFeature.SetDescriptor, LuaLibFeature.ObjectAssign],
DelegatedYield: [LuaLibFeature.StringAccess],
Delete: [LuaLibFeature.ObjectGetOwnPropertyDescriptors, LuaLibFeature.Error, LuaLibFeature.New],
Error: [LuaLibFeature.Class, LuaLibFeature.ClassExtends, LuaLibFeature.New],
FunctionBind: [LuaLibFeature.Unpack],
Generator: [LuaLibFeature.Symbol],
InstanceOf: [LuaLibFeature.Symbol],
Iterator: [LuaLibFeature.Symbol],
NumberToString: [LuaLibFeature.StringAccess],
ObjectDefineProperty: [LuaLibFeature.CloneDescriptor, LuaLibFeature.SetDescriptor],
ObjectFromEntries: [LuaLibFeature.Iterator, LuaLibFeature.Symbol],
Promise: [
LuaLibFeature.ArrayPush,
LuaLibFeature.Class,
LuaLibFeature.FunctionBind,
LuaLibFeature.InstanceOf,
LuaLibFeature.New,
],
PromiseAll: [LuaLibFeature.InstanceOf, LuaLibFeature.New, LuaLibFeature.Promise, LuaLibFeature.Iterator],
PromiseAllSettled: [LuaLibFeature.InstanceOf, LuaLibFeature.New, LuaLibFeature.Promise, LuaLibFeature.Iterator],
PromiseAny: [
LuaLibFeature.ArrayPush,
LuaLibFeature.InstanceOf,
LuaLibFeature.New,
LuaLibFeature.Promise,
LuaLibFeature.Iterator,
],
PromiseRace: [
LuaLibFeature.ArrayPush,
LuaLibFeature.InstanceOf,
LuaLibFeature.New,
LuaLibFeature.Promise,
LuaLibFeature.Iterator,
],
ParseFloat: [LuaLibFeature.StringAccess],
ParseInt: [LuaLibFeature.StringSubstr, LuaLibFeature.StringSubstring],
SetDescriptor: [LuaLibFeature.CloneDescriptor],
Spread: [LuaLibFeature.Iterator, LuaLibFeature.StringAccess, LuaLibFeature.Unpack],
StringSplit: [LuaLibFeature.StringSubstring, LuaLibFeature.StringAccess],
SymbolRegistry: [LuaLibFeature.Symbol],
Map: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
Set: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
WeakMap: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
WeakSet: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
};
/* eslint-enable @typescript-eslint/naming-convention */
function loadLuaLibFeatures(features, emitHost) {
let result = "";
exports.luaLibModulesInfoFileName = "lualib_module_info.json";
let luaLibModulesInfo;
function getLuaLibModulesInfo(emitHost) {
if (luaLibModulesInfo === undefined) {
const lualibPath = path.resolve(__dirname, `../dist/lualib/${exports.luaLibModulesInfoFileName}`);
const result = emitHost.readFile(lualibPath);
if (result !== undefined) {
luaLibModulesInfo = JSON.parse(result);
}
else {
throw new Error(`Could not load lualib dependencies from '${lualibPath}'`);
}
}
return luaLibModulesInfo;
}
exports.getLuaLibModulesInfo = getLuaLibModulesInfo;
function readLuaLibFeature(feature, emitHost) {
const featurePath = path.resolve(__dirname, `../dist/lualib/${feature}.lua`);
const luaLibFeature = emitHost.readFile(featurePath);
if (luaLibFeature === undefined) {
throw new Error(`Could not load lualib feature from '${featurePath}'`);
}
return luaLibFeature;
}
exports.readLuaLibFeature = readLuaLibFeature;
function resolveRecursiveLualibFeatures(features, emitHost, luaLibModulesInfo = getLuaLibModulesInfo(emitHost)) {
const loadedFeatures = new Set();
const result = [];
function load(feature) {
var _a;
if (loadedFeatures.has(feature))
return;
loadedFeatures.add(feature);
const dependencies = luaLibDependencies[feature];
const dependencies = (_a = luaLibModulesInfo[feature]) === null || _a === void 0 ? void 0 : _a.dependencies;
if (dependencies) {
dependencies.forEach(load);
}
const featurePath = path.resolve(__dirname, `../dist/lualib/${feature}.lua`);
const luaLibFeature = emitHost.readFile(featurePath);
if (luaLibFeature !== undefined) {
result += luaLibFeature + "\n";
}
else {
throw new Error(`Could not load lualib feature from '${featurePath}'`);
}
result.push(feature);
}

@@ -181,3 +149,31 @@ for (const feature of features) {

}
exports.loadLuaLibFeatures = loadLuaLibFeatures;
exports.resolveRecursiveLualibFeatures = resolveRecursiveLualibFeatures;
function loadInlineLualibFeatures(features, emitHost) {
let result = "";
for (const feature of resolveRecursiveLualibFeatures(features, emitHost)) {
const luaLibFeature = readLuaLibFeature(feature, emitHost);
result += luaLibFeature + "\n";
}
return result;
}
exports.loadInlineLualibFeatures = loadInlineLualibFeatures;
function loadImportedLualibFeatures(features, emitHost) {
const luaLibModuleInfo = getLuaLibModulesInfo(emitHost);
const imports = Array.from(features).flatMap(feature => luaLibModuleInfo[feature].exports);
const requireCall = lua.createCallExpression(lua.createIdentifier("require"), [
lua.createStringLiteral("lualib_bundle"),
]);
if (imports.length === 0) {
return [];
}
const luaLibId = lua.createIdentifier("____lualib");
const importStatement = lua.createVariableDeclarationStatement(luaLibId, requireCall);
const statements = [importStatement];
// local <export> = ____luaLib.<export>
for (const item of imports) {
statements.push(lua.createVariableDeclarationStatement(lua.createIdentifier(item), lua.createTableIndexExpression(luaLibId, lua.createStringLiteral(item))));
}
return statements;
}
exports.loadImportedLualibFeatures = loadImportedLualibFeatures;
let luaLibBundleContent;

@@ -184,0 +180,0 @@ function getLuaLibBundle(emitHost) {

@@ -6,3 +6,2 @@ "use strict";

const source_map_1 = require("source-map");
const _1 = require(".");
const CompilerOptions_1 = require("./CompilerOptions");

@@ -12,2 +11,3 @@ const lua = require("./LuaAST");

const safe_names_1 = require("./transformation/utils/safe-names");
const transpilation_1 = require("./transpilation");
const utils_1 = require("./utils");

@@ -84,3 +84,3 @@ // https://www.lua.org/pil/2.4.html

this.options = program.getCompilerOptions();
this.luaFile = (0, utils_1.normalizeSlashes)((0, _1.getEmitPath)(this.sourceFile, this.program));
this.luaFile = (0, utils_1.normalizeSlashes)((0, transpilation_1.getEmitPath)(this.sourceFile, this.program));
// Source nodes contain relative path from mapped lua file to original TS source file

@@ -139,7 +139,8 @@ this.relativeSourcePath = (0, utils_1.normalizeSlashes)(path.relative(path.dirname(this.luaFile), this.sourceFile));

}
let statements = file.statements;
const luaLibImport = (_a = this.options.luaLibImport) !== null && _a !== void 0 ? _a : CompilerOptions_1.LuaLibImportKind.Require;
if (luaLibImport === CompilerOptions_1.LuaLibImportKind.Always ||
(luaLibImport === CompilerOptions_1.LuaLibImportKind.Require && file.luaLibFeatures.size > 0)) {
// Require lualib bundle
header += 'require("lualib_bundle");\n';
if (luaLibImport === CompilerOptions_1.LuaLibImportKind.Require && file.luaLibFeatures.size > 0) {
// Import lualib features
const importStatements = (0, LuaLib_1.loadImportedLualibFeatures)(file.luaLibFeatures, this.emitHost);
statements = importStatements.concat(statements);
}

@@ -149,3 +150,3 @@ else if (luaLibImport === CompilerOptions_1.LuaLibImportKind.Inline && file.luaLibFeatures.size > 0) {

header += "-- Lua Library inline imports\n";
header += (0, LuaLib_1.loadLuaLibFeatures)(file.luaLibFeatures, this.emitHost);
header += (0, LuaLib_1.loadInlineLualibFeatures)(file.luaLibFeatures, this.emitHost);
}

@@ -157,3 +158,3 @@ if (this.options.sourceMapTraceback && !(0, CompilerOptions_1.isBundleEnabled)(this.options)) {

}
return this.concatNodes(header, ...this.printStatementArray(file.statements));
return this.concatNodes(header, ...this.printStatementArray(statements));
}

@@ -160,0 +161,0 @@ pushIndent() {

@@ -22,3 +22,4 @@ "use strict";

case "apply":
return lua.createCallExpression(caller, [params[0], (0, lua_ast_1.createUnpackCall)(context, params[1], node.arguments[1])], node);
const nonContextArgs = params.length > 1 ? [(0, lua_ast_1.createUnpackCall)(context, params[1], node.arguments[1])] : [];
return lua.createCallExpression(caller, [params[0], ...nonContextArgs], node);
case "bind":

@@ -25,0 +26,0 @@ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.FunctionBind, node, caller, ...params);

@@ -7,1 +7,2 @@ import * as ts from "typescript";

export declare function transformBuiltinIdentifierExpression(context: TransformationContext, node: ts.Identifier): lua.Expression | undefined;
export declare function checkForLuaLibType(context: TransformationContext, type: ts.Type): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformBuiltinIdentifierExpression = exports.transformBuiltinCallExpression = exports.transformBuiltinPropertyAccessExpression = void 0;
exports.checkForLuaLibType = exports.transformBuiltinIdentifierExpression = exports.transformBuiltinCallExpression = exports.transformBuiltinPropertyAccessExpression = void 0;
const ts = require("typescript");

@@ -11,3 +11,2 @@ const lua = require("../../LuaAST");

const typescript_1 = require("../utils/typescript");
const new_1 = require("../visitors/class/new");
const array_1 = require("./array");

@@ -26,2 +25,10 @@ const console_1 = require("./console");

const ownerType = context.checker.getTypeAtLocation(node.expression);
if (ts.isIdentifier(node.expression) && (0, typescript_1.isStandardLibraryType)(context, ownerType, undefined)) {
switch (node.expression.text) {
case "Math":
return (0, math_1.transformMathProperty)(context, node);
case "Symbol":
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Symbol);
}
}
if ((0, typescript_1.isStringType)(context, ownerType)) {

@@ -36,10 +43,2 @@ return (0, string_1.transformStringProperty)(context, node);

}
if (ts.isIdentifier(node.expression) && (0, typescript_1.isStandardLibraryType)(context, ownerType, undefined)) {
switch (node.expression.text) {
case "Math":
return (0, math_1.transformMathProperty)(context, node);
case "Symbol":
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Symbol);
}
}
}

@@ -54,4 +53,3 @@ exports.transformBuiltinPropertyAccessExpression = transformBuiltinPropertyAccessExpression;

if (ts.isIdentifier(node.expression) && (0, typescript_1.isStandardLibraryType)(context, expressionType, undefined)) {
// TODO:
(0, new_1.checkForLuaLibType)(context, expressionType);
checkForLuaLibType(context, expressionType);
const result = (0, global_1.transformGlobalCall)(context, node);

@@ -109,3 +107,5 @@ if (result) {

}
if ((0, typescript_1.isStringType)(context, ownerType) && (0, typescript_1.hasStandardLibrarySignature)(context, node)) {
const isStringFunction = (0, typescript_1.isStringType)(context, ownerType) ||
(expression.questionDotToken && (0, typescript_1.isNullableType)(context, ownerType, typescript_1.isStringType));
if (isStringFunction && (0, typescript_1.hasStandardLibrarySignature)(context, node)) {
if (isOptionalCall)

@@ -115,3 +115,5 @@ return unsupportedOptionalCall();

}
if ((0, typescript_1.isNumberType)(context, ownerType) && (0, typescript_1.hasStandardLibrarySignature)(context, node)) {
const isNumberFunction = (0, typescript_1.isNumberType)(context, ownerType) ||
(expression.questionDotToken && (0, typescript_1.isNullableType)(context, ownerType, typescript_1.isNumberType));
if (isNumberFunction && (0, typescript_1.hasStandardLibrarySignature)(context, node)) {
if (isOptionalCall)

@@ -121,3 +123,5 @@ return unsupportedOptionalCall();

}
if ((0, typescript_1.isArrayType)(context, ownerType) && (0, typescript_1.hasStandardLibrarySignature)(context, node)) {
const isArrayFunction = (0, typescript_1.isArrayType)(context, ownerType) ||
(expression.questionDotToken && (0, typescript_1.isNullableType)(context, ownerType, typescript_1.isArrayType));
if (isArrayFunction && (0, typescript_1.hasStandardLibrarySignature)(context, node)) {
if (isOptionalCall)

@@ -127,3 +131,5 @@ return unsupportedOptionalCall();

}
if ((0, typescript_1.isFunctionType)(ownerType) && (0, typescript_1.hasStandardLibrarySignature)(context, node)) {
const isFunctionFunction = (0, typescript_1.isFunctionType)(ownerType) ||
(expression.questionDotToken && (0, typescript_1.isNullableType)(context, ownerType, (_, t) => (0, typescript_1.isFunctionType)(t)));
if (isFunctionFunction && (0, typescript_1.hasStandardLibrarySignature)(context, node)) {
if (isOptionalCall)

@@ -154,2 +160,43 @@ return unsupportedOptionalCall();

exports.transformBuiltinIdentifierExpression = transformBuiltinIdentifierExpression;
const builtinErrorTypeNames = new Set([
"Error",
"ErrorConstructor",
"RangeError",
"RangeErrorConstructor",
"ReferenceError",
"ReferenceErrorConstructor",
"SyntaxError",
"SyntaxErrorConstructor",
"TypeError",
"TypeErrorConstructor",
"URIError",
"URIErrorConstructor",
]);
function checkForLuaLibType(context, type) {
if (!type.symbol)
return;
const name = context.checker.getFullyQualifiedName(type.symbol);
switch (name) {
case "Map":
case "MapConstructor":
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Map);
return;
case "Set":
case "SetConstructor":
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Set);
return;
case "WeakMap":
case "WeakMapConstructor":
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.WeakMap);
return;
case "WeakSet":
case "WeakSetConstructor":
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.WeakSet);
return;
}
if (builtinErrorTypeNames.has(name)) {
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Error);
}
}
exports.checkForLuaLibType = checkForLuaLibType;
//# sourceMappingURL=index.js.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -97,1 +97,4 @@ import * as ts from "typescript";

};
export declare const undefinedInArrayLiteral: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
code: number;
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.annotationDeprecated = exports.annotationRemoved = exports.invalidTableExtensionUse = exports.invalidOperatorMappingUse = exports.invalidMultiReturnAccess = exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = exports.invalidMultiTypeToNonArrayLiteral = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = 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.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.annotationDeprecated = exports.annotationRemoved = exports.invalidTableExtensionUse = exports.invalidOperatorMappingUse = exports.invalidMultiReturnAccess = exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = exports.invalidMultiTypeToNonArrayLiteral = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = 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");

@@ -62,2 +62,3 @@ const CompilerOptions_1 = require("../../CompilerOptions");

exports.unsupportedOptionalCompileMembersOnly = createErrorDiagnosticFactory("Optional calls are not supported on enums marked with @compileMembersOnly.");
exports.undefinedInArrayLiteral = createErrorDiagnosticFactory("Array literals may not contain undefined or null.");
//# sourceMappingURL=diagnostics.js.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -6,4 +6,6 @@ import * as ts from "typescript";

export declare function typeCanSatisfy(context: TransformationContext, type: ts.Type, predicate: (type: ts.Type) => boolean): boolean;
export declare function isNullishType(context: TransformationContext, type: ts.Type): boolean;
export declare function isStringType(context: TransformationContext, type: ts.Type): boolean;
export declare function isNumberType(context: TransformationContext, type: ts.Type): boolean;
export declare function isNullableType(context: TransformationContext, type: ts.Type, isType: (c: TransformationContext, t: ts.Type) => boolean): boolean;
/**

@@ -10,0 +12,0 @@ * Iterate over a type and its bases until the callback returns true.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.canBeFalsyWhenNotNull = exports.canBeFalsy = exports.isFunctionType = exports.isArrayType = exports.forTypeOrAnySupertype = exports.isNumberType = exports.isStringType = exports.typeCanSatisfy = exports.typeAlwaysSatisfies = exports.isTypeWithFlags = void 0;
exports.canBeFalsyWhenNotNull = exports.canBeFalsy = exports.isFunctionType = exports.isArrayType = exports.forTypeOrAnySupertype = exports.isNullableType = exports.isNumberType = exports.isStringType = exports.isNullishType = exports.typeCanSatisfy = exports.typeAlwaysSatisfies = exports.isTypeWithFlags = void 0;
const ts = require("typescript");

@@ -49,2 +49,6 @@ function isTypeWithFlags(context, type, flags) {

exports.typeCanSatisfy = typeCanSatisfy;
function isNullishType(context, type) {
return isTypeWithFlags(context, type, ts.TypeFlags.Undefined | ts.TypeFlags.Null | ts.TypeFlags.VoidLike);
}
exports.isNullishType = isNullishType;
function isStringType(context, type) {

@@ -58,2 +62,7 @@ return isTypeWithFlags(context, type, ts.TypeFlags.String | ts.TypeFlags.StringLike | ts.TypeFlags.StringLiteral);

exports.isNumberType = isNumberType;
function isNullableType(context, type, isType) {
return (typeCanSatisfy(context, type, t => isType(context, t)) &&
typeAlwaysSatisfies(context, type, t => isType(context, t) || isNullishType(context, t)));
}
exports.isNullableType = isNullableType;
function isExplicitArrayType(context, type) {

@@ -60,0 +69,0 @@ if (type.symbol) {

@@ -18,5 +18,4 @@ "use strict";

const method_1 = require("./members/method");
const new_1 = require("./new");
const utils_2 = require("./utils");
const setup_1 = require("./setup");
const utils_2 = require("./utils");
const transformClassDeclaration = (declaration, context) => {

@@ -65,5 +64,2 @@ // If declaration is a default export, transform to export variable assignment instead

superInfo.push({ className, extendedTypeNode });
if (extendedType) {
(0, new_1.checkForLuaLibType)(context, extendedType);
}
// Get all properties with value

@@ -70,0 +66,0 @@ const properties = classDeclaration.members.filter(ts.isPropertyDeclaration).filter(member => member.initializer);

import * as ts from "typescript";
import { FunctionVisitor, TransformationContext } from "../../context";
export declare function checkForLuaLibType(context: TransformationContext, type: ts.Type): void;
import { FunctionVisitor } from "../../context";
export declare const transformNewExpression: FunctionVisitor<ts.NewExpression>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformNewExpression = exports.checkForLuaLibType = void 0;
exports.transformNewExpression = void 0;
const ts = require("typescript");

@@ -11,40 +11,2 @@ const lua = require("../../../LuaAST");

const table_1 = require("../language-extensions/table");
const builtinErrorTypeNames = new Set([
"Error",
"ErrorConstructor",
"RangeError",
"RangeErrorConstructor",
"ReferenceError",
"ReferenceErrorConstructor",
"SyntaxError",
"SyntaxErrorConstructor",
"TypeError",
"TypeErrorConstructor",
"URIError",
"URIErrorConstructor",
]);
// TODO: Do it in identifier?
function checkForLuaLibType(context, type) {
if (!type.symbol)
return;
const name = context.checker.getFullyQualifiedName(type.symbol);
switch (name) {
case "Map":
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Map);
return;
case "Set":
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Set);
return;
case "WeakMap":
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.WeakMap);
return;
case "WeakSet":
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.WeakSet);
return;
}
if (builtinErrorTypeNames.has(name)) {
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Error);
}
}
exports.checkForLuaLibType = checkForLuaLibType;
const transformNewExpression = (node, context) => {

@@ -62,3 +24,2 @@ var _a, _b;

const [name, params] = (0, call_1.transformCallAndArguments)(context, node.expression, (_a = node.arguments) !== null && _a !== void 0 ? _a : [ts.factory.createTrue()], signature);
checkForLuaLibType(context, type);
const customConstructorAnnotation = annotations.get(annotations_1.AnnotationKind.CustomConstructor);

@@ -65,0 +26,0 @@ if (customConstructorAnnotation) {

@@ -10,12 +10,10 @@ "use strict";

const typescript_1 = require("../utils/typescript");
function transformProtectedConditionalExpression(context, expression) {
function transformProtectedConditionalExpression(context, expression, condition, whenTrue, whenFalse) {
const tempVar = context.createTempNameForNode(expression.condition);
const condition = context.transformExpression(expression.condition);
const [trueStatements, val1] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.whenTrue));
trueStatements.push(lua.createAssignmentStatement(lua.cloneIdentifier(tempVar), val1, expression.whenTrue));
const [falseStatements, val2] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.whenFalse));
falseStatements.push(lua.createAssignmentStatement(lua.cloneIdentifier(tempVar), val2, expression.whenFalse));
const trueStatements = whenTrue[0].concat(lua.createAssignmentStatement(lua.cloneIdentifier(tempVar), whenTrue[1], expression.whenTrue));
const falseStatements = whenFalse[0].concat(lua.createAssignmentStatement(lua.cloneIdentifier(tempVar), whenFalse[1], expression.whenFalse));
context.addPrecedingStatements([
lua.createVariableDeclarationStatement(tempVar, undefined, expression.condition),
lua.createIfStatement(condition, lua.createBlock(trueStatements, expression.whenTrue), lua.createBlock(falseStatements, expression.whenFalse), expression),
...condition[0],
lua.createIfStatement(condition[1], lua.createBlock(trueStatements, expression.whenTrue), lua.createBlock(falseStatements, expression.whenFalse), expression),
]);

@@ -25,11 +23,14 @@ return lua.cloneIdentifier(tempVar);

const transformConditionalExpression = (expression, context) => {
if ((0, typescript_1.canBeFalsy)(context, context.checker.getTypeAtLocation(expression.whenTrue))) {
return transformProtectedConditionalExpression(context, expression);
const condition = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.condition));
const whenTrue = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.whenTrue));
const whenFalse = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.whenFalse));
if (whenTrue[0].length > 0 ||
whenFalse[0].length > 0 ||
(0, typescript_1.canBeFalsy)(context, context.checker.getTypeAtLocation(expression.whenTrue))) {
return transformProtectedConditionalExpression(context, expression, condition, whenTrue, whenFalse);
}
const condition = context.transformExpression(expression.condition);
const val1 = context.transformExpression(expression.whenTrue);
const val2 = context.transformExpression(expression.whenFalse);
// condition and v1 or v2
const conditionAnd = lua.createBinaryExpression(condition, val1, lua.SyntaxKind.AndOperator);
return lua.createBinaryExpression(conditionAnd, val2, lua.SyntaxKind.OrOperator, expression);
context.addPrecedingStatements(condition[0]);
const conditionAnd = lua.createBinaryExpression(condition[1], whenTrue[1], lua.SyntaxKind.AndOperator);
return lua.createBinaryExpression(conditionAnd, whenFalse[1], lua.SyntaxKind.OrOperator, expression);
};

@@ -36,0 +37,0 @@ exports.transformConditionalExpression = transformConditionalExpression;

@@ -21,2 +21,3 @@ "use strict";

const optional_chaining_1 = require("./optional-chaining");
const typescript_1 = require("../utils/typescript");
function transformIdentifier(context, identifier) {

@@ -51,2 +52,6 @@ if ((0, optional_chaining_1.isOptionalContinuation)(identifier)) {

}
const type = context.checker.getTypeAtLocation(identifier);
if ((0, typescript_1.isStandardLibraryType)(context, type, undefined)) {
(0, builtins_1.checkForLuaLibType)(context, type);
}
const text = (0, safe_names_1.hasUnsafeIdentifierName)(context, identifier) ? (0, safe_names_1.createSafeName)(identifier.text) : identifier.text;

@@ -53,0 +58,0 @@ const symbolId = (0, symbols_1.getIdentifierSymbolId)(context, identifier);

@@ -177,2 +177,4 @@ "use strict";

const transformArrayLiteralExpression = (expression, context) => {
// Disallow using undefined/null in array literals
checkForUndefinedOrNullInArrayLiteral(expression, context);
const filteredElements = expression.elements.map(e => ts.isOmittedExpression(e) ? ts.factory.createIdentifier("undefined") : e);

@@ -182,2 +184,22 @@ const values = (0, expression_list_1.transformExpressionList)(context, filteredElements).map(e => lua.createTableFieldExpression(e));

};
function checkForUndefinedOrNullInArrayLiteral(array, context) {
// Look for last non-nil element in literal
let lastNonUndefinedIndex = array.elements.length - 1;
for (; lastNonUndefinedIndex >= 0; lastNonUndefinedIndex--) {
if (!isUndefinedOrNull(array.elements[lastNonUndefinedIndex])) {
break;
}
}
// Add diagnostics for non-trailing nil elements in array literal
for (let i = 0; i < array.elements.length; i++) {
if (i < lastNonUndefinedIndex && isUndefinedOrNull(array.elements[i])) {
context.diagnostics.push((0, diagnostics_1.undefinedInArrayLiteral)(array.elements[i]));
}
}
}
function isUndefinedOrNull(node) {
return (node.kind === ts.SyntaxKind.UndefinedKeyword ||
node.kind === ts.SyntaxKind.NullKeyword ||
(ts.isIdentifier(node) && node.text === "undefined"));
}
exports.literalVisitors = {

@@ -184,0 +206,0 @@ [ts.SyntaxKind.NullKeyword]: node => lua.createNilLiteral(node),

@@ -51,9 +51,4 @@ "use strict";

result.push(lua.createExpressionStatement(requireCall));
if (scope.importStatements) {
scope.importStatements.push(...result);
return undefined;
}
else {
return result;
}
scope.importStatements.push(...result);
return undefined;
}

@@ -104,9 +99,4 @@ const importPath = ts.isStringLiteral(statement.moduleSpecifier)

}
if (scope.importStatements) {
scope.importStatements.push(...result);
return undefined;
}
else {
return result;
}
scope.importStatements.push(...result);
return undefined;
};

@@ -113,0 +103,0 @@ exports.transformImportDeclaration = transformImportDeclaration;

@@ -88,3 +88,3 @@ "use strict";

// Generates SourceMapTraceback for the entire file
footers.push('require("lualib_bundle")\n');
footers.push('local __TS__SourceMapTraceBack = require("lualib_bundle").__TS__SourceMapTraceBack\n');
footers.push(`${exports.sourceMapTracebackBundlePlaceholder}\n`);

@@ -91,0 +91,0 @@ }

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

import * as ts from "typescript";
import { EmitHost } from "..";
import { CompilerOptions } from "../CompilerOptions";
import { Printer } from "../LuaPrinter";
import { Visitors } from "../transformation/context";
import { ProcessedFile } from "./utils";
export interface Plugin {

@@ -17,3 +20,11 @@ /**

printer?: Printer;
/**
* This function is called before transpilation of the TypeScript program starts.
*/
beforeTransform?: (program: ts.Program, options: CompilerOptions, emitHost: EmitHost) => ts.Diagnostic[] | void;
/**
* This function is called after TypeScriptToLua has translated the input program to Lua.
*/
afterPrint?: (program: ts.Program, options: CompilerOptions, emitHost: EmitHost, result: ProcessedFile[]) => ts.Diagnostic[] | void;
}
export declare function getPlugins(program: ts.Program, diagnostics: ts.Diagnostic[], customPlugins: Plugin[]): Plugin[];

@@ -13,2 +13,3 @@ "use strict";

function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceFiles: targetSourceFiles, customTransformers = {}, plugins: customPlugins = [] }) {
var _a, _b;
const options = program.getCompilerOptions();

@@ -47,2 +48,8 @@ if (options.tstlVerbose) {

}
for (const plugin of plugins) {
if (plugin.beforeTransform) {
const pluginDiagnostics = (_a = plugin.beforeTransform(program, options, emitHost)) !== null && _a !== void 0 ? _a : [];
diagnostics.push(...pluginDiagnostics);
}
}
const visitorMap = (0, transformation_1.createVisitorMap)(plugins.map(p => p.visitors).filter(utils_1.isNonNull));

@@ -100,2 +107,8 @@ const printer = (0, LuaPrinter_1.createPrinter)(plugins.map(p => p.printer).filter(utils_1.isNonNull));

}
for (const plugin of plugins) {
if (plugin.afterPrint) {
const pluginDiagnostics = (_b = plugin.afterPrint(program, options, emitHost, transpiledFiles)) !== null && _b !== void 0 ? _b : [];
diagnostics.push(...pluginDiagnostics);
}
}
return { diagnostics, transpiledFiles };

@@ -102,0 +115,0 @@ }

@@ -83,2 +83,3 @@ "use strict";

function getEmitPathRelativeToOutDir(fileName, program) {
var _a;
const sourceDir = getSourceDir(program);

@@ -93,4 +94,7 @@ // Default output path is relative path in source dir

}
// Make extension lua
emitPathSplits[emitPathSplits.length - 1] = (0, utils_1.trimExtension)(emitPathSplits[emitPathSplits.length - 1]) + ".lua";
// Set extension
const extension = ((_a = program.getCompilerOptions().extension) !== null && _a !== void 0 ? _a : "lua").trim();
const trimmedExtension = extension.startsWith(".") ? extension.substring(1) : extension;
emitPathSplits[emitPathSplits.length - 1] =
(0, utils_1.trimExtension)(emitPathSplits[emitPathSplits.length - 1]) + "." + trimmedExtension;
return path.join(...emitPathSplits);

@@ -97,0 +101,0 @@ }

{
"name": "typescript-to-lua",
"version": "1.3.4",
"version": "1.4.0",
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",

@@ -21,2 +21,3 @@ "repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",

"dist/**/*.ts",
"dist/lualib/*.json",
"language-extensions/**/*.ts"

@@ -28,3 +29,3 @@ ],

"build": "tsc && npm run build-lualib",
"build-lualib": "node build-lualib.js",
"build-lualib": "node dist/tstl.js -p src/lualib/tsconfig.json",
"pretest": "npm run lint && npm run check:language-extensions && npm run build-lualib",

@@ -47,3 +48,3 @@ "test": "jest",

"peerDependencies": {
"typescript": "~4.5.2"
"typescript": "~4.6.2"
},

@@ -58,10 +59,10 @@ "dependencies": {

"@types/glob": "^7.1.1",
"@types/jest": "^25.1.3",
"@types/jest": "^27.4.1",
"@types/node": "^13.7.7",
"@types/resolve": "1.14.0",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"eslint": "^7.32.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^24.4.0",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
"eslint": "^8.10.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^26.1.1",
"fs-extra": "^8.1.0",

@@ -74,6 +75,6 @@ "javascript-stringify": "^2.0.1",

"prettier": "^2.3.2",
"ts-jest": "^27.0.7",
"ts-jest": "^27.1.3",
"ts-node": "^10.3.0",
"typescript": "~4.5.2"
"typescript": "~4.6.2"
}
}

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 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc