MCPcopy Create free account
hub / github.com/angular/components / analyzeDecorators

Function analyzeDecorators

tools/tslint-rules/lightweightTokensRule.ts:168–193  ·  view source on GitHub ↗

* Analyzes the decorators of the given parameter. Returns whether it has * an `@Inject` or `@Optional` decorator applied.

(param: ts.ParameterDeclaration)

Source from the content-addressed store, hash-verified

166 * an `@Inject` or `@Optional` decorator applied.
167 */
168function analyzeDecorators(param: ts.ParameterDeclaration): {
169 hasInject: boolean;
170 isOptional: boolean;
171} {
172 const decorators = ts.getDecorators(param);
173
174 if (!decorators) {
175 return {hasInject: false, isOptional: false};
176 }
177
178 let hasInject = false;
179 let isOptional = false;
180 for (const decorator of decorators) {
181 const expr = decorator.expression;
182 if (!ts.isCallExpression(expr) || !ts.isIdentifier(expr.expression)) {
183 continue;
184 }
185 if (expr.expression.text === 'Inject') {
186 hasInject = true;
187 }
188 if (expr.expression.text === 'Optional') {
189 isOptional = true;
190 }
191 }
192 return {hasInject, isOptional};
193}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected