Skip to content

Commit e8410d6

Browse files
committed
Fixing comments
1 parent 57b4e3d commit e8410d6

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

Diff for: src/components/classDeclaration/ClassDeclaration.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,15 @@ export class ClassDeclaration extends FileDeclaration {
9797
}
9898

9999
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]);
104109
forEachComment(
105110
fileClass,
106111
(sourceFile, comment) => {

Diff for: src/components/interfaceDeclaration/InterfaceDeclaration.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,15 @@ export class InterfaceDeclaration extends FileDeclaration {
7575
}
7676

7777
parseComments(fileInterface: ts.Node, sourceFile: ts.SourceFile) {
78-
// getText() returns the first line without comments
79-
let firstLine: string = sourceFile.getText();
80-
// getFullText() returns also the comments, now I need the position of the declared class
81-
let declarationPos: number = sourceFile.getFullText().indexOf(firstLine);
78+
// Now I need the position of the declared class
79+
let text: string = sourceFile.getFullText();
80+
let regex: string = 'interface +(' + this.getIdentifier() + ')';
81+
82+
let match = text.match(regex);
83+
84+
if (match == null) return;
85+
86+
let declarationPos: number = text.indexOf(match[0]);
8287
forEachComment(
8388
fileInterface,
8489
(sourceFile, comment) => {

0 commit comments

Comments
 (0)