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

Allow for dynamic imports using non-static string #24

Open
AStoker opened this issue Feb 24, 2021 · 3 comments
Open

Allow for dynamic imports using non-static string #24

AStoker opened this issue Feb 24, 2021 · 3 comments

Comments

@AStoker
Copy link

AStoker commented Feb 24, 2021

if (node.source.type === 'Literal' && node.source.value.match(/^(?:https?:)?\//)) {

Reference #21

Hate to bring this back up, but it looks like maybe we missed a use case.
The change works perfect for a static url

const viewmodel = await import('https://localhost:44301/dist/external-reports/Unbundled-2/report-view.js');

But doesn't work with a dynamic url like this

const viewmodel = await import(`https://localhost:44301/dist/external-reports/${reportCode}/report-view.js`);

I recognize that we probably can't just make it blankly accept dynamic imports all the time, because perhaps the evaluation of a dynamic string is or isn't an http request. At this point, I'm thinking that there needs to be some kind of configuration to allow import to work as expected in particular scenarios.

@3cp
Copy link
Member

3cp commented Feb 25, 2021

Agree. Config is easy to turn it on/off globally.

How to provide a per file/line config? For example, we still want use transpiled import() to load local route pages, but want to skip transpiling on some import() fetching remote resources.

@AStoker
Copy link
Author

AStoker commented Feb 26, 2021

It would have to be a per-line kind of config, because we might have both use cases in the same file... I hate adding comment directives in code, but that might be a requirement here? Not sure how else we can allow the native imports... Well, another options would be to provide some kind of callback config so whenever we hit an import, we can call a user defined function to determine if we want to transpile or not.

@3cp
Copy link
Member

3cp commented Feb 27, 2021

I also thought about comments. The trouble is the parser I am using is meriyah, it doesn't have comments in AST tree (comment is not defined in estree AST spec). Eslint parser can definitely look into comments.

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