@@ -229,6 +229,26 @@ module.exports = function convert(config) {
229229 } ) ;
230230 }
231231
232+ /**
233+ * Converts an array of TSNode parameters into an array of ESTreeNode params
234+ * @param {TSNode[] } parameters An array of TSNode params to be converted
235+ * @returns {ESTreeNode[] } an array of converted ESTreeNode params
236+ */
237+ function convertParameters ( parameters ) {
238+ if ( ! parameters || ! parameters . length ) {
239+ return [ ] ;
240+ }
241+ return parameters . map ( param => {
242+ const convertedParam = convertChild ( param ) ;
243+ if ( ! param . decorators || ! param . decorators . length ) {
244+ return convertedParam ;
245+ }
246+ return Object . assign ( convertedParam , {
247+ decorators : convertDecorators ( param . decorators )
248+ } ) ;
249+ } ) ;
250+ }
251+
232252 /**
233253 * For nodes that are copied directly from the TypeScript AST into
234254 * ESTree mostly as-is. The only difference is the addition of a type
@@ -470,7 +490,7 @@ module.exports = function convert(config) {
470490
471491 case SyntaxKind . ForInStatement :
472492 case SyntaxKind . ForOfStatement : {
473- const isAwait = node . awaitModifier && node . awaitModifier . kind === SyntaxKind . AwaitKeyword ;
493+ const isAwait = ! ! ( node . awaitModifier && node . awaitModifier . kind === SyntaxKind . AwaitKeyword ) ;
474494 Object . assign ( result , {
475495 type : SyntaxKind [ node . kind ] ,
476496 left : convertChild ( node . initializer ) ,
@@ -507,7 +527,7 @@ module.exports = function convert(config) {
507527 generator : ! ! node . asteriskToken ,
508528 expression : false ,
509529 async : nodeUtils . hasModifier ( SyntaxKind . AsyncKeyword , node ) ,
510- params : node . parameters . map ( convertChild ) ,
530+ params : convertParameters ( node . parameters ) ,
511531 body : convertChild ( node . body )
512532 } ) ;
513533
@@ -724,12 +744,19 @@ module.exports = function convert(config) {
724744 value : convertChild ( node . initializer ) ,
725745 computed : nodeUtils . isComputedProperty ( node . name ) ,
726746 static : nodeUtils . hasStaticModifierFlag ( node ) ,
727- accessibility : nodeUtils . getTSNodeAccessibility ( node ) ,
728747 readonly : nodeUtils . hasModifier ( SyntaxKind . ReadonlyKeyword , node ) ,
729- decorators : convertDecorators ( node . decorators ) ,
730748 typeAnnotation : ( node . type ) ? convertTypeAnnotation ( node . type ) : null
731749 } ) ;
732750
751+ if ( node . decorators ) {
752+ result . decorators = convertDecorators ( node . decorators ) ;
753+ }
754+
755+ const accessibility = nodeUtils . getTSNodeAccessibility ( node ) ;
756+ if ( accessibility ) {
757+ result . accessibility = accessibility ;
758+ }
759+
733760 if ( node . name . kind === SyntaxKind . Identifier && node . questionToken ) {
734761 result . key . optional = true ;
735762 }
@@ -788,11 +815,7 @@ module.exports = function convert(config) {
788815 /**
789816 * Unlike in object literal methods, class method params can have decorators
790817 */
791- method . params = node . parameters . map ( param => {
792- const convertedParam = convertChild ( param ) ;
793- convertedParam . decorators = convertDecorators ( param . decorators ) ;
794- return convertedParam ;
795- } ) ;
818+ method . params = convertParameters ( node . parameters ) ;
796819
797820 /**
798821 * TypeScript class methods can be defined as "abstract"
@@ -807,11 +830,18 @@ module.exports = function convert(config) {
807830 value : method ,
808831 computed : nodeUtils . isComputedProperty ( node . name ) ,
809832 static : nodeUtils . hasStaticModifierFlag ( node ) ,
810- kind : "method" ,
811- accessibility : nodeUtils . getTSNodeAccessibility ( node ) ,
812- decorators : convertDecorators ( node . decorators )
833+ kind : "method"
813834 } ) ;
814835
836+ if ( node . decorators ) {
837+ result . decorators = convertDecorators ( node . decorators ) ;
838+ }
839+
840+ const accessibility = nodeUtils . getTSNodeAccessibility ( node ) ;
841+ if ( accessibility ) {
842+ result . accessibility = accessibility ;
843+ }
844+
815845 }
816846
817847 if ( result . key . type === AST_NODE_TYPES . Identifier && node . questionToken ) {
@@ -845,13 +875,7 @@ module.exports = function convert(config) {
845875 constructor = {
846876 type : AST_NODE_TYPES . FunctionExpression ,
847877 id : null ,
848- params : node . parameters . map ( param => {
849- const convertedParam = convertChild ( param ) ;
850- const decorators = convertDecorators ( param . decorators ) ;
851- return Object . assign ( convertedParam , {
852- decorators
853- } ) ;
854- } ) ,
878+ params : convertParameters ( node . parameters ) ,
855879 generator : false ,
856880 expression : false ,
857881 async : false ,
@@ -912,10 +936,15 @@ module.exports = function convert(config) {
912936 key : constructorKey ,
913937 value : constructor ,
914938 computed : constructorIsComputed ,
915- accessibility : nodeUtils . getTSNodeAccessibility ( node ) ,
916939 static : constructorIsStatic ,
917940 kind : ( constructorIsStatic || constructorIsComputed ) ? "method" : "constructor"
918941 } ) ;
942+
943+ const accessibility = nodeUtils . getTSNodeAccessibility ( node ) ;
944+ if ( accessibility ) {
945+ result . accessibility = accessibility ;
946+ }
947+
919948 break ;
920949
921950 }
@@ -925,7 +954,7 @@ module.exports = function convert(config) {
925954 type : AST_NODE_TYPES . FunctionExpression ,
926955 id : convertChild ( node . name ) ,
927956 generator : ! ! node . asteriskToken ,
928- params : node . parameters . map ( convertChild ) ,
957+ params : convertParameters ( node . parameters ) ,
929958 body : convertChild ( node . body ) ,
930959 async : nodeUtils . hasModifier ( SyntaxKind . AsyncKeyword , node ) ,
931960 expression : false
@@ -1024,7 +1053,7 @@ module.exports = function convert(config) {
10241053 type : AST_NODE_TYPES . ArrowFunctionExpression ,
10251054 generator : false ,
10261055 id : null ,
1027- params : node . parameters . map ( convertChild ) ,
1056+ params : convertParameters ( node . parameters ) ,
10281057 body : convertChild ( node . body ) ,
10291058 async : nodeUtils . hasModifier ( SyntaxKind . AsyncKeyword , node ) ,
10301059 expression : node . body . kind !== SyntaxKind . Block
@@ -1273,11 +1302,17 @@ module.exports = function convert(config) {
12731302 range : [ openBrace . getStart ( ) , result . range [ 1 ] ] ,
12741303 loc : nodeUtils . getLocFor ( openBrace . getStart ( ) , node . end , ast )
12751304 } ,
1276- superClass : ( superClass ? convertChild ( superClass . types [ 0 ] . expression ) : null ) ,
1277- implements : hasImplements ? heritageClauses [ 0 ] . types . map ( convertClassImplements ) : [ ] ,
1278- decorators : convertDecorators ( node . decorators )
1305+ superClass : ( superClass ? convertChild ( superClass . types [ 0 ] . expression ) : null )
12791306 } ) ;
12801307
1308+ if ( hasImplements ) {
1309+ result . implements = heritageClauses [ 0 ] . types . map ( convertClassImplements ) ;
1310+ }
1311+
1312+ if ( node . decorators ) {
1313+ result . decorators = convertDecorators ( node . decorators ) ;
1314+ }
1315+
12811316 const filteredMembers = node . members . filter ( nodeUtils . isESTreeClassMember ) ;
12821317
12831318 if ( filteredMembers . length ) {
@@ -1845,14 +1880,18 @@ module.exports = function convert(config) {
18451880 optional : nodeUtils . isOptional ( node ) ,
18461881 computed : nodeUtils . isComputedProperty ( node . name ) ,
18471882 key : convertChild ( node . name ) ,
1848- params : node . parameters . map ( parameter => convertChild ( parameter ) ) ,
1883+ params : convertParameters ( node . parameters ) ,
18491884 typeAnnotation : ( node . type ) ? convertTypeAnnotation ( node . type ) : null ,
1850- accessibility : nodeUtils . getTSNodeAccessibility ( node ) ,
18511885 readonly : nodeUtils . hasModifier ( SyntaxKind . ReadonlyKeyword , node ) ,
18521886 static : nodeUtils . hasModifier ( SyntaxKind . StaticKeyword , node ) ,
18531887 export : nodeUtils . hasModifier ( SyntaxKind . ExportKeyword , node )
18541888 } ) ;
18551889
1890+ const accessibility = nodeUtils . getTSNodeAccessibility ( node ) ;
1891+ if ( accessibility ) {
1892+ result . accessibility = accessibility ;
1893+ }
1894+
18561895 if ( node . typeParameters ) {
18571896 result . typeParameters = convertTSTypeParametersToTypeParametersDeclaration ( node . typeParameters ) ;
18581897 }
@@ -1868,12 +1907,16 @@ module.exports = function convert(config) {
18681907 key : convertChild ( node . name ) ,
18691908 typeAnnotation : ( node . type ) ? convertTypeAnnotation ( node . type ) : null ,
18701909 initializer : convertChild ( node . initializer ) ,
1871- accessibility : nodeUtils . getTSNodeAccessibility ( node ) ,
18721910 readonly : nodeUtils . hasModifier ( SyntaxKind . ReadonlyKeyword , node ) ,
18731911 static : nodeUtils . hasModifier ( SyntaxKind . StaticKeyword , node ) ,
18741912 export : nodeUtils . hasModifier ( SyntaxKind . ExportKeyword , node )
18751913 } ) ;
18761914
1915+ const accessibility = nodeUtils . getTSNodeAccessibility ( node ) ;
1916+ if ( accessibility ) {
1917+ result . accessibility = accessibility ;
1918+ }
1919+
18771920 break ;
18781921 }
18791922
@@ -1882,19 +1925,23 @@ module.exports = function convert(config) {
18821925 type : AST_NODE_TYPES . TSIndexSignature ,
18831926 index : convertChild ( node . parameters [ 0 ] ) ,
18841927 typeAnnotation : ( node . type ) ? convertTypeAnnotation ( node . type ) : null ,
1885- accessibility : nodeUtils . getTSNodeAccessibility ( node ) ,
18861928 readonly : nodeUtils . hasModifier ( SyntaxKind . ReadonlyKeyword , node ) ,
18871929 static : nodeUtils . hasModifier ( SyntaxKind . StaticKeyword , node ) ,
18881930 export : nodeUtils . hasModifier ( SyntaxKind . ExportKeyword , node )
18891931 } ) ;
18901932
1933+ const accessibility = nodeUtils . getTSNodeAccessibility ( node ) ;
1934+ if ( accessibility ) {
1935+ result . accessibility = accessibility ;
1936+ }
1937+
18911938 break ;
18921939 }
18931940
18941941 case SyntaxKind . ConstructSignature : {
18951942 Object . assign ( result , {
18961943 type : AST_NODE_TYPES . TSConstructSignature ,
1897- params : node . parameters . map ( parameter => convertChild ( parameter ) ) ,
1944+ params : convertParameters ( node . parameters ) ,
18981945 typeAnnotation : ( node . type ) ? convertTypeAnnotation ( node . type ) : null
18991946 } ) ;
19001947
0 commit comments