📄 FunctionNode.js
¶
📊 Analysis Summary¶
Metric | Count |
---|---|
🔧 Functions | 8 |
🧱 Classes | 1 |
📦 Imports | 2 |
📊 Variables & Constants | 4 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 src/nodes/code/FunctionNode.js
📦 Imports¶
Name | Source |
---|---|
CodeNode |
./CodeNode.js |
nodeObject |
../tsl/TSLBase.js |
Variables & Constants¶
Name | Type | Kind | Value | Exported |
---|---|---|---|---|
nodeFunction |
any |
let/var | nodeData.nodeFunction |
✗ |
name |
any |
let/var | nodeFunction.name |
✗ |
type |
any |
let/var | nodeFunction.type |
✗ |
include |
any |
let/var | includes[ i ] |
✗ |
Functions¶
FunctionNode.getNodeType(builder: any): any
¶
Parameters:
builder
any
Returns: any
Calls:
this.getNodeFunction
FunctionNode.getInputs(builder: NodeBuilder): NodeFunctionInput[]
¶
JSDoc:
/**
* Returns the inputs of this function node.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {Array<NodeFunctionInput>} The inputs.
*/
Parameters:
builder
NodeBuilder
Returns: NodeFunctionInput[]
Calls:
this.getNodeFunction
FunctionNode.getNodeFunction(builder: NodeBuilder): NodeFunction
¶
JSDoc:
/**
* Returns the node function for this function node.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {NodeFunction} The node function.
*/
Parameters:
builder
NodeBuilder
Returns: NodeFunction
Calls:
builder.getDataFromNode
builder.parser.parseFunction
Code
FunctionNode.generate(builder: any, output: any): any
¶
Parameters:
builder
any
output
any
Returns: any
Calls:
super.generate
this.getNodeFunction
builder.getCodeFromNode
builder.getPropertyName
this.getNodeFunction( builder ).getCode
builder.format
Internal Comments:
Code
generate( builder, output ) {
super.generate( builder );
const nodeFunction = this.getNodeFunction( builder );
const name = nodeFunction.name;
const type = nodeFunction.type;
const nodeCode = builder.getCodeFromNode( this, type );
if ( name !== '' ) {
// use a custom property name
nodeCode.name = name;
}
const propertyName = builder.getPropertyName( nodeCode );
const code = this.getNodeFunction( builder ).getCode( propertyName );
nodeCode.code = code + '\n';
if ( output === 'property' ) {
return propertyName;
} else {
return builder.format( `${ propertyName }()`, type, output );
}
}
nativeFn(code: any, includes: any[], language: string): { (...params: any[]): any; functionNode: any; }
¶
Parameters:
code
any
includes
any[]
language
string
Returns: { (...params: any[]): any; functionNode: any; }
Calls:
nodeObject (from ../tsl/TSLBase.js)
functionNode.call
Internal Comments:
Code
( code, includes = [], language = '' ) => {
for ( let i = 0; i < includes.length; i ++ ) {
const include = includes[ i ];
// TSL Function: glslFn, wgslFn
if ( typeof include === 'function' ) {
includes[ i ] = include.functionNode;
}
}
const functionNode = nodeObject( new FunctionNode( code, includes, language ) );
const fn = ( ...params ) => functionNode.call( ...params );
fn.functionNode = functionNode;
return fn;
}
fn(params: any[]): any
¶
Parameters:
params
any[]
Returns: any
Calls:
functionNode.call
glslFn(code: any, includes: any): { (...params: any[]): any; functionNode: any; }
¶
Parameters:
code
any
includes
any
Returns: { (...params: any[]): any; functionNode: any; }
Calls:
nativeFn
wgslFn(code: any, includes: any): { (...params: any[]): any; functionNode: any; }
¶
Parameters:
code
any
includes
any
Returns: { (...params: any[]): any; functionNode: any; }
Calls:
nativeFn
Classes¶
FunctionNode
¶
Class Code
class FunctionNode extends CodeNode {
static get type() {
return 'FunctionNode';
}
/**
* Constructs a new function node.
*
* @param {string} [code=''] - The native code.
* @param {Array<Node>} [includes=[]] - An array of includes.
* @param {('js'|'wgsl'|'glsl')} [language=''] - The used language.
*/
constructor( code = '', includes = [], language = '' ) {
super( code, includes, language );
}
getNodeType( builder ) {
return this.getNodeFunction( builder ).type;
}
/**
* Returns the inputs of this function node.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {Array<NodeFunctionInput>} The inputs.
*/
getInputs( builder ) {
return this.getNodeFunction( builder ).inputs;
}
/**
* Returns the node function for this function node.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {NodeFunction} The node function.
*/
getNodeFunction( builder ) {
const nodeData = builder.getDataFromNode( this );
let nodeFunction = nodeData.nodeFunction;
if ( nodeFunction === undefined ) {
nodeFunction = builder.parser.parseFunction( this.code );
nodeData.nodeFunction = nodeFunction;
}
return nodeFunction;
}
generate( builder, output ) {
super.generate( builder );
const nodeFunction = this.getNodeFunction( builder );
const name = nodeFunction.name;
const type = nodeFunction.type;
const nodeCode = builder.getCodeFromNode( this, type );
if ( name !== '' ) {
// use a custom property name
nodeCode.name = name;
}
const propertyName = builder.getPropertyName( nodeCode );
const code = this.getNodeFunction( builder ).getCode( propertyName );
nodeCode.code = code + '\n';
if ( output === 'property' ) {
return propertyName;
} else {
return builder.format( `${ propertyName }()`, type, output );
}
}
}
Methods¶
getNodeType(builder: any): any
¶
getInputs(builder: NodeBuilder): NodeFunctionInput[]
¶
getNodeFunction(builder: NodeBuilder): NodeFunction
¶
Code
generate(builder: any, output: any): any
¶
Code
generate( builder, output ) {
super.generate( builder );
const nodeFunction = this.getNodeFunction( builder );
const name = nodeFunction.name;
const type = nodeFunction.type;
const nodeCode = builder.getCodeFromNode( this, type );
if ( name !== '' ) {
// use a custom property name
nodeCode.name = name;
}
const propertyName = builder.getPropertyName( nodeCode );
const code = this.getNodeFunction( builder ).getCode( propertyName );
nodeCode.code = code + '\n';
if ( output === 'property' ) {
return propertyName;
} else {
return builder.format( `${ propertyName }()`, type, output );
}
}