File tree Expand file tree Collapse file tree 1 file changed +12
-22
lines changed Expand file tree Collapse file tree 1 file changed +12
-22
lines changed Original file line number Diff line number Diff line change @@ -8,30 +8,20 @@ const utils = require('../utils')
88
99/** @param {VElement[] } elements */
1010function isConditionalGroup ( elements ) {
11- let hasIf = false
12- let hasElse = false
13-
14- for ( const element of elements ) {
15- if ( utils . hasDirective ( element , 'if' ) ) {
16- if ( hasIf || hasElse ) {
17- return false
18- }
19- hasIf = true
20- } else if ( utils . hasDirective ( element , 'else-if' ) ) {
21- if ( ! hasIf || hasElse ) {
22- return false
23- }
24- } else if ( utils . hasDirective ( element , 'else' ) ) {
25- if ( ! hasIf || hasElse ) {
26- return false
27- }
28- hasElse = true
29- } else {
30- return false
31- }
11+ if ( elements . length < 2 ) {
12+ return false
3213 }
3314
34- return hasIf && ( elements . length === 1 || hasElse )
15+ const firstElement = element [ 0 ]
16+ const lastElement = elements [ elements . length - 1 ]
17+ const inBetweenElements = elements . slice ( 1 , - 1 )
18+
19+ return (
20+ utils . hasDirective ( firstElement , 'if' ) &&
21+ ( utils . hasDirective ( lastElement , 'else-if' ) ||
22+ utils . hasDirective ( lastElement , 'else' ) ) &&
23+ inBetweenElements . every ( ( element ) => utils . hasDirective ( element , 'else-if' ) )
24+ )
3525}
3626
3727/** @param {VElement[] } elements */
You can’t perform that action at this time.
0 commit comments