Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function extractEndpointTags(
decoratorConfig: ObjectLiteralExpression
): Result {
const tagsProp = getObjLiteralProp(decoratorConfig, "tags");
if (tagsProp === undefined) return ok([]);
const tagsLiteral = getPropValueAsArrayOrThrow(tagsProp);
const tags: string[] = [];
for (const elementExpr of tagsLiteral.getElements()) {
// Sanity check, typesafety should prevent any non-string tags
if (!TypeGuards.isStringLiteral(elementExpr)) {
return err(
new ParserError("endpoint tag must be a string", {
file: elementExpr.getSourceFile().getFilePath(),
position: elementExpr.getPos()
})
);
}
const tag = elementExpr.getLiteralText().trim();
if (tag.length === 0) {
return err(
new ParserError("endpoint tag cannot be blank", {
file: elementExpr.getSourceFile().getFilePath(),
position: elementExpr.getPos()
})
);
}
function parseLiteralType(
typeNode: LiteralTypeNode
): Result<
BooleanLiteralType | StringLiteralType | FloatLiteralType | IntLiteralType,
ParserError
> {
const literal = typeNode.getLiteral();
if (TypeGuards.isBooleanLiteral(literal)) {
return ok(booleanLiteralType(literal.getLiteralValue()));
} else if (TypeGuards.isStringLiteral(literal)) {
return ok(stringLiteralType(literal.getLiteralText()));
} else if (TypeGuards.isNumericLiteral(literal)) {
const numericValue = literal.getLiteralValue();
return ok(
Number.isInteger(numericValue)
? intLiteralType(numericValue)
: floatLiteralType(numericValue)
);
} else {
return err(
new TypeNotAllowedError("unexpected literal type", {
file: typeNode.getSourceFile().getFilePath(),
position: typeNode.getPos()
})
);
}
if (literalChain.some(literal => !TypeGuards.isStringLiteral(literal))) {
throw new Error("indexed access type error: not a string literal");
export function parseExpression(expression: Expression): DataExpression {
if (TypeGuards.isNullLiteral(expression)) {
return nullExpression();
} else if (TypeGuards.isBooleanLiteral(expression)) {
return booleanExpression(expression.getLiteralValue());
} else if (TypeGuards.isStringLiteral(expression)) {
return stringExpression(expression.getLiteralValue());
} else if (TypeGuards.isPrefixUnaryExpression(expression)) {
const operand = expression.getOperand();
if (!TypeGuards.isNumericLiteral(operand)) {
throw new Error("unary operators may only be used with numeric literals");
}
switch (expression.getOperatorToken()) {
case SyntaxKind.MinusToken:
return numberExpression(-operand.getLiteralValue());
case SyntaxKind.PlusToken:
return numberExpression(operand.getLiteralValue());
default:
throw new Error("unknown prefix operator token");
}
} else if (TypeGuards.isNumericLiteral(expression)) {
return numberExpression(expression.getLiteralValue());
export function isMap(node: (sast.InterfaceDeclaration | sast.ClassDeclaration | sast.TypeLiteralNode)) : boolean {
const members = node.getMembers();
if (members.length === 0)
return false;
let isMap : boolean = true;
for (let m = 0; m < members.length; m++)
{
const member = members[m];
if (TypeGuards.isPropertySignature(member))
{
const name = member.getName();
const memberType = member.getNameNode();
if (!TypeGuards.isStringLiteral(memberType))
{
isMap = false;
break;
}
}
else
{
isMap = false;
break;
}
}
return isMap;
}
function parseLiteralType(typeNode: LiteralTypeNode): PrimitiveLiteral {
const literal = typeNode.getLiteral();
if (TypeGuards.isBooleanLiteral(literal)) {
return booleanLiteral(literal.getLiteralValue());
} else if (TypeGuards.isStringLiteral(literal)) {
return stringLiteral(literal.getLiteralText());
} else if (TypeGuards.isNumericLiteral(literal)) {
return numberLiteral(literal.getLiteralValue());
} else {
throw new Error("unexpected literal type");
}
}
const value = literal.getElements().map(e => {
if (TypeGuards.isStringLiteral(e)) {
return e.getLiteralText();
} else {
throw new Error(`expected string literal`);
}
});
const location = property.getSourceFile().getFilePath();