You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.5 KiB

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