score:1

Accepted answer

you cannot do that, because @jsimports must be top-level, and macros can only be called in places which are not top-level.

the reason that @jsimport must be top-level is that it does not semantically correspond to require. instead, it corresponds to import in es2015. they desugar into require when targeting commonjs modules, but that is a special case. dynamic uses of require cannot be written in terms of import in es2015, and therefore not in terms of @jsimport either.

now the reason you have to tweak $g.require into require is another issue. it used to be the case that this was simply node.js hijacking javascript in a non-spec-compliant way, and scala.js would not allow you to access it. now it turns out that es2015 kind of makes that special require thing valid-ish, so eventually you'll be able to access it natively in scala.js, through https://github.com/scala-js/scala-js/issues/2800


Related Query

More Query from same tag