mirror of
https://github.com/hanzoai/esbuild.git
synced 2026-09-24 16:58:50 +00:00
disable ts cast warning for parenthesized exprs
This commit is contained in:
@@ -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 }
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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", "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user