HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.19k stars 655 forks source link

[Haxe/JS] Externs issues doesn't work in Haxe 3.2 #4371

Closed as3boyan closed 9 years ago

as3boyan commented 9 years ago

After updating to Haxe 3.2, I tried to compile Haxe/JS project

which depends on those externs https://github.com/HaxeIDE/HIDE/blob/master/libs/nodejs-std/nodejs/webkit/UI.hx

Haxe 3.0: this used to generate

var nodejs = {}
nodejs.webkit = {}

but in Haxe 3.2 this doesn't happens, I tried @:jsRequire('nw', 'gui') - doesn't works

https://github.com/HaxeIDE/HIDE/blob/master/externs/alertify/Alertify.hx#L22

This is basically hack, I need to access window.alertify but I doesn't want to create additional variable for it.

And they doesn't work anymore, I understand that some of these are hacks(especially second one) and depend on generated code.

Thanks.

as3boyan commented 9 years ago

I can provide generated code if that helps.

nadako commented 9 years ago

That class is not even an extern and is too hacky not to break. Haxe 3.2 has js-flatten enabled by default, so it generates nodejs_webkit_$ui which then fails to be assigned to because of raw js injection that works with nodejs.webkit.$ui.

The following code works good and is the preferred way:

@:jsRequire("nw.gui")
extern class UI {}
as3boyan commented 9 years ago

Thanks making class an extern with jsRequire works. But how to deal with nodejs.webkit.Window = nodejs_webkit_UI.Window; where nodejs is still not defined?

nadako commented 9 years ago

Remove that __init__ and use @:jsRequire("nw.gui", "Window")

nadako commented 9 years ago

Well, @:jsRequire("nw.gui", "Window") generates exactly require('nw.gui').Window

as3boyan commented 9 years ago

Thank you very much for quick solution.

as3boyan commented 9 years ago

To access window.alertify I used @:native("alertify") on extern class, works fine. Everything works. :+1: