Don't output parameter initializer statement if default value is nil#1424
Conversation
| context.transformExpression(value) | ||
| ); | ||
| const statements = [...precedingStatements]; | ||
| if (!lua.isNilLiteral(parameterValue)) { |
There was a problem hiding this comment.
Couldn't we do that at the top of the function? Check ts.isUndefinedLiteral || ts.isNullLiteral? That way we can avoid a whole bunch of transformations.
There was a problem hiding this comment.
Doing this makes this the most general; it applies to anything that results in a nil literal (casts/parenthesis/etc, language extensions, plugins) and shouldn't have any performance impact.
| const lua = builder.getMainLuaCodeChunk(); | ||
| expect(lua).not.toMatch(" x = nil"); | ||
| }) | ||
| .expectToEqual(["bar", "nil", "baz"]); |
There was a problem hiding this comment.
Would prefer if you could just use expectToMatchJsResult here, using default TS (no language extensions) with an object and helper function for example.
There was a problem hiding this comment.
Could you give a more detailed example what that could look like?
Besides using language extensions, I can't think of a good method that transpiles to nil (not just returns undefined) that works both in JS and lua.
There was a problem hiding this comment.
Oh I see what you are testing now, that seems maybe a bit too specific but okay
Closes #1422
Also fixes #1423