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.5.0 to 0.6.0

dist/Index.js

19

CHANGELOG.md
# Changelog
## 0.6.0
* Reworked part of the class system to solve some issues.
* Reworked class tests from translation to functional.
* Fixed issue with Lua splice implementation.
* Added threaded test runner to use for faster testing (use with `npm run test-threaded`).
* Added support for string-valued enums.
* Added tsconfig values to target Lua 5.1 and 5.2.
## 0.5.0
* Added support for `**` operator.
* Added support for `~` operator.
* Improved handling of assignment binary operators (`+=`,`*=`,`&=`, etc).
* Rewrote `Map` and `Set` to implement the ES6 specification for [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) and [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).
* Added support for `baseUrl` in [tsconfig](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
* Added `bit32` bit operations for Lua 5.2.
* Fixed various little bugs.
* Added tslint rule to enforce use of `/** @override */` decorator.
* Improved tests.
## 0.4.0

@@ -4,0 +23,0 @@ * Added support for `typeof`

109

dist/CommandLineParser.js
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var fs = require("fs");
var path = require("path");
var ts = require("typescript");
var yargs = require("yargs");
var CLIError = /** @class */ (function (_super) {
__extends(CLIError, _super);
function CLIError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return CLIError;
}(Error));
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const ts = require("typescript");
const yargs = require("yargs");
class CLIError extends Error {
}
exports.CLIError = CLIError;
var optionDeclarations = {
addHeader: {
alias: ["ah", "header"],
"default": true,
describe: "Specify if a header will be added to compiled files.",
type: "boolean"
const optionDeclarations = {
luaLibImport: {
choices: ["inline", "require", "none"],
default: "inline",
describe: "Specify Lua target version.",
type: "string",
},
dontRequireLuaLib: {
"default": false,
describe: "Dont require lua library that enables advanced Typescipt/JS functionality.",
type: "boolean"
},
luaTarget: {
alias: "lt",
choices: ["JIT", "5.3"],
"default": "JIT",
choices: ["JIT", "5.3", "5.2", "5.1"],
default: "JIT",
describe: "Specify Lua target version.",
type: "string"
}
type: "string",
},
noHeader: {
default: false,
describe: "Specify if a header will be added to compiled files.",
type: "boolean",
},
};

@@ -50,3 +35,3 @@ /**

function parseCommandLine(args) {
var parsedArgs = yargs
const parsedArgs = yargs
.usage("Syntax: tstl [options] [files...]\n\n" +

@@ -60,7 +45,7 @@ "In addition to the options listed below you can also pass options" +

.options(optionDeclarations)
.fail(function (msg, err) {
.fail((msg, err) => {
throw new CLIError(msg);
})
.parse(args);
var commandLine = ts.parseCommandLine(args);
let commandLine = ts.parseCommandLine(args);
// Run diagnostics to check for invalid tsc/tstl options

@@ -73,5 +58,5 @@ runDiagnostics(commandLine);

findConfigFile(commandLine);
var configPath = commandLine.options.project;
var configContents = fs.readFileSync(configPath).toString();
var configJson = ts.parseConfigFileTextToJson(configPath, configContents);
const configPath = commandLine.options.project;
const configContents = fs.readFileSync(configPath).toString();
const configJson = ts.parseConfigFileTextToJson(configPath, configContents);
commandLine = ts.parseJsonConfigFileContent(configJson.config, ts.sys, path.dirname(configPath), commandLine.options);

@@ -99,3 +84,3 @@ }

if (additionalArgs) {
for (var arg in additionalArgs) {
for (const arg in additionalArgs) {
// dont override, this will prioritize CLI over tsconfig.

@@ -110,25 +95,25 @@ if (optionDeclarations[arg] && (!commandLine.options[arg] || forceOverride)) {

function runDiagnostics(commandLine) {
var tsInvalidCompilerOptionErrorCode = 5023;
// Remove files that dont exist
commandLine.fileNames = commandLine.fileNames.filter(file => fs.existsSync(file) || fs.existsSync(file + ".ts"));
const tsInvalidCompilerOptionErrorCode = 5023;
if (commandLine.errors.length !== 0) {
// Generate a list of valid option names and aliases
var optionNames_1 = [];
for (var _i = 0, _a = Object.keys(optionDeclarations); _i < _a.length; _i++) {
var key = _a[_i];
optionNames_1.push(key);
var alias = optionDeclarations[key].alias;
const optionNames = [];
for (const key of Object.keys(optionDeclarations)) {
optionNames.push(key);
const alias = optionDeclarations[key].alias;
if (alias) {
if (typeof alias === "string") {
optionNames_1.push(alias);
optionNames.push(alias);
}
else {
optionNames_1.push.apply(optionNames_1, alias);
optionNames.push(...alias);
}
}
}
commandLine.errors.forEach(function (err) {
var ignore = false;
commandLine.errors.forEach(err => {
let ignore = false;
// Ignore errors caused by tstl specific compiler options
if (err.code === tsInvalidCompilerOptionErrorCode) {
for (var _i = 0, optionNames_2 = optionNames_1; _i < optionNames_2.length; _i++) {
var optionName = optionNames_2[_i];
for (const optionName of optionNames) {
if (err.messageText.toString().indexOf(optionName) !== -1) {

@@ -139,3 +124,3 @@ ignore = true;

if (!ignore) {
throw new CLIError("error TS" + err.code + ": " + err.messageText);
throw new CLIError(`error TS${err.code}: ${err.messageText}`);
}

@@ -149,5 +134,5 @@ }

if (!commandLine.options.project) {
throw new CLIError("error no base path provided, could not find config.");
throw new CLIError(`error no base path provided, could not find config.`);
}
var configPath;
let configPath;
/* istanbul ignore else: Testing else part is not really possible via automated tests */

@@ -166,5 +151,5 @@ if (path.isAbsolute(commandLine.options.project)) {

// Search for tsconfig upwards in directory hierarchy starting from the file path
var dir = path.dirname(configPath).split(path.sep);
for (var i = dir.length; i > 0; i--) {
var searchPath = dir.slice(0, i).join("/") + path.sep + "tsconfig.json";
const dir = path.dirname(configPath).split(path.sep);
for (let i = dir.length; i > 0; i--) {
const searchPath = dir.slice(0, i).join("/") + path.sep + "tsconfig.json";
// If tsconfig.json was found, stop searching

@@ -171,0 +156,0 @@ if (ts.sys.fileExists(searchPath)) {

@@ -1,45 +0,50 @@

#!/usr/bin/env node
"use strict";
exports.__esModule = true;
var fs = require("fs");
var path = require("path");
var ts = require("typescript");
var CommandLineParser_1 = require("./CommandLineParser");
var Transpiler_51_1 = require("./targets/Transpiler.51");
var Transpiler_52_1 = require("./targets/Transpiler.52");
var Transpiler_53_1 = require("./targets/Transpiler.53");
var Transpiler_JIT_1 = require("./targets/Transpiler.JIT");
var Transpiler_1 = require("./Transpiler");
function compile(fileNames, options) {
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const ts = require("typescript");
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");
function compile(argv) {
const commandLine = CommandLineParser_1.parseCommandLine(argv);
compileFilesWithOptions(commandLine.fileNames, commandLine.options);
}
exports.compile = compile;
function compileFilesWithOptions(fileNames, options) {
if (!options.luaTarget) {
options.luaTarget = Transpiler_1.LuaTarget.LuaJIT;
}
var program = ts.createProgram(fileNames, options);
var checker = program.getTypeChecker();
const program = ts.createProgram(fileNames, options);
const checker = program.getTypeChecker();
// Get all diagnostics, ignore unsupported extension
var diagnostics = ts.getPreEmitDiagnostics(program).filter(function (diag) { return diag.code !== 6054; });
diagnostics.forEach(function (diagnostic) {
const diagnostics = ts.getPreEmitDiagnostics(program).filter(diag => diag.code !== 6054);
diagnostics.forEach(diagnostic => {
if (diagnostic.file) {
var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character;
var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
console.log(diagnostic.file.fileName + " (" + (line + 1) + "," + (character + 1) + "): " + message);
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
}
else {
console.log("" + ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
console.log(`${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`);
}
});
// If there are errors dont emit
if (diagnostics.filter(function (diag) { return diag.category === ts.DiagnosticCategory.Error; }).length > 0) {
if (diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error).length > 0) {
console.log("Stopping compilation process because of errors.");
process.exit(1);
}
program.getSourceFiles().forEach(function (sourceFile) {
program.getSourceFiles().forEach(sourceFile => {
if (!sourceFile.isDeclarationFile) {
try {
var rootDir = options.rootDir;
const rootDir = options.rootDir;
// console.log(`Transpiling ${sourceFile.fileName}...`);
// Transpile AST
var lua = createTranspiler(checker, options, sourceFile).transpileSourceFile();
var outPath = sourceFile.fileName;
const lua = createTranspiler(checker, options, sourceFile).transpileSourceFile();
let outPath = sourceFile.fileName;
if (options.outDir !== options.rootDir) {
var relativeSourcePath = path.resolve(sourceFile.fileName)
const relativeSourcePath = path.resolve(sourceFile.fileName)
.replace(path.resolve(rootDir), "");

@@ -59,3 +64,3 @@ outPath = path.join(options.outDir, relativeSourcePath);

else {
var fileNameLua = path.basename(outPath, path.extname(outPath)) + ".lua";
const fileNameLua = path.basename(outPath, path.extname(outPath)) + ".lua";
outPath = path.join(path.dirname(outPath), fileNameLua);

@@ -69,3 +74,3 @@ }

if (exception.node) {
var pos = ts.getLineAndCharacterOfPosition(sourceFile, exception.node.pos);
const pos = ts.getLineAndCharacterOfPosition(sourceFile, exception.node.pos);
// Graciously handle transpilation errors

@@ -84,7 +89,9 @@ console.error("Encountered error parsing file: " + exception.message);

// Copy lualib to target dir
fs.copyFileSync(path.resolve(__dirname, "../dist/lualib/typescript.lua"), path.join(options.outDir, "typescript_lualib.lua"));
if (options.luaLibImport === Transpiler_1.LuaLibImportKind.Require) {
fs.copyFileSync(path.resolve(__dirname, "../dist/lualib/lualib_bundle.lua"), path.join(options.outDir, "lualib_bundle.lua"));
}
}
exports.compile = compile;
exports.compileFilesWithOptions = compileFilesWithOptions;
function createTranspiler(checker, options, sourceFile) {
var luaTargetTranspiler;
let luaTargetTranspiler;
switch (options.luaTarget) {

@@ -110,9 +117,2 @@ case Transpiler_1.LuaTarget.LuaJIT:

exports.createTranspiler = createTranspiler;
function execCommandLine(argv) {
argv = argv ? argv : process.argv.slice(2);
var commandLine = CommandLineParser_1.parseCommandLine(argv);
compile(commandLine.fileNames, commandLine.options);
}
exports.execCommandLine = execCommandLine;
execCommandLine();
//# sourceMappingURL=Compiler.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var Transpiler_1 = require("../Transpiler");
var LuaTranspiler51 = /** @class */ (function (_super) {
__extends(LuaTranspiler51, _super);
function LuaTranspiler51() {
return _super !== null && _super.apply(this, arguments) || this;
}
return LuaTranspiler51;
}(Transpiler_1.LuaTranspiler));
Object.defineProperty(exports, "__esModule", { value: true });
const Transpiler_1 = require("../Transpiler");
class LuaTranspiler51 extends Transpiler_1.LuaTranspiler {
}
exports.LuaTranspiler51 = LuaTranspiler51;
//# sourceMappingURL=Transpiler.51.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var Transpiler_51_1 = require("./Transpiler.51");
var ts = require("typescript");
var LuaTranspiler52 = /** @class */ (function (_super) {
__extends(LuaTranspiler52, _super);
function LuaTranspiler52() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(exports, "__esModule", { value: true });
const Transpiler_51_1 = require("./Transpiler.51");
const ts = require("typescript");
class LuaTranspiler52 extends Transpiler_51_1.LuaTranspiler51 {
/** @override */
LuaTranspiler52.prototype.transpileLoopBody = function (node) {
transpileLoopBody(node) {
this.loopStack.push(this.genVarCounter);
this.genVarCounter++;
var result = this.indent + "do\n";
let result = this.indent + "do\n";
this.pushIndent();

@@ -29,36 +15,35 @@ result += this.transpileStatement(node.statement);

result += this.indent + "end\n";
result += this.indent + ("::__continue" + this.loopStack.pop() + "::\n");
result += this.indent + `::__continue${this.loopStack.pop()}::\n`;
return result;
};
}
/** @override */
LuaTranspiler52.prototype.transpileContinue = function (node) {
return this.indent + ("goto __continue" + this.loopStack[this.loopStack.length - 1] + "\n");
};
transpileContinue(node) {
return this.indent + `goto __continue${this.loopStack[this.loopStack.length - 1]}\n`;
}
/** @override */
LuaTranspiler52.prototype.transpileUnaryBitOperation = function (node, operand) {
transpileUnaryBitOperation(node, operand) {
switch (node.operator) {
case ts.SyntaxKind.TildeToken:
return "bit32.bnot(" + operand + ")";
return `bit32.bnot(${operand})`;
}
};
}
/** @override */
LuaTranspiler52.prototype.transpileBitOperation = function (node, lhs, rhs) {
transpileBitOperation(node, lhs, rhs) {
switch (node.operatorToken.kind) {
case ts.SyntaxKind.AmpersandToken:
return "bit32.band(" + lhs + "," + rhs + ")";
return `bit32.band(${lhs},${rhs})`;
case ts.SyntaxKind.BarToken:
return "bit32.bor(" + lhs + "," + rhs + ")";
return `bit32.bor(${lhs},${rhs})`;
case ts.SyntaxKind.CaretToken:
return "bit32.bxor(" + lhs + "," + rhs + ")";
return `bit32.bxor(${lhs},${rhs})`;
case ts.SyntaxKind.LessThanLessThanToken:
return "bit32.lshift(" + lhs + "," + rhs + ")";
return `bit32.lshift(${lhs},${rhs})`;
case ts.SyntaxKind.GreaterThanGreaterThanToken:
return "bit32.rshift(" + lhs + "," + rhs + ")";
return `bit32.rshift(${lhs},${rhs})`;
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
return "bit32.arshift(" + lhs + "," + rhs + ")";
return `bit32.arshift(${lhs},${rhs})`;
}
};
return LuaTranspiler52;
}(Transpiler_51_1.LuaTranspiler51));
}
}
exports.LuaTranspiler52 = LuaTranspiler52;
//# sourceMappingURL=Transpiler.52.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var Transpiler_1 = require("../Transpiler");
var Transpiler_52_1 = require("./Transpiler.52");
var ts = require("typescript");
var LuaTranspiler53 = /** @class */ (function (_super) {
__extends(LuaTranspiler53, _super);
function LuaTranspiler53() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(exports, "__esModule", { value: true });
const Transpiler_1 = require("../Transpiler");
const Transpiler_52_1 = require("./Transpiler.52");
const ts = require("typescript");
class LuaTranspiler53 extends Transpiler_52_1.LuaTranspiler52 {
/** @override */
LuaTranspiler53.prototype.transpileUnaryBitOperation = function (node, operand) {
transpileUnaryBitOperation(node, operand) {
switch (node.operator) {
case ts.SyntaxKind.TildeToken:
return "~" + operand;
return `~${operand}`;
}
};
}
/** @override */
LuaTranspiler53.prototype.transpileBitOperation = function (node, lhs, rhs) {
transpileBitOperation(node, lhs, rhs) {
switch (node.operatorToken.kind) {
case ts.SyntaxKind.AmpersandToken:
return lhs + " & " + rhs;
return `${lhs} & ${rhs}`;
case ts.SyntaxKind.BarToken:
return lhs + " | " + rhs;
return `${lhs} | ${rhs}`;
case ts.SyntaxKind.CaretToken:
return lhs + " ~ " + rhs;
return `${lhs} ~ ${rhs}`;
case ts.SyntaxKind.LessThanLessThanToken:
return lhs + " << " + rhs;
return `${lhs} << ${rhs}`;
case ts.SyntaxKind.GreaterThanGreaterThanToken:
return lhs + " >> " + rhs;
return `${lhs} >> ${rhs}`;
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
throw new Transpiler_1.TranspileError("Bitwise operator >>> not supported in Lua 5.3", node);
}
};
}
/** @override */
LuaTranspiler53.prototype.getValidStringProperties = function () {
getValidStringProperties() {
return {
fromCharCode: "string.char",
fromCodePoint: "utf8.char"
fromCodePoint: "utf8.char",
};
};
return LuaTranspiler53;
}(Transpiler_52_1.LuaTranspiler52));
}
}
exports.LuaTranspiler53 = LuaTranspiler53;
//# sourceMappingURL=Transpiler.53.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var Transpiler_52_1 = require("./Transpiler.52");
var ts = require("typescript");
var LuaTranspilerJIT = /** @class */ (function (_super) {
__extends(LuaTranspilerJIT, _super);
function LuaTranspilerJIT() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(exports, "__esModule", { value: true });
const Transpiler_52_1 = require("./Transpiler.52");
const ts = require("typescript");
class LuaTranspilerJIT extends Transpiler_52_1.LuaTranspiler52 {
/** @override */
LuaTranspilerJIT.prototype.transpileUnaryBitOperation = function (node, operand) {
transpileUnaryBitOperation(node, operand) {
switch (node.operator) {
case ts.SyntaxKind.TildeToken:
return "bit.bnot(" + operand + ")";
return `bit.bnot(${operand})`;
}
};
}
/** @override */
LuaTranspilerJIT.prototype.transpileBitOperation = function (node, lhs, rhs) {
transpileBitOperation(node, lhs, rhs) {
switch (node.operatorToken.kind) {
case ts.SyntaxKind.AmpersandToken:
return "bit.band(" + lhs + "," + rhs + ")";
return `bit.band(${lhs},${rhs})`;
case ts.SyntaxKind.BarToken:
return "bit.bor(" + lhs + "," + rhs + ")";
return `bit.bor(${lhs},${rhs})`;
case ts.SyntaxKind.CaretToken:
return "bit.bxor(" + lhs + "," + rhs + ")";
return `bit.bxor(${lhs},${rhs})`;
case ts.SyntaxKind.LessThanLessThanToken:
return "bit.lshift(" + lhs + "," + rhs + ")";
return `bit.lshift(${lhs},${rhs})`;
case ts.SyntaxKind.GreaterThanGreaterThanToken:
return "bit.rshift(" + lhs + "," + rhs + ")";
return `bit.rshift(${lhs},${rhs})`;
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
return "bit.arshift(" + lhs + "," + rhs + ")";
return `bit.arshift(${lhs},${rhs})`;
}
};
return LuaTranspilerJIT;
}(Transpiler_52_1.LuaTranspiler52));
}
}
exports.LuaTranspilerJIT = LuaTranspilerJIT;
//# sourceMappingURL=Transpiler.JIT.js.map
"use strict";
exports.__esModule = true;
var ts = require("typescript");
var TSHelper = /** @class */ (function () {
function TSHelper() {
}
Object.defineProperty(exports, "__esModule", { value: true });
const ts = require("typescript");
class TSHelper {
// Reverse lookup of enum key by value
TSHelper.enumName = function (needle, haystack) {
for (var name_1 in haystack) {
if (haystack[name_1] === needle) {
return name_1;
static enumName(needle, haystack) {
for (const name in haystack) {
if (haystack[name] === needle) {
return name;
}
}
return "unknown";
};
}
// Breaks down a mask into all flag names.
TSHelper.enumNames = function (mask, haystack) {
var result = [];
for (var name_2 in haystack) {
if ((mask & haystack[name_2]) !== 0 && mask >= haystack[name_2]) {
result.push(name_2);
static enumNames(mask, haystack) {
const result = [];
for (const name in haystack) {
if ((mask & haystack[name]) !== 0 && mask >= haystack[name]) {
result.push(name);
}
}
return result;
};
TSHelper.containsStatement = function (statements, kind) {
return statements.some(function (statement) { return statement.kind === kind; });
};
TSHelper.isFileModule = function (sourceFile) {
}
static containsStatement(statements, kind) {
return statements.some(statement => statement.kind === kind);
}
static getExtendedType(node, checker) {
if (node.heritageClauses) {
for (const clause of node.heritageClauses) {
if (clause.token === ts.SyntaxKind.ExtendsKeyword) {
const superType = checker.getTypeAtLocation(clause.types[0]);
if (!this.isPureAbstractClass(superType, checker)) {
return superType;
}
}
}
}
return undefined;
}
static isFileModule(sourceFile) {
if (sourceFile) {
// Vanilla ts flags files as external module if they have an import or
// export statement, we only check for export statements
return sourceFile.statements.some(function (statement) {
return (ts.getCombinedModifierFlags(statement) & ts.ModifierFlags.Export) !== 0
|| statement.kind === ts.SyntaxKind.ExportAssignment
|| statement.kind === ts.SyntaxKind.ExportDeclaration;
});
return sourceFile.statements.some(statement => (ts.getCombinedModifierFlags(statement) & ts.ModifierFlags.Export) !== 0
|| statement.kind === ts.SyntaxKind.ExportAssignment
|| statement.kind === ts.SyntaxKind.ExportDeclaration);
}
return false;
};
TSHelper.isInDestructingAssignment = function (node) {
}
static isInDestructingAssignment(node) {
return node.parent && ts.isVariableDeclaration(node.parent) && ts.isArrayBindingPattern(node.parent.name);
};
TSHelper.isStringType = function (type) {
}
static isStringType(type) {
return (type.flags & ts.TypeFlags.String) !== 0
|| (type.flags & ts.TypeFlags.StringLike) !== 0
|| (type.flags & ts.TypeFlags.StringLiteral) !== 0;
};
TSHelper.isArrayType = function (type, checker) {
var typeNode = checker.typeToTypeNode(type);
}
static isArrayType(type, checker) {
const typeNode = checker.typeToTypeNode(type);
return typeNode && (typeNode.kind === ts.SyntaxKind.ArrayType || typeNode.kind === ts.SyntaxKind.TupleType);
};
TSHelper.isCompileMembersOnlyEnum = function (type, checker) {
}
static isCompileMembersOnlyEnum(type, checker) {
return type.symbol

@@ -58,21 +67,21 @@ && ((type.symbol.flags & ts.SymbolFlags.Enum) !== 0)

&& this.hasCustomDecorator(type, checker, "!CompileMembersOnly");
};
TSHelper.isPureAbstractClass = function (type, checker) {
}
static isPureAbstractClass(type, checker) {
return type.symbol
&& ((type.symbol.flags & ts.SymbolFlags.Class) !== 0)
&& this.hasCustomDecorator(type, checker, "!PureAbstract");
};
TSHelper.isExtensionClass = function (type, checker) {
}
static isExtensionClass(type, checker) {
return type.symbol
&& ((type.symbol.flags & ts.SymbolFlags.Class) !== 0)
&& this.hasCustomDecorator(type, checker, "!Extension");
};
TSHelper.isPhantom = function (type, checker) {
}
static isPhantom(type, checker) {
return type.symbol
&& ((type.symbol.flags & ts.SymbolFlags.Namespace) !== 0)
&& this.hasCustomDecorator(type, checker, "!Phantom");
};
TSHelper.isTupleReturnCall = function (node, checker) {
}
static isTupleReturnCall(node, checker) {
if (ts.isCallExpression(node)) {
var type = checker.getTypeAtLocation(node.expression);
const type = checker.getTypeAtLocation(node.expression);
return this.isTupleReturnFunction(type, checker);

@@ -83,4 +92,4 @@ }

}
};
TSHelper.isTupleReturnFunction = function (type, checker) {
}
static isTupleReturnFunction(type, checker) {
return type.symbol

@@ -90,16 +99,16 @@ && ((type.symbol.flags & ts.SymbolFlags.Function) !== 0

&& this.hasCustomDecorator(type, checker, "!TupleReturn");
};
TSHelper.hasCustomDecorator = function (type, checker, decorator) {
}
static hasCustomDecorator(type, checker, decorator) {
if (type.symbol) {
var comments = type.symbol.getDocumentationComment(checker);
var decorators = comments.filter(function (comment) { return comment.kind === "text"; })
.map(function (comment) { return comment.text.trim(); })
.filter(function (comment) { return comment[0] === "!"; });
const comments = type.symbol.getDocumentationComment(checker);
const decorators = comments.filter(comment => comment.kind === "text")
.map(comment => comment.text.trim())
.filter(comment => comment[0] === "!");
return decorators.indexOf(decorator) > -1;
}
return false;
};
}
// Search up until finding a node satisfying the callback
TSHelper.findFirstNodeAbove = function (node, callback) {
var current = node;
static findFirstNodeAbove(node, callback) {
let current = node;
while (current.parent) {

@@ -114,9 +123,9 @@ if (callback(current.parent)) {

return null;
};
TSHelper.hasGetAccessor = function (node, checker) {
}
static hasGetAccessor(node, checker) {
if (ts.isPropertyAccessExpression(node)) {
var name_3 = node.name.escapedText;
var type = checker.getTypeAtLocation(node.expression);
const name = node.name.escapedText;
const type = checker.getTypeAtLocation(node.expression);
if (type && type.symbol && type.symbol.members) {
var field = type.symbol.members.get(name_3);
const field = type.symbol.members.get(name);
return field && (field.flags & ts.SymbolFlags.GetAccessor) !== 0;

@@ -126,9 +135,9 @@ }

return false;
};
TSHelper.hasSetAccessor = function (node, checker) {
}
static hasSetAccessor(node, checker) {
if (ts.isPropertyAccessExpression(node)) {
var name_4 = node.name.escapedText;
var type = checker.getTypeAtLocation(node.expression);
const name = node.name.escapedText;
const type = checker.getTypeAtLocation(node.expression);
if (type && type.symbol && type.symbol.members) {
var field = type.symbol.members.get(name_4);
const field = type.symbol.members.get(name);
return field && (field.flags & ts.SymbolFlags.SetAccessor) !== 0;

@@ -138,4 +147,4 @@ }

return false;
};
TSHelper.isBinaryAssignmentToken = function (token) {
}
static isBinaryAssignmentToken(token) {
switch (token) {

@@ -168,6 +177,5 @@ case ts.SyntaxKind.BarEqualsToken:

return [false, null];
};
return TSHelper;
}());
}
}
exports.TSHelper = TSHelper;
//# sourceMappingURL=TSHelper.js.map
{
"name": "typescript-to-lua",
"license": "MIT",
"version": "0.5.0",
"version": "0.6.0",
"repository": "https://github.com/Perryvw/TypescriptToLua",

@@ -13,6 +13,8 @@ "keywords": [

"scripts": {
"build": "tsc -p tsconfig.json",
"test": "tslint -p . && ts-node ./test/runner.ts",
"coverage": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov && codecov",
"build": "tsc -p tsconfig.json && npm run build-lualib",
"build-lualib": "ts-node ./build_lualib.ts",
"test": "tslint -p . && tslint -c ./tslint.json src/lualib/*.ts && ts-node ./test/runner.ts",
"coverage": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov",
"coverage-html": "nyc npm test && nyc report --reporter=html",
"test-threaded": "tslint -p . && npm run build && ts-node ./test/threaded_runner.ts",
"release-patch": "npm version patch",

@@ -25,3 +27,3 @@ "release-minor": "npm version minor",

"bin": {
"tstl": "./dist/Compiler.js"
"tstl": "./dist/index.js"
},

@@ -35,2 +37,5 @@ "nyc": {

"src/**/*"
],
"exclude": [
"src/lualib/*"
]

@@ -46,9 +51,13 @@ },

"devDependencies": {
"@types/glob": "^5.0.35",
"@types/node": "^9.6.23",
"@types/yargs": "^11.0.0",
"alsatian": "^2.2.1",
"circular-json": "^0.5.5",
"codecov": "3.0.2",
"deep-equal": "^1.0.1",
"fengari": "^0.1.2",
"glob": "^7.1.2",
"nyc": "^11.9.0",
"threads": "^0.12.0",
"ts-node": "^7.0.0",

@@ -55,0 +64,0 @@ "tslint": "^5.10.0",

@@ -48,2 +48,12 @@ # TypescriptToLua

## Building & Tests
`npm run build` to build the project.
`npm run test` to run tests.
`npm run test-threaded` runs test in parallel, faster but less detailed output.
`npm run coverage` or `npm run coverage-html` to generate a coverage report.
## Sublime Text integration

@@ -50,0 +60,0 @@ This compiler works great in combination with the [Sublime Text Typescript plugin](https://github.com/Microsoft/TypeScript-Sublime-Plugin) (available through the package manager as `TypeScript`).

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

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