File tree 6 files changed +26
-2
lines changed
fixtures/form/ternary-operator
6 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -74,9 +74,10 @@ export default function replace(options = {}) {
74
74
if ( objectGuards ) expandTypeofReplacements ( replacements ) ;
75
75
const functionValues = mapToFunctions ( replacements ) ;
76
76
const keys = Object . keys ( functionValues ) . sort ( longest ) . map ( escape ) ;
77
- const lookahead = preventAssignment ? '(?!\\s*(=[^=]|:[^:]))' : '' ;
77
+ const lookbehind = preventAssignment ? '(?<!\\b(?:const|let|var)\\s*)' : '' ;
78
+ const lookahead = preventAssignment ? '(?!\\s*=[^=])' : '' ;
78
79
const pattern = new RegExp (
79
- `${ delimiters [ 0 ] } (${ keys . join ( '|' ) } )${ delimiters [ 1 ] } ${ lookahead } ` ,
80
+ `${ lookbehind } ${ delimiters [ 0 ] } (${ keys . join ( '|' ) } )${ delimiters [ 1 ] } ${ lookahead } ` ,
80
81
'g'
81
82
) ;
82
83
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ description : "replaces value inside ternary operators" ,
3
+ options : {
4
+ condition : 'first' ,
5
+ exprIfTrue : 'second' ,
6
+ exprIfFalse : 'third' ,
7
+ preventAssignment : true
8
+ }
9
+ } ;
Original file line number Diff line number Diff line change
1
+ /* eslint-disable */
2
+ condition ? exprIfTrue : exprIfFalse ;
3
+ console . log ( condition , exprIfTrue , exprIfFalse ) ;
Original file line number Diff line number Diff line change
1
+ /* eslint-disable */
2
+ first ? second : third ;
3
+ console . log ( first , second , third ) ;
Original file line number Diff line number Diff line change @@ -87,6 +87,14 @@ Generated by [AVA](https://avajs.dev).
87
87
replaced.doSomething()␊
88
88
\`);`
89
89
90
+ ## ternary-operator: replaces value inside ternary operators
91
+
92
+ > Snapshot 1
93
+
94
+ `/* eslint-disable */␊
95
+ first ? second : third;␊
96
+ console.log(first, second, third);`
97
+
90
98
## typescript-declare: doesn't replace lvalue in typescript declare
91
99
92
100
> Snapshot 1
You can’t perform that action at this time.
0 commit comments