ast-types
ast-types copied to clipboard
node.extra for `RegExpLiteral` appears to produce the wrong value
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