122 lines
15 KiB
JavaScript
122 lines
15 KiB
JavaScript
"use strict";
|
|
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.applyToUpdateRecorder = exports.ReplaceChange = exports.RemoveChange = exports.InsertChange = exports.NoopChange = void 0;
|
|
/**
|
|
* An operation that does nothing.
|
|
*/
|
|
class NoopChange {
|
|
constructor() {
|
|
this.description = 'No operation.';
|
|
this.order = Infinity;
|
|
this.path = null;
|
|
}
|
|
apply() {
|
|
return Promise.resolve();
|
|
}
|
|
}
|
|
exports.NoopChange = NoopChange;
|
|
/**
|
|
* Will add text to the source code.
|
|
*/
|
|
class InsertChange {
|
|
constructor(path, pos, toAdd) {
|
|
this.path = path;
|
|
this.pos = pos;
|
|
this.toAdd = toAdd;
|
|
if (pos < 0) {
|
|
throw new Error('Negative positions are invalid');
|
|
}
|
|
this.description = `Inserted ${toAdd} into position ${pos} of ${path}`;
|
|
this.order = pos;
|
|
}
|
|
/**
|
|
* This method does not insert spaces if there is none in the original string.
|
|
*/
|
|
apply(host) {
|
|
return host.read(this.path).then((content) => {
|
|
const prefix = content.substring(0, this.pos);
|
|
const suffix = content.substring(this.pos);
|
|
return host.write(this.path, `${prefix}${this.toAdd}${suffix}`);
|
|
});
|
|
}
|
|
}
|
|
exports.InsertChange = InsertChange;
|
|
/**
|
|
* Will remove text from the source code.
|
|
*/
|
|
class RemoveChange {
|
|
constructor(path, pos, toRemove) {
|
|
this.path = path;
|
|
this.pos = pos;
|
|
this.toRemove = toRemove;
|
|
if (pos < 0) {
|
|
throw new Error('Negative positions are invalid');
|
|
}
|
|
this.description = `Removed ${toRemove} into position ${pos} of ${path}`;
|
|
this.order = pos;
|
|
}
|
|
apply(host) {
|
|
return host.read(this.path).then((content) => {
|
|
const prefix = content.substring(0, this.pos);
|
|
const suffix = content.substring(this.pos + this.toRemove.length);
|
|
// TODO: throw error if toRemove doesn't match removed string.
|
|
return host.write(this.path, `${prefix}${suffix}`);
|
|
});
|
|
}
|
|
}
|
|
exports.RemoveChange = RemoveChange;
|
|
/**
|
|
* Will replace text from the source code.
|
|
*/
|
|
class ReplaceChange {
|
|
constructor(path, pos, oldText, newText) {
|
|
this.path = path;
|
|
this.pos = pos;
|
|
this.oldText = oldText;
|
|
this.newText = newText;
|
|
if (pos < 0) {
|
|
throw new Error('Negative positions are invalid');
|
|
}
|
|
this.description = `Replaced ${oldText} into position ${pos} of ${path} with ${newText}`;
|
|
this.order = pos;
|
|
}
|
|
apply(host) {
|
|
return host.read(this.path).then((content) => {
|
|
const prefix = content.substring(0, this.pos);
|
|
const suffix = content.substring(this.pos + this.oldText.length);
|
|
const text = content.substring(this.pos, this.pos + this.oldText.length);
|
|
if (text !== this.oldText) {
|
|
return Promise.reject(new Error(`Invalid replace: "${text}" != "${this.oldText}".`));
|
|
}
|
|
// TODO: throw error if oldText doesn't match removed string.
|
|
return host.write(this.path, `${prefix}${this.newText}${suffix}`);
|
|
});
|
|
}
|
|
}
|
|
exports.ReplaceChange = ReplaceChange;
|
|
function applyToUpdateRecorder(recorder, changes) {
|
|
for (const change of changes) {
|
|
if (change instanceof InsertChange) {
|
|
recorder.insertLeft(change.pos, change.toAdd);
|
|
}
|
|
else if (change instanceof RemoveChange) {
|
|
recorder.remove(change.order, change.toRemove.length);
|
|
}
|
|
else if (change instanceof ReplaceChange) {
|
|
recorder.remove(change.order, change.oldText.length);
|
|
recorder.insertLeft(change.order, change.newText);
|
|
}
|
|
else if (!(change instanceof NoopChange)) {
|
|
throw new Error('Unknown Change type encountered when updating a recorder.');
|
|
}
|
|
}
|
|
}
|
|
exports.applyToUpdateRecorder = applyToUpdateRecorder;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hhbmdlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdX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