Просмотр исходного кода

ConditionalNode: Fix setup process (#30229)

* fix conditional setup process

* fix nodeType

* cleanup

* Update ConditionalNode.js
sunag 1 год назад
Родитель
Сommit
1a4f44bb91
2 измененных файлов с 25 добавлено и 4 удалено
  1. 10 1
      src/nodes/core/CacheNode.js
  2. 15 3
      src/nodes/math/ConditionalNode.js

+ 10 - 1
src/nodes/core/CacheNode.js

@@ -56,7 +56,16 @@ class CacheNode extends Node {
 
 	getNodeType( builder ) {
 
-		return this.node.getNodeType( builder );
+		const previousCache = builder.getCache();
+		const cache = builder.getCacheFromNode( this, this.parent );
+
+		builder.setCache( cache );
+
+		const nodeType = this.node.getNodeType( builder );
+
+		builder.setCache( previousCache );
+
+		return nodeType;
 
 	}
 

+ 15 - 3
src/nodes/math/ConditionalNode.js

@@ -69,11 +69,23 @@ class ConditionalNode extends Node {
 	 */
 	getNodeType( builder ) {
 
-		const ifType = this.ifNode.getNodeType( builder );
+		const { ifNode, elseNode } = builder.getNodeProperties( this );
 
-		if ( this.elseNode !== null ) {
+		if ( ifNode === undefined ) {
 
-			const elseType = this.elseNode.getNodeType( builder );
+			// fallback setup
+
+			this.setup( builder );
+
+			return this.getNodeType( builder );
+
+		}
+
+		const ifType = ifNode.getNodeType( builder );
+
+		if ( elseNode !== null ) {
+
+			const elseType = elseNode.getNodeType( builder );
 
 			if ( builder.getTypeLength( elseType ) > builder.getTypeLength( ifType ) ) {
 

粤ICP备19079148号