1
1
namespace ts {
2
2
describe ( "FactoryAPI" , ( ) => {
3
+ function assertSyntaxKind ( node : Node , expected : SyntaxKind ) {
4
+ assert . strictEqual ( node . kind , expected , `Actual: ${ Debug . showSyntaxKind ( node ) } Expected: ${ ( ts as any ) . SyntaxKind [ expected ] } ` ) ;
5
+ }
3
6
describe ( "createExportAssignment" , ( ) => {
4
7
it ( "parenthesizes default export if necessary" , ( ) => {
5
8
function checkExpression ( expression : Expression ) {
@@ -9,7 +12,7 @@ namespace ts {
9
12
/*isExportEquals*/ false ,
10
13
expression ,
11
14
) ;
12
- assert . strictEqual ( node . expression . kind , SyntaxKind . ParenthesizedExpression ) ;
15
+ assertSyntaxKind ( node . expression , SyntaxKind . ParenthesizedExpression ) ;
13
16
}
14
17
15
18
const clazz = createClassExpression ( /*modifiers*/ undefined , "C" , /*typeParameters*/ undefined , /*heritageClauses*/ undefined , [
@@ -39,7 +42,7 @@ namespace ts {
39
42
/*equalsGreaterThanToken*/ undefined ,
40
43
body ,
41
44
) ;
42
- assert . strictEqual ( node . body . kind , SyntaxKind . ParenthesizedExpression ) ;
45
+ assertSyntaxKind ( node . body , SyntaxKind . ParenthesizedExpression ) ;
43
46
}
44
47
45
48
checkBody ( createObjectLiteral ( ) ) ;
@@ -50,5 +53,30 @@ namespace ts {
50
53
checkBody ( createBinary ( createLiteral ( "a" ) , SyntaxKind . CommaToken , createLiteral ( "b" ) ) ) ;
51
54
} ) ;
52
55
} ) ;
56
+
57
+ describe ( "createBinaryExpression" , ( ) => {
58
+ it ( "parenthesizes arrow function in RHS if necessary" , ( ) => {
59
+ const lhs = createIdentifier ( "foo" ) ;
60
+ const rhs = createArrowFunction (
61
+ /*modifiers*/ undefined ,
62
+ /*typeParameters*/ undefined ,
63
+ [ ] ,
64
+ /*type*/ undefined ,
65
+ /*equalsGreaterThanToken*/ undefined ,
66
+ createBlock ( [ ] ) ,
67
+ ) ;
68
+ function checkRhs ( operator : BinaryOperator , expectParens : boolean ) {
69
+ const node = createBinary ( lhs , operator , rhs ) ;
70
+ assertSyntaxKind ( node . right , expectParens ? SyntaxKind . ParenthesizedExpression : SyntaxKind . ArrowFunction ) ;
71
+ }
72
+
73
+ checkRhs ( SyntaxKind . CommaToken , /*expectParens*/ false ) ;
74
+ checkRhs ( SyntaxKind . EqualsToken , /*expectParens*/ false ) ;
75
+ checkRhs ( SyntaxKind . PlusEqualsToken , /*expectParens*/ false ) ;
76
+ checkRhs ( SyntaxKind . BarBarToken , /*expectParens*/ true ) ;
77
+ checkRhs ( SyntaxKind . AmpersandAmpersandToken , /*expectParens*/ true ) ;
78
+ checkRhs ( SyntaxKind . EqualsEqualsToken , /*expectParens*/ true ) ;
79
+ } ) ;
80
+ } ) ;
53
81
} ) ;
54
82
}
0 commit comments