systemjs / babel-plugin-transform-global-system-wrapper

Converts global scripts into named System.registerDynamic('name', [], ...
MIT License
4 stars 4 forks source link

Make this transform independent of @@global-helpers #1

Open guybedford opened 7 years ago

guybedford commented 7 years ago

Currently we output by using the @@global-helpers.prepareGlobal method for reading the global as defined in https://github.com/systemjs/systemjs/blob/master/src/format-helpers.js#L284.

This method does global detection as used by SystemJS based on detecting the diff of the global object and making the new globals the resultant module value if there is only one, or an object with the global names as exports if there are multiple, with this behaviour being overridden by the exports metadata.

Ideally this transformer can gain the ability to do this detection as much as possible statically, and while never completely perfect we should be able to get a 99% accuracy for this to get equal behaviour.

guybedford commented 7 years ago

(this would be necessary to support the production loader use case)

asapach commented 7 years ago

I don't think this can be done statically reliably, since there are so many ways to define a global variable, and most of them are dynamic. Inlining @@global-helpers seems more realistic, but that would bloat the output.

guybedford commented 7 years ago

@asapach certainly not with the tools we have today... it's a hard problem. But hard problems are fun :P

asapach commented 7 years ago

Another option is to get rid of automatic detection and rely explicitly on exports metadata. That would make it simpler and more reliable.

guybedford commented 7 years ago

@asapach that would be a good way to start certainly - when the exportName is explicitly provided, the helper shouldn't need to be used at all.