From 73f85d2ba001ff25c7948c51a675d25f7010a8c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Eriksson?= Date: Sat, 8 Jun 2024 17:34:50 +0200 Subject: [PATCH] tsparser: handle unary plus and minus --- tsparser/src/parser/types/type_resolve.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tsparser/src/parser/types/type_resolve.rs b/tsparser/src/parser/types/type_resolve.rs index a20368f016..2513b771b8 100644 --- a/tsparser/src/parser/types/type_resolve.rs +++ b/tsparser/src/parser/types/type_resolve.rs @@ -752,11 +752,15 @@ impl<'a> Ctx<'a> { // See https://www.typescriptlang.org/docs/handbook/2/typeof-types.html ast::UnaryOp::TypeOf => Type::Basic(Basic::String), - ast::UnaryOp::Minus - | ast::UnaryOp::Plus - | ast::UnaryOp::Bang - | ast::UnaryOp::Tilde - | ast::UnaryOp::Delete => self.expr(&expr.arg), + ast::UnaryOp::Plus => Type::Basic(Basic::Number), + ast::UnaryOp::Minus => match self.expr(&expr.arg) { + Type::Literal(Literal::Number(num)) => Type::Literal(Literal::Number(-num)), + other => other, + }, + + ast::UnaryOp::Bang | ast::UnaryOp::Tilde | ast::UnaryOp::Delete => { + self.expr(&expr.arg) + } }, ast::Expr::Update(expr) => self.expr(&expr.arg), ast::Expr::Bin(expr) => {