{
if (lastStatement === undefined) {
return undefined;
}
if (ts.isDeclaration(lastStatement)) {
return ts.getNameOfDeclaration(lastStatement).escapedText;
}
if (ts.isVariableStatement(lastStatement)) {
if (lastStatement.declarationList.declarations.length != 1) {
throw `Variable statement must have only one declaration but got ${lastStatement.declarationList.declarations.length}`
}
return lastStatement.declarationList.declarations[0].name.escapedText
}
return undefined;
}