Skip to content

Commit 7fa5c3e

Browse files
clydindgp1130
authored andcommitted
refactor(@angular-devkit/schematics): use modern language features in test engine host
The `NodeModulesTestEngineHost` class has been adjusted to use modern JavaScript language features such as private fields and nullish coalescing.
1 parent b60b7da commit 7fa5c3e

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

packages/angular_devkit/schematics/tools/node-modules-test-engine-host.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,33 @@ import { NodeModulesEngineHost } from './node-module-engine-host';
1515
* revert back to using node modules resolution. This is done for testing.
1616
*/
1717
export class NodeModulesTestEngineHost extends NodeModulesEngineHost {
18-
private _collections = new Map<string, string>();
19-
private _tasks = [] as TaskConfiguration[];
18+
#collections = new Map<string, string>();
19+
#tasks: TaskConfiguration[] = [];
2020

2121
get tasks() {
22-
return this._tasks;
22+
return this.#tasks;
2323
}
2424

2525
clearTasks() {
26-
this._tasks = [];
26+
this.#tasks = [];
2727
}
2828

2929
registerCollection(name: string, path: string) {
30-
this._collections.set(name, path);
30+
this.#collections.set(name, path);
3131
}
3232

3333
override transformContext(context: FileSystemSchematicContext): FileSystemSchematicContext {
34-
const oldAddTask = context.addTask;
35-
context.addTask = (task: TaskConfigurationGenerator<{}>, dependencies?: Array<TaskId>) => {
36-
this._tasks.push(task.toConfiguration());
34+
const oldAddTask = context.addTask.bind(context);
35+
context.addTask = (task: TaskConfigurationGenerator, dependencies?: TaskId[]) => {
36+
this.#tasks.push(task.toConfiguration());
3737

38-
return oldAddTask.call(context, task, dependencies);
38+
return oldAddTask(task, dependencies);
3939
};
4040

4141
return context;
4242
}
4343

4444
protected override _resolveCollectionPath(name: string, requester?: string): string {
45-
const maybePath = this._collections.get(name);
46-
if (maybePath) {
47-
return maybePath;
48-
}
49-
50-
return super._resolveCollectionPath(name, requester);
45+
return this.#collections.get(name) ?? super._resolveCollectionPath(name, requester);
5146
}
5247
}

0 commit comments

Comments
 (0)