@@ -263,12 +263,12 @@ export class JavaScriptParserVisitor {
263263 | ts . FunctionDeclaration | ts . ParameterDeclaration | ts . MethodDeclaration | ts . EnumDeclaration | ts . InterfaceDeclaration
264264 | ts . PropertySignature | ts . ConstructorDeclaration | ts . ModuleDeclaration | ts . GetAccessorDeclaration | ts . SetAccessorDeclaration
265265 | ts . ArrowFunction | ts . IndexSignatureDeclaration | ts . TypeAliasDeclaration | ts . ExportDeclaration | ts . ExportAssignment | ts . FunctionExpression
266- | ts . ConstructorTypeNode ) {
266+ | ts . ConstructorTypeNode | ts . TypeParameterDeclaration ) {
267267 if ( ts . isVariableStatement ( node ) || ts . isModuleDeclaration ( node ) || ts . isClassDeclaration ( node ) || ts . isEnumDeclaration ( node )
268268 || ts . isInterfaceDeclaration ( node ) || ts . isPropertyDeclaration ( node ) || ts . isPropertySignature ( node ) || ts . isParameter ( node )
269269 || ts . isMethodDeclaration ( node ) || ts . isConstructorDeclaration ( node ) || ts . isArrowFunction ( node )
270270 || ts . isIndexSignatureDeclaration ( node ) || ts . isTypeAliasDeclaration ( node ) || ts . isExportDeclaration ( node )
271- || ts . isFunctionDeclaration ( node ) || ts . isFunctionExpression ( node ) || ts . isConstructorTypeNode ( node ) ) {
271+ || ts . isFunctionDeclaration ( node ) || ts . isFunctionExpression ( node ) || ts . isConstructorTypeNode ( node ) || ts . isTypeParameterDeclaration ( node ) ) {
272272 return node . modifiers ? node . modifiers ?. filter ( ts . isModifier ) . map ( this . mapModifier ) : [ ] ;
273273 }
274274 else if ( ts . isExportAssignment ( node ) ) {
@@ -648,7 +648,7 @@ export class JavaScriptParserVisitor {
648648 this . prefix ( node ) ,
649649 Markers . EMPTY ,
650650 [ ] ,
651- [ ] ,
651+ this . mapModifiers ( node ) ,
652652 this . visit ( node . name ) ,
653653 ( node . constraint || node . default ) ?
654654 new JContainer (
@@ -771,17 +771,8 @@ export class JavaScriptParserVisitor {
771771 let _arguments : JContainer < J . Expression > | null = null ;
772772
773773 if ( ts . isCallExpression ( node . expression ) ) {
774- let callExpression : J . MethodInvocation = this . convert ( node . expression ) ;
775- annotationType = callExpression . select === null ? callExpression . name :
776- new J . FieldAccess (
777- randomId ( ) ,
778- callExpression . prefix ,
779- Markers . EMPTY ,
780- callExpression . select ,
781- this . leftPadded ( callExpression . padding . select ! . after , callExpression . name ) ,
782- callExpression . type
783- ) ;
784- _arguments = callExpression . padding . arguments ;
774+ annotationType = this . convert ( node . expression . expression ) ;
775+ _arguments = this . mapCommaSeparatedList ( node . expression . getChildren ( this . sourceFile ) . slice ( - 3 ) )
785776 } else if ( ts . isIdentifier ( node . expression ) ) {
786777 annotationType = this . convert ( node . expression ) ;
787778 } else if ( ts . isPropertyAccessExpression ( node . expression ) ) {
@@ -1333,7 +1324,8 @@ export class JavaScriptParserVisitor {
13331324 this . mapTypeParametersAsObject ( node ) ,
13341325 new JContainer (
13351326 this . prefix ( node . getChildAt ( node . getChildren ( ) . findIndex ( n => n . pos === node . parameters . pos ) - 1 ) ) ,
1336- node . parameters . map ( p => this . rightPadded ( this . visit ( p ) , this . suffix ( p ) ) ) ,
1327+ node . parameters . map ( p => this . rightPadded ( this . visit ( p ) , this . suffix ( p ) ) )
1328+ . concat ( node . parameters . hasTrailingComma ? this . rightPadded ( this . newJEmpty ( ) , this . prefix ( this . findChildNode ( node , ts . SyntaxKind . CloseParenToken ) ! ) ) : [ ] ) ,
13371329 Markers . EMPTY ) ,
13381330 this . prefix ( this . findChildNode ( node , ts . SyntaxKind . EqualsGreaterThanToken ) ! ) ,
13391331 this . convert ( node . type ) ,
@@ -1363,6 +1355,7 @@ export class JavaScriptParserVisitor {
13631355 this . prefix ( node ) ,
13641356 Markers . EMPTY ,
13651357 this . convert ( node . exprName ) ,
1358+ node . typeArguments ? this . mapTypeArguments ( this . suffix ( node . exprName ) , node . typeArguments ) : null ,
13661359 this . mapType ( node )
13671360 )
13681361 }
@@ -1899,36 +1892,19 @@ export class JavaScriptParserVisitor {
18991892 if ( ts . isIdentifier ( node . expression ) && ! node . questionDotToken ) {
19001893 select = null ;
19011894 name = this . convert ( node . expression ) ;
1902- } else if ( ts . isPropertyAccessExpression ( node . expression ) ) {
1903- select = this . rightPadded (
1904- node . expression . questionDotToken ?
1905- new JS . Unary (
1906- randomId ( ) ,
1907- Space . EMPTY ,
1908- Markers . EMPTY ,
1909- this . leftPadded ( this . suffix ( node . expression . expression ) , JS . Unary . Type . QuestionDot ) ,
1910- this . visit ( node . expression . expression ) ,
1911- this . mapType ( node )
1912- ) :
1913- this . convert < J . Expression > ( node . expression . expression ) ,
1914- this . prefix ( node . expression . getChildAt ( 1 , this . sourceFile ) )
1915- ) ;
1916- name = this . convert ( node . expression . name ) ;
1895+ } else if ( node . questionDotToken ) {
1896+ select = this . rightPadded ( new JS . Unary (
1897+ randomId ( ) ,
1898+ Space . EMPTY ,
1899+ Markers . EMPTY ,
1900+ this . leftPadded ( this . suffix ( node . expression ) , JS . Unary . Type . QuestionDotWithDot ) ,
1901+ this . visit ( node . expression ) ,
1902+ this . mapType ( node )
1903+ ) ,
1904+ Space . EMPTY
1905+ )
19171906 } else {
1918- if ( node . questionDotToken ) {
1919- select = this . rightPadded ( new JS . Unary (
1920- randomId ( ) ,
1921- Space . EMPTY ,
1922- Markers . EMPTY ,
1923- this . leftPadded ( this . suffix ( node . expression ) , JS . Unary . Type . QuestionDotWithDot ) ,
1924- this . visit ( node . expression ) ,
1925- this . mapType ( node )
1926- ) ,
1927- Space . EMPTY
1928- )
1929- } else {
1930- select = this . rightPadded ( this . visit ( node . expression ) , this . suffix ( node . expression ) )
1931- }
1907+ select = this . rightPadded ( this . visit ( node . expression ) , this . suffix ( node . expression ) )
19321908 }
19331909
19341910 return new J . MethodInvocation (
@@ -1975,7 +1951,7 @@ export class JavaScriptParserVisitor {
19751951 Markers . EMPTY ,
19761952 this . rightPadded ( this . visit ( node . tag ) , this . suffix ( node . tag ) ) ,
19771953 node . typeArguments ? this . mapTypeArguments ( Space . EMPTY , node . typeArguments ) : null ,
1978- this . visit ( node . template ) ,
1954+ this . convert ( node . template ) ,
19791955 this . mapType ( node )
19801956 )
19811957 }
@@ -2561,8 +2537,8 @@ export class JavaScriptParserVisitor {
25612537 }
25622538
25632539 visitIfStatement ( node : ts . IfStatement ) {
2564- const semicolonAfterThen = node . thenStatement . getLastToken ( ) ?. kind == ts . SyntaxKind . SemicolonToken ;
2565- const semicolonAfterElse = node . elseStatement ?. getLastToken ( ) ?. kind == ts . SyntaxKind . SemicolonToken ;
2540+ const semicolonAfterThen = ( node . thenStatement ?. kind != ts . SyntaxKind . IfStatement ) && ( node . thenStatement . getLastToken ( ) ?. kind == ts . SyntaxKind . SemicolonToken ) ;
2541+ const semicolonAfterElse = ( node . elseStatement ?. kind != ts . SyntaxKind . IfStatement ) && ( node . elseStatement ?. getLastToken ( ) ?. kind == ts . SyntaxKind . SemicolonToken ) ;
25662542 return new J . If (
25672543 randomId ( ) ,
25682544 this . prefix ( node ) ,
@@ -2641,9 +2617,9 @@ export class JavaScriptParserVisitor {
26412617 ( ts . isVariableDeclarationList ( node . initializer ) ? this . rightPadded ( this . visit ( node . initializer ) , Space . EMPTY ) :
26422618 this . rightPadded ( new ExpressionStatement ( randomId ( ) , this . visit ( node . initializer ) ) , this . suffix ( node . initializer . getLastToken ( ) ! ) ) ) :
26432619 this . rightPadded ( this . newJEmpty ( ) , this . suffix ( this . findChildNode ( node , ts . SyntaxKind . OpenParenToken ) ! ) ) ] , // to handle for (/*_*/; ; );
2644- node . condition ? this . rightPadded ( ts . isStatement ( node . condition ) ? this . visit ( node . condition ) : new ExpressionStatement ( randomId ( ) , this . visit ( node . condition ) ) , this . suffix ( node . condition . getLastToken ( ) ! ) ) :
2620+ node . condition ? this . rightPadded ( ts . isStatement ( node . condition ) ? this . visit ( node . condition ) : new ExpressionStatement ( randomId ( ) , this . visit ( node . condition ) ) , this . suffix ( node . condition ) ) :
26452621 this . rightPadded ( this . newJEmpty ( ) , this . suffix ( this . findChildNode ( node , ts . SyntaxKind . SemicolonToken ) ! ) ) , // to handle for ( ;/*_*/; );
2646- [ node . incrementor ? this . rightPadded ( ts . isStatement ( node . incrementor ) ? this . visit ( node . incrementor ) : new ExpressionStatement ( randomId ( ) , this . visit ( node . incrementor ) ) , this . suffix ( node . incrementor . getLastToken ( ) ! ) ) :
2622+ [ node . incrementor ? this . rightPadded ( ts . isStatement ( node . incrementor ) ? this . visit ( node . incrementor ) : new ExpressionStatement ( randomId ( ) , this . visit ( node . incrementor ) ) , this . suffix ( node . incrementor ) ) :
26472623 this . rightPadded ( this . newJEmpty ( this . prefix ( this . findChildNode ( node , ts . SyntaxKind . CloseParenToken ) ! ) ) , Space . EMPTY ) ] , // to handle for ( ; ;/*_*/);
26482624 ) ,
26492625 this . rightPadded (
@@ -3435,7 +3411,7 @@ export class JavaScriptParserVisitor {
34353411 this . prefix ( node ) ,
34363412 Markers . EMPTY ,
34373413 [ ] ,
3438- node . name ? this . convert ( node . name ) : this . mapIdentifier ( node , "" ) ,
3414+ node . name ? ts . isStringLiteral ( node . name ) ? this . mapIdentifier ( node . name , node . name . getText ( ) ) : this . convert ( node . name ) : this . mapIdentifier ( node , "" ) ,
34393415 node . initializer ? new J . NewClass (
34403416 randomId ( ) ,
34413417 this . suffix ( node . name ) ,
@@ -3789,6 +3765,7 @@ export class JavaScriptParserVisitor {
37893765 Markers . EMPTY ,
37903766 [ ] ,
37913767 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 ) ! ) ) : [ ] ) ,
37923769 ) ;
37933770 }
37943771
0 commit comments