HaxeFoundation / HaxeFoundation/haxe

Feature Request: Support for renaming methods, classes, variables, etc.

Open
#12,216 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Currently in Haxe, we can use @:native or @:jsName to control how classes, methods, and fields are named in the generated output. However, these approaches are either target-specific or not fully consistent across all backends.

I propose introducing a new built-in metadata: `@:rename`.

The idea is simple:
- `@:rename` would allow developers to rename classes, methods, and fields **independently of the target platform**.
- It would be handled directly by the Haxe compiler, ensuring consistent behavior across all targets
- It would **only** affect the output symbol names, without changing the runtime behavior (unless otherwise specified).

**Example:**

```haxe
@:rename("CoolClass")
class MyClass {
@:rename("doStuff")
public function myMethod() {
trace("Doing something!");
}
}
```

Generated JavaScript (for example):

```js
class CoolClass {
doStuff() {
console.log("Doing something!");
}
}
```

### Why this is useful:

- Easier integration with external APIs expecting certain names.
- Better control over output when targeting multiple platforms.
- Supports code obfuscation and minification without losing readability at the source level.
- Cleaner and more predictable output across targets.

### Important notes:

This is different from @:native, which usually implies binding to an external object or API.

Reflection behavior (Type.resolveClass, Reflect.field, etc.) needs to be clearly defined: whether it refers to the original or renamed symbols (probably original for internal Haxe consistency).

Conclusion: A native @:rename metadata would provide developers with a clean, consistent way to control output symbol names without relying on target-specific hacks. It would make cross-platform development smoother and more flexible.

The original concept was implemented in [hxobfuscator](https://github.com/markknol/hxobfuscator) with some hacks.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing how the compiler currently handles @:native and @:jsName, then compare the original hxobfuscator implementation. Clarify symbol-renaming and reflection semantics across classes, methods, fields, and all backends. Done requires an agreed design and consistent compiler support, but the issue names no files or tests.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.