File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
test/cases/parsing/evaluate Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -291,7 +291,15 @@ class ConstPlugin {
291
291
( expression . operator === "||" && ! bool ) ;
292
292
293
293
if ( param . isBoolean ( ) || keepRight ) {
294
- const dep = new ConstDependency ( `${ bool } ` , param . range ) ;
294
+ // for case like
295
+ //
296
+ // return'development'===process.env.NODE_ENV&&'foo'
297
+ //
298
+ // we need a space before the bool to prevent result like
299
+ //
300
+ // returnfalse&&'foo'
301
+ //
302
+ const dep = new ConstDependency ( ` ${ bool } ` , param . range ) ;
295
303
dep . loc = expression . loc ;
296
304
parser . state . current . addDependency ( dep ) ;
297
305
} else {
Original file line number Diff line number Diff line change @@ -11,12 +11,15 @@ it("should evaluate logical expression", function() {
11
11
var value4 = typeof require !== "function" && require ( "fail" ) ;
12
12
var value5 = "hello" && ( ( ) => "value5" ) ( ) ;
13
13
var value6 = "" || ( ( ) => "value6" ) ( ) ;
14
+ var value7 = ( function ( ) { return 'value7' === typeof 'value7' && 'value7' } ) ( ) ;
15
+
14
16
expect ( value1 ) . toBe ( "hello" ) ;
15
17
expect ( value2 ) . toBe ( true ) ;
16
18
expect ( value3 ) . toBe ( "" ) ;
17
19
expect ( value4 ) . toBe ( false ) ;
18
20
expect ( value5 ) . toBe ( "value5" ) ;
19
21
expect ( value6 ) . toBe ( "value6" ) ;
22
+ expect ( value7 ) . toBe ( false ) ;
20
23
} ) ;
21
24
22
25
if ( "shouldn't evaluate expression" , function ( ) {
You can’t perform that action at this time.
0 commit comments