MCPcopy Index your code
hub / github.com/material-shell/material-shell / getDecoratorTargets

Function getDecoratorTargets

scripts/transpile.ts:126–166  ·  view source on GitHub ↗

The name of the decorated class if it's a block on the form ... ... = __decorate([registerGObjectClass, ...], NameOfDecoratedClass); ...

(node: BaseNode)

Source from the content-addressed store, hash-verified

124...
125*/
126function getDecoratorTargets(node: BaseNode): string[] | null {
127 if (isBlockStatement(node) || isProgram(node)) {
128 let targets = [];
129 for (let child of node.body) {
130 if (!isExpressionStatement(child)) continue;
131 if (!isAssignmentExpression(child.expression)) continue;
132 let rhs = child.expression.right;
133
134 // Essentially go from expressions on the form `a = b = c = d` to `a = d`
135 while (isAssignmentExpression(rhs)) rhs = rhs.right;
136
137 if (!isSimpleCallExpression(rhs)) continue;
138 if (!isIdentifier(rhs.callee)) continue;
139
140 if (rhs.callee.name != '__decorate') continue;
141
142 let args = rhs.arguments;
143 if (args.length != 2) continue;
144
145 let decoratorFunctions = args[0];
146 if (!isArrayExpression(decoratorFunctions)) continue;
147
148 const gObjectDecorator = decoratorFunctions.elements.find(
149 (item) => {
150 return (
151 isIdentifier(item) &&
152 item.name == 'registerGObjectClass'
153 );
154 }
155 );
156 if (gObjectDecorator === undefined) continue;
157
158 let targetClass = args[1];
159 if (!isIdentifier(targetClass)) continue;
160
161 targets.push(targetClass.name);
162 }
163 return targets;
164 }
165 return null;
166}
167
168/// Converts imports on the form
169/// import * from 'source'

Callers 1

transpileFunction · 0.85

Calls 9

isBlockStatementFunction · 0.85
isProgramFunction · 0.85
isExpressionStatementFunction · 0.85
isAssignmentExpressionFunction · 0.85
isSimpleCallExpressionFunction · 0.85
isIdentifierFunction · 0.85
isArrayExpressionFunction · 0.85
findMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected