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.6.0 to 1.6.1

9

dist/transformation/utils/function-context.js

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

const options = program.getCompilerOptions();
if (options.noImplicitSelf && program.getSourceFile(signatureDeclaration.getSourceFile().fileName) !== undefined) {
return ContextType.Void;
if (options.noImplicitSelf) {
const sourceFile = program.getSourceFile(signatureDeclaration.getSourceFile().fileName);
if (sourceFile !== undefined &&
!program.isSourceFileDefaultLibrary(sourceFile) &&
!program.isSourceFileFromExternalLibrary(sourceFile)) {
return ContextType.Void;
}
}

@@ -66,0 +71,0 @@ // Walk up to find @noSelf or @noSelfInFile

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

function transformDestructuredAssignmentExpression(context, expression) {
const rootIdentifier = context.createTempNameForNode(expression.right);
let [rightPrecedingStatements, right] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.right));

@@ -82,7 +81,5 @@ context.addPrecedingStatements(rightPrecedingStatements);

}
const statements = [
lua.createVariableDeclarationStatement(rootIdentifier, right),
...(0, destructuring_assignments_1.transformDestructuringAssignment)(context, expression, rootIdentifier, rightPrecedingStatements.length > 0),
];
return { statements, result: rootIdentifier };
const rightExpr = (0, expression_list_1.moveToPrecedingTemp)(context, right, expression.right);
const statements = (0, destructuring_assignments_1.transformDestructuringAssignment)(context, expression, rightExpr, rightPrecedingStatements.length > 0);
return { statements, result: rightExpr };
}

@@ -104,11 +101,8 @@ function transformAssignmentExpression(context, expression) {

if (ts.isPropertyAccessExpression(expression.left) || ts.isElementAccessExpression(expression.left)) {
const tempVar = context.createTempNameForNode(expression.right);
const [precedingStatements, right] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.right));
const left = transformAssignmentLeftHandSideExpression(context, expression.left, precedingStatements.length > 0);
context.addPrecedingStatements([
...precedingStatements,
lua.createVariableDeclarationStatement(tempVar, right, expression.right),
lua.createAssignmentStatement(left, lua.cloneIdentifier(tempVar), expression.left),
]);
return lua.cloneIdentifier(tempVar);
context.addPrecedingStatements(precedingStatements);
const rightExpr = (0, expression_list_1.moveToPrecedingTemp)(context, right, expression.right);
context.addPrecedingStatements(lua.createAssignmentStatement(left, rightExpr, expression.left));
return rightExpr;
}

@@ -164,12 +158,4 @@ else {

}
let [rightPrecedingStatements, right] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.right));
context.addPrecedingStatements(rightPrecedingStatements);
if ((0, multi_1.isMultiReturnCall)(context, expression.right)) {
right = (0, lua_ast_1.wrapInTable)(right);
}
const rootIdentifier = context.createTempNameForNode(expression.left);
return [
lua.createVariableDeclarationStatement(rootIdentifier, right),
...(0, destructuring_assignments_1.transformDestructuringAssignment)(context, expression, rootIdentifier, rightPrecedingStatements.length > 0),
];
const { statements } = transformDestructuredAssignmentExpression(context, expression);
return statements;
}

@@ -176,0 +162,0 @@ else {

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

}
const signatureDeclaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
let callPath;
let parameters;
const isContextualCall = !signatureDeclaration || (0, function_context_1.getDeclarationContextType)(context, signatureDeclaration) !== function_context_1.ContextType.Void;
const isContextualCall = isContextualCallExpression(context, signature);
if (!isContextualCall) {

@@ -199,5 +198,3 @@ [callPath, parameters] = transformCallAndArguments(context, calledExpression, node.arguments, signature);

const callContext = useGlobalContext ? ts.factory.createIdentifier("_G") : ts.factory.createNull();
[callPath, parameters] = transformCallAndArguments(context, calledExpression, node.arguments, signature,
// Only pass context if noImplicitSelf is not configured
context.options.noImplicitSelf ? undefined : callContext);
[callPath, parameters] = transformCallAndArguments(context, calledExpression, node.arguments, signature, callContext);
}

