MCPcopy Index your code
hub / github.com/gpujs/gpu.js / getJsAST

Method getJsAST

src/backend/function-node.js:186–212  ·  view source on GitHub ↗

* @desc Parses the class function JS, and returns its Abstract Syntax Tree object. * This is used internally to convert to shader code * * @param {Object} [inParser] - Parser to use, assumes in scope 'parser' if null or undefined * * @returns {Object} The function AST Object, note tha

(inParser)

Source from the content-addressed store, hash-verified

184 * @returns {Object} The function AST Object, note that result is cached under this.ast;
185 */
186 getJsAST(inParser) {
187 if (this.ast) {
188 return this.ast;
189 }
190 if (typeof this.source === 'object') {
191 this.traceFunctionAST(this.source);
192 return this.ast = this.source;
193 }
194
195 inParser = inParser || acorn;
196 if (inParser === null) {
197 throw new Error('Missing JS to AST parser');
198 }
199
200 const ast = Object.freeze(inParser.parse(`const parser_${ this.name } = ${ this.source };`, {
201 locations: true
202 }));
203 // take out the function object, outside the var declarations
204 const functionAST = ast.body[0].declarations[0].init;
205 this.traceFunctionAST(functionAST);
206
207 if (!ast) {
208 throw new Error('Failed to parse JS code');
209 }
210
211 return this.ast = functionAST;
212 }
213
214 traceFunctionAST(ast) {
215 const { contexts, declarations, functions, identifiers, functionCalls } = new FunctionTracer(ast);

Callers 6

toStringMethod · 0.95
function-node.jsFile · 0.80
runFunction · 0.80
runFunction · 0.80
lookupReturnTypeMethod · 0.80

Calls 1

traceFunctionASTMethod · 0.95

Tested by

no test coverage detected