benmerckx / genes

Generates split ES6 modules and Typescript definitions from Haxe modules.
44 stars 8 forks source link

Adds function arguments default values. #3

Closed Sanva closed 4 years ago

benmerckx commented 4 years ago

This is great, I completely missed default values (assumed haxe would present these in the function body instead). Since we have emitValue for this purpose I used that instead. The difference is in expressions that wouldn't be a value in javascript. For example:

var value = if (true) 1 else 2;

Which is valid haxe code but the if expression must be emitted as value.

// with emitExpr
var value = if (true) 1 else 2; // invalid js
// with emitValue
var value = (true) ? 1 : 2; // valid js

Because default parameters are expected to be constant this works with emitExpr as well. But haxe could eventually support other expressions too. Since we're outputting as a value the Const(_) check can go too.