Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline helpers without globals #65

Closed
lennart-m opened this issue Mar 23, 2021 · 1 comment
Closed

Inline helpers without globals #65

lennart-m opened this issue Mar 23, 2021 · 1 comment

Comments

@lennart-m
Copy link

Hi, I'm heavily using this plugin for SAPUI5 apps. Thanks for this great plugin!

But I am thinking about how this can be adjusted even better for UI5. With UI5 we use custom AMD and custom bundling of apps.
A typical module looks like this:

sap.ui.define([ /* dependencies as strings */ ], (/* resolved dependencies */) => {
  /* module definition */ return 3;
});

The UI5 bundler works best if the first call is sap.ui.define, without any defined global variables. In this case the bundler will extract all dependencies and use this information to optimize the bundle.

But when using this plugin (even with inlineHelpers activated) some of the helpers (like _catch, _finally) get inserted on the top level, before the sap.ui.define call.
Would it be possible to insert the inline helpers directly in the function where they are used, or maybe have some kind of "target" variable/comment that determines where the helpers are to be inserted?
I'm thinking of something like this:

sap.ui.define([], () => {
let _finally; // plugin automatically inserts helper code here
// or:
/* babel-plugin-transform-async-to-promises target */
});

Alternatively I might try to use the provided helpers but I would have to convert them to use the custom AMD syntax.

My current workaround is using babel-plugin-iife-wrap in order not to have global variables in my modules, but this just removes bundler warnings about global variables; extraction of dependencies still does not work.

Thanks a lot!

@rpetrich
Copy link
Owner

I suspect that transform-async-to-promises is processing the output of your custom bundling step rather than the other way around. Could you describe your bundling setup in more detail if this is still an issue for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants