MCPcopy Index your code
hub / github.com/nodejs/node / checkPrefixUnaryExpression

Function checkPrefixUnaryExpression

test/fixtures/snapshot/typescript.js:78464–78517  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

78462 return awaitedType;
78463 }
78464 function checkPrefixUnaryExpression(node) {
78465 var operandType = checkExpression(node.operand);
78466 if (operandType === silentNeverType) {
78467 return silentNeverType;
78468 }
78469 switch (node.operand.kind) {
78470 case 8 /* SyntaxKind.NumericLiteral */:
78471 switch (node.operator) {
78472 case 40 /* SyntaxKind.MinusToken */:
78473 return getFreshTypeOfLiteralType(getNumberLiteralType(-node.operand.text));
78474 case 39 /* SyntaxKind.PlusToken */:
78475 return getFreshTypeOfLiteralType(getNumberLiteralType(+node.operand.text));
78476 }
78477 break;
78478 case 9 /* SyntaxKind.BigIntLiteral */:
78479 if (node.operator === 40 /* SyntaxKind.MinusToken */) {
78480 return getFreshTypeOfLiteralType(getBigIntLiteralType({
78481 negative: true,
78482 base10Value: ts.parsePseudoBigInt(node.operand.text)
78483 }));
78484 }
78485 }
78486 switch (node.operator) {
78487 case 39 /* SyntaxKind.PlusToken */:
78488 case 40 /* SyntaxKind.MinusToken */:
78489 case 54 /* SyntaxKind.TildeToken */:
78490 checkNonNullType(operandType, node.operand);
78491 if (maybeTypeOfKindConsideringBaseConstraint(operandType, 12288 /* TypeFlags.ESSymbolLike */)) {
78492 error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator));
78493 }
78494 if (node.operator === 39 /* SyntaxKind.PlusToken */) {
78495 if (maybeTypeOfKind(operandType, 2112 /* TypeFlags.BigIntLike */)) {
78496 error(node.operand, ts.Diagnostics.Operator_0_cannot_be_applied_to_type_1, ts.tokenToString(node.operator), typeToString(getBaseTypeOfLiteralType(operandType)));
78497 }
78498 return numberType;
78499 }
78500 return getUnaryResultType(operandType);
78501 case 53 /* SyntaxKind.ExclamationToken */:
78502 checkTruthinessExpression(node.operand);
78503 var facts = getTypeFacts(operandType) & (4194304 /* TypeFacts.Truthy */ | 8388608 /* TypeFacts.Falsy */);
78504 return facts === 4194304 /* TypeFacts.Truthy */ ? falseType :
78505 facts === 8388608 /* TypeFacts.Falsy */ ? trueType :
78506 booleanType;
78507 case 45 /* SyntaxKind.PlusPlusToken */:
78508 case 46 /* SyntaxKind.MinusMinusToken */:
78509 var ok = checkArithmeticOperandType(node.operand, checkNonNullType(operandType, node.operand), ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type);
78510 if (ok) {
78511 // run check only if former checks succeeded to avoid reporting cascading errors
78512 checkReferenceExpression(node.operand, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_may_not_be_an_optional_property_access);
78513 }
78514 return getUnaryResultType(operandType);
78515 }
78516 return errorType;
78517 }
78518 function checkPostfixUnaryExpression(node) {
78519 var operandType = checkExpression(node.operand);
78520 if (operandType === silentNeverType) {

Callers 1

checkExpressionWorkerFunction · 0.85

Calls 15

getNumberLiteralTypeFunction · 0.85
getBigIntLiteralTypeFunction · 0.85
checkNonNullTypeFunction · 0.85
maybeTypeOfKindFunction · 0.85
typeToStringFunction · 0.85
getBaseTypeOfLiteralTypeFunction · 0.85
getUnaryResultTypeFunction · 0.85
getTypeFactsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…