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.21.0 to 1.22.0

dist/lualib/5.0/NumberIsInteger.lua

1

dist/LuaLib.d.ts

@@ -63,2 +63,3 @@ import { EmitHost } from "./transpilation";

NumberIsFinite = "NumberIsFinite",
NumberIsInteger = "NumberIsInteger",
NumberIsNaN = "NumberIsNaN",

@@ -65,0 +66,0 @@ NumberParseInt = "ParseInt",

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

LuaLibFeature["NumberIsFinite"] = "NumberIsFinite";
LuaLibFeature["NumberIsInteger"] = "NumberIsInteger";
LuaLibFeature["NumberIsNaN"] = "NumberIsNaN";

@@ -70,0 +71,0 @@ LuaLibFeature["NumberParseInt"] = "ParseInt";

@@ -384,2 +384,10 @@ {

},
"NumberIsInteger": {
"exports": [
"__TS__NumberIsInteger"
],
"dependencies": [
"NumberIsFinite"
]
},
"NumberIsNaN": {

@@ -386,0 +394,0 @@ "exports": [

@@ -390,2 +390,10 @@ {

},
"NumberIsInteger": {
"exports": [
"__TS__NumberIsInteger"
],
"dependencies": [
"NumberIsFinite"
]
},
"NumberIsNaN": {

@@ -392,0 +400,0 @@ "exports": [

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

switch (methodName) {
case "isInteger":
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberIsInteger, node, ...parameters);
case "isNaN":

@@ -79,0 +81,0 @@ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberIsNaN, node, ...parameters);

2

dist/transformation/utils/function-context.d.ts

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

}
export declare function getDeclarationContextType(context: TransformationContext, signatureDeclaration: ts.SignatureDeclaration): ContextType;
export declare function getCallContextType(context: TransformationContext, callExpression: ts.CallLikeExpression): ContextType;
export declare function getFunctionContextType(context: TransformationContext, type: ts.Type): ContextType;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFunctionContextType = exports.getDeclarationContextType = exports.ContextType = void 0;
exports.getFunctionContextType = exports.getCallContextType = exports.ContextType = void 0;
const ts = require("typescript");

@@ -35,4 +35,29 @@ const annotations_1 = require("./annotations");

}
const callContextTypes = new WeakMap();
function getCallContextType(context, callExpression) {
const known = callContextTypes.get(callExpression);
if (known !== undefined)
return known;
const signature = context.checker.getResolvedSignature(callExpression);
const signatureDeclaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
let contextType = ContextType.None;
if (signatureDeclaration) {
contextType = computeDeclarationContextType(context, signatureDeclaration);
}
else {
// No signature declaration could be resolved, so instead try to see if the declaration is in a
// noSelfInFile file
const declarations = findRootDeclarations(context, callExpression);
contextType = declarations.some(d => (0, annotations_1.getFileAnnotations)(d.getSourceFile()).has(annotations_1.AnnotationKind.NoSelfInFile))
? ContextType.Void
: context.options.noImplicitSelf
? ContextType.Void
: ContextType.NonVoid;
}
callContextTypes.set(callExpression, contextType);
return contextType;
}
exports.getCallContextType = getCallContextType;
const signatureDeclarationContextTypes = new WeakMap();
function getDeclarationContextType(context, signatureDeclaration) {
function getSignatureContextType(context, signatureDeclaration) {
const known = signatureDeclarationContextTypes.get(signatureDeclaration);

@@ -45,3 +70,25 @@ if (known !== undefined)

}
exports.getDeclarationContextType = getDeclarationContextType;
function findRootDeclarations(context, callExpression) {
var _a, _b;
const calledExpression = ts.isTaggedTemplateExpression(callExpression)
? callExpression.tag
: ts.isJsxSelfClosingElement(callExpression)
? callExpression.tagName
: ts.isJsxOpeningElement(callExpression)
? callExpression.tagName
: callExpression.expression;
const calledSymbol = context.checker.getSymbolAtLocation(calledExpression);
if (calledSymbol === undefined)
return [];
return ((_b = (_a = calledSymbol.getDeclarations()) === null || _a === void 0 ? void 0 : _a.flatMap(d => {
var _a;
if (ts.isImportSpecifier(d)) {
const aliasSymbol = context.checker.getAliasedSymbol(calledSymbol);
return (_a = aliasSymbol.getDeclarations()) !== null && _a !== void 0 ? _a : [];
}
else {
return [d];
}
})) !== null && _b !== void 0 ? _b : []);
}
function computeDeclarationContextType(context, signatureDeclaration) {

@@ -145,4 +192,4 @@ const thisParameter = getExplicitThisParameter(signatureDeclaration);

}
return reduceContextTypes(signatures.flatMap(s => getSignatureDeclarations(context, s)).map(s => getDeclarationContextType(context, s)));
return reduceContextTypes(signatures.flatMap(s => getSignatureDeclarations(context, s)).map(s => getSignatureContextType(context, s)));
}
//# sourceMappingURL=function-context.js.map

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

export declare function transformCallAndArguments(context: TransformationContext, callExpression: ts.Expression, params: readonly ts.Expression[], signature?: ts.Signature, callContext?: ts.Expression): [lua.Expression, lua.Expression[]];
export declare function transformContextualCallExpression(context: TransformationContext, node: ts.CallExpression | ts.TaggedTemplateExpression, args: ts.Expression[] | ts.NodeArray<ts.Expression>, signature?: ts.Signature): lua.Expression;
export declare function transformContextualCallExpression(context: TransformationContext, node: ts.CallExpression | ts.TaggedTemplateExpression, args: ts.Expression[] | ts.NodeArray<ts.Expression>): lua.Expression;
export declare const transformCallExpression: FunctionVisitor<ts.CallExpression>;
export declare function getCalledExpression(node: ts.CallExpression): ts.Expression;

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

}
function transformContextualCallExpression(context, node, args, signature) {
function transformContextualCallExpression(context, node, args) {
if (ts.isOptionalChain(node)) {

@@ -87,3 +87,3 @@ return (0, optional_chaining_1.transformOptionalChain)(context, node);

const left = ts.isCallExpression(node) ? getCalledExpression(node) : node.tag;
let { precedingStatements: argPrecedingStatements, result: transformedArguments } = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => transformArguments(context, args, signature));
let { precedingStatements: argPrecedingStatements, result: transformedArguments } = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => transformArguments(context, args));
if (ts.isPropertyAccessExpression(left) &&

@@ -131,6 +131,5 @@ ts.isIdentifier(left.name) &&

}
const signatureDeclaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
if (!signatureDeclaration || (0, function_context_1.getDeclarationContextType)(context, signatureDeclaration) !== function_context_1.ContextType.Void) {
if ((0, function_context_1.getCallContextType)(context, node) !== function_context_1.ContextType.Void) {
// table:name()
return transformContextualCallExpression(context, node, node.arguments, signature);
return transformContextualCallExpression(context, node, node.arguments);
}

@@ -144,11 +143,9 @@ else {

function transformElementCall(context, node) {
const signature = context.checker.getResolvedSignature(node);
const signatureDeclaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
if (!signatureDeclaration || (0, function_context_1.getDeclarationContextType)(context, signatureDeclaration) !== function_context_1.ContextType.Void) {
if ((0, function_context_1.getCallContextType)(context, node) !== function_context_1.ContextType.Void) {
// A contextual parameter must be given to this call expression
return transformContextualCallExpression(context, node, node.arguments, signature);
return transformContextualCallExpression(context, node, node.arguments);
}
else {
// No context
const [expression, parameters] = transformCallAndArguments(context, node.expression, node.arguments, signature);
const [expression, parameters] = transformCallAndArguments(context, node.expression, node.arguments);
return lua.createCallExpression(expression, parameters, node);

@@ -193,3 +190,3 @@ }

let parameters;
const isContextualCall = isContextualCallExpression(context, signature);
const isContextualCall = (0, function_context_1.getCallContextType)(context, node) !== function_context_1.ContextType.Void;
if (!isContextualCall) {

@@ -211,9 +208,2 @@ [callPath, parameters] = transformCallAndArguments(context, calledExpression, node.arguments, signature);

exports.transformCallExpression = transformCallExpression;
function isContextualCallExpression(context, signature) {
const declaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
if (!declaration) {
return !context.options.noImplicitSelf;
}
return (0, function_context_1.getDeclarationContextType)(context, declaration) !== function_context_1.ContextType.Void;
}
function getCalledExpression(node) {

@@ -220,0 +210,0 @@ return ts.skipOuterExpressions(node.expression);

@@ -69,10 +69,8 @@ "use strict";

// Evaluate if there is a self parameter to be used.
const signature = context.checker.getResolvedSignature(expression);
const signatureDeclaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
const useSelfParameter = signatureDeclaration && (0, function_context_1.getDeclarationContextType)(context, signatureDeclaration) !== function_context_1.ContextType.Void;
const useSelfParameter = (0, function_context_1.getCallContextType)(context, expression) !== function_context_1.ContextType.Void;
if (useSelfParameter) {
return (0, call_1.transformContextualCallExpression)(context, expression, expressions, signature);
return (0, call_1.transformContextualCallExpression)(context, expression, expressions);
}
// Argument evaluation.
const callArguments = (0, call_1.transformArguments)(context, expressions, signature);
const callArguments = (0, call_1.transformArguments)(context, expressions);
const leftHandSideExpression = context.transformExpression(expression.tag);

@@ -79,0 +77,0 @@ return lua.createCallExpression(leftHandSideExpression, callArguments);

@@ -32,2 +32,10 @@ import * as ts from "typescript";

beforeEmit?: (program: ts.Program, options: CompilerOptions, emitHost: EmitHost, result: EmitFile[]) => ts.Diagnostic[] | void;
/**
* This function is called after translating the input program to Lua, after resolving dependencies, after bundling and writing files to disk.
*/
afterEmit?: (program: ts.Program, options: CompilerOptions, emitHost: EmitHost, result: EmitFile[]) => ts.Diagnostic[] | void;
/**
* This function is called when trying to resolve the .lua file corresponding to a Lua require statement. Allows you to provide
* your own module resolution logic. If return value is undefined, regular module resolution is done.
*/
moduleResolution?: (moduleIdentifier: string, requiringFile: string, options: CompilerOptions, emitHost: EmitHost) => string | undefined;

@@ -34,0 +42,0 @@ }

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

emitFiles(program, plugins, emitPlan, writeFile) {
var _a, _b;
var _a, _b, _c;
performance.startSection("emit");

@@ -58,2 +58,8 @@ const options = program.getCompilerOptions();

}
for (const plugin of plugins) {
if (plugin.afterEmit) {
const afterEmitPluginDiagnostics = (_c = plugin.afterEmit(program, options, this.emitHost, emitPlan)) !== null && _c !== void 0 ? _c : [];
diagnostics.push(...afterEmitPluginDiagnostics);
}
}
if (options.tstlVerbose) {

@@ -60,0 +66,0 @@ console.log("Emit finished!");

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

@@ -5,0 +5,0 @@ "repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",

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