File tree Expand file tree Collapse file tree 2 files changed +18
-14
lines changed
packages/webcrack/src/unminify Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Original file line number Diff line number Diff line change @@ -63,3 +63,6 @@ test('ignore other operators', () =>
6363
6464test ( 'ignore when right side is a literal' , ( ) =>
6565 expectJS ( '1 === 2' ) . toMatchInlineSnapshot ( '1 === 2;' ) ) ;
66+
67+ test ( 'ignore when both sides are pure values' , ( ) =>
68+ expectJS ( 'NaN == Infinity' ) . toMatchInlineSnapshot ( `NaN == Infinity;` ) ) ;
Original file line number Diff line number Diff line change @@ -23,22 +23,23 @@ export default {
2323 name : 'yoda' ,
2424 tags : [ 'safe' ] ,
2525 visitor : ( ) => {
26+ const pureValue = m . or (
27+ m . stringLiteral ( ) ,
28+ m . numericLiteral ( ) ,
29+ m . unaryExpression (
30+ '-' ,
31+ m . or ( m . numericLiteral ( ) , m . identifier ( 'Infinity' ) ) ,
32+ ) ,
33+ m . booleanLiteral ( ) ,
34+ m . nullLiteral ( ) ,
35+ m . identifier ( 'undefined' ) ,
36+ m . identifier ( 'NaN' ) ,
37+ m . identifier ( 'Infinity' ) ,
38+ ) ;
2639 const matcher = m . binaryExpression (
2740 m . or ( ...Object . values ( FLIPPED_OPERATORS ) ) ,
28- m . or (
29- m . stringLiteral ( ) ,
30- m . numericLiteral ( ) ,
31- m . unaryExpression (
32- '-' ,
33- m . or ( m . numericLiteral ( ) , m . identifier ( 'Infinity' ) ) ,
34- ) ,
35- m . booleanLiteral ( ) ,
36- m . nullLiteral ( ) ,
37- m . identifier ( 'undefined' ) ,
38- m . identifier ( 'NaN' ) ,
39- m . identifier ( 'Infinity' ) ,
40- ) ,
41- m . matcher ( ( node ) => ! t . isLiteral ( node ) ) ,
41+ pureValue ,
42+ m . matcher ( ( node ) => ! pureValue . match ( node ) ) ,
4243 ) ;
4344
4445 return {
You can’t perform that action at this time.
0 commit comments