@@ -211,2 +208,9 @@ const callExpression = lua.createCallExpression(callPath, parameters, node);

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

@@ -213,0 +217,0 @@ function unwrapExpression(expression) {

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

!(lua.isIdentifier(expression) && expression.symbolId === context_1.tempSymbolId) && // Treat generated temps as consts
!(tsOriginal && ((0, typescript_1.isConstIdentifier)(context, tsOriginal) || (0, optional_chaining_1.isOptionalContinuation)(tsOriginal))));
!(tsOriginal &&
((0, typescript_1.isConstIdentifier)(context, tsOriginal) ||
(0, optional_chaining_1.isOptionalContinuation)(tsOriginal) ||
tsOriginal.kind === ts.SyntaxKind.ThisKeyword)));
}

@@ -18,0 +21,0 @@ exports.shouldMoveToTemp = shouldMoveToTemp;

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

export declare function transformArrayBindingElement(context: TransformationContext, name: ts.ArrayBindingElement): lua.Identifier;
export declare function transformBindingPattern(context: TransformationContext, pattern: ts.BindingPattern, table: lua.Identifier, propertyAccessStack?: ts.PropertyName[]): lua.Statement[];
export declare function transformBindingPattern(context: TransformationContext, pattern: ts.BindingPattern, table: lua.Expression, propertyAccessStack?: ts.PropertyName[]): lua.Statement[];
export declare function transformBindingVariableDeclaration(context: TransformationContext, bindingPattern: ts.BindingPattern, initializer?: ts.Expression): lua.Statement[];

@@ -8,0 +8,0 @@ export declare function transformVariableDeclaration(context: TransformationContext, statement: ts.VariableDeclaration): lua.Statement[];

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

const literal_1 = require("./literal");
const expression_list_1 = require("./expression-list");
function transformArrayBindingElement(context, name) {

@@ -121,19 +122,15 @@ if (ts.isOmittedExpression(name)) {

let table;
if (initializer !== undefined && ts.isIdentifier(initializer)) {
table = (0, identifier_1.transformIdentifier)(context, initializer);
}
else {
if (initializer) {
// Contain the expression in a temporary variable
if (initializer) {
table = context.createTempNameForNode(initializer);
let expression = context.transformExpression(initializer);
if ((0, multi_1.isMultiReturnCall)(context, initializer)) {
expression = (0, lua_ast_1.wrapInTable)(expression);
}
statements.push(lua.createVariableDeclarationStatement(table, expression));
let expression = context.transformExpression(initializer);
if ((0, multi_1.isMultiReturnCall)(context, initializer)) {
expression = (0, lua_ast_1.wrapInTable)(expression);
}
else {
table = lua.createAnonymousIdentifier();
}
const [moveStatements, movedExpr] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => (0, expression_list_1.moveToPrecedingTemp)(context, expression, initializer));
statements.push(...moveStatements);
table = movedExpr;
}
else {
table = lua.createAnonymousIdentifier();
}
statements.push(...transformBindingPattern(context, bindingPattern, table));

@@ -140,0 +137,0 @@ return statements;

@@ -118,4 +118,4 @@ "use strict";

for (const required of findRequiredPaths(file.code)) {
// Do no resolve lualib, unless it is included from node_modules
if (required === "lualib_bundle" && !isNodeModulesFile(file.fileName)) {
// Do no resolve lualib - always use the lualib of the application entry point, not the lualib from external packages
if (required === "lualib_bundle") {
dependencies.push({ fileName: "lualib_bundle", code: "" });

@@ -122,0 +122,0 @@ continue;

{
"name": "typescript-to-lua",
"version": "1.6.0",
"version": "1.6.1",
"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

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