mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Merge pull request #4641 from vilic/cast-expression-parentheses-with-numeric-literal
Do not omit parentheses for numeric literal with ".property" if it can not be followed by dot operator directly.
This commit is contained in:
commit
bed25ddf18
@ -2354,7 +2354,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
operand.kind !== SyntaxKind.PostfixUnaryExpression &&
|
||||
operand.kind !== SyntaxKind.NewExpression &&
|
||||
!(operand.kind === SyntaxKind.CallExpression && node.parent.kind === SyntaxKind.NewExpression) &&
|
||||
!(operand.kind === SyntaxKind.FunctionExpression && node.parent.kind === SyntaxKind.CallExpression)) {
|
||||
!(operand.kind === SyntaxKind.FunctionExpression && node.parent.kind === SyntaxKind.CallExpression) &&
|
||||
!(operand.kind === SyntaxKind.NumericLiteral && node.parent.kind === SyntaxKind.PropertyAccessExpression)) {
|
||||
emit(operand);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -7,6 +7,11 @@ declare var a;
|
||||
(<any>[1,3,]);
|
||||
(<any>"string");
|
||||
(<any>23.0);
|
||||
(<any>1);
|
||||
(<any>1.);
|
||||
(<any>1.0);
|
||||
(<any>12e+34);
|
||||
(<any>0xff);
|
||||
(<any>/regexp/g);
|
||||
(<any>false);
|
||||
(<any>true);
|
||||
@ -23,6 +28,12 @@ declare var a;
|
||||
declare var A;
|
||||
|
||||
// should keep the parentheses in emit
|
||||
(<any>1).foo;
|
||||
(<any>1.).foo;
|
||||
(<any>1.0).foo;
|
||||
(<any>12e+34).foo;
|
||||
(<any>0xff).foo;
|
||||
(<any>(1.0));
|
||||
(<any>new A).foo;
|
||||
(<any>typeof A).x;
|
||||
(<any>-A).x;
|
||||
@ -46,6 +57,11 @@ new (<any>A());
|
||||
[1, 3,];
|
||||
"string";
|
||||
23.0;
|
||||
1;
|
||||
1.;
|
||||
1.0;
|
||||
12e+34;
|
||||
0xff;
|
||||
/regexp/g;
|
||||
false;
|
||||
true;
|
||||
@ -59,6 +75,12 @@ a[0];
|
||||
a.b["0"];
|
||||
a().x;
|
||||
// should keep the parentheses in emit
|
||||
(1).foo;
|
||||
(1.).foo;
|
||||
(1.0).foo;
|
||||
(12e+34).foo;
|
||||
(0xff).foo;
|
||||
(1.0);
|
||||
(new A).foo;
|
||||
(typeof A).x;
|
||||
(-A).x;
|
||||
|
||||
@ -10,6 +10,11 @@ declare var a;
|
||||
(<any>[1,3,]);
|
||||
(<any>"string");
|
||||
(<any>23.0);
|
||||
(<any>1);
|
||||
(<any>1.);
|
||||
(<any>1.0);
|
||||
(<any>12e+34);
|
||||
(<any>0xff);
|
||||
(<any>/regexp/g);
|
||||
(<any>false);
|
||||
(<any>true);
|
||||
@ -33,36 +38,42 @@ declare var a;
|
||||
>a : Symbol(a, Decl(castExpressionParentheses.ts, 0, 11))
|
||||
|
||||
declare var A;
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11))
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11))
|
||||
|
||||
// should keep the parentheses in emit
|
||||
(<any>1).foo;
|
||||
(<any>1.).foo;
|
||||
(<any>1.0).foo;
|
||||
(<any>12e+34).foo;
|
||||
(<any>0xff).foo;
|
||||
(<any>(1.0));
|
||||
(<any>new A).foo;
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11))
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11))
|
||||
|
||||
(<any>typeof A).x;
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11))
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11))
|
||||
|
||||
(<any>-A).x;
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11))
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11))
|
||||
|
||||
new (<any>A());
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11))
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11))
|
||||
|
||||
(<Tany>()=> {})();
|
||||
>Tany : Symbol(Tany, Decl(castExpressionParentheses.ts, 28, 2))
|
||||
>Tany : Symbol(Tany, Decl(castExpressionParentheses.ts, 39, 2))
|
||||
|
||||
(<any>function foo() { })();
|
||||
>foo : Symbol(foo, Decl(castExpressionParentheses.ts, 29, 6))
|
||||
>foo : Symbol(foo, Decl(castExpressionParentheses.ts, 40, 6))
|
||||
|
||||
(<any><number><any>-A).x;
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11))
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11))
|
||||
|
||||
// nested cast, should keep one pair of parenthese
|
||||
(<any><number>(<any>-A)).x;
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11))
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11))
|
||||
|
||||
// nested parenthesized expression, should keep one pair of parenthese
|
||||
(<any>(A))
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11))
|
||||
>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11))
|
||||
|
||||
|
||||
|
||||
@ -28,6 +28,31 @@ declare var a;
|
||||
><any>23.0 : any
|
||||
>23.0 : number
|
||||
|
||||
(<any>1);
|
||||
>(<any>1) : any
|
||||
><any>1 : any
|
||||
>1 : number
|
||||
|
||||
(<any>1.);
|
||||
>(<any>1.) : any
|
||||
><any>1. : any
|
||||
>1. : number
|
||||
|
||||
(<any>1.0);
|
||||
>(<any>1.0) : any
|
||||
><any>1.0 : any
|
||||
>1.0 : number
|
||||
|
||||
(<any>12e+34);
|
||||
>(<any>12e+34) : any
|
||||
><any>12e+34 : any
|
||||
>12e+34 : number
|
||||
|
||||
(<any>0xff);
|
||||
>(<any>0xff) : any
|
||||
><any>0xff : any
|
||||
>0xff : number
|
||||
|
||||
(<any>/regexp/g);
|
||||
>(<any>/regexp/g) : any
|
||||
><any>/regexp/g : any
|
||||
@ -104,6 +129,47 @@ declare var A;
|
||||
>A : any
|
||||
|
||||
// should keep the parentheses in emit
|
||||
(<any>1).foo;
|
||||
>(<any>1).foo : any
|
||||
>(<any>1) : any
|
||||
><any>1 : any
|
||||
>1 : number
|
||||
>foo : any
|
||||
|
||||
(<any>1.).foo;
|
||||
>(<any>1.).foo : any
|
||||
>(<any>1.) : any
|
||||
><any>1. : any
|
||||
>1. : number
|
||||
>foo : any
|
||||
|
||||
(<any>1.0).foo;
|
||||
>(<any>1.0).foo : any
|
||||
>(<any>1.0) : any
|
||||
><any>1.0 : any
|
||||
>1.0 : number
|
||||
>foo : any
|
||||
|
||||
(<any>12e+34).foo;
|
||||
>(<any>12e+34).foo : any
|
||||
>(<any>12e+34) : any
|
||||
><any>12e+34 : any
|
||||
>12e+34 : number
|
||||
>foo : any
|
||||
|
||||
(<any>0xff).foo;
|
||||
>(<any>0xff).foo : any
|
||||
>(<any>0xff) : any
|
||||
><any>0xff : any
|
||||
>0xff : number
|
||||
>foo : any
|
||||
|
||||
(<any>(1.0));
|
||||
>(<any>(1.0)) : any
|
||||
><any>(1.0) : any
|
||||
>(1.0) : number
|
||||
>1.0 : number
|
||||
|
||||
(<any>new A).foo;
|
||||
>(<any>new A).foo : any
|
||||
>(<any>new A) : any
|
||||
|
||||
@ -6,6 +6,11 @@ declare var a;
|
||||
(<any>[1,3,]);
|
||||
(<any>"string");
|
||||
(<any>23.0);
|
||||
(<any>1);
|
||||
(<any>1.);
|
||||
(<any>1.0);
|
||||
(<any>12e+34);
|
||||
(<any>0xff);
|
||||
(<any>/regexp/g);
|
||||
(<any>false);
|
||||
(<any>true);
|
||||
@ -22,6 +27,12 @@ declare var a;
|
||||
declare var A;
|
||||
|
||||
// should keep the parentheses in emit
|
||||
(<any>1).foo;
|
||||
(<any>1.).foo;
|
||||
(<any>1.0).foo;
|
||||
(<any>12e+34).foo;
|
||||
(<any>0xff).foo;
|
||||
(<any>(1.0));
|
||||
(<any>new A).foo;
|
||||
(<any>typeof A).x;
|
||||
(<any>-A).x;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user