HaxeFoundation / HaxeFoundation/haxe
Type from JSGenApi is different from expected
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
```haxe
// foo/Main.hx
package foo;
@:native('foo')
class Main {
static function main() {
Macro.expr((null:Main));
}
}
// Macro.hx
class Macro {
public static macro function expr(e) {
log('build macro', haxe.macro.Context.typeof(e));
return macro null;
}
#if macro
public static function build() {
haxe.macro.Compiler.setCustomJSGenerator(function(api) {
api.setTypeAccessor(function(type) {
log('js gen', type);
return '';
});
api.generateStatement(api.main);
});
}
#end
static function log(title:String, type:haxe.macro.Type) {
switch type {
case TInst(_.get() => c, _):
trace('$title >>>>>>>>>>');
trace('name = ${c.name}, module = ${c.module}, pack = ${c.pack}');
for(m in c.meta.get()) trace(m);
trace('');
case _:
}
}
}
```
add `--macro Macro.build()` to hxml
Outputs:
```
build macro >>>>>>>>>>
name = Main, module = foo.Main, pack = [foo]
{ name => :native, params => [{ expr => EConst(CString(foo)), pos => #pos(src/foo/Main.hx:3: characters 9-14) }], pos => #pos(src/foo/Main.hx:3: characters 1-8) }
js gen >>>>>>>>>>
name = foo, module = foo.Main, pack = []
{ name => :realPath, params => [{ expr => EConst(CString(foo.Main)), pos => #pos(src/foo/Main.hx:3: characters 9-14) }], pos => #pos(src/foo/Main.hx:3: characters 9-14) }
{ name => :keep, params => [], pos => #pos(src/foo/Main.hx:4: lines 4-8) }
{ name => :used, params => [], pos => #pos(src/foo/Main.hx:4: lines 4-8) }
{ name => :native, params => [{ expr => EConst(CString(foo)), pos => #pos(src/foo/Main.hx:3: characters 9-14) }], pos => #pos(src/foo/Main.hx:3: characters 1-8) }
```
Note that in normal build macro the type is `name = Main, module = foo.Main, pack = [foo]`
while in JSGenApi it becomes: `name = foo, module = foo.Main, pack = []` (name replaced, pack is gone). This only happens when `@:native` meta is present.
I wonder if it is really the expected behavior?
Contributor guide
Assessment
This issue has not been assessed yet.