MCPcopy
hub / github.com/angular/angular-cli / RemoveChange

Class RemoveChange

packages/schematics/angular/utility/change.ts:78–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76 * Will remove text from the source code.
77 */
78export class RemoveChange implements Change {
79 order: number;
80 description: string;
81
82 constructor(
83 public path: string,
84 private pos: number,
85 public toRemove: string,
86 ) {
87 if (pos < 0) {
88 throw new Error('Negative positions are invalid');
89 }
90 this.description = `Removed ${toRemove} into position ${pos} of ${path}`;
91 this.order = pos;
92 }
93
94 apply(host: Host): Promise<void> {
95 return host.read(this.path).then((content) => {
96 const prefix = content.substring(0, this.pos);
97 const suffix = content.substring(this.pos + this.toRemove.length);
98
99 // TODO: throw error if toRemove doesn't match removed string.
100 return host.write(this.path, `${prefix}${suffix}`);
101 });
102 }
103}
104
105/**
106 * Will replace text from the source code.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected