Skip to content

Commit 085145e

Browse files
committed
fix: c6e7797 should account for evaluation in 2020+
1 parent 8f67c45 commit 085145e

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/compile.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,15 @@ const compileSchema = (schema, root, opts, scope, basePathRoot = '') => {
469469
const nexthistory = () => [...history, { stat, prop: current }]
470470
// Can not be used before undefined check! The one performed by present()
471471
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) => {
475475
if (args[0] === current || noDelta) {
476476
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+
}
478481
if (constval === false) return { sub: format('false'), delta: { type: [] } }
479482
}
480483
const sub = gensym('sub')
@@ -896,10 +899,11 @@ const compileSchema = (schema, root, opts, scope, basePathRoot = '') => {
896899

897900
const suberr = suberror()
898901
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'))
900904
fun.if(sub, () => {
901905
fun.write('%s++', passes)
902-
if (getMeta().containsEvaluates) {
906+
if (ev) {
903907
enforce(!removeAdditional, 'Can\'t use removeAdditional with draft2020+ "contains"')
904908
evaluate()
905909
}
@@ -916,7 +920,7 @@ const compileSchema = (schema, root, opts, scope, basePathRoot = '') => {
916920
}
917921

918922
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')))
920924
if (node.not) uncertain('not')
921925

922926
const thenOrElse = node.then || node.then === false || node.else || node.else === false

0 commit comments

Comments
 (0)