Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static getContainerBodyPos(container: ContainerNodes, sourceFile: ts.SourceFile) {
if (ts.isSourceFile(container))
return 0;
if (ts.isClassDeclaration(container)
|| ts.isEnumDeclaration(container)
|| ts.isInterfaceDeclaration(container)
|| ts.isTypeLiteralNode(container)
|| ts.isClassExpression(container)
|| ts.isBlock(container)
|| ts.isModuleBlock(container)
|| ts.isObjectLiteralExpression(container))
{
// this function is only used when there are no statements or members, so only do this
return getTokenEnd(container, SyntaxKind.OpenBraceToken);
}
if (ts.isCaseClause(container) || ts.isDefaultClause(container))
return getTokenEnd(container, SyntaxKind.ColonToken);
return errors.throwNotImplementedForNeverValueError(container);
function getTokenEnd(node: ts.Node, kind: SyntaxKind.OpenBraceToken | SyntaxKind.ColonToken) {
// @code-fence-allow(getChildren): Ok, not searching for comments.
const token = node.getChildren(sourceFile).find(c => c.kind === kind);
if (token == null)
throw new errors.NotImplementedError(`Unexpected scenario where a(n) ${getSyntaxKindName(kind)} was not found.`);
return token.end;
function getCtor() {
if (isStatementContainerNode(container))
return CompilerCommentStatement;
if (ts.isClassLike(container))
return CompilerCommentClassElement;
if (ts.isInterfaceDeclaration(container) || ts.isTypeLiteralNode(container))
return CompilerCommentTypeElement;
if (ts.isObjectLiteralExpression(container))
return CompilerCommentObjectLiteralElement;
if (ts.isEnumDeclaration(container))
return CompilerCommentEnumMember;
throw new errors.NotImplementedError(`Not implemented comment node container type: ${getSyntaxKindName(container.kind)}`);
}
}
function getContainerChildren() {
if (ts.isSourceFile(container) || ts.isBlock(container) || ts.isModuleBlock(container) || ts.isCaseClause(container) || ts.isDefaultClause(container))
return container.statements;
if (ts.isClassDeclaration(container)
|| ts.isClassExpression(container)
|| ts.isEnumDeclaration(container)
|| ts.isInterfaceDeclaration(container)
|| ts.isTypeLiteralNode(container)
|| ts.isClassExpression(container))
{
return container.members;
}
if (ts.isObjectLiteralExpression(container))
return container.properties;
return errors.throwNotImplementedForNeverValueError(container);
}