if.jst 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. {{# def.definitions }}
  2. {{# def.errors }}
  3. {{# def.setupKeyword }}
  4. {{# def.setupNextLevel }}
  5. {{## def.validateIfClause:_clause:
  6. {{
  7. $it.schema = it.schema['_clause'];
  8. $it.schemaPath = it.schemaPath + '._clause';
  9. $it.errSchemaPath = it.errSchemaPath + '/_clause';
  10. }}
  11. {{# def.insertSubschemaCode }}
  12. {{=$valid}} = {{=$nextValid}};
  13. {{? $thenPresent && $elsePresent }}
  14. {{ $ifClause = 'ifClause' + $lvl; }}
  15. var {{=$ifClause}} = '_clause';
  16. {{??}}
  17. {{ $ifClause = '\'_clause\''; }}
  18. {{?}}
  19. #}}
  20. {{
  21. var $thenSch = it.schema['then']
  22. , $elseSch = it.schema['else']
  23. , $thenPresent = $thenSch !== undefined && {{# def.nonEmptySchema:$thenSch }}
  24. , $elsePresent = $elseSch !== undefined && {{# def.nonEmptySchema:$elseSch }}
  25. , $currentBaseId = $it.baseId;
  26. }}
  27. {{? $thenPresent || $elsePresent }}
  28. {{
  29. var $ifClause;
  30. $it.createErrors = false;
  31. $it.schema = $schema;
  32. $it.schemaPath = $schemaPath;
  33. $it.errSchemaPath = $errSchemaPath;
  34. }}
  35. var {{=$errs}} = errors;
  36. var {{=$valid}} = true;
  37. {{# def.setCompositeRule }}
  38. {{# def.insertSubschemaCode }}
  39. {{ $it.createErrors = true; }}
  40. {{# def.resetErrors }}
  41. {{# def.resetCompositeRule }}
  42. {{? $thenPresent }}
  43. if ({{=$nextValid}}) {
  44. {{# def.validateIfClause:then }}
  45. }
  46. {{? $elsePresent }}
  47. else {
  48. {{?}}
  49. {{??}}
  50. if (!{{=$nextValid}}) {
  51. {{?}}
  52. {{? $elsePresent }}
  53. {{# def.validateIfClause:else }}
  54. }
  55. {{?}}
  56. if (!{{=$valid}}) {
  57. {{# def.extraError:'if' }}
  58. }
  59. {{? $breakOnError }} else { {{?}}
  60. {{??}}
  61. {{? $breakOnError }}
  62. if (true) {
  63. {{?}}
  64. {{?}}