license import { DEBUG } from "./global" ; import { NameOrCtorDef } from "./types" ; /**
 * Keeps track whether or not we are in an attributes declaration (after
 * elementOpenStart, but before elementOpenEnd).
 */ let inAttributes = false ; /**
 * Keeps track whether or not we are in an element that should not have its
 * children cleared.
 */ let inSkip = false ; /**
 * Keeps track of whether or not we are in a patch.
 */ let inPatch = false ; param val returns function assert < T extends { } > ( val ) { if ( DEBUG && ! val ) { throw new Error ( "Expected value to be defined" ) ; } return val ! ; } param functionName function assertInPatch ( functionName ) { if ( ! inPatch ) { throw new Error ( "Cannot call " + functionName + "() unless in patch." ) ; } } param openElement param root function assertNoUnclosedTags ( openElement , root ) { if ( openElement === root ) { return ; } let currentElement = openElement ; const openTags = [ ] ; while ( currentElement && currentElement !== root ) { openTags . push ( currentElement . nodeName . toLowerCase ( ) ) ; currentElement = currentElement . parentNode ; } throw new Error ( "One or more tags were not closed:\n" + openTags . join ( "\n" ) ) ; } param parent function assertPatchOuterHasParentNode ( parent ) { if ( ! parent ) { console . warn ( "patchOuter requires the node have a parent if there is a key." ) ; } } param functionName function assertNotInAttributes ( functionName ) { if ( inAttributes ) { throw new Error ( functionName + "() can not be called between " + "elementOpenStart() and elementOpenEnd()." ) ; } } param functionName function assertNotInSkip ( functionName ) { if ( inSkip ) { throw new Error ( functionName + "() may not be called inside an element " + "that has called skip()." ) ; } } param functionName function assertInAttributes ( functionName ) { if ( ! inAttributes ) { throw new Error ( functionName + "() can only be called after calling " + "elementOpenStart()." ) ; } } /**
 * Makes sure the patch closes virtual attributes call
 */ function assertVirtualAttributesClosed ( ) { if ( inAttributes ) { throw new Error ( "elementOpenEnd() must be called after calling " + "elementOpenStart()." ) ; } } param currentNameOrCtor param nameOrCtor function assertCloseMatchesOpenTag ( currentNameOrCtor , nameOrCtor ) { if ( currentNameOrCtor !== nameOrCtor ) { throw new Error ( 'Received a call to close "' + nameOrCtor + '" but "' + currentNameOrCtor + '" was open.' ) ; } } param functionName param previousNode function assertNoChildrenDeclaredYet ( functionName , previousNode ) { if ( previousNode !== null ) { throw new Error ( functionName + "() must come before any child " + "declarations inside the current element." ) ; } } param maybeStartNode param maybeCurrentNode param expectedNextNode param expectedPrevNode function assertPatchElementNoExtras ( maybeStartNode , maybeCurrentNode , expectedNextNode , expectedPrevNode ) { const startNode = assert ( maybeStartNode ) ; const currentNode = assert ( maybeCurrentNode ) ; const wasUpdated = currentNode . nextSibling === expectedNextNode && currentNode . previousSibling === expectedPrevNode ; const wasChanged = currentNode . nextSibling === startNode . nextSibling && currentNode . previousSibling === expectedPrevNode ; const wasRemoved = currentNode === startNode ; if ( ! wasUpdated && ! wasChanged && ! wasRemoved ) { throw new Error ( "There must be exactly one top level call corresponding " + "to the patched element." ) ; } } param newContext function updatePatchContext ( newContext ) { inPatch = newContext != null ; } param value return function setInAttributes ( value ) { const previous = inAttributes ; inAttributes = value ; return previous ; } param value return function setInSkip ( value ) { const previous = inSkip ; inSkip = value ; return previous ; } export { assert , assertInPatch , assertNoUnclosedTags , assertNotInAttributes , assertInAttributes , assertCloseMatchesOpenTag , assertVirtualAttributesClosed , assertNoChildrenDeclaredYet , assertNotInSkip , assertPatchElementNoExtras , assertPatchOuterHasParentNode , setInAttributes , setInSkip , updatePatchContext } ;