@@ -469,12 +469,15 @@ const compileSchema = (schema, root, opts, scope, basePathRoot = '') => {
469
469
const nexthistory = ( ) => [ ...history , { stat, prop : current } ]
470
470
// Can not be used before undefined check! The one performed by present()
471
471
const rule = ( ...args ) => visit ( errors , nexthistory ( ) , ...args ) . stat
472
- const subrule = ( ...args ) => subruleImpl ( false , ...args )
473
- const subruleSub = ( ...args ) => subruleImpl ( true , ...args ) . sub
474
- const subruleImpl = ( noDelta , suberr , ...args ) => {
472
+ const subrule = ( ...args ) => subruleImpl ( false , false , ...args )
473
+ const subruleSub = ( noEval , ...args ) => subruleImpl ( true , noEval , ...args ) . sub
474
+ const subruleImpl = ( noDelta , noEval , suberr , ...args ) => {
475
475
if ( args [ 0 ] === current || noDelta ) {
476
476
const constval = constantValue ( args [ 1 ] )
477
- if ( constval === true ) return { sub : format ( 'true' ) , delta : { } }
477
+ // We can optimize out only false _or_ when we don't need evaluation
478
+ if ( args [ 0 ] === current || noEval ) {
479
+ if ( constval === true ) return { sub : format ( 'true' ) , delta : { } }
480
+ }
478
481
if ( constval === false ) return { sub : format ( 'false' ) , delta : { type : [ ] } }
479
482
}
480
483
const sub = gensym ( 'sub' )
@@ -896,10 +899,11 @@ const compileSchema = (schema, root, opts, scope, basePathRoot = '') => {
896
899
897
900
const suberr = suberror ( )
898
901
iterate ( ( prop , evaluate ) => {
899
- const sub = subruleSub ( suberr , prop , node . contains , subPath ( 'contains' ) )
902
+ const ev = getMeta ( ) . containsEvaluates
903
+ const sub = subruleSub ( ! ev , suberr , prop , node . contains , subPath ( 'contains' ) )
900
904
fun . if ( sub , ( ) => {
901
905
fun . write ( '%s++' , passes )
902
- if ( getMeta ( ) . containsEvaluates ) {
906
+ if ( ev ) {
903
907
enforce ( ! removeAdditional , 'Can\'t use removeAdditional with draft2020+ "contains"' )
904
908
evaluate ( )
905
909
}
@@ -916,7 +920,7 @@ const compileSchema = (schema, root, opts, scope, basePathRoot = '') => {
916
920
}
917
921
918
922
const checkGeneric = ( ) => {
919
- handle ( 'not' , [ 'object' , 'boolean' ] , ( not ) => subruleSub ( null , current , not , subPath ( 'not' ) ) )
923
+ handle ( 'not' , [ 'object' , 'boolean' ] , ( not ) => subruleSub ( true , null , current , not , subPath ( 'not' ) ) )
920
924
if ( node . not ) uncertain ( 'not' )
921
925
922
926
const thenOrElse = node . then || node . then === false || node . else || node . else === false
0 commit comments