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 0.39.3 to 0.39.4

3

dist/cli/diagnostics.js

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

}));
exports.watchErrorSummary = (errorCount) => ({
const watchErrorSummary = (errorCount) => ({
file: undefined,

@@ -22,2 +22,3 @@ start: undefined,

});
exports.watchErrorSummary = watchErrorSummary;
const createCommandLineError = (code, getMessage) => utils_1.createDiagnosticFactoryWithCode(code, (...args) => ({ messageText: getMessage(...args) }));

@@ -24,0 +25,0 @@ exports.unknownCompilerOption = createCommandLineError(5023, (name) => `Unknown compiler option '${name}'.`);

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

const ts = require("typescript");
exports.prepareDiagnosticForFormatting = (diagnostic) => diagnostic.source === "typescript-to-lua" ? { ...diagnostic, code: "TL" } : diagnostic;
const prepareDiagnosticForFormatting = (diagnostic) => diagnostic.source === "typescript-to-lua" ? { ...diagnostic, code: "TL" } : diagnostic;
exports.prepareDiagnosticForFormatting = prepareDiagnosticForFormatting;
function createDiagnosticReporter(pretty, system = ts.sys) {

@@ -8,0 +9,0 @@ const reporter = ts.createDiagnosticReporter(system, pretty);

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

}
const searchPath = utils_1.normalizeSlashes(ts.sys.getCurrentDirectory());
const searchPath = utils_1.normalizeSlashes(process.cwd());
return ts.findConfigFile(searchPath, ts.sys.fileExists);

@@ -23,3 +23,3 @@ }

// TODO: Unlike tsc, this resolves `.` to absolute path
const fileOrDirectory = utils_1.normalizeSlashes(path.resolve(ts.sys.getCurrentDirectory(), project));
const fileOrDirectory = utils_1.normalizeSlashes(path.resolve(process.cwd(), project));
if (ts.sys.directoryExists(fileOrDirectory)) {

@@ -26,0 +26,0 @@ const configFileName = path.posix.join(fileOrDirectory, "tsconfig.json");

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

})(LuaTarget = exports.LuaTarget || (exports.LuaTarget = {}));
exports.isBundleEnabled = (options) => options.luaBundle !== undefined && options.luaBundleEntry !== undefined;
const isBundleEnabled = (options) => options.luaBundle !== undefined && options.luaBundleEntry !== undefined;
exports.isBundleEnabled = isBundleEnabled;
function validateOptions(options) {

@@ -24,0 +25,0 @@ const diagnostics = [];

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.isInlineFunctionExpression = exports.isFunctionDefinition = exports.isAssignmentLeftHandSideExpression = exports.createTableIndexExpression = exports.isTableIndexExpression = exports.createAnonymousIdentifier = exports.cloneIdentifier = exports.createIdentifier = exports.isIdentifier = exports.createMethodCallExpression = exports.isMethodCallExpression = exports.createCallExpression = exports.isCallExpression = exports.createBinaryExpression = exports.isBinaryExpression = exports.createUnaryExpression = exports.isUnaryExpression = exports.createTableExpression = exports.isTableExpression = exports.createTableFieldExpression = exports.isTableFieldExpression = exports.createFunctionExpression = exports.isFunctionExpression = exports.FunctionExpressionFlags = exports.createStringLiteral = exports.isStringLiteral = exports.createNumericLiteral = exports.isNumericLiteral = exports.createDotsLiteral = exports.isDotsLiteral = exports.createBooleanLiteral = exports.isBooleanLiteral = exports.createNilLiteral = exports.isNilLiteral = exports.createExpressionStatement = exports.isExpressionStatement = exports.createBreakStatement = exports.isBreakStatement = exports.createReturnStatement = exports.isReturnStatement = exports.createLabelStatement = exports.isLabelStatement = exports.createGotoStatement = exports.isGotoStatement = exports.createForInStatement = exports.isForInStatement = exports.createForStatement = exports.isForStatement = exports.createRepeatStatement = exports.isRepeatStatement = exports.createWhileStatement = exports.isWhileStatement = exports.isIterationStatement = exports.createIfStatement = exports.isIfStatement = exports.createAssignmentStatement = exports.isAssignmentStatement = exports.createVariableDeclarationStatement = exports.isVariableDeclarationStatement = exports.createDoStatement = exports.isDoStatement = exports.createBlock = exports.isBlock = exports.createFile = exports.isFile = exports.getOriginalPos = exports.setNodeOriginal = exports.setNodePosition = exports.cloneNode = exports.createNode = exports.SyntaxKind = void 0;
exports.createFunctionExpression = exports.isFunctionExpression = exports.FunctionExpressionFlags = exports.createStringLiteral = exports.isStringLiteral = exports.createNumericLiteral = exports.isNumericLiteral = exports.createDotsLiteral = exports.isDotsLiteral = exports.createBooleanLiteral = exports.isBooleanLiteral = exports.createNilLiteral = exports.isNilLiteral = exports.createExpressionStatement = exports.isExpressionStatement = exports.createBreakStatement = exports.isBreakStatement = exports.createReturnStatement = exports.isReturnStatement = exports.createLabelStatement = exports.isLabelStatement = exports.createGotoStatement = exports.isGotoStatement = exports.createForInStatement = exports.isForInStatement = exports.createForStatement = exports.isForStatement = exports.createRepeatStatement = exports.isRepeatStatement = exports.createWhileStatement = exports.isWhileStatement = exports.isIterationStatement = exports.createIfStatement = exports.isIfStatement = exports.createAssignmentStatement = exports.isAssignmentStatement = exports.createVariableDeclarationStatement = exports.isVariableDeclarationStatement = exports.createDoStatement = exports.isDoStatement = exports.createBlock = exports.isBlock = exports.createFile = exports.isFile = exports.getOriginalPos = exports.setNodeOriginal = exports.setNodePosition = exports.cloneNode = exports.createNode = exports.SyntaxKind = void 0;
exports.isInlineFunctionExpression = exports.isFunctionDefinition = exports.isAssignmentLeftHandSideExpression = exports.createTableIndexExpression = exports.isTableIndexExpression = exports.createAnonymousIdentifier = exports.cloneIdentifier = exports.createIdentifier = exports.isIdentifier = exports.createMethodCallExpression = exports.isMethodCallExpression = exports.createCallExpression = exports.isCallExpression = exports.createBinaryExpression = exports.isBinaryExpression = exports.createUnaryExpression = exports.isUnaryExpression = exports.createTableExpression = exports.isTableExpression = exports.createTableFieldExpression = exports.isTableFieldExpression = void 0;
// We can elide a lot of nodes especially tokens and keywords

@@ -8,0 +9,0 @@ // because we don't create the AST from text

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

};
exports.escapeString = (value) => `"${value.replace(escapeStringRegExp, char => escapeStringMap[char])}"`;
const escapeString = (value) => `"${value.replace(escapeStringRegExp, char => escapeStringMap[char])}"`;
exports.escapeString = escapeString;
/**

@@ -103,3 +104,3 @@ * Checks that a name is valid for use in lua function declaration syntax:

? // According to spec, sourceRoot is simply prepended to the source name, so the slash should be included
this.options.sourceRoot.replace(/[\\/]+$/, "") + "/"
`${this.options.sourceRoot.replace(/[\\/]+$/, "")}/`
: "";

@@ -106,0 +107,0 @@ const rootSourceNode = this.printFile(file);

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

readonly isModule: boolean;
readonly isStrict: boolean;
readonly isStrict: any;
constructor(program: ts.Program, sourceFile: ts.SourceFile, visitorMap: VisitorMap);

@@ -34,0 +34,0 @@ private currentNodeVisitors;

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

export declare function isForRangeType(context: TransformationContext, node: ts.Node): boolean;
export declare function getTagArgsFromComment(tag: ts.JSDocTag): string[];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isForRangeType = exports.isVarargType = exports.isLuaIteratorType = exports.isInTupleReturnFunction = exports.isTupleReturnCall = exports.getSignatureAnnotations = exports.getFileAnnotations = exports.getNodeAnnotations = exports.getTypeAnnotations = exports.getSymbolAnnotations = exports.AnnotationKind = void 0;
exports.getTagArgsFromComment = exports.isForRangeType = exports.isVarargType = exports.isLuaIteratorType = exports.isInTupleReturnFunction = exports.isTupleReturnCall = exports.getSignatureAnnotations = exports.getFileAnnotations = exports.getNodeAnnotations = exports.getTypeAnnotations = exports.getSymbolAnnotations = exports.AnnotationKind = void 0;
const ts = require("typescript");

@@ -30,4 +30,5 @@ const typescript_1 = require("./typescript");

function collectAnnotations(source, annotationsMap) {
var _a, _b;
for (const tag of source.getJsDocTags()) {
const annotation = createAnnotation(tag.name, tag.text ? tag.text.split(" ") : []);
const annotation = createAnnotation(tag.name, (_b = (_a = tag.text) === null || _a === void 0 ? void 0 : _a.map(p => p.text)) !== null && _b !== void 0 ? _b : []);
if (annotation) {

@@ -57,3 +58,3 @@ annotationsMap.set(annotation.kind, annotation);

const tagName = tag.tagName.text;
const annotation = createAnnotation(tagName, tag.comment ? tag.comment.split(" ") : []);
const annotation = createAnnotation(tagName, getTagArgsFromComment(tag));
if (annotation) {

@@ -74,3 +75,3 @@ annotationsMap.set(annotation.kind, annotation);

const tagName = tag.tagName.text;
const annotation = createAnnotation(tagName, tag.comment ? tag.comment.split(" ") : []);
const annotation = createAnnotation(tagName, getTagArgsFromComment(tag));
if (annotation) {

@@ -164,2 +165,14 @@ annotationsMap.set(annotation.kind, annotation);

exports.isForRangeType = isForRangeType;
function getTagArgsFromComment(tag) {
if (tag.comment) {
if (typeof tag.comment === "string") {
return tag.comment.split(" ");
}
else {
return tag.comment.map(part => part.text);
}
}
return [];
}
exports.getTagArgsFromComment = getTagArgsFromComment;
//# sourceMappingURL=annotations.js.map

@@ -15,4 +15,6 @@ "use strict";

exports.hasDefaultExportModifier = hasDefaultExportModifier;
exports.createDefaultExportIdentifier = (original) => lua.createIdentifier("default", original);
exports.createDefaultExportStringLiteral = (original) => lua.createStringLiteral("default", original);
const createDefaultExportIdentifier = (original) => lua.createIdentifier("default", original);
exports.createDefaultExportIdentifier = createDefaultExportIdentifier;
const createDefaultExportStringLiteral = (original) => lua.createStringLiteral("default", original);
exports.createDefaultExportStringLiteral = createDefaultExportStringLiteral;
function getExportedSymbolDeclaration(symbol) {

@@ -74,6 +76,6 @@ const declarations = symbol.getDeclarations();

function getDependenciesOfSymbol(context, originalSymbol) {
return getExportedSymbolsFromScope(context, context.sourceFile).filter(exportSymbol => exportSymbol.declarations
.filter(ts.isExportSpecifier)
.map(context.checker.getExportSpecifierLocalTargetSymbol)
.includes(originalSymbol));
return getExportedSymbolsFromScope(context, context.sourceFile).filter(exportSymbol => {
var _a;
return (_a = exportSymbol.declarations) === null || _a === void 0 ? void 0 : _a.filter(ts.isExportSpecifier).map(context.checker.getExportSpecifierLocalTargetSymbol).includes(originalSymbol);
});
}

@@ -80,0 +82,0 @@ exports.getDependenciesOfSymbol = getDependenciesOfSymbol;

@@ -112,6 +112,7 @@ "use strict";

function isExtensionValue(context, symbol, extensionKind) {
var _a;
return (symbol.getName() === extensionKindToValueName[extensionKind] &&
symbol.declarations.some(d => isExtensionType(context.checker.getTypeAtLocation(d), extensionKind)));
((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(d => isExtensionType(context.checker.getTypeAtLocation(d), extensionKind))) === true);
}
exports.isExtensionValue = isExtensionValue;
//# sourceMappingURL=language-extensions.js.map

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

exports.createLocalOrExportedOrGlobalDeclaration = createLocalOrExportedOrGlobalDeclaration;
exports.createNaN = (tsOriginal) => lua.createBinaryExpression(lua.createNumericLiteral(0), lua.createNumericLiteral(0), lua.SyntaxKind.DivisionOperator, tsOriginal);
const createNaN = (tsOriginal) => lua.createBinaryExpression(lua.createNumericLiteral(0), lua.createNumericLiteral(0), lua.SyntaxKind.DivisionOperator, tsOriginal);
exports.createNaN = createNaN;
//# sourceMappingURL=lua-ast.js.map

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

const typescript_1 = require("./typescript");
exports.isValidLuaIdentifier = (name) => !exports.luaKeywords.has(name) && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name);
const isValidLuaIdentifier = (name) => !exports.luaKeywords.has(name) && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name);
exports.isValidLuaIdentifier = isValidLuaIdentifier;
exports.luaKeywords = new Set([

@@ -54,3 +55,4 @@ "and",

]);
exports.isUnsafeName = (name) => !exports.isValidLuaIdentifier(name) || luaBuiltins.has(name);
const isUnsafeName = (name) => !exports.isValidLuaIdentifier(name) || luaBuiltins.has(name);
exports.isUnsafeName = isUnsafeName;
function checkName(context, name, node) {

@@ -67,3 +69,4 @@ const isInvalid = !exports.isValidLuaIdentifier(name);

function hasUnsafeSymbolName(context, symbol, tsOriginal) {
const isAmbient = symbol.declarations && symbol.declarations.some(d => typescript_1.isAmbientNode(d));
var _a, _b;
const isAmbient = (_b = (_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(d => typescript_1.isAmbientNode(d))) !== null && _b !== void 0 ? _b : false;
// Catch ambient declarations of identifiers with bad names

@@ -88,3 +91,4 @@ if (isAmbient && checkName(context, symbol.name, tsOriginal)) {

const fixInvalidLuaIdentifier = (name) => name.replace(/[^a-zA-Z0-9_]/g, c => `_${c.charCodeAt(0).toString(16).toUpperCase()}`);
exports.createSafeName = (name) => "____" + fixInvalidLuaIdentifier(name);
const createSafeName = (name) => "____" + fixInvalidLuaIdentifier(name);
exports.createSafeName = createSafeName;
//# sourceMappingURL=safe-names.js.map

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

function isDeclaredInScope(symbol, scopeNode) {
return symbol === null || symbol === void 0 ? void 0 : symbol.declarations.some(d => typescript_1.findFirstNodeAbove(d, (n) => n === scopeNode));
var _a;
return (_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(d => typescript_1.findFirstNodeAbove(d, (n) => n === scopeNode));
}

@@ -75,0 +76,0 @@ // Checks for references to local functions which haven't been defined yet,

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

exports.transformElementAccessArgument = transformElementAccessArgument;
exports.transformElementAccessExpression = (node, context) => {
const transformElementAccessExpression = (node, context) => {
lua_table_1.validateLuaTableElementAccessExpression(context, node);

@@ -51,3 +51,4 @@ const constEnumValue = enum_1.tryGetConstEnumValue(context, node);

};
exports.transformPropertyAccessExpression = (expression, context) => {
exports.transformElementAccessExpression = transformElementAccessExpression;
const transformPropertyAccessExpression = (expression, context) => {
if (ts.isOptionalChain(expression)) {

@@ -87,3 +88,4 @@ context.diagnostics.push(diagnostics_1.optionalChainingNotSupported(expression));

};
exports.transformQualifiedName = (node, context) => {
exports.transformPropertyAccessExpression = transformPropertyAccessExpression;
const transformQualifiedName = (node, context) => {
const right = lua.createStringLiteral(node.right.text, node.right);

@@ -93,2 +95,3 @@ const left = context.transformExpression(node.left);

};
exports.transformQualifiedName = transformQualifiedName;
//# sourceMappingURL=access.js.map

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

const left = ts.isPropertyAccessExpression(node)
? (_a = lua_table_1.transformLuaTablePropertyAccessInAssignment(context, node)) !== null && _a !== void 0 ? _a : context.transformExpression(node) : context.transformExpression(node);
? (_a = lua_table_1.transformLuaTablePropertyAccessInAssignment(context, node)) !== null && _a !== void 0 ? _a : context.transformExpression(node)
: context.transformExpression(node);
return lua.isIdentifier(left) && symbol && export_1.isSymbolExported(context, symbol)

@@ -26,0 +27,0 @@ ? export_1.createExportedIdentifier(context, left)

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

const diagnostics_1 = require("../../utils/diagnostics");
exports.isBitOperator = (operator) => operator in bitOperatorToLibOperation;
const isBitOperator = (operator) => operator in bitOperatorToLibOperation;
exports.isBitOperator = isBitOperator;
const bitOperatorToLibOperation = {

@@ -12,0 +13,0 @@ [ts.SyntaxKind.AmpersandToken]: "band",

@@ -50,4 +50,6 @@ "use strict";

};
exports.isCompoundAssignmentToken = (token) => token in compoundToAssignmentTokens;
exports.unwrapCompoundAssignmentToken = (token) => compoundToAssignmentTokens[token];
const isCompoundAssignmentToken = (token) => token in compoundToAssignmentTokens;
exports.isCompoundAssignmentToken = isCompoundAssignmentToken;
const unwrapCompoundAssignmentToken = (token) => compoundToAssignmentTokens[token];
exports.unwrapCompoundAssignmentToken = unwrapCompoundAssignmentToken;
function transformCompoundAssignment(context, expression, lhs, rhs, operator, isPostfix) {

@@ -54,0 +56,0 @@ const left = utils_1.cast(context.transformExpression(lhs), lua.isAssignmentLeftHandSideExpression);

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

exports.transformBinaryOperation = transformBinaryOperation;
exports.transformBinaryExpression = (node, context) => {
const transformBinaryExpression = (node, context) => {
const operator = node.operatorToken.kind;

@@ -100,2 +100,3 @@ const typeOfResult = typeof_1.transformTypeOfBinaryExpression(context, node);

};
exports.transformBinaryExpression = transformBinaryExpression;
function transformBinaryExpressionStatement(context, node) {

@@ -102,0 +103,0 @@ const expression = node.expression;

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

exports.transformScopeBlock = transformScopeBlock;
exports.transformBlock = (node, context) => {
const transformBlock = (node, context) => {
scope_1.pushScope(context, scope_1.ScopeType.Block);

@@ -25,2 +25,3 @@ const statements = scope_1.performHoisting(context, context.transformStatements(node.statements));

};
exports.transformBlock = transformBlock;
//# sourceMappingURL=block.js.map

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

const scope_1 = require("../utils/scope");
exports.transformBreakStatement = (breakStatement, context) => {
const transformBreakStatement = (breakStatement, context) => {
const breakableScope = scope_1.findScope(context, scope_1.ScopeType.Loop | scope_1.ScopeType.Switch);

@@ -18,3 +18,4 @@ if ((breakableScope === null || breakableScope === void 0 ? void 0 : breakableScope.type) === scope_1.ScopeType.Switch) {

};
exports.transformContinueStatement = (statement, context) => {
exports.transformBreakStatement = transformBreakStatement;
const transformContinueStatement = (statement, context) => {
var _a;

@@ -30,2 +31,3 @@ if (context.luaTarget === CompilerOptions_1.LuaTarget.Universal || context.luaTarget === CompilerOptions_1.LuaTarget.Lua51) {

};
exports.transformContinueStatement = transformContinueStatement;
//# sourceMappingURL=break-continue.js.map

@@ -79,4 +79,6 @@ "use strict";

const paramType = context.checker.getTypeAtLocation(param);
const signatureType = context.checker.getTypeAtLocation(signatureParameter.valueDeclaration);
assignment_validation_1.validateAssignment(context, param, paramType, signatureType, signatureParameter.name);
if (signatureParameter.valueDeclaration !== undefined) {
const signatureType = context.checker.getTypeAtLocation(signatureParameter.valueDeclaration);
assignment_validation_1.validateAssignment(context, param, paramType, signatureType, signatureParameter.name);
}
}

@@ -165,3 +167,3 @@ }

}
exports.transformCallExpression = (node, context) => {
const transformCallExpression = (node, context) => {
const luaTableResult = lua_table_1.transformLuaTableCallExpression(context, node);

@@ -218,2 +220,3 @@ if (luaTableResult) {

};
exports.transformCallExpression = transformCallExpression;
//# sourceMappingURL=call.js.map

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

const utils_2 = require("./utils");
exports.transformClassDeclaration = (declaration, context) => {
const transformClassDeclaration = (declaration, context) => {
// If declaration is a default export, transform to export variable assignment instead

@@ -34,3 +34,5 @@ if (export_1.hasDefaultExportModifier(declaration)) {

};
exports.transformThisExpression = node => lua_ast_1.createSelfIdentifier(node);
exports.transformClassDeclaration = transformClassDeclaration;
const transformThisExpression = node => lua_ast_1.createSelfIdentifier(node);
exports.transformThisExpression = transformThisExpression;
function transformClassAsExpression(expression, context) {

@@ -170,3 +172,3 @@ return transform_1.transformToImmediatelyInvokedFunctionExpression(context, () => {

}
exports.transformSuperExpression = (expression, context) => {
const transformSuperExpression = (expression, context) => {
const superInfos = utils_1.getOrUpdate(classSuperInfos, context, () => []);

@@ -193,2 +195,3 @@ const superInfo = superInfos[superInfos.length - 1];

};
exports.transformSuperExpression = transformSuperExpression;
//# sourceMappingURL=index.js.map

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

const parameterDecorators = node.parameters
.flatMap((parameter, index) => { var _a; return (_a = parameter.decorators) === null || _a === void 0 ? void 0 : _a.map(decorator => lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.DecorateParam, node, lua.createNumericLiteral(index), decorators_1.transformDecoratorExpression(context, decorator))); })
.flatMap((parameter, index) => {
var _a;
return (_a = parameter.decorators) === null || _a === void 0 ? void 0 : _a.map(decorator => lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.DecorateParam, node, lua.createNumericLiteral(index), decorators_1.transformDecoratorExpression(context, decorator)));
})
.filter(utils_2.isNonNull);

@@ -42,0 +45,0 @@ const methodDecorators = (_b = (_a = node.decorators) === null || _a === void 0 ? void 0 : _a.map(d => decorators_1.transformDecoratorExpression(context, d))) !== null && _b !== void 0 ? _b : [];

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

exports.checkForLuaLibType = checkForLuaLibType;
exports.transformNewExpression = (node, context) => {
const transformNewExpression = (node, context) => {
var _a;

@@ -78,2 +78,3 @@ const luaTableResult = lua_table_1.transformLuaTableNewExpression(context, node);

};
exports.transformNewExpression = transformNewExpression;
//# sourceMappingURL=new.js.map

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

}
exports.transformConditionalExpression = (expression, context) => {
const transformConditionalExpression = (expression, context) => {
if (canBeFalsy(context, context.checker.getTypeAtLocation(expression.whenTrue))) {

@@ -57,2 +57,3 @@ return transformProtectedConditionalExpression(context, expression);

};
exports.transformConditionalExpression = transformConditionalExpression;
function transformIfStatement(statement, context) {

@@ -59,0 +60,0 @@ scope_1.pushScope(context, scope_1.ScopeType.Conditional);

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

const lua_ast_1 = require("../utils/lua-ast");
exports.transformDeleteExpression = (node, context) => {
const transformDeleteExpression = (node, context) => {
let ownerExpression;

@@ -35,2 +35,3 @@ let propertyExpression;

};
exports.transformDeleteExpression = transformDeleteExpression;
//# sourceMappingURL=delete.js.map

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

exports.tryGetConstEnumValue = tryGetConstEnumValue;
exports.transformEnumDeclaration = (node, context) => {
const transformEnumDeclaration = (node, context) => {
if (ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Const && !context.options.preserveConstEnums) {

@@ -78,2 +78,3 @@ return undefined;

};
exports.transformEnumDeclaration = transformEnumDeclaration;
//# sourceMappingURL=enum.js.map

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

const multi_1 = require("./language-extensions/multi");
exports.transformTryStatement = (statement, context) => {
const transformTryStatement = (statement, context) => {
const [tryBlock, tryScope] = block_1.transformScopeBlock(context, statement.tryBlock, scope_1.ScopeType.Try);

@@ -87,3 +87,4 @@ const tryResultIdentifier = lua.createIdentifier("____try");

};
exports.transformThrowStatement = (statement, context) => {
exports.transformTryStatement = transformTryStatement;
const transformThrowStatement = (statement, context) => {
const parameters = [];

@@ -96,2 +97,3 @@ if (statement.expression) {

};
exports.transformThrowStatement = transformThrowStatement;
//# sourceMappingURL=errors.js.map

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

const unary_expression_1 = require("./unary-expression");
exports.transformExpressionStatement = (node, context) => {
const transformExpressionStatement = (node, context) => {
const luaTableResult = lua_table_1.transformLuaTableExpressionStatement(context, node);

@@ -34,2 +34,3 @@ if (luaTableResult) {

};
exports.transformExpressionStatement = transformExpressionStatement;
//# sourceMappingURL=expression-statement.js.map

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

exports.transformFunctionLikeDeclaration = transformFunctionLikeDeclaration;
exports.transformFunctionDeclaration = (node, context) => {
const transformFunctionDeclaration = (node, context) => {
var _a;

@@ -195,3 +195,4 @@ // Don't transform functions without body (overload declarations)

};
exports.transformYieldExpression = (expression, context) => {
exports.transformFunctionDeclaration = transformFunctionDeclaration;
const transformYieldExpression = (expression, context) => {
const parameters = expression.expression ? [context.transformExpression(expression.expression)] : [];

@@ -202,2 +203,3 @@ return expression.asteriskToken

};
exports.transformYieldExpression = transformYieldExpression;
//# sourceMappingURL=function.js.map

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

exports.transformIdentifier = transformIdentifier;
exports.transformIdentifierExpression = (node, context) => {
const transformIdentifierExpression = (node, context) => {
const symbol = context.checker.getSymbolAtLocation(node);

@@ -70,2 +70,3 @@ if (symbol) {

};
exports.transformIdentifierExpression = transformIdentifierExpression;
//# sourceMappingURL=identifier.js.map

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

const utils_1 = require("./utils");
exports.transformWhileStatement = (statement, context) => lua.createWhileStatement(lua.createBlock(utils_1.transformLoopBody(context, statement)), context.transformExpression(statement.expression), statement);
exports.transformDoStatement = (statement, context) => {
const transformWhileStatement = (statement, context) => lua.createWhileStatement(lua.createBlock(utils_1.transformLoopBody(context, statement)), context.transformExpression(statement.expression), statement);
exports.transformWhileStatement = transformWhileStatement;
const transformDoStatement = (statement, context) => {
const body = lua.createDoStatement(utils_1.transformLoopBody(context, statement));

@@ -19,2 +20,3 @@ let condition = context.transformExpression(statement.expression);

};
exports.transformDoStatement = transformDoStatement;
//# sourceMappingURL=do-while.js.map

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

const utils_1 = require("./utils");
exports.transformForInStatement = (statement, context) => {
const transformForInStatement = (statement, context) => {
if (typescript_1.isArrayType(context, context.checker.getTypeAtLocation(statement.expression))) {

@@ -21,2 +21,3 @@ context.diagnostics.push(diagnostics_1.forbiddenForIn(statement));

};
exports.transformForInStatement = transformForInStatement;
//# sourceMappingURL=for-in.js.map

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

}
exports.transformForOfStatement = (node, context) => {
const transformForOfStatement = (node, context) => {
const body = lua.createBlock(utils_2.transformLoopBody(context, node));

@@ -121,2 +121,3 @@ if (ts.isCallExpression(node.expression) && range_1.isRangeFunction(context, node.expression)) {

};
exports.transformForOfStatement = transformForOfStatement;
//# sourceMappingURL=for-of.js.map

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

const utils_1 = require("./utils");
exports.transformForStatement = (statement, context) => {
const transformForStatement = (statement, context) => {
const result = [];

@@ -33,2 +33,3 @@ if (statement.initializer) {

};
exports.transformForStatement = transformForStatement;
//# sourceMappingURL=for.js.map

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

const import_1 = require("./import");
exports.transformExportAssignment = (node, context) => {
const transformExportAssignment = (node, context) => {
if (!context.resolver.isValueAliasDeclaration(node)) {

@@ -31,2 +31,3 @@ return undefined;

};
exports.transformExportAssignment = transformExportAssignment;
function transformExportAll(context, node) {

@@ -96,4 +97,5 @@ utils_1.assert(node.moduleSpecifier);

}
exports.getExported = (context, exportSpecifiers) => exportSpecifiers.elements.filter(exportSpecifier => context.resolver.isValueAliasDeclaration(exportSpecifier));
exports.transformExportDeclaration = (node, context) => {
const getExported = (context, exportSpecifiers) => exportSpecifiers.elements.filter(exportSpecifier => context.resolver.isValueAliasDeclaration(exportSpecifier));
exports.getExported = getExported;
const transformExportDeclaration = (node, context) => {
if (!node.exportClause) {

@@ -118,2 +120,3 @@ // export * from "...";

};
exports.transformExportDeclaration = transformExportDeclaration;
//# sourceMappingURL=export.js.map

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

}
exports.transformImportDeclaration = (statement, context) => {
const transformImportDeclaration = (statement, context) => {
const scope = scope_1.peekScope(context);

@@ -131,4 +131,6 @@ if (!scope.importStatements) {

};
exports.transformExternalModuleReference = (node, context) => createModuleRequire(context, node.expression, node);
exports.transformImportEqualsDeclaration = (node, context) => {
exports.transformImportDeclaration = transformImportDeclaration;
const transformExternalModuleReference = (node, context) => createModuleRequire(context, node.expression, node);
exports.transformExternalModuleReference = transformExternalModuleReference;
const transformImportEqualsDeclaration = (node, context) => {
if (!context.resolver.isReferencedAliasDeclaration(node) &&

@@ -144,2 +146,3 @@ (ts.isExternalModuleReference(node.moduleReference) ||

};
exports.transformImportEqualsDeclaration = transformImportEqualsDeclaration;
//# sourceMappingURL=import.js.map

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

const currentNamespaces = new WeakMap();
exports.transformModuleDeclaration = (node, context) => {
const transformModuleDeclaration = (node, context) => {
var _a, _b;
const annotations = annotations_1.getTypeAnnotations(context.checker.getTypeAtLocation(node));

@@ -59,4 +60,4 @@ // If phantom namespace elide the declaration and return the body

const isFirstDeclaration = symbol === undefined ||
(!symbol.declarations.some(d => ts.isClassLike(d) || ts.isFunctionDeclaration(d)) &&
ts.getOriginalNode(node) === symbol.declarations.find(ts.isModuleDeclaration));
(!((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(d => ts.isClassLike(d) || ts.isFunctionDeclaration(d))) &&
ts.getOriginalNode(node) === ((_b = symbol.declarations) === null || _b === void 0 ? void 0 : _b.find(ts.isModuleDeclaration)));
if (isNonModuleMergeable) {

@@ -90,2 +91,3 @@ // 'local NS = NS or {}' or 'exportTable.NS = exportTable.NS or {}'

};
exports.transformModuleDeclaration = transformModuleDeclaration;
//# sourceMappingURL=namespace.js.map

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

exports.transformExpressionBodyToReturnStatement = transformExpressionBodyToReturnStatement;
exports.transformReturnStatement = (statement, context) => {
const transformReturnStatement = (statement, context) => {
// Bubble up explicit return flag and check if we're inside a try/catch block

@@ -95,2 +95,3 @@ let insideTryCatch = false;

};
exports.transformReturnStatement = transformReturnStatement;
//# sourceMappingURL=return.js.map

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

const typescript_1 = require("../utils/typescript");
exports.transformSourceFileNode = (node, context) => {
const transformSourceFileNode = (node, context) => {
var _a, _b;

@@ -45,2 +45,3 @@ let statements = [];

};
exports.transformSourceFileNode = transformSourceFileNode;
//# sourceMappingURL=sourceFile.js.map

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

// TODO: Currently it's also used as an array member
exports.transformSpreadElement = (node, context) => {
const transformSpreadElement = (node, context) => {
if (ts.isIdentifier(node.expression)) {

@@ -71,2 +71,3 @@ if (annotations_1.isVarargType(context, node.expression)) {

};
exports.transformSpreadElement = transformSpreadElement;
//# sourceMappingURL=spread.js.map

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

const scope_1 = require("../utils/scope");
exports.transformSwitchStatement = (statement, context) => {
const transformSwitchStatement = (statement, context) => {
if (context.luaTarget === CompilerOptions_1.LuaTarget.Universal || context.luaTarget === CompilerOptions_1.LuaTarget.Lua51) {

@@ -47,2 +47,3 @@ context.diagnostics.push(diagnostics_1.unsupportedForTarget(statement, "Switch statements", CompilerOptions_1.LuaTarget.Lua51));

};
exports.transformSwitchStatement = transformSwitchStatement;
//# sourceMappingURL=switch.js.map

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

}
exports.transformTemplateExpression = (node, context) => {
const transformTemplateExpression = (node, context) => {
const parts = [];

@@ -41,3 +41,4 @@ const head = node.head.text;

};
exports.transformTaggedTemplateExpression = (expression, context) => {
exports.transformTemplateExpression = transformTemplateExpression;
const transformTaggedTemplateExpression = (expression, context) => {
const strings = [];

@@ -78,2 +79,3 @@ const rawStrings = [];

};
exports.transformTaggedTemplateExpression = transformTaggedTemplateExpression;
//# sourceMappingURL=template.js.map

@@ -9,6 +9,7 @@ "use strict";

const binary_expression_1 = require("./binary-expression");
exports.transformTypeOfExpression = (node, context) => {
const transformTypeOfExpression = (node, context) => {
const innerExpression = context.transformExpression(node.expression);
return lualib_1.transformLuaLibFunction(context, LuaLib_1.LuaLibFeature.TypeOf, node, innerExpression);
};
exports.transformTypeOfExpression = transformTypeOfExpression;
function transformTypeOfBinaryExpression(context, node) {

@@ -15,0 +16,0 @@ const operator = node.operatorToken.kind;

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

exports.transformUnaryExpressionStatement = transformUnaryExpressionStatement;
exports.transformPostfixUnaryExpression = (expression, context) => {
const transformPostfixUnaryExpression = (expression, context) => {
switch (expression.operator) {

@@ -35,3 +35,4 @@ case ts.SyntaxKind.PlusPlusToken:

};
exports.transformPrefixUnaryExpression = (expression, context) => {
exports.transformPostfixUnaryExpression = transformPostfixUnaryExpression;
const transformPrefixUnaryExpression = (expression, context) => {
switch (expression.operator) {

@@ -55,2 +56,3 @@ case ts.SyntaxKind.PlusPlusToken:

};
exports.transformPrefixUnaryExpression = transformPrefixUnaryExpression;
//# sourceMappingURL=unary-expression.js.map

@@ -191,6 +191,7 @@ "use strict";

exports.checkVariableDeclarationList = checkVariableDeclarationList;
exports.transformVariableStatement = (node, context) => {
const transformVariableStatement = (node, context) => {
checkVariableDeclarationList(context, node.declarationList);
return node.declarationList.declarations.flatMap(declaration => transformVariableDeclaration(context, declaration));
};
exports.transformVariableStatement = transformVariableStatement;
//# sourceMappingURL=variable-declaration.js.map

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

exports.getTransformers = getTransformers;
exports.noImplicitSelfTransformer = () => node => {
const noImplicitSelfTransformer = () => node => {
const transformSourceFile = node => {

@@ -47,2 +47,3 @@ const empty = ts.factory.createNotEmittedStatement(undefined);

};
exports.noImplicitSelfTransformer = noImplicitSelfTransformer;
function loadTransformersFromOptions(program, diagnostics) {

@@ -49,0 +50,0 @@ const customTransformers = {

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

const diagnosticFactories = require("./diagnostics");
exports.getConfigDirectory = (options) => options.configFilePath ? path.dirname(options.configFilePath) : process.cwd();
const getConfigDirectory = (options) => options.configFilePath ? path.dirname(options.configFilePath) : process.cwd();
exports.getConfigDirectory = getConfigDirectory;
function resolvePlugin(kind, optionName, basedir, query, importName = "default") {

@@ -12,0 +13,0 @@ if (typeof query !== "string") {

@@ -11,6 +11,9 @@ "use strict";

exports.castArray = castArray;
exports.intersperse = (values, separator) => values.flatMap((value, index) => (index === 0 ? [value] : [separator, value]));
exports.union = (...values) => [...new Set(...values)];
exports.intersection = (first, ...rest) => exports.union(first).filter(x => rest.every(r => r.includes(x)));
exports.createDiagnosticFactoryWithCode = (code, create) => Object.assign((...args) => ({
const intersperse = (values, separator) => values.flatMap((value, index) => (index === 0 ? [value] : [separator, value]));
exports.intersperse = intersperse;
const union = (...values) => [...new Set(...values)];
exports.union = union;
const intersection = (first, ...rest) => exports.union(first).filter(x => rest.every(r => r.includes(x)));
exports.intersection = intersection;
const createDiagnosticFactoryWithCode = (code, create) => Object.assign((...args) => ({
file: undefined,

@@ -24,6 +27,10 @@ start: undefined,

}), { code });
exports.createDiagnosticFactoryWithCode = createDiagnosticFactoryWithCode;
let serialDiagnosticCodeCounter = 100000;
exports.createSerialDiagnosticFactory = (create) => exports.createDiagnosticFactoryWithCode(serialDiagnosticCodeCounter++, create);
exports.normalizeSlashes = (filePath) => filePath.replace(/\\/g, "/");
exports.trimExtension = (filePath) => filePath.slice(0, -path.extname(filePath).length);
const createSerialDiagnosticFactory = (create) => exports.createDiagnosticFactoryWithCode(serialDiagnosticCodeCounter++, create);
exports.createSerialDiagnosticFactory = createSerialDiagnosticFactory;
const normalizeSlashes = (filePath) => filePath.replace(/\\/g, "/");
exports.normalizeSlashes = normalizeSlashes;
const trimExtension = (filePath) => filePath.slice(0, -path.extname(filePath).length);
exports.trimExtension = trimExtension;
function formatPathToLuaPath(filePath) {

@@ -38,3 +45,5 @@ filePath = filePath.replace(/\.json$/, "");

exports.formatPathToLuaPath = formatPathToLuaPath;
function getOrUpdate(map, key, getDefaultValue) {
function getOrUpdate(
// eslint-disable-next-line @typescript-eslint/ban-types
map, key, getDefaultValue) {
if (!map.has(key)) {

@@ -41,0 +50,0 @@ map.set(key, getDefaultValue());

@@ -0,1 +1,5 @@

type AnyTable = Record<any, any>;
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/consistent-type-definitions
type AnyNotNil = {};
/**

@@ -448,3 +452,6 @@ * Indicates a type is a language extension provided by TypescriptToLua.

*/
declare type LuaTableGet<TTable extends object, TKey extends {}, TValue> = ((table: TTable, key: TKey) => TValue) &
declare type LuaTableGet<TTable extends AnyTable, TKey extends AnyNotNil, TValue> = ((
table: TTable,
key: TKey
) => TValue) &
LuaExtension<"__luaTableGetBrand">;

