Enforcing private semantics in Haxe JavaScript ES6 compilation
0 reputation · 09 May 2025, 01:23 UTC
Haxe class members default to public visibility unless explicitly marked private, protected, or internal. This default behavior influences how APIs are exposed when compiling to different targets, particularly JavaScript, where the runtime semantics differ from Haxe's source-level model.
The compiler currently does not enforce true private semantics for JavaScript ES5 output, as generated code exposes members marked private in Haxe source due to JavaScript's historical lack of native private class fields. An ongoing language design discussion considers whether the compiler should generate `#private` fields for ES6+ targets, but this decision remains unresolved in the stable release.
Which visibility modifiers does Haxe preserve when targeting JavaScript ES6+? Does the compiler generate `#private` fields for members marked private in Haxe source? What are the implications for library authors relying on private encapsulation across compilation targets?