kevinresol / hxgenjs

Extensible JS generator for Haxe
57 stars 16 forks source link

@:jsRequire object to load from module, not supported by hxgenjs? #21

Closed fullofcaffeine closed 6 years ago

fullofcaffeine commented 6 years ago

I'm using the latest version of hxgenjs and I have the following extern class:

package externs.angular;

@:jsRequire('@angular/platform-browser-dynamic', 'platformBrowserDynamic')
  extern class PlatformBrowserDynamic implements Dynamic {
    @:selfCall public function new() {}
 }

As far as I understand, the @:jsRequire above should generate something like:

function externs_angular_PlatformBrowserDynamic() {return require("@angular/platform-browser-dynamic").platformBrowserDynamic;}

But it's generating it without the call to the platformBrowserDynamic object:

function externs_angular_PlatformBrowserDynamic() {return require("@angular/platform-browser-dynamic");}

The documentation for @:jsRequire (https://haxe.org/manual/target-javascript-require.html) states that the second argument to the metatag is an object to load from module.

Am I missing something here or does that mean that this functionality is not implemented in hxgenjs for the @:jsRequire tag?

Thanks in advance!

kevinresol commented 6 years ago

iirc the field access part should be generated at the call site, can you see the following code somewhere?

externs_angular_PlatformBrowserDynamic().platformBrowserDynamic
fullofcaffeine commented 6 years ago

Yeah, it does. My bad :(

 11 var $hxClasses = require("./hxClasses_stub").default;
 12 var $import = require("./import_stub").default;
 13 function externs_angular_PlatformBrowserDynamic() {return require("@angular/platform-browser-dynamic");}
 14 function App() {return require("./App");}
 15
 16 // Constructor
 17
 18 class Main {
 19   constructor(){}
 20   static main() {
 21     (externs_angular_PlatformBrowserDynamic().platformBrowserDynamic)().bootstrapModule((App().default));
 22   }
 23 }
 24

Thanks for the prompt response. Closing this.