Skip to content

Commit e79e42b

Browse files
tomblindPerryvw
authored andcommitted
New functions - merge from master (#306)
* converting 'else if' statements to lua 'elseif' instead of nested ifs (#254) * Const enum support (#253) * Const enum support * Changed string concatenation to interpolation * refactored try block to allow rethrow (#251) * refactored try block to allow rethrow * updated rethrow test with something less convoluted * Made LuaJIT use table.unpack for destructing assignments (#257) * Fixed JIT using table.unpack (#258) * Fixed JIT using table.unpack sry * Fixed test for JIT unpack * Moved transpileDestructingAssignmentValue from 5.1 to 5.0 * Moved transpile switch to Lua 5.2 (#259) * Moved transpile switch to Lua 5.2 Closes #194 * Fixed typo * Cleaned up ForOf code (#260) * Cleaned up forOf loop, made it use numeric loop instead of ipairs * Fixed bug in non-array loop header and fixed tests * Fixed up some PR comments * passing nil instead of _G as context for global functions when in ES strict mode * fixed logic for determining strict mode * replaced hack-around when passing nil as a function context with a null keyword * testing viability of wrapping context/no-context calls on assignment * working on more function assignment situations * Fix error in module namespace enum exporting (#272) * fixed getting constructor signature and refactored things a bit * checking resolved signature when comparing function types passed as arguments * 0.11.0 * Update CHANGELOG.md * Luajit unpack fix (#273) * LuaJIT uses LuaTranspiler's spread * Added some unit tests for spreading * Stopped using prototype * Removed Transpiler import * Fixed constructor overloads (#275) * Fixed constructor overloads Fixes #274 * Removed lambda body * Removed transpileFile (should be added to changelog since this was exposed in the API) * Lualib omit when unused (#280) * lualib inline omit header when no features are used * Tests to enforce no lualib text when unused, unless using always * Fixed bug with default values for constructor parameters * 0.11.1 * working on assignment checks for methods vs functions * handling context in calls and decls * refactoring and handling tuple destructuring * generalized tuple assignment checking * overloads with function and method signatures default to functions now * preventing non-methods from being passed to bind/call/apply * removed uneccessary helpers * using proper exceptions for function conversion errors * removed context arg from custom constructors and added check for assigning to untyped vars * updated tests * removing leftover NoContext decorators * Added discord badge and link to readme * Added support for JSDoc tags as decorators * Fixed invalid jsdoc failing a test * Added deprecation warning for ! decorators * Refactored decorator creation, made decorators case-insensitive * Fixed jsdoc tests * Fixed test runner not failing * recursing into interfaces during assignment validation * Update README.md * fixes for issues with overloads using different context types * Fixed casing and symbol of decorators to be consistent with the new convention * less-lazy variable naming and improved error message * removing assignments translation test (#296) * Create CONTRIBUTING.md * Update README.md * Detecting types derived from array (#289) * check the base types to determine if a type inherits from Array<T> * dont block exceptions * remove empty else clause * remove space * added tsHelper.isDefaultArrayCallExpression() * added derived array recognition test code * Added isExplicitArrayType() method * added unit test * rewrite isDefaultArrayCall() -> isDefaultArrayCallMethodName() * change switch statement to Set<string> lookup * 0.12.0 * stabilize package lock * Check inherited accessors (#297) * check for inherited accessor methods * diversify test * removed FocusTests and repositioned forAllTypes * rename forTypeOrAnySupertype * Fixed default constructor on subclass (#301) * Use declared types (#302) * update forTypeOrAnySupertype() to use declared type * added test case for accessor using this * enhance test to use generics * 0.12.1 * suite of tests for new functions and fixes for edge-cases found * validating return values and hanlding inference of contexts when passing functions as arguments or return values * renamed getFunctionReturnType to getContainingFunctionReturnType * handling more edge cases, adding more tests and a little bit of refactoring
1 parent e856699 commit e79e42b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1796
-1266
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Changelog
22

3+
## 0.11.0
4+
* Fixed bug when throwing anything that was not a string. (@tomblind)
5+
* Added support for object literal method declarations. (@tomblind)
6+
* Fixed several issues with assignment operators (@tomblind)
7+
* `else if` statements are now transpiled to Lua `elseif` instead of nested ifs statements. (@tomblind)
8+
* Occurrences of const enum values are now directly replaced with their value in the Lua output. (@DoctorGester)
9+
* Rethrowing is now possible from try/catch blocks (@tomblind)
10+
* Destructing statements in LuaJit now use `unpack` instead of `table.unpack`
11+
* Removed support for switch statements for versions <= 5.1.
12+
* Refactored `for ... of` translation, it now uses numeric `for ` loops instead of `ipairs` for performance reasons.
13+
14+
## 0.10.0
15+
* Added support for NonNullExpression (`abc!` transforming the type from `abc | undefined` to `abc`)
16+
* Added expression position to replacement binary expression to improve error messages.
17+
* Fixed various issues with !TupleReturn (@tomblind)
18+
* Added support for `array.reverse`, `array.shift`, `array.unshift`, `array.sort`. (@andreiradu)
19+
* Added translation for `Object.hasOwnProperty()`. (@andreiradu)
20+
* Added support for class expressions (@andreiradu)
21+
* Fixed bug in detecting array types (@tomblind)
22+
* Added public API functions and better webpack functionality.
23+
324
## 0.9.0
425
* Fixed an issue where default parameter values were ignored in function declarations.
526
* Fixed a bug where `self` was undefined in function properties.

CONTRIBUTING.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Contributing to TypeScriptToLua
2+
3+
1) [Project Overview](#project-overview)
4+
2) [Running Tests](#running-tests)
5+
3) [Testing Guidelines](#testing-guidelines)
6+
4) [Coding Conventions](#coding-conventions)
7+
8+
## Project Overview
9+
To get familiar with the project structure, here is a short overview of each directory and their function.
10+
- `src/`
11+
* Source code for the project, has the transpiler core files in its root.
12+
* `src/lualib/`
13+
- Contains the TypeScript source for the lualib. This consists of implementations of standard TypeScript functions that are not present in Lua. These files are compiled to Lua using the transpiler. They are included in the Lua result when transpiling.
14+
* `src/targets/`
15+
- Version-specific transpiler overrides for the different Lua targets. The main transpiler transpiles Lua 5.0, each target-specific transpiler extends the transpiler of the version before it, so the 5.3 inherits 5.2 which inherits 5.1 which inherits 5.0. LuaJIT is based on 5.2 so inherits from the 5.2 transpiler.
16+
* *Compiler.ts* - Main entry point of the transpiler, this is what interfaces with the TypeScript compiler API.
17+
* *Transpiler.ts* - Main transpiler code, transforms a TypeScript AST to a Lua string.
18+
* *TSHelper.ts* - Helper methods used during the transpilation process.
19+
- `test/`
20+
* This directory contains all testing code for the transpiler.
21+
* `test/src/`
22+
- Contains all extra source and utility used to run tests.
23+
* `test/unit/`
24+
- Unit/Functional tests for the transpiler. Tests in here are grouped by functionality they are testing. Generally each of these tests uses the transpiler to transpile some TypeScript to Lua, then executes it using the Fengari Lua VM. Assertion is done on the result of the lua code.
25+
* `test/translation/`
26+
- **[Obsolete]** Contains tests that only check the transpiled Lua String. We prefer adding unit/functional tests over translation tests. This directory will probably be removed at some point.
27+
28+
## Running Tests
29+
The tests for this project can be executed using the standard `npm test`. This runs all tests (can take a while!).
30+
31+
### Testing while developing
32+
Due to the time required to run all tests, it is impractical to run every test while developing part of the transpiler. To speed up the test run you can import `FocusTest` or `FocusTests` from Alsatian. If a class is decorated with `@FocusTests`, all other test classes will be ignored. Similarly, if any test method is decorated with `@FocusTest`, only `@FocusTest` methods will be run during `npm test`.
33+
34+
For example:
35+
```ts
36+
import { Expect, FocusTests, Test, TestCase } from "alsatian";
37+
38+
@FocusTests
39+
export class FunctionTests {
40+
// All tests in here will be executed.
41+
}
42+
43+
// All other tests will be ignored.
44+
```
45+
46+
Or
47+
48+
```ts
49+
import { Expect, FocusTest, Test, TestCase } from "alsatian";
50+
51+
export class FunctionTests {
52+
@FocusTest
53+
@Test("Example test 1")
54+
public test1(): void { // Will be executed
55+
}
56+
57+
@FocusTest
58+
@Test("Example test 2")
59+
public test2(): void { // Will also be executed
60+
}
61+
62+
@Test("Example test 3")
63+
public test3(): void { // Will be ignored
64+
}
65+
}
66+
67+
// All other tests will be ignored.
68+
```
69+
70+
71+
## Testing Guidelines
72+
When submitting a pull request with new functionality, we require some functional (transpile and execute Lua) to be added, to ensure the new functionality works as expected, and will continue to work that way.
73+
74+
Translation tests are discouraged as in most cases as we do not really care about the exact Lua output, as long as executing it results in the correct result (which is tested by functional tests).
75+
76+
## Coding Conventions
77+
Most coding conventions are enforced by the ts-lint configuration. The test process will fail if code does not pass the linter. Some extra conventions worth mentioning:
78+
* Do not abbreviate variable names. The exception here are inline lambda arguments, if it is obvious what the argument is you can abbreviate to the first letter, e.g: `statements.filter(s => ts.VariableStatement(s))`
79+
* Readability of code is more important than the amount of space it takes. If extra line breaks make your code more readable, add them.
80+
* Functional style is encouraged!

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Large projects written in lua can become hard to maintain and make it easy to ma
66
[![Build Status](https://travis-ci.org/Perryvw/TypescriptToLua.svg?branch=master)](https://travis-ci.org/Perryvw/TypescriptToLua)
77
[![Build status](https://ci.appveyor.com/api/projects/status/github/perryvw/typescripttolua?branch=master&svg=true)](https://ci.appveyor.com/project/Perryvw/typescripttolua)
88
[![Coverage](https://codecov.io/gh/perryvw/typescripttolua/branch/master/graph/badge.svg)](https://codecov.io/gh/perryvw/typescripttolua)
9-
[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/TypescriptToLua/Lobby)
9+
10+
You can chat with us on Discord: [![Discord](https://img.shields.io/discord/515854149821267971.svg)](https://discord.gg/BWAq58Y)
1011

1112
## Documentation
1213
More detailed documentation and info on writing declarations can be found [on the wiki](https://github.com/Perryvw/TypescriptToLua/wiki).
@@ -40,6 +41,9 @@ Changelog can be found in [CHANGELOG.md](https://github.com/Perryvw/TypescriptTo
4041
}
4142
```
4243

44+
## Contributing
45+
All contributions are welcome, but please read our [contribution guidelines](https://github.com/Perryvw/TypescriptToLua/blob/master/CONTRIBUTING.md)!
46+
4347
## Declarations
4448
The real power of this transpiler is usage together with good declarations for the Lua API provided. Some examples of Lua interface declarations can be found here:
4549
- [Dota 2 Modding](https://github.com/ModDota/API/tree/master/declarations/server)

0 commit comments

Comments
 (0)