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

Add support for dynamic imports #54

Merged
merged 2 commits into from
Aug 21, 2020
Merged

Conversation

bnf
Copy link
Contributor

@bnf bnf commented Aug 21, 2020

They are mapped to a promise that uses require()
in the background. Therefore "require" is added as dependency.

This PR raises abstract-syntax-tree dependnecy to at least 2.8 to
provide support for ImportExpression.

Also side-effect-middle test case is fixed, as that failed for me, due to another default ordering.

The sorting function needs to cope for
ordering in both directions, therefore
we add the inverse check as well.
They are mapped to a promise that uses require()
in the background. Therefore require() is added as dependency.

Raise abstract-syntax-tree dependnecy to at least 2.8 to
provide support for ImportExpression.
Copy link
Contributor

@emilos emilos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks :) would be nice to double check cases like:

Promise.all([
  import('foo.js'),
  import('bar.js')
]

or chained imports, like:

import('foo.js').then(() => {
  return import('bar.js')
})

I'll just merge as is, good start :)

@emilos emilos merged commit 565a858 into buxlabs:master Aug 21, 2020
@bnf
Copy link
Contributor Author

bnf commented Aug 21, 2020

Thank you for the quick merge and the release – and this tool. :)

would be nice to double check cases like:

You are right, added in #55

@bnf
Copy link
Contributor Author

bnf commented Sep 1, 2020

Hey, I missed one point, regarding default exports. Sorry for that.

ES6 compatible code needs to use the .default property, which isn't available with AMD modules generated by @buxlabs/es6-to-amd, because the default export is mapped directly to a return (which is nice in general):

One might want to write the following invalid code, that currently works:

import('foo').then(foo => {
  // use default export, this is invalid but currently works
  console.log(foo);
});

To be ES2020 compatible that code needs to read:

import('foo').then(foo => {
  // Use default export of 'foo' module
  console.log(foo.default);
});

With the current implementation the correct code wouldn't work, as default wouldn't be available.
Therefore we could some automagic that wraps the module in an object with a default property, if it is the default export.
That is of course not always easy to guess, and gets a bit ugly. Please see #57 for a workaround that would/could work.

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

Successfully merging this pull request may close these issues.

2 participants