|
@@ -26,6 +26,38 @@ class Node {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ getChildren() {
|
|
|
+
|
|
|
+ const children = [];
|
|
|
+
|
|
|
+ for ( const property in this ) {
|
|
|
+
|
|
|
+ const object = this[ property ];
|
|
|
+
|
|
|
+ if ( Array.isArray( object ) === true ) {
|
|
|
+
|
|
|
+ for ( const child of object ) {
|
|
|
+
|
|
|
+ if ( child?.isNode === true ) {
|
|
|
+
|
|
|
+ children.push( child );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if ( object?.isNode === true ) {
|
|
|
+
|
|
|
+ children.push( object );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return children;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
getHash( /*builder*/ ) {
|
|
|
|
|
|
return this.uuid;
|
|
@@ -44,6 +76,12 @@ class Node {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ getConstructHash( /*builder*/ ) {
|
|
|
+
|
|
|
+ return this.uuid;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
getReference( builder ) {
|
|
|
|
|
|
const hash = this.getHash( builder );
|
|
@@ -53,41 +91,66 @@ class Node {
|
|
|
|
|
|
}
|
|
|
|
|
|
- update( /*frame*/ ) {
|
|
|
+ construct( builder ) {
|
|
|
|
|
|
- console.warn( 'Abstract function.' );
|
|
|
+ const nodeProperties = builder.getNodeProperties( this );
|
|
|
|
|
|
- }
|
|
|
+ for ( const childNode of this.getChildren() ) {
|
|
|
|
|
|
- generate( /*builder, output*/ ) {
|
|
|
+ nodeProperties[ '_node' + childNode.id ] = childNode;
|
|
|
|
|
|
- console.warn( 'Abstract function.' );
|
|
|
+ }
|
|
|
+
|
|
|
+ // return a outputNode if exists
|
|
|
+ return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
analyze( builder ) {
|
|
|
|
|
|
- const refNode = this.getReference( builder );
|
|
|
+ const nodeData = builder.getDataFromNode( this );
|
|
|
+ nodeData.dependenciesCount = nodeData.dependenciesCount === undefined ? 1 : nodeData.dependenciesCount + 1;
|
|
|
|
|
|
- if ( this !== refNode ) {
|
|
|
+ if ( nodeData.dependenciesCount === 1 ) {
|
|
|
+
|
|
|
+ // node flow children
|
|
|
+
|
|
|
+ const nodeProperties = builder.getNodeProperties( this );
|
|
|
+
|
|
|
+ for ( const childNode of Object.values( nodeProperties ) ) {
|
|
|
+
|
|
|
+ if ( childNode?.isNode === true ) {
|
|
|
|
|
|
- return refNode.analyze( builder );
|
|
|
+ childNode.build( builder );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- const nodeData = builder.getDataFromNode( this );
|
|
|
- nodeData.dependenciesCount = nodeData.dependenciesCount === undefined ? 1 : nodeData.dependenciesCount + 1;
|
|
|
+ }
|
|
|
|
|
|
- const nodeKeys = getNodesKeys( this );
|
|
|
+ generate( builder ) {
|
|
|
|
|
|
- for ( const property of nodeKeys ) {
|
|
|
+ const { outputNode } = builder.getNodeProperties( this );
|
|
|
|
|
|
- this[ property ].analyze( builder );
|
|
|
+ if ( outputNode?.isNode === true ) {
|
|
|
+
|
|
|
+ const type = this.getNodeType( builder );
|
|
|
+
|
|
|
+ return outputNode.build( builder, type );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ update( /*frame*/ ) {
|
|
|
+
|
|
|
+ console.warn( 'Abstract function.' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
build( builder, output = null ) {
|
|
|
|
|
|
const refNode = this.getReference( builder );
|
|
@@ -101,36 +164,74 @@ class Node {
|
|
|
builder.addNode( this );
|
|
|
builder.addStack( this );
|
|
|
|
|
|
- const nodeData = builder.getDataFromNode( this );
|
|
|
- const isGenerateOnce = this.generate.length === 1;
|
|
|
+ /* expected return:
|
|
|
+ - "construct" -> Node
|
|
|
+ - "analyze" -> null
|
|
|
+ - "generat" -> String
|
|
|
+ */
|
|
|
+ let result = null;
|
|
|
|
|
|
- let snippet = null;
|
|
|
+ const buildStage = builder.getBuildStage();
|
|
|
|
|
|
- if ( isGenerateOnce ) {
|
|
|
+ if ( buildStage === 'construct' ) {
|
|
|
|
|
|
- const type = this.getNodeType( builder );
|
|
|
+ const properties = builder.getNodeProperties( this );
|
|
|
+ const nodeData = builder.getDataFromNode( this );
|
|
|
|
|
|
- snippet = nodeData.snippet;
|
|
|
+ if ( properties.initied !== true ) {
|
|
|
|
|
|
- if ( snippet === undefined ) {
|
|
|
+ nodeData.initied = true;
|
|
|
|
|
|
- snippet = this.generate( builder ) || '';
|
|
|
+ properties.outputNode = this.construct( builder );
|
|
|
|
|
|
- nodeData.snippet = snippet;
|
|
|
+ for ( const childNode of Object.values( properties ) ) {
|
|
|
+
|
|
|
+ if ( childNode?.isNode === true ) {
|
|
|
+
|
|
|
+ childNode.build( builder );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- snippet = builder.format( snippet, type, output );
|
|
|
+ } else if ( buildStage === 'analyze' ) {
|
|
|
+
|
|
|
+ this.analyze( builder );
|
|
|
+
|
|
|
+ } else if ( buildStage === 'generate' ) {
|
|
|
+
|
|
|
+ const isGenerateOnce = this.generate.length === 1;
|
|
|
+
|
|
|
+ if ( isGenerateOnce ) {
|
|
|
+
|
|
|
+ const type = this.getNodeType( builder );
|
|
|
+ const nodeData = builder.getDataFromNode( this );
|
|
|
|
|
|
- } else {
|
|
|
+ result = nodeData.snippet;
|
|
|
|
|
|
- snippet = this.generate( builder, output ) || '';
|
|
|
+ if ( result === undefined ) {
|
|
|
+
|
|
|
+ result = this.generate( builder ) || '';
|
|
|
+
|
|
|
+ nodeData.snippet = result;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ result = builder.format( result, type, output );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ result = this.generate( builder, output ) || '';
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
builder.removeStack( this );
|
|
|
|
|
|
- return snippet;
|
|
|
+ return result;
|
|
|
|
|
|
}
|
|
|
|