Skip to content

Conversation

@Poliklot
Copy link
Contributor

@Poliklot Poliklot commented Jul 1, 2025

Types of changes

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • docs change
  • breaking change

Motivation / Use-Case

This PR fixes a bug in the stripComments function, which incorrectly treated comment-like syntax (//, /* */)
inside regular expressions as actual comments. This led to invalid output JS when processing .hbs templates with
helper files containing such patterns.

Example that caused the error:

const SEP = /(\s|&nbsp;|<br\s*\/?>)+/gi;
const firstPart = parts.join(''); // magic comment

In large projects, this resulted in:

Module parse failed: Unexpected token
result.push is not a function

This PR resolves #180 by improving the parsing logic
to recognize and correctly skip over RegExp literals, including those containing //, /*, and character classes.

Breaking Changes

None.

Additional Info

This is my first detailed pull request — I hope everything is correct!
Let me know if anything needs to be changed — happy to fix it.


Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have updated the CHANGELOG.md.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Appreciation for the useful project

  • Do not forget to give a star ⭐

@webdiscus webdiscus added the enhancement New feature or request label Jul 1, 2025
@webdiscus webdiscus added this to the test milestone Jul 1, 2025
@webdiscus
Copy link
Owner

@Poliklot,

Thanks for your contribution!

I have added tests for stripComments.test.js.

Can you please add your tests for RegExp?

@Poliklot
Copy link
Contributor Author

Poliklot commented Jul 2, 2025

@webdiscus,

Added the RegExp tests—everything passes locally.
If you need anything else tweaked, just let me know and I’ll update.🫡

@webdiscus webdiscus merged commit fa459b1 into webdiscus:master Jul 2, 2025
4 checks passed
@webdiscus
Copy link
Owner

@Poliklot

Thank you for the improvement!
I will publish a fixed version soon.

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.

Mysterious Build Failure When Importing Modal Template in Large Project

2 participants