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.9.0 to 0.10.0

dist/CommandLineParser.d.ts

16

CHANGELOG.md
# Changelog
## 0.9.0
* Fixed an issue where default parameter values were ignored in function declarations.
* Fixed a bug where `self` was undefined in function properties.
* Fixed a bug where addition of +1 to indices sometimes caused issues with operation order (thanks @brianhang)
* Fixed super calls having issues with their `self` instance. (thanks @hazzard993)
* Methods now also accept custom decorators (thanks @hazzard993)
* Improved support for `toString` calls (thanks @andreiradu)
* Added support for block expressions (thanks @andreiradu)
Thanks @tomblind for the following changes:
* Fixed a bug where recursive use of a function expression caused a nil error.
* Fixed syntax error when compiling variable declaration lists.
* Fixed an issue with assignment order in exported namespaces.
* Various fixes to `!TupleReturn` functions.
* Fixed an issue with declaration merging.
## 0.8.0

@@ -4,0 +20,0 @@ * Added experimental watch mode, use it with `tstl --watch`

5

dist/CommandLineParser.js

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

const yargs = require("yargs");
class CLIError extends Error {
}
exports.CLIError = CLIError;
exports.optionDeclarations = {

@@ -31,2 +28,4 @@ luaLibImport: {

};
class CLIError extends Error {
}
/**

@@ -33,0 +32,0 @@ * Removes defaults from the arguments.

68

dist/Compiler.js

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

const CommandLineParser_1 = require("./CommandLineParser");
const Transpiler_51_1 = require("./targets/Transpiler.51");
const Transpiler_52_1 = require("./targets/Transpiler.52");
const Transpiler_53_1 = require("./targets/Transpiler.53");
const Transpiler_JIT_1 = require("./targets/Transpiler.JIT");
const Transpiler_1 = require("./Transpiler");
const TranspilerFactory_1 = require("./TranspilerFactory");
function compile(argv) {

@@ -84,3 +81,3 @@ const commandLine = CommandLineParser_1.parseCommandLine(argv);

// Transpile AST
const lua = createTranspiler(checker, options, sourceFile).transpileSourceFile();
const lua = TranspilerFactory_1.createTranspiler(checker, options, sourceFile).transpileSourceFile();
let outPath = sourceFile.fileName;

@@ -131,22 +128,45 @@ if (options.outDir !== options.rootDir) {

}
function createTranspiler(checker, options, sourceFile) {
let luaTargetTranspiler;
const target = options.luaTarget ? options.luaTarget.toLowerCase() : "";
switch (target) {
case Transpiler_1.LuaTarget.Lua51:
luaTargetTranspiler = new Transpiler_51_1.LuaTranspiler51(checker, options, sourceFile);
break;
case Transpiler_1.LuaTarget.Lua52:
luaTargetTranspiler = new Transpiler_52_1.LuaTranspiler52(checker, options, sourceFile);
break;
case Transpiler_1.LuaTarget.Lua53:
luaTargetTranspiler = new Transpiler_53_1.LuaTranspiler53(checker, options, sourceFile);
break;
default:
luaTargetTranspiler = new Transpiler_JIT_1.LuaTranspilerJIT(checker, options, sourceFile);
break;
}
return luaTargetTranspiler;
const libSource = fs.readFileSync(path.join(path.dirname(require.resolve("typescript")), "lib.es6.d.ts")).toString();
function transpileString(str, options = {
luaLibImport: Transpiler_1.LuaLibImportKind.Require,
luaTarget: Transpiler_1.LuaTarget.Lua53,
}) {
const compilerHost = {
directoryExists: () => true,
fileExists: (fileName) => true,
getCanonicalFileName: fileName => fileName,
getCurrentDirectory: () => "",
getDefaultLibFileName: () => "lib.es6.d.ts",
getDirectories: () => [],
getNewLine: () => "\n",
getSourceFile: (filename, languageVersion) => {
if (filename === "file.ts") {
return ts.createSourceFile(filename, str, ts.ScriptTarget.Latest, false);
}
if (filename === "lib.es6.d.ts") {
return ts.createSourceFile(filename, libSource, ts.ScriptTarget.Latest, false);
}
return undefined;
},
readFile: () => "",
useCaseSensitiveFileNames: () => false,
// Don't write output
writeFile: (name, text, writeByteOrderMark) => null,
};
const program = ts.createProgram(["file.ts"], options, compilerHost);
const result = TranspilerFactory_1.createTranspiler(program.getTypeChecker(), options, program.getSourceFile("file.ts")).transpileSourceFile();
return result.trim();
}
exports.createTranspiler = createTranspiler;
exports.transpileString = transpileString;
function transpileFile(filePath) {
const program = ts.createProgram([filePath], {});
const checker = program.getTypeChecker();
// Output errors
const diagnostics = ts.getPreEmitDiagnostics(program).filter(diag => diag.code !== 6054);
diagnostics.forEach(diagnostic => console.log(`${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`));
const options = { luaLibImport: "none" };
const result = TranspilerFactory_1.createTranspiler(checker, options, program.getSourceFile(filePath)).transpileSourceFile();
return result.trim();
}
exports.transpileFile = transpileFile;
function reportDiagnostic(diagnostic) {

@@ -153,0 +173,0 @@ if (diagnostic.file) {

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

// export statement, we only check for export statements
// TODO will break in 3.x
return sourceFile.statements.some(statement => (ts.getCombinedModifierFlags(statement) & ts.ModifierFlags.Export) !== 0

@@ -62,5 +63,11 @@ || statement.kind === ts.SyntaxKind.ExportAssignment

}
static isArrayTypeNode(typeNode) {
return typeNode.kind === ts.SyntaxKind.ArrayType
|| typeNode.kind === ts.SyntaxKind.TupleType
|| ((typeNode.kind === ts.SyntaxKind.UnionType || typeNode.kind === ts.SyntaxKind.IntersectionType)
&& typeNode.types.some(this.isArrayTypeNode));
}
static isArrayType(type, checker) {
const typeNode = checker.typeToTypeNode(type);
return typeNode && (typeNode.kind === ts.SyntaxKind.ArrayType || typeNode.kind === ts.SyntaxKind.TupleType);
const typeNode = checker.typeToTypeNode(type, undefined, ts.NodeBuilderFlags.InTypeAlias);
return typeNode && this.isArrayTypeNode(typeNode);
}

@@ -77,2 +84,12 @@ static isTupleReturnCall(node, checker) {

}
static isInTupleReturnFunction(node, checker) {
const declaration = this.findFirstNodeAbove(node, (n) => ts.isFunctionDeclaration(n) || ts.isMethodDeclaration(n));
if (declaration) {
const decorators = this.getCustomDecorators(checker.getTypeAtLocation(declaration), checker);
return decorators.has(Decorator_1.DecoratorKind.TupleReturn);
}
else {
return false;
}
}
static getCustomDecorators(type, checker) {

@@ -79,0 +96,0 @@ if (type.symbol) {

{
"name": "typescript-to-lua",
"license": "MIT",
"version": "0.9.0",
"version": "0.10.0",
"repository": "https://github.com/Perryvw/TypescriptToLua",

@@ -12,2 +12,4 @@ "keywords": [

],
"main": "dist/tstl.js",
"types": "dist/tstl.d.ts",
"scripts": {

@@ -45,3 +47,3 @@ "build": "tsc -p tsconfig.json && npm run build-lualib",

"dependencies": {
"typescript": "^2.9.2",
"typescript": "2.9.2",
"yargs": "^12.0.1"

@@ -48,0 +50,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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