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

[BUG] Maximum call stack size exceeded #66

Closed
matthew-dean opened this issue Aug 20, 2023 · 2 comments
Closed

[BUG] Maximum call stack size exceeded #66

matthew-dean opened this issue Aug 20, 2023 · 2 comments

Comments

@matthew-dean
Copy link

Describe the bug
I'm using XRegExp to build complex / nested regular expressions. I'm investigating using ts-macros for this purpose.

Code to reproduce

import * as XRegExp from 'xregexp'

const $buildFragments = (rawFragments: string[][]) => {
  const fragments: Record<string, RegExp> = {}
  rawFragments.forEach(fragment => {
    fragments[fragment[0]] = XRegExp.build(fragment[1], fragments)
  })
  return fragments
}

const fragments: Record<string, RegExp> = $buildFragments!(rawFragments)

(Fragments are regex strings like:)

const fragments = () => [
  ['newline', '\\n|\\r\\n?|\\f'],
  ['whitespace', '[ ]|\\t|{{newline}}'],
  ['ws', '{{whitespace}}+'],
  ['comment', '\\/\\*[^*]*\\*+(?:[^/*][^*]*\\*+)*\\/'],
  ['hex', '[\\da-fA-F]'],
  ['unicode', '\\\\{{hex}}{1,6}{{whitespace}}?']
]

Expected behavior
I expected a static object to be output with a map of regular expressions.

Additional context
Add any other context about the problem here.

@GoogleFeud
Copy link
Owner

Thanks for the bug report! You can only define macros with the function keyword, the code below works correctly:

function $buildFragments(rawFragments: string[][]) {
      const fragments: Record<string, RegExp> = {}
      rawFragments.forEach(fragment => {
      fragments[fragment[0]] = XRegExp.build(fragment[1], fragments)
  })
  return fragments
}

However there's definitely something wrong going on if you try to declare it as an arrow function, I'll look into it!

@matthew-dean
Copy link
Author

@GoogleFeud Ohhhh ha, I didn't think of that, thanks!

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