File tree 1 file changed +11
-1
lines changed
1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -107,10 +107,20 @@ if (typeof fname !== 'string') {
107
107
process . exit ( 1 ) ;
108
108
}
109
109
110
+ // Special handling for regular expression literal since we need to
111
+ // convert it to a string literal, otherwise it will be decoded
112
+ // as object "{}" and the regular expression would be lost.
113
+ function adjustRegexLiteral ( key , value ) {
114
+ if ( key === 'value' && value instanceof RegExp ) {
115
+ value = value . toString ( ) ;
116
+ }
117
+ return value ;
118
+ }
119
+
110
120
try {
111
121
content = fs . readFileSync ( fname , 'utf-8' ) ;
112
122
syntax = esprima . parse ( content , options ) ;
113
- console . log ( JSON . stringify ( syntax , null , 4 ) ) ;
123
+ console . log ( JSON . stringify ( syntax , adjustRegexLiteral , 4 ) ) ;
114
124
} catch ( e ) {
115
125
console . log ( 'Error: ' + e . message ) ;
116
126
process . exit ( 1 ) ;
You can’t perform that action at this time.
0 commit comments