switch.jst (1523B)
1 {{# def.definitions }} 2 {{# def.errors }} 3 {{# def.setupKeyword }} 4 {{# def.setupNextLevel }} 5 6 7 {{## def.validateIf: 8 {{# def.setCompositeRule }} 9 {{ $it.createErrors = false; }} 10 {{# def._validateSwitchRule:if }} 11 {{ $it.createErrors = true; }} 12 {{# def.resetCompositeRule }} 13 {{=$ifPassed}} = {{=$nextValid}}; 14 #}} 15 16 {{## def.validateThen: 17 {{? typeof $sch.then == 'boolean' }} 18 {{? $sch.then === false }} 19 {{# def.error:'switch' }} 20 {{?}} 21 var {{=$nextValid}} = {{= $sch.then }}; 22 {{??}} 23 {{# def._validateSwitchRule:then }} 24 {{?}} 25 #}} 26 27 {{## def._validateSwitchRule:_clause: 28 {{ 29 $it.schema = $sch._clause; 30 $it.schemaPath = $schemaPath + '[' + $caseIndex + ']._clause'; 31 $it.errSchemaPath = $errSchemaPath + '/' + $caseIndex + '/_clause'; 32 }} 33 {{# def.insertSubschemaCode }} 34 #}} 35 36 {{## def.switchCase: 37 {{? $sch.if && {{# def.nonEmptySchema:$sch.if }} }} 38 var {{=$errs}} = errors; 39 {{# def.validateIf }} 40 if ({{=$ifPassed}}) { 41 {{# def.validateThen }} 42 } else { 43 {{# def.resetErrors }} 44 } 45 {{??}} 46 {{=$ifPassed}} = true; 47 {{# def.validateThen }} 48 {{?}} 49 #}} 50 51 52 {{ 53 var $ifPassed = 'ifPassed' + it.level 54 , $currentBaseId = $it.baseId 55 , $shouldContinue; 56 }} 57 var {{=$ifPassed}}; 58 59 {{~ $schema:$sch:$caseIndex }} 60 {{? $caseIndex && !$shouldContinue }} 61 if (!{{=$ifPassed}}) { 62 {{ $closingBraces+= '}'; }} 63 {{?}} 64 65 {{# def.switchCase }} 66 {{ $shouldContinue = $sch.continue }} 67 {{~}} 68 69 {{= $closingBraces }} 70 71 var {{=$valid}} = {{=$nextValid}};