@@ -97,10 +97,15 @@ export class ClassDeclaration extends FileDeclaration {
97
97
}
98
98
99
99
parseComments ( fileClass : ts . Node , sourceFile : ts . SourceFile ) {
100
- // getText() returns the first line without comments
101
- let firstLine : string = sourceFile . getText ( ) ;
102
- // getFullText() returns also the comments, now I need the position of the declared class
103
- let declarationPos : number = sourceFile . getFullText ( ) . indexOf ( firstLine ) ;
100
+ // Now I need the position of the declared class
101
+ let text : string = sourceFile . getFullText ( ) ;
102
+ let regex : string = 'class +(' + this . getIdentifier ( ) + ')' ;
103
+
104
+ let match = text . match ( regex ) ;
105
+
106
+ if ( match == null ) return ;
107
+
108
+ let declarationPos : number = text . indexOf ( match [ 0 ] ) ;
104
109
forEachComment (
105
110
fileClass ,
106
111
( sourceFile , comment ) => {
@@ -118,12 +123,6 @@ export class ClassDeclaration extends FileDeclaration {
118
123
119
124
toString ( ) : String {
120
125
let classDeclaration : String [ ] = [ ] ;
121
- this . decorators . forEach ( ( decorator ) => {
122
- classDeclaration . push ( decorator . toString ( ) , '\n' ) ;
123
- } ) ;
124
- super . getModifiers ( ) . forEach ( ( modifier ) => {
125
- classDeclaration . push ( modifier , ' ' ) ;
126
- } ) ;
127
126
128
127
if ( this . comments . length > 0 ) {
129
128
this . comments . forEach ( ( comment ) => {
@@ -133,6 +132,13 @@ export class ClassDeclaration extends FileDeclaration {
133
132
}
134
133
classDeclaration . push ( '\n' ) ;
135
134
135
+ this . decorators . forEach ( ( decorator ) => {
136
+ classDeclaration . push ( decorator . toString ( ) , '\n' ) ;
137
+ } ) ;
138
+ super . getModifiers ( ) . forEach ( ( modifier ) => {
139
+ classDeclaration . push ( modifier , ' ' ) ;
140
+ } ) ;
141
+
136
142
classDeclaration . push ( 'class ' , this . getIdentifier ( ) ) ;
137
143
super . getHeritages ( ) . forEach ( ( heritage ) => {
138
144
classDeclaration . push ( heritage ) ;
0 commit comments