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 @@ -279,7 +279,15 @@ class ConstPlugin {
279
279
( expression . operator === "||" && ! bool ) ;
280
280
281
281
if ( param . isBoolean ( ) || keepRight ) {
282
- const dep = new ConstDependency ( `${ bool } ` , param . range ) ;
282
+ // for case like
283
+ //
284
+ // return'development'===process.env.NODE_ENV&&'foo'
285
+ //
286
+ // we need a space before the bool to prevent result like
287
+ //
288
+ // returnfalse&&'foo'
289
+ //
290
+ const dep = new ConstDependency ( ` ${ bool } ` , param . range ) ;
283
291
dep . loc = expression . loc ;
284
292
parser . state . current . addDependency ( dep ) ;
285
293
} 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