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.
I'm currently using
jscodeshift
to implement some codemod. While usingbuilders.regExpLiteral
, I noticed any kind of regular expression was being output as/undefined/
.I managed to get a reproducer using this code:
The output was:
The expected output is:
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: