disable ts cast warning for parenthesized exprs

This commit is contained in:
Evan Wallace
2026-08-07 18:37:55 -04:00
parent f9ffe5770d
commit 9e39dc0d0a
3 changed files with 15 additions and 4 deletions
+4 -3
View File
@@ -540,9 +540,10 @@ type EUnary struct {
}
type EBinary struct {
Left Expr
Right Expr
Op OpCode
Left Expr
Right Expr
Op OpCode
IsParenthesized bool
}
type EBoolean struct{ Value bool }
+3 -1
View File
@@ -4989,7 +4989,7 @@ func (p *parser) parseSuffix(left js_ast.Expr, level js_ast.L, errors *deferredE
// See: https://github.com/microsoft/TypeScript/issues/63527
if isAfterAs {
if binary, ok := left.Data.(*js_ast.EBinary); ok {
if binaryLeft, ok := binary.Left.Data.(*js_ast.EBinary); ok {
if binaryLeft, ok := binary.Left.Data.(*js_ast.EBinary); ok && !binaryLeft.IsParenthesized {
rightLevel := js_ast.OpTable[binary.Op].Level
if binary.Op.IsRightAssociative() {
rightLevel++
@@ -11906,6 +11906,8 @@ func (p *parser) markExprAsParenthesized(value js_ast.Expr, openParenLoc logger.
e.IsParenthesized = true
case *js_ast.EArrow:
e.IsParenthesized = true
case *js_ast.EBinary:
e.IsParenthesized = true
}
}
+8
View File
@@ -3336,14 +3336,22 @@ func TestTSWarningBinaryOperatorAfterCast(t *testing.T) {
expectParseErrorTS(t, "1 * 2 as number * 3", "")
expectParseErrorTS(t, "1 * 2 as number + 3", "")
expectParseErrorTS(t, "1 + 2 as number * 3", "<stdin>: WARNING: Operator \"*\" should not directly follow a TypeScript type cast after the \"+\" operator\n"+note)
expectParseErrorTS(t, "(1 + 2) as number * 3", "")
expectParseErrorTS(t, "(1 + 2 as number) * 3", "")
expectParseErrorTS(t, "1 satisfies number + 2", "")
expectParseErrorTS(t, "1 + 2 satisfies number + 3", "")
expectParseErrorTS(t, "1 + 2 satisfies number - 3", "")
expectParseErrorTS(t, "1 * 2 satisfies number * 3", "")
expectParseErrorTS(t, "1 * 2 satisfies number + 3", "")
expectParseErrorTS(t, "1 + 2 satisfies number * 3", "<stdin>: WARNING: Operator \"*\" should not directly follow a TypeScript type cast after the \"+\" operator\n"+note)
expectParseErrorTS(t, "(1 + 2) satisfies number * 3", "")
expectParseErrorTS(t, "(1 + 2 satisfies number) * 3", "")
// See: https://github.com/microsoft/TypeScript/issues/63661
expectParseErrorTS(t, "1 ** 2 as number ** 3", "<stdin>: WARNING: Operator \"**\" should not directly follow a TypeScript type cast after the \"**\" operator\n"+note)
expectParseErrorTS(t, "(1 ** 2) as number ** 3", "")
expectParseErrorTS(t, "(1 ** 2 as number) ** 3", "")
expectParseErrorTS(t, "1 ** 2 satisfies number ** 3", "<stdin>: WARNING: Operator \"**\" should not directly follow a TypeScript type cast after the \"**\" operator\n"+note)
expectParseErrorTS(t, "(1 ** 2) satisfies number ** 3", "")
expectParseErrorTS(t, "(1 ** 2 satisfies number) ** 3", "")
}