88
99import './ng_dev_mode' ;
1010
11- import { assertEqual , assertLessThan , assertNotEqual , assertNotNull } from './assert' ;
11+ import { assertEqual , assertLessThan , assertNotEqual , assertNotNull , assertNull , assertSame } from './assert' ;
1212import { LContainer , TContainer } from './interfaces/container' ;
1313import { CssSelector , LProjection } from './interfaces/projection' ;
1414import { LQueries } from './interfaces/query' ;
@@ -233,7 +233,7 @@ export function createLNode(
233233 if ( ( type & LNodeFlags . ViewOrElement ) === LNodeFlags . ViewOrElement && isState ) {
234234 // Bit of a hack to bust through the readonly because there is a circular dep between
235235 // LView and LNode.
236- ngDevMode && assertEqual ( ( state as LView ) . node , null , 'lView .node') ;
236+ ngDevMode && assertNull ( ( state as LView ) . node , 'LView .node should not have been initialized ') ;
237237 ( state as LView as { node : LNode } ) . node = node ;
238238 }
239239 if ( index != null ) {
@@ -254,13 +254,17 @@ export function createLNode(
254254 if ( previousOrParentNode . view === currentView ||
255255 ( previousOrParentNode . flags & LNodeFlags . TYPE_MASK ) === LNodeFlags . View ) {
256256 // We are in the same view, which means we are adding content node to the parent View.
257- ngDevMode && assertEqual ( previousOrParentNode . child , null , 'previousNode.child' ) ;
257+ ngDevMode && assertNull (
258+ previousOrParentNode . child ,
259+ `previousOrParentNode's child should not have been set.` ) ;
258260 previousOrParentNode . child = node ;
259261 } else {
260262 // We are adding component view, so we don't link parent node child to this node.
261263 }
262264 } else if ( previousOrParentNode ) {
263- ngDevMode && assertEqual ( previousOrParentNode . next , null , 'previousNode.next' ) ;
265+ ngDevMode && assertNull (
266+ previousOrParentNode . next ,
267+ `previousOrParentNode's next property should not have been set.` ) ;
264268 previousOrParentNode . next = node ;
265269 }
266270 }
@@ -300,7 +304,7 @@ export function renderTemplate<T>(
300304 - 1 , providedRendererFactory . createRenderer ( null , null ) , getOrCreateTView ( template ) ) ) ;
301305 }
302306 const hostView = host . data ! ;
303- ngDevMode && assertNotEqual ( hostView , null , 'hostView ') ;
307+ ngDevMode && assertNotNull ( hostView , 'Host node should have an LView defined in host.data. ') ;
304308 renderComponentOrTemplate ( host , hostView , context , template ) ;
305309 return host ;
306310}
@@ -381,7 +385,8 @@ export function elementStart(
381385 const node = data [ index ] ! ;
382386 native = node && ( node as LElementNode ) . native ;
383387 } else {
384- ngDevMode && assertEqual ( currentView . bindingStartIndex , null , 'bindingStartIndex' ) ;
388+ ngDevMode &&
389+ assertNull ( currentView . bindingStartIndex , 'elements should be created before any bindings' ) ;
385390 const isHostElement = typeof nameOrComponentType !== 'string' ;
386391 // MEGAMORPHIC: `ngComponentDef` is a megamorphic property access here.
387392 // This is OK, since we will refactor this code and store the result in `TView.data`
@@ -504,7 +509,7 @@ export function createTView(): TView {
504509}
505510
506511function setUpAttributes ( native : RElement , attrs : string [ ] ) : void {
507- ngDevMode && assertEqual ( attrs . length % 2 , 0 , 'attrs.length % 2 ' ) ;
512+ ngDevMode && assertEqual ( attrs . length % 2 , 0 , 'each attribute should have a key and a value ' ) ;
508513
509514 const isProc = isProceduralRenderer ( renderer ) ;
510515 for ( let i = 0 ; i < attrs . length ; i += 2 ) {
@@ -809,7 +814,8 @@ export function elementStyle<T>(
809814 * If value is not provided than the actual creation of the text node is delayed.
810815 */
811816export function text ( index : number , value ?: any ) : void {
812- ngDevMode && assertEqual ( currentView . bindingStartIndex , null , 'bindingStartIndex' ) ;
817+ ngDevMode &&
818+ assertNull ( currentView . bindingStartIndex , 'text nodes should be created before bindings' ) ;
813819 const textNode = value != null ?
814820 ( isProceduralRenderer ( renderer ) ? renderer . createText ( stringify ( value ) ) :
815821 renderer . createTextNode ( stringify ( value ) ) ) :
@@ -865,7 +871,8 @@ export function textBinding<T>(index: number, value: T | NO_CHANGE): void {
865871export function directiveCreate < T > (
866872 index : number , directive : T , directiveDef : DirectiveDef < T > , queryName ?: string | null ) : T {
867873 let instance ;
868- ngDevMode && assertEqual ( currentView . bindingStartIndex , null , 'bindingStartIndex' ) ;
874+ ngDevMode &&
875+ assertNull ( currentView . bindingStartIndex , 'directives should be created before any bindings' ) ;
869876 ngDevMode && assertPreviousIsParent ( ) ;
870877 let flags = previousOrParentNode ! . flags ;
871878 let size = flags & LNodeFlags . SIZE_MASK ;
@@ -984,10 +991,12 @@ function generateInitialInputs(
984991export function container (
985992 index : number , directiveTypes ?: DirectiveType < any > [ ] , template ?: ComponentTemplate < any > ,
986993 tagName ?: string , attrs ?: string [ ] , localRefs ?: string [ ] | null ) : void {
987- ngDevMode && assertEqual ( currentView . bindingStartIndex , null , 'bindingStartIndex' ) ;
994+ ngDevMode &&
995+ assertNull (
996+ currentView . bindingStartIndex , 'container nodes should be created before any bindings' ) ;
988997
989998 const currentParent = isParent ? previousOrParentNode : previousOrParentNode . parent ! ;
990- ngDevMode && assertNotEqual ( currentParent , null , 'currentParent ') ;
999+ ngDevMode && assertNotNull ( currentParent , 'containers should have a parent ') ;
9911000
9921001 const lContainer = < LContainer > {
9931002 views : [ ] ,
@@ -1037,9 +1046,9 @@ export function containerRefreshStart(index: number): void {
10371046 ngDevMode && assertNodeType ( previousOrParentNode , LNodeFlags . Container ) ;
10381047 isParent = true ;
10391048 ( previousOrParentNode as LContainerNode ) . data . nextIndex = 0 ;
1040- ngDevMode && assertEqual (
1041- ( previousOrParentNode as LContainerNode ) . native === undefined , true ,
1042- 'previousOrParentNode. native === undefined' ) ;
1049+ ngDevMode && assertSame (
1050+ ( previousOrParentNode as LContainerNode ) . native , undefined ,
1051+ `the container's native element should not have been set yet.` ) ;
10431052
10441053 // We need to execute init hooks here so ngOnInit hooks are called in top level views
10451054 // before they are called in embedded views (for backwards compatibility).
@@ -1181,11 +1190,11 @@ export function componentRefresh<T>(directiveIndex: number, elementIndex: number
11811190 ngDevMode && assertDataInRange ( elementIndex ) ;
11821191 const element = data ! [ elementIndex ] as LElementNode ;
11831192 ngDevMode && assertNodeType ( element , LNodeFlags . Element ) ;
1184- ngDevMode && assertNotEqual ( element . data , null , 'isComponent' ) ;
1193+ ngDevMode &&
1194+ assertNotNull ( element . data , `Component's host node should have an LView attached.` ) ;
11851195 ngDevMode && assertDataInRange ( directiveIndex ) ;
11861196 const directive = getDirectiveInstance < T > ( data [ directiveIndex ] ) ;
11871197 const hostView = element . data ! ;
1188- ngDevMode && assertNotEqual ( hostView , null , 'hostView' ) ;
11891198 const oldView = enterView ( hostView , element ) ;
11901199 try {
11911200 template ( directive , creationMode ) ;
@@ -1243,9 +1252,9 @@ function appendToProjectionNode(
12431252 projectionNode : LProjectionNode ,
12441253 appendedFirst : LElementNode | LTextNode | LContainerNode | null ,
12451254 appendedLast : LElementNode | LTextNode | LContainerNode | null ) {
1246- // appendedFirst can be null if and only if appendedLast is also null
1247- ngDevMode &&
1248- assertEqual ( ! appendedFirst === ! appendedLast , true , '! appendedFirst === ! appendedLast') ;
1255+ ngDevMode && assertEqual (
1256+ ! ! appendedFirst , ! ! appendedLast ,
1257+ ' appendedFirst can be null if and only if appendedLast is also null ') ;
12491258 if ( ! appendedLast ) {
12501259 // nothing to append
12511260 return ;
@@ -1760,18 +1769,18 @@ export function getDirectiveInstance<T>(instanceOrArray: T | [T]): T {
17601769}
17611770
17621771export function assertPreviousIsParent ( ) {
1763- assertEqual ( isParent , true , 'isParent ' ) ;
1772+ assertEqual ( isParent , true , 'previousOrParentNode should be a parent ' ) ;
17641773}
17651774
17661775function assertHasParent ( ) {
1767- assertNotEqual ( previousOrParentNode . parent , null , 'isParent ') ;
1776+ assertNotNull ( previousOrParentNode . parent , 'previousOrParentNode should have a parent ') ;
17681777}
17691778
17701779function assertDataInRange ( index : number , arr ?: any [ ] ) {
17711780 if ( arr == null ) arr = data ;
1772- assertLessThan ( index , arr ? arr . length : 0 , 'data.length ' ) ;
1781+ assertLessThan ( index , arr ? arr . length : 0 , 'index expected to be a valid data index ' ) ;
17731782}
17741783
17751784function assertDataNext ( index : number ) {
1776- assertEqual ( data . length , index , 'data.length not in sequence ' ) ;
1785+ assertEqual ( data . length , index , 'index expected to be at the end of data ' ) ;
17771786}
0 commit comments