-added support for standard array functions#234
-added support for standard array functions#234Perryvw merged 3 commits intoTypeScriptToLua:masterfrom
Conversation
Perryvw
left a comment
There was a problem hiding this comment.
Looks nice, would like some more tests for edge cases as indicated in the comments. We should probably also add them for the other array function tests at some point 🤔
src/Transpiler.ts
Outdated
| if (params.length > 1) { | ||
| return `__TS__${func}(${params.join(", ")})`; | ||
| } else { | ||
| return `__TS__${func}(${params[0]})`; |
There was a problem hiding this comment.
What is the purpose of this if/else? params[0] and params.join(", ") look like they would produce exactly the same result?
There was a problem hiding this comment.
Fixed this. It was intended as a fix for calling with 0 params.
test/unit/lualib/lualib.spec.ts
Outdated
| // Transpile | ||
| const lua = util.transpileString( | ||
| `let testArray = ${array}; | ||
| let val = testArray.shift(); |
There was a problem hiding this comment.
I would like to also have a test that checks the value of val
|
|
||
| public transpileLuaLibFunction(func: LuaLibFeature, ...params: string[]): string { | ||
| this.importLuaLibFeature(func); | ||
| params = params.filter(element => { |
There was a problem hiding this comment.
I still don't understand in what situation element.tostring() would be empty string, could you give an example?
There was a problem hiding this comment.
sure, I hit this when calling array.unshift() with no params
array.shift, array.unshift, array.sort and array.reverse
sort uses table.sort which has slightly different behavior than js. It works by default with items other than string(which I think is a good thing). It's also not guaranteed to be stable.