Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function addReducerToStateInterface(source, reducersPath, options) {
const stateInterface = source.statements.find(stm => stm.kind === ts.SyntaxKind.InterfaceDeclaration);
let node = stateInterface;
if (!node) {
return new change_1.NoopChange();
}
const state = options.plural
? stringUtils.pluralize(options.name)
: stringUtils.camelize(options.name);
const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;';
const expr = node;
let position;
let toInsert;
if (expr.members.length === 0) {
position = expr.getEnd() - 1;
toInsert = ` ${keyInsert}\n`;
}
else {
node = expr.members[expr.members.length - 1];
position = node.getEnd() + 1;
// Get the indentation of the last element, if any.
const text = node.getFullText(source);
const matches = text.match(/^\r?\n+(\s*)/);
if (matches.length > 0) {
toInsert = `${matches[1]}${keyInsert}\n`;