Skip to content

Commit 41f90f8

Browse files
committed
feat(injectable): display extends and providedIn metadata
closes #1556
1 parent 693c02b commit 41f90f8

5 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎src/app/compiler/angular-dependencies.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,18 @@ export class AngularDependencies extends FrameworkDependencies {
740740
if (IO.extends) {
741741
injectableDeps.extends = IO.extends;
742742
}
743+
const providedInRaw = this.symbolHelper.getSymbolDepsRaw(
744+
props,
745+
'providedIn',
746+
);
747+
if (providedInRaw.length > 0) {
748+
const rawNode = providedInRaw[0] as ts.PropertyAssignment;
749+
if (rawNode && rawNode.initializer) {
750+
injectableDeps.providedIn = ts.isStringLiteral(rawNode.initializer)
751+
? rawNode.initializer.text
752+
: rawNode.initializer.getText(srcFile);
753+
}
754+
}
743755
if (Configuration.mainData.disableLifeCycleHooks) {
744756
injectableDeps.methods =
745757
cleanLifecycleHooksFromMethods(

‎src/app/compiler/angular/dependencies.interfaces.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface IInjectableDep extends IDep {
1616
sourceCode: string;
1717
exampleUrls?;
1818
extends?;
19+
providedIn?: string;
1920

2021
accessors?: Object;
2122
constructorObj?: Object;

‎src/templates/partials/injectable.hbs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@
5757
</p>
5858
{{/if}}
5959

60+
{{#if injectable.providedIn}}
61+
<section data-compodoc="block-metadata">
62+
<h3>{{t "metadata" }}</h3>
63+
<table class="table table-sm table-hover metadata">
64+
<tbody>
65+
<tr>
66+
<td class="col-md-3">providedIn</td>
67+
<td class="col-md-9"><code>{{injectable.providedIn}}</code></td>
68+
</tr>
69+
</tbody>
70+
</table>
71+
</section>
72+
{{/if}}
73+
6074
{{#if injectable.jsdoctags}}
6175
<p class="comment">
6276
<h3>{{t "example" }}</h3>

‎test/fixtures/todomvc-ng2/src/app/shared/services/todo.store.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { Todo } from '../models/todo.model';
77
* See {@link Todo} for details about the main data of this store
88
* @deprecated This service is deprecated
99
*/
10-
@Injectable()
10+
@Injectable({
11+
providedIn: 'root'
12+
})
1113
export class TodoStore {
1214
/**
1315
* Local array of Todos

‎test/src/cli/cli-generation-big-app.spec.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ describe("CLI simple generation - big app", () => {
228228
expect(file).to.be.true;
229229
});
230230

231+
it("should display providedIn metadata for injectables", () => {
232+
expect(todoStoreFile).to.contain("providedIn");
233+
expect(todoStoreFile).to.contain("<code>root</code>");
234+
});
235+
231236
it("should have generated the not-injectable guards", () => {
232237
const file = exists(`${distFolder}/guards/AuthGuard.html`);
233238
expect(file).to.be.true;

0 commit comments

Comments
 (0)