@@ -771,7 +771,14 @@ export class JavaScriptParserVisitor {
771771 let _arguments : JContainer < J . Expression > | null = null ;
772772
773773 if ( ts . isCallExpression ( node . expression ) ) {
774- annotationType = this . convert ( node . expression . expression ) ;
774+ annotationType = new JS . ExpressionWithTypeArguments (
775+ randomId ( ) ,
776+ Space . EMPTY ,
777+ Markers . EMPTY ,
778+ this . convert ( node . expression . expression ) ,
779+ node . expression . typeArguments ? this . mapTypeArguments ( this . suffix ( node . expression . expression ) , node . expression . typeArguments ) : null ,
780+ null
781+ ) ;
775782 _arguments = this . mapCommaSeparatedList ( node . expression . getChildren ( this . sourceFile ) . slice ( - 3 ) )
776783 } else if ( ts . isIdentifier ( node . expression ) ) {
777784 annotationType = this . convert ( node . expression ) ;
@@ -1146,7 +1153,7 @@ export class JavaScriptParserVisitor {
11461153 randomId ( ) ,
11471154 this . prefix ( node ) ,
11481155 Markers . EMPTY ,
1149- [ ] ,
1156+ this . mapDecorators ( node ) ,
11501157 this . mapModifiers ( node ) ,
11511158 null ,
11521159 this . mapTypeInfo ( node ) ,
@@ -1163,7 +1170,7 @@ export class JavaScriptParserVisitor {
11631170 randomId ( ) ,
11641171 this . prefix ( node ) ,
11651172 Markers . EMPTY ,
1166- [ ] ,
1173+ this . mapDecorators ( node ) ,
11671174 this . mapModifiers ( node ) ,
11681175 null ,
11691176 this . mapTypeInfo ( node ) ,
@@ -1186,7 +1193,7 @@ export class JavaScriptParserVisitor {
11861193 randomId ( ) ,
11871194 this . prefix ( node ) ,
11881195 Markers . EMPTY ,
1189- [ ] ,
1196+ this . mapDecorators ( node ) ,
11901197 this . mapModifiers ( node ) ,
11911198 null ,
11921199 null ,
@@ -1203,7 +1210,7 @@ export class JavaScriptParserVisitor {
12031210 randomId ( ) ,
12041211 this . prefix ( node ) ,
12051212 Markers . EMPTY ,
1206- [ ] ,
1213+ this . mapDecorators ( node ) ,
12071214 this . mapModifiers ( node ) ,
12081215 null ,
12091216 null ,
@@ -2615,7 +2622,7 @@ export class JavaScriptParserVisitor {
26152622 Markers . EMPTY ,
26162623 [ node . initializer ?
26172624 ( ts . isVariableDeclarationList ( node . initializer ) ? this . rightPadded ( this . visit ( node . initializer ) , Space . EMPTY ) :
2618- this . rightPadded ( new ExpressionStatement ( randomId ( ) , this . visit ( node . initializer ) ) , this . suffix ( node . initializer . getLastToken ( ) ! ) ) ) :
2625+ this . rightPadded ( new ExpressionStatement ( randomId ( ) , this . visit ( node . initializer ) ) , this . suffix ( node . initializer ) ) ) :
26192626 this . rightPadded ( this . newJEmpty ( ) , this . suffix ( this . findChildNode ( node , ts . SyntaxKind . OpenParenToken ) ! ) ) ] , // to handle for (/*_*/; ; );
26202627 node . condition ? this . rightPadded ( ts . isStatement ( node . condition ) ? this . visit ( node . condition ) : new ExpressionStatement ( randomId ( ) , this . visit ( node . condition ) ) , this . suffix ( node . condition ) ) :
26212628 this . rightPadded ( this . newJEmpty ( ) , this . suffix ( this . findChildNode ( node , ts . SyntaxKind . SemicolonToken ) ! ) ) , // to handle for ( ;/*_*/; );
@@ -2758,7 +2765,7 @@ export class JavaScriptParserVisitor {
27582765 visitVariableDeclaration ( node : ts . VariableDeclaration ) {
27592766 const nameExpression = this . visit ( node . name ) ;
27602767
2761- if ( nameExpression instanceof J . Identifier ) {
2768+ if ( nameExpression instanceof J . Identifier && ! node . exclamationToken ) {
27622769 return new J . VariableDeclarations . NamedVariable (
27632770 randomId ( ) ,
27642771 this . prefix ( node ) ,
@@ -2774,7 +2781,17 @@ export class JavaScriptParserVisitor {
27742781 randomId ( ) ,
27752782 this . prefix ( node ) ,
27762783 Markers . EMPTY ,
2777- nameExpression ,
2784+ node . exclamationToken ? new JS . Unary (
2785+ randomId ( ) ,
2786+ Space . EMPTY ,
2787+ Markers . EMPTY ,
2788+ this . leftPadded (
2789+ this . suffix ( node . name ) ,
2790+ JS . Unary . Type . Exclamation
2791+ ) ,
2792+ nameExpression ,
2793+ this . mapType ( node )
2794+ ) : nameExpression ,
27782795 [ ] ,
27792796 node . initializer ? this . leftPadded ( this . prefix ( node . getChildAt ( node . getChildCount ( this . sourceFile ) - 2 ) ) , this . visit ( node . initializer ) ) : null ,
27802797 this . mapVariableType ( node )
@@ -2945,9 +2962,15 @@ export class JavaScriptParserVisitor {
29452962 visitModuleDeclaration ( node : ts . ModuleDeclaration ) {
29462963 const body = node . body ? this . visit ( node . body as ts . Node ) : null ;
29472964
2948- let namespaceKeyword = this . findChildNode ( node , ts . SyntaxKind . NamespaceKeyword ) ;
2949- const keywordType = namespaceKeyword ? JS . NamespaceDeclaration . KeywordType . Namespace : JS . NamespaceDeclaration . KeywordType . Module
2950- namespaceKeyword ??= this . findChildNode ( node , ts . SyntaxKind . ModuleKeyword ) ;
2965+ let namespaceKeyword = this . findChildNode ( node , ts . SyntaxKind . NamespaceKeyword ) ?? this . findChildNode ( node , ts . SyntaxKind . ModuleKeyword ) ;
2966+ let keywordType : JS . NamespaceDeclaration . KeywordType ;
2967+ if ( namespaceKeyword == undefined ) {
2968+ keywordType = JS . NamespaceDeclaration . KeywordType . Empty ;
2969+ } else if ( namespaceKeyword ?. kind === ts . SyntaxKind . NamespaceKeyword ) {
2970+ keywordType = JS . NamespaceDeclaration . KeywordType . Namespace ;
2971+ } else {
2972+ keywordType = JS . NamespaceDeclaration . KeywordType . Module ;
2973+ }
29512974 if ( body instanceof JS . NamespaceDeclaration ) {
29522975 return new JS . NamespaceDeclaration (
29532976 randomId ( ) ,
@@ -3368,6 +3391,7 @@ export class JavaScriptParserVisitor {
33683391 this . prefix ( node ) ,
33693392 Markers . EMPTY ,
33703393 this . rightPadded ( this . visit ( node . name ) , this . suffix ( node . name ) ) ,
3394+ JS . PropertyAssignment . AssigmentToken . Colon ,
33713395 this . visit ( node . initializer )
33723396 ) ;
33733397 }
@@ -3378,7 +3402,8 @@ export class JavaScriptParserVisitor {
33783402 this . prefix ( node ) ,
33793403 Markers . EMPTY ,
33803404 this . rightPadded ( this . visit ( node . name ) , this . suffix ( node . name ) ) ,
3381- null
3405+ JS . PropertyAssignment . AssigmentToken . Equals ,
3406+ node . objectAssignmentInitializer ? this . visit ( node . objectAssignmentInitializer ) : null
33823407 ) ;
33833408 }
33843409
@@ -3401,6 +3426,7 @@ export class JavaScriptParserVisitor {
34013426 ) ,
34023427 this . suffix ( node . expression )
34033428 ) ,
3429+ JS . PropertyAssignment . AssigmentToken . Empty ,
34043430 null
34053431 ) ;
34063432 }
@@ -3740,15 +3766,18 @@ export class JavaScriptParserVisitor {
37403766 return args ;
37413767 }
37423768
3743- private mapDecorators ( node : ts . ClassDeclaration | ts . FunctionDeclaration | ts . MethodDeclaration | ts . ConstructorDeclaration | ts . ParameterDeclaration | ts . PropertyDeclaration ) : J . Annotation [ ] {
3769+ private mapDecorators ( node : ts . ClassDeclaration | ts . FunctionDeclaration | ts . MethodDeclaration | ts . ConstructorDeclaration | ts . ParameterDeclaration | ts . PropertyDeclaration | ts . SetAccessorDeclaration | ts . GetAccessorDeclaration ) : J . Annotation [ ] {
37443770 return node . modifiers ?. filter ( ts . isDecorator ) ?. map ( this . convert < J . Annotation > ) ?? [ ] ;
37453771 }
37463772
37473773 private mapTypeParametersAsJContainer ( node : ts . ClassDeclaration | ts . InterfaceDeclaration | ts . ClassExpression ) : JContainer < J . TypeParameter > | null {
37483774 return node . typeParameters
37493775 ? JContainer . build (
37503776 this . suffix ( this . findChildNode ( node , ts . SyntaxKind . Identifier ) ! ) ,
3751- this . mapTypeParametersList ( node . typeParameters ) ,
3777+ this . mapTypeParametersList ( node . typeParameters )
3778+ . concat ( node . typeParameters . hasTrailingComma ? this . rightPadded (
3779+ new J . TypeParameter ( randomId ( ) , Space . EMPTY , Markers . EMPTY , [ ] , [ ] , this . newJEmpty ( ) , null ) ,
3780+ this . prefix ( this . findChildNode ( node , ts . SyntaxKind . GreaterThanToken ) ! ) ) : [ ] ) ,
37523781 Markers . EMPTY
37533782 )
37543783 : null ;
@@ -3765,7 +3794,9 @@ export class JavaScriptParserVisitor {
37653794 Markers . EMPTY ,
37663795 [ ] ,
37673796 typeParameters . map ( tp => this . rightPadded ( this . visit ( tp ) , this . suffix ( tp ) ) )
3768- . concat ( typeParameters . hasTrailingComma ? this . rightPadded ( this . newJEmpty ( ) , this . prefix ( this . findChildNode ( node , ts . SyntaxKind . GreaterThanToken ) ! ) ) : [ ] ) ,
3797+ . concat ( typeParameters . hasTrailingComma ? this . rightPadded (
3798+ new J . TypeParameter ( randomId ( ) , Space . EMPTY , Markers . EMPTY , [ ] , [ ] , this . newJEmpty ( ) , null ) ,
3799+ this . prefix ( this . findChildNode ( node , ts . SyntaxKind . GreaterThanToken ) ! ) ) : [ ] ) ,
37693800 ) ;
37703801 }
37713802
0 commit comments