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

node.extra for RegExpLiteral appears to produce the wrong value #900

Open
yjwong opened this issue Jan 8, 2023 · 0 comments
Open

node.extra for RegExpLiteral appears to produce the wrong value #900

yjwong opened this issue Jan 8, 2023 · 0 comments

Comments

@yjwong
Copy link

yjwong commented Jan 8, 2023

I'm currently using jscodeshift to implement some codemod. While using builders.regExpLiteral, I noticed any kind of regular expression was being output as /undefined/.

I managed to get a reproducer using this code:

import { builders as b, getFieldValue } from 'ast-types';
const node = b.regExpLiteral('test', ''); 

console.log(getFieldValue(node, 'extra'));

The output was:

{ rawValue: /test/, raw: '/undefined/' }

The expected output is:

{ rawValue: /test/, raw: '/test/' }

Upon investigation, it appears that this line is accessing the .pattern property of a RegExp object, which doesn't seem to exist according to MDN. If the .pattern access is replaced with .source, the output becomes correct.

Version information:

  • ast-types: 0.15.2 and 0.16.0.
  • Node.js: v18.12.1
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

1 participant