File tree 1 file changed +15
-0
lines changed
1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ function calculateBinaryExpression(path) {
50
50
* - the operator is `!` and the argument is ArrayExpression or Literal.
51
51
* - the operator is `-` and the argument is a negative number
52
52
* - the operator is `+`, or `~`, and the argument is a number
53
+ * - the operator is 'void' and the argument is Literal.
54
+ * - the operator is 'typeof' and the argument is Literal.
53
55
*
54
56
* Otherwise, the expression can't be simplified.
55
57
* For example, `typeof window` can be calculated but it's not constant.
@@ -84,6 +86,19 @@ function calculateUnaryExpression(path) {
84
86
}
85
87
return
86
88
}
89
+ if ( node0 . operator === 'void' ) {
90
+ if ( isLiteral ) {
91
+ path . replaceWith ( t . identifier ( 'undefined' ) )
92
+ }
93
+ return
94
+ }
95
+ if ( node0 . operator === 'typeof' ) {
96
+ if ( isLiteral ) {
97
+ const code = generator ( node0 ) . code
98
+ path . replaceWith ( t . stringLiteral ( eval ( code ) ) )
99
+ }
100
+ return
101
+ }
87
102
}
88
103
89
104
module . exports = {
You can’t perform that action at this time.
0 commit comments