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

[vite-plugin-require-context] Import fails when the regular expression contains , #44

Open
am-ma opened this issue Mar 3, 2023 · 1 comment

Comments

@am-ma
Copy link

am-ma commented Mar 3, 2023

Versions

  • originjs: v1.0.9
  • node: v18.12.1

Steps to reproduce

  • setup vite-plugin-require-context
  • use require.context with the regular expression contains ,
    • ex. require.context(/[a-Z,]+.js/)

What is Expected?

  • Import must not fail

What is actually happening?

  • Import fails
    • because the following code causes the regular expression to be split in the middle.
    • const params = paramsSyntax.split(','); (lib/index.js: 54)
SyntaxError: Invalid regular expression: missing /
❯ node_modules/@originjs/vite-plugin-require-context/lib/index.js:57:40
❯ TransformContext.transform node_modules/@originjs/vite-plugin-require-context/lib/index.js:52:35
@PeterAlfredLee
Copy link
Member

Hi @am-ma

vite-plugin-require-context uses regexp to find all occurences of require.context syntax, and then extract the parameters from the regexp. Therefore, I have to use comma as the split character.

Seems I have to use AST instead of regexp to handle your case, which I do not expect to happen. If you have any better ideas, feel free to tell me. :)

For your issue, I do not have a good enough solution but to remove comma in your regexp.

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