Add tests for issue #4603

This commit is contained in:
vilicvane 2015-09-04 22:15:10 +08:00
parent 856f2d895c
commit 32d8a22990
8 changed files with 120 additions and 10 deletions

View file

@ -7,6 +7,11 @@ declare var a;
(<any>[1,3,]);
(<any>"string");
(<any>23.0);
(<any>1);
(<any>1.).foo;
(<any>1.0).foo;
(<any>12e+34).foo;
(<any>0xff).foo;
(<any>/regexp/g);
(<any>false);
(<any>true);
@ -23,6 +28,8 @@ declare var a;
declare var A;
// should keep the parentheses in emit
(<any>1).foo;
(<any>(1.0)).foo;
(<any>new A).foo;
(<any>typeof A).x;
(<any>-A).x;
@ -46,6 +53,11 @@ new (<any>A());
[1, 3,];
"string";
23.0;
1;
1..foo;
1.0.foo;
12e+34.foo;
0xff.foo;
/regexp/g;
false;
true;
@ -59,6 +71,8 @@ a[0];
a.b["0"];
a().x;
// should keep the parentheses in emit
(1).foo;
(1.0).foo;
(new A).foo;
(typeof A).x;
(-A).x;

View file

@ -10,6 +10,11 @@ declare var a;
(<any>[1,3,]);
(<any>"string");
(<any>23.0);
(<any>1);
(<any>1.).foo;
(<any>1.0).foo;
(<any>12e+34).foo;
(<any>0xff).foo;
(<any>/regexp/g);
(<any>false);
(<any>true);
@ -33,36 +38,38 @@ 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.0)).foo;
(<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, 35, 2))
(<any>function foo() { })();
>foo : Symbol(foo, Decl(castExpressionParentheses.ts, 29, 6))
>foo : Symbol(foo, Decl(castExpressionParentheses.ts, 36, 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))

View file

@ -28,6 +28,39 @@ declare var a;
><any>23.0 : any
>23.0 : number
(<any>1);
>(<any>1) : any
><any>1 : any
>1 : number
(<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>/regexp/g);
>(<any>/regexp/g) : any
><any>/regexp/g : any
@ -104,6 +137,21 @@ 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.0)).foo;
>(<any>(1.0)).foo : any
>(<any>(1.0)) : any
><any>(1.0) : any
>(1.0) : number
>1.0 : number
>foo : any
(<any>new A).foo;
>(<any>new A).foo : any
>(<any>new A) : any

View file

@ -0,0 +1,11 @@
//// [castExpressionParentheses_ES6.ts]
// parentheses should be omitted
// numeric literal
(<any>0o123).foo;
//// [castExpressionParentheses_ES6.js]
// parentheses should be omitted
// numeric literal
0o123.foo;

View file

@ -0,0 +1,7 @@
=== tests/cases/compiler/castExpressionParentheses_ES6.ts ===
No type information for this code.// parentheses should be omitted
No type information for this code.// numeric literal
No type information for this code.(<any>0o123).foo;
No type information for this code.
No type information for this code.

View file

@ -0,0 +1,11 @@
=== tests/cases/compiler/castExpressionParentheses_ES6.ts ===
// parentheses should be omitted
// numeric literal
(<any>0o123).foo;
>(<any>0o123).foo : any
>(<any>0o123) : any
><any>0o123 : any
>0o123 : number
>foo : any

View file

@ -6,6 +6,11 @@ declare var a;
(<any>[1,3,]);
(<any>"string");
(<any>23.0);
(<any>1);
(<any>1.).foo;
(<any>1.0).foo;
(<any>12e+34).foo;
(<any>0xff).foo;
(<any>/regexp/g);
(<any>false);
(<any>true);
@ -22,6 +27,8 @@ declare var a;
declare var A;
// should keep the parentheses in emit
(<any>1).foo;
(<any>(1.0)).foo;
(<any>new A).foo;
(<any>typeof A).x;
(<any>-A).x;

View file

@ -0,0 +1,5 @@
// @target: es6
// parentheses should be omitted
// numeric literal
(<any>0o123).foo;