benmerckx / genes

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

Using 'name' as function name generates flawed Javascript. #68

Closed mikkelmr closed 1 year ago

mikkelmr commented 1 year ago

The code

`class TestClass { public static function name(n : String) : Void { } }

class Main { TestClass.name("Joe"); }`

Produces Javascript that fails with following error:

ComposedComponentEditor.js?t=1685628854343:26 Uncaught TypeError: TestClass.$name is not a function

Somehow the generated javascript uses $name for refencing the function name in calls, but the generated function declaration is named 'name'.

Normal haxe js output generates $name in both the function declaration and when referencing the function.

This only applies to functions named 'name' and I guess it's because in javascript functions have a name property.

benmerckx commented 1 year ago

Thanks for the report. Seems this is the case for "length" and "name".

https://github.com/HaxeFoundation/haxe/blob/fb2492f0c36ef071af87b6f5cbebd678889b47c7/src/generators/genjs.ml#L146

mikkelmr commented 1 year ago

I can confirm that my issue was resolved with the fix for this issue.

Thanks a LOT for the quick response, it's very much appreciated.