Closed kevinresol closed 4 years ago
Webpack actually emits a warning:
560:0-5 "export 'default' (imported as 'Utils') was not found in 'react-three-fiber'
We could generate this?
import * as Utils from 'react-three-fiber'
But then I wouldn't be quite sure how to require default. Would that be @:jsRequire('package', 'default')
only?
Gave the above a go. It fails this test: https://github.com/benmerckx/genes/blob/20f8b140847a2e94dc1efd2e840abdd5fb89e96b/tests/TestRequire.hx#L3
When imported as import * as Assert from "assert"
it fail with 'Assert is not a function'
.
Because of @:selfCall
here it actually requires a default import:
https://github.com/HaxeFoundation/hxnodejs/blob/1201320d159a583e613d3076eb00850ffeac57ca/src/js/node/Assert.hx#L56
And I realize there's more than a few instances where a default require is expected: https://grep.app/search?q=%40%3AjsRequire%5C%28%5B%5E%5C%2C%29%5D%2A%5C%29®exp=true
I'm thinking of either processing the class and checking if it only has statics or providing some custom metadata to generate asterisk imports.
@:genes.wildcardImport
?
Meta is easier for the macro.
Processing the class would be easier for user. I guess the requirements are as follow (any more?)
@:jsRequire
has only one argument@:selfCall
How about implementing the metadata solution first so that I can continue testing on my codebase?
Yeah, I'll try it this week
I tried the "check for only statics" way.
In ES it is written as:
In Haxe:
Haxe-generated js (works):
but genes generates (doesn't work):
which is then translated by webpack into:
Note the
default
field access is invalid because the originalexport
is notdefault
: