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

Method getDependencies

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

* * @param ast * @param dependencies * @param isNotSafe * @return {Array}

(ast, dependencies, isNotSafe)

Source from the content-addressed store, hash-verified

678 * @return {Array}
679 */
680 getDependencies(ast, dependencies, isNotSafe) {
681 if (!dependencies) {
682 dependencies = [];
683 }
684 if (!ast) return null;
685 if (Array.isArray(ast)) {
686 for (let i = 0; i < ast.length; i++) {
687 this.getDependencies(ast[i], dependencies, isNotSafe);
688 }
689 return dependencies;
690 }
691 switch (ast.type) {
692 case 'AssignmentExpression':
693 this.getDependencies(ast.left, dependencies, isNotSafe);
694 this.getDependencies(ast.right, dependencies, isNotSafe);
695 return dependencies;
696 case 'ConditionalExpression':
697 this.getDependencies(ast.test, dependencies, isNotSafe);
698 this.getDependencies(ast.alternate, dependencies, isNotSafe);
699 this.getDependencies(ast.consequent, dependencies, isNotSafe);
700 return dependencies;
701 case 'Literal':
702 dependencies.push({
703 origin: 'literal',
704 value: ast.value,
705 isSafe: isNotSafe === true ? false : ast.value > -Infinity && ast.value < Infinity && !isNaN(ast.value)
706 });
707 break;
708 case 'VariableDeclarator':
709 return this.getDependencies(ast.init, dependencies, isNotSafe);
710 case 'Identifier':
711 const declaration = this.getDeclaration(ast);
712 if (declaration) {
713 dependencies.push({
714 name: ast.name,
715 origin: 'declaration',
716 isSafe: isNotSafe ? false : this.isSafeDependencies(declaration.dependencies),
717 });
718 } else if (this.argumentNames.indexOf(ast.name) > -1) {
719 dependencies.push({
720 name: ast.name,
721 origin: 'argument',
722 isSafe: false,
723 });
724 } else if (this.strictTypingChecking) {
725 throw new Error(`Cannot find identifier origin "${ast.name}"`);
726 }
727 break;
728 case 'FunctionDeclaration':
729 return this.getDependencies(ast.body.body[ast.body.body.length - 1], dependencies, isNotSafe);
730 case 'ReturnStatement':
731 return this.getDependencies(ast.argument, dependencies);
732 case 'BinaryExpression':
733 case 'LogicalExpression':
734 isNotSafe = (ast.operator === '/' || ast.operator === '*');
735 this.getDependencies(ast.left, dependencies, isNotSafe);
736 this.getDependencies(ast.right, dependencies, isNotSafe);
737 return dependencies;

Callers 2

traceFunctionASTMethod · 0.95
isSafeMethod · 0.95

Calls 4

getDeclarationMethod · 0.95
isSafeDependenciesMethod · 0.95
astErrorOutputMethod · 0.95

Tested by

no test coverage detected