@@ -459,3 +466,3 @@

*/
declare type LuaTableGetMethod<TKey extends {}, TValue> = ((key: TKey) => TValue) &
declare type LuaTableGetMethod<TKey extends AnyNotNil, TValue> = ((key: TKey) => TValue) &
LuaExtension<"__luaTableGetMethodBrand">;

@@ -471,3 +478,3 @@

*/
declare type LuaTableSet<TTable extends object, TKey extends {}, TValue> = ((
declare type LuaTableSet<TTable extends AnyTable, TKey extends AnyNotNil, TValue> = ((
table: TTable,

@@ -486,3 +493,3 @@ key: TKey,

*/
declare type LuaTableSetMethod<TKey extends {}, TValue> = ((key: TKey, value: TValue) => void) &
declare type LuaTableSetMethod<TKey extends AnyNonNil, TValue> = ((key: TKey, value: TValue) => void) &
LuaExtension<"__luaTableSetMethodBrand">;

@@ -497,3 +504,3 @@

*/
declare interface LuaTable<TKey extends {} = {}, TValue = any> {
declare interface LuaTable<TKey extends AnyTable = AnyNotNil, TValue = any> {
length: LuaLengthMethod<number>;

@@ -511,3 +518,6 @@ get: LuaTableGetMethod<TKey, TValue>;

*/
declare type LuaTableConstructor = (new <TKey extends {} = {}, TValue = any>() => LuaTable<TKey, TValue>) &
declare type LuaTableConstructor = (new <TKey extends AnyNotNil = AnyNotNil, TValue = any>() => LuaTable<
TKey,
TValue
>) &
LuaExtension<"__luaTableNewBrand">;

@@ -514,0 +524,0 @@

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

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

"source-map": "^0.7.3",
"typescript": ">=4.0.2"
"typescript": "~4.3.2"
},

@@ -55,5 +55,5 @@ "devDependencies": {

"@types/resolve": "1.14.0",
"@typescript-eslint/eslint-plugin": "^2.31.0",
"@typescript-eslint/parser": "^4.1.0",
"eslint": "^6.8.0",
"@typescript-eslint/eslint-plugin": "^4.26.1",
"@typescript-eslint/parser": "^4.26.1",
"eslint": "^7.28.0",
"eslint-plugin-import": "^2.20.1",

@@ -60,0 +60,0 @@ "eslint-plugin-jest": "^23.8.2",

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