mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
@@ -2553,7 +2553,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
operand = (<TypeAssertion | NonNullExpression>operand).expression;
|
||||
}
|
||||
|
||||
// We have an expression of the form: (<Type>SubExpr)
|
||||
// We have an expression of the form: (<Type>SubExpr) or (SubExpr as Type)
|
||||
// Emitting this as (SubExpr) is really not desirable. We would like to emit the subexpr as is.
|
||||
// Omitting the parentheses, however, could cause change in the semantics of the generated
|
||||
// code if the casted expression has a lower precedence than the rest of the expression, e.g.:
|
||||
@@ -2567,6 +2567,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
operand.kind !== SyntaxKind.DeleteExpression &&
|
||||
operand.kind !== SyntaxKind.PostfixUnaryExpression &&
|
||||
operand.kind !== SyntaxKind.NewExpression &&
|
||||
!(operand.kind === SyntaxKind.BinaryExpression && node.expression.kind === SyntaxKind.AsExpression) &&
|
||||
!(operand.kind === SyntaxKind.CallExpression && node.parent.kind === SyntaxKind.NewExpression) &&
|
||||
!(operand.kind === SyntaxKind.FunctionExpression && node.parent.kind === SyntaxKind.CallExpression) &&
|
||||
!(operand.kind === SyntaxKind.NumericLiteral && node.parent.kind === SyntaxKind.PropertyAccessExpression)) {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
//// [asOpEmitParens.ts]
|
||||
declare var x;
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1 as number) * 3;
|
||||
|
||||
// Should still emit as x.y
|
||||
(x as any).y;
|
||||
|
||||
// Emit as new (x())
|
||||
new (x() as any);
|
||||
|
||||
|
||||
//// [asOpEmitParens.js]
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1) * 3;
|
||||
// Should still emit as x.y
|
||||
x.y;
|
||||
// Emit as new (x())
|
||||
new (x());
|
||||
@@ -0,0 +1,16 @@
|
||||
=== tests/cases/conformance/expressions/asOperator/asOpEmitParens.ts ===
|
||||
declare var x;
|
||||
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
|
||||
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1 as number) * 3;
|
||||
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
|
||||
|
||||
// Should still emit as x.y
|
||||
(x as any).y;
|
||||
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
|
||||
|
||||
// Emit as new (x())
|
||||
new (x() as any);
|
||||
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
=== tests/cases/conformance/expressions/asOperator/asOpEmitParens.ts ===
|
||||
declare var x;
|
||||
>x : any
|
||||
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1 as number) * 3;
|
||||
>(x + 1 as number) * 3 : number
|
||||
>(x + 1 as number) : number
|
||||
>x + 1 as number : number
|
||||
>x + 1 : any
|
||||
>x : any
|
||||
>1 : number
|
||||
>3 : number
|
||||
|
||||
// Should still emit as x.y
|
||||
(x as any).y;
|
||||
>(x as any).y : any
|
||||
>(x as any) : any
|
||||
>x as any : any
|
||||
>x : any
|
||||
>y : any
|
||||
|
||||
// Emit as new (x())
|
||||
new (x() as any);
|
||||
>new (x() as any) : any
|
||||
>(x() as any) : any
|
||||
>x() as any : any
|
||||
>x() : any
|
||||
>x : any
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
declare var x;
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1 as number) * 3;
|
||||
|
||||
// Should still emit as x.y
|
||||
(x as any).y;
|
||||
|
||||
// Emit as new (x())
|
||||
new (x() as any);
|
||||
Reference in New Issue
Block a user