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

fix(babel): fixed esm detection in node_modules #1245

Merged
merged 1 commit into from
May 5, 2023
Merged

fix(babel): fixed esm detection in node_modules #1245

merged 1 commit into from
May 5, 2023

Conversation

Anber
Copy link
Collaborator

@Anber Anber commented May 5, 2023

Motivation

Some files in node_modules weren't detected as ESM. See #1242

Summary

The regular expression used to detect the keywords export or import contained an error that resulted in a false negative for ESM files that did not have any imports.

@changeset-bot
Copy link

changeset-bot bot commented May 5, 2023

🦋 Changeset detected

Latest commit: b5031e9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 15 packages
Name Type
@linaria/babel-preset Patch
@linaria/cli Patch
@linaria/esbuild Patch
linaria Patch
@linaria/rollup Patch
@linaria/stylelint Patch
@linaria/testkit Patch
@linaria/vite Patch
@linaria/webpack4-loader Patch
@linaria/webpack5-loader Patch
esbuild-example Patch
rollup-example Patch
vite-example Patch
vpssr-linaria-solid-example Patch
@linaria/webpack-loader Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Anber Anber merged commit 821a681 into master May 5, 2023
@Anber Anber deleted the issue/1242 branch May 5, 2023 11:46
@nstepien
Copy link
Contributor

nstepien commented May 5, 2023

I wonder if this is safe, the import or export words could be in a string in the code for example.
Using babel's parser to get the AST may be safer, no?

@Anber
Copy link
Collaborator Author

Anber commented May 5, 2023

False positive causes just a bit more work, whereas false negative causes errors during the evaluation stage. So, false positive cases are not a big problem.
AST will be safer but more expensive cause we need to parse each file. Theoretically, we can parse only files that contain import or export and then reuse parsed AST, but it requires more complicated rules definition API.

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