Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
stm => stm.kind === ts.SyntaxKind.ClassDeclaration
);
const component = componentClass as ts.ClassDeclaration;
const componentConstructor = component.members.find(
member => member.kind === ts.SyntaxKind.Constructor
);
const cmpCtr = componentConstructor as ts.ConstructorDeclaration;
const { pos } = cmpCtr;
const stateType = options.state
? `fromStore.${options.stateInterface}`
: 'any';
const constructorText = cmpCtr.getText();
const [start, end] = constructorText.split('()');
const storeText = `private store: Store<${stateType}>`;
const storeConstructor = [start, `(${storeText})`, end].join('');
const constructorUpdate = new ReplaceChange(
componentPath,
pos,
` ${constructorText}\n\n`,
`\n\n ${storeConstructor}`
);
const changes = [storeImport, stateImport, constructorUpdate];
const recorder = host.beginUpdate(componentPath);
for (const change of changes) {
if (change instanceof InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
} else if (change instanceof ReplaceChange) {
recorder.remove(pos, change.oldText.length);
recorder.insertLeft(change.order, change.newText);
}