X Tutup
Skip to content

New functions#307

Merged
Perryvw merged 17 commits intomasterfrom
new-functions
Dec 22, 2018
Merged

New functions#307
Perryvw merged 17 commits intomasterfrom
new-functions

Conversation

@Perryvw
Copy link
Member

@Perryvw Perryvw commented Dec 15, 2018

Rework of how functions are transpiled, adds bind/apply/call methods.

Closes #250, #192, #281

Perryvw and others added 14 commits October 18, 2018 21:45
* initial re-work of function transpiling, including NoContext decorator

* added lib function for bind()

* decorated lib functions with NoContext

* added apply and call lib functions

* checking type aliases for custom decorators to fix tslint issues with new lib functions
* initial re-work of function transpiling, including NoContext decorator

* added lib function for bind()

* decorated lib functions with NoContext

* added apply and call lib functions

* checking type aliases for custom decorators to fix tslint issues with new lib functions

* injecting JSONStringify decl directly into transpileString for tests
#271)

* 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
* 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

* fixed getting constructor signature and refactored things a bit

* checking resolved signature when comparing function types passed as arguments

* 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
* recursing into interfaces during assignment validation
* 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

* fixed getting constructor signature and refactored things a bit

* checking resolved signature when comparing function types passed as arguments

* 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

* recursing into interfaces during assignment validation

* fixes for issues with overloads using different context types

* less-lazy variable naming and improved error message
* 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

* fixed getting constructor signature and refactored things a bit

* checking resolved signature when comparing function types passed as arguments

* 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

* recursing into interfaces during assignment validation

* fixes for issues with overloads using different context types

* less-lazy variable naming and improved error message

* suite of tests for new functions and fixes for edge-cases found
* 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

* fixed getting constructor signature and refactored things a bit

* checking resolved signature when comparing function types passed as arguments

* 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

* recursing into interfaces during assignment validation

* fixes for issues with overloads using different context types

* less-lazy variable naming and improved error message

* 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
* 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

* fixed getting constructor signature and refactored things a bit

* checking resolved signature when comparing function types passed as arguments

* 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

* recursing into interfaces during assignment validation

* fixes for issues with overloads using different context types

* less-lazy variable naming and improved error message

* 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
* 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
@Perryvw Perryvw requested review from lolleko and tomblind December 15, 2018 18:09
# Conflicts:
#	src/TSHelper.ts
#	src/Transpiler.ts
#	test/runner.ts
#	test/src/util.ts
@@ -1,6 +1,6 @@
classInstance:colonMethod();
classInstance.dotMethod();
classInstance:dotMethod();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably get rid of this translation test. It's fully covered by functional tests and doesn't even make sense with how functions are transpiled now.

Copy link
Collaborator

@tomblind tomblind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great - thanks for adding the additional tests.

@TheLartians
Copy link
Contributor

When casting types, the transpiler wrongly accepts methods as functions.

interface Callbacks { callback:(this:void,i:number)=>number }
let callbacks = <Callbacks>{ callback:(i)=>{ return 2*i; } }
callbacks.callback(2) // arithmetic on nil

I believe the second line should throw an unsupported conversion error.
Transpiled lua code for reference:

local callbacks = {callback = function(____,i)
    return 2*i
end};
callbacks.callback(2);

@tomblind
Copy link
Collaborator

@TheLartians Good catch - we can probably add validation to casts pretty easily. But I'll probably do it as a separate pr once things are merged.

# Conflicts:
#	src/TSHelper.ts
@Perryvw Perryvw merged commit 463a4ea into master Dec 22, 2018
@tomblind tomblind deleted the new-functions branch December 23, 2018 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

X Tutup