@@ -26,31 +26,29 @@ function transform(babel) {
26
26
return null ;
27
27
}
28
28
29
- let conditions = null ;
30
- for ( const line of comments ) {
31
- const commentStr = line . value . trim ( ) ;
32
- if ( commentStr . startsWith ( GATE_VERSION_STR ) ) {
33
- const condition = t . stringLiteral (
34
- commentStr . slice ( GATE_VERSION_STR . length )
35
- ) ;
36
- if ( conditions === null ) {
37
- conditions = [ condition ] ;
38
- } else {
39
- conditions . push ( condition ) ;
29
+ const resultingCondition = comments . reduce (
30
+ ( accumulatedCondition , commentLine ) => {
31
+ const commentStr = commentLine . value . trim ( ) ;
32
+
33
+ if ( ! commentStr . startsWith ( GATE_VERSION_STR ) ) {
34
+ return accumulatedCondition ;
35
+ }
36
+
37
+ const condition = commentStr . slice ( GATE_VERSION_STR . length ) ;
38
+ if ( accumulatedCondition === null ) {
39
+ return condition ;
40
40
}
41
- }
42
- }
43
41
44
- if ( conditions !== null ) {
45
- let condition = conditions [ 0 ] ;
46
- for ( let i = 1 ; i < conditions . length ; i ++ ) {
47
- const right = conditions [ i ] ;
48
- condition = t . logicalExpression ( '&&' , condition , right ) ;
49
- }
50
- return condition ;
51
- } else {
42
+ return accumulatedCondition . concat ( ' ' , condition ) ;
43
+ } ,
44
+ null
45
+ ) ;
46
+
47
+ if ( resultingCondition === null ) {
52
48
return null ;
53
49
}
50
+
51
+ return t . stringLiteral ( resultingCondition ) ;
54
52
}
55
53
56
54
return {
0 commit comments