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

support import sync with dynamic expression #1845

Merged
merged 11 commits into from
Apr 9, 2024

Conversation

patricklx
Copy link
Contributor

No description provided.

@patricklx
Copy link
Contributor Author

e.g. ember-svg-jar
image
compiles to
image

@patricklx patricklx marked this pull request as ready for review March 21, 2024 14:55
@patricklx
Copy link
Contributor Author

The screenshot shows keys with extension. That is fixed.
Open question: should we filter by files, so exclude folders? It could be possible that folders have a index.js file

@ef4
Copy link
Contributor

ef4 commented Apr 2, 2024

Thanks, the output of this transformation looks great.

Please remove the BinaryExpression support. It's not always correct (people can use operators other than +) and it doesn't expand out correctly for all the combinations of literals and identifiers. Also the Embroider V2 Addon RFC says that imports (including importSync) only support template strings.

@patricklx
Copy link
Contributor Author

patricklx commented Apr 2, 2024

@ef4 i removed the binary expression support

relativePath = specifier.quasis[0].value.cooked!;
property = specifier.expressions[0];
}
// babel might transform template form `../my-path/${id}` to '../my-path/'.concat(id)
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't notice before that this stuff is distinct from the BinaryExpression support. I don't think it's correct.

Consider:

importSync(`one${two}three${four}`)
// becomes
importSync("one".concat(two, "three").concat(four));

(It would be even better to figure out how to run before preset-env, but I recognize that this is already in an exit hook because it's trying to interoperate with other plugins that adjust the import specifiers themselves.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, i only support "one".concat. this is done by ensuring that the object of the member expression is a string.
one${two}three${four} is also not supported

@ef4 ef4 merged commit ef8eacd into embroider-build:main Apr 9, 2024
90 checks passed
@mansona mansona added the enhancement New feature or request label Apr 10, 2024
@github-actions github-actions bot mentioned this pull request Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants