Skip to content

Commit 7194fc0

Browse files
authored
Merge pull request #33 from jdiazgon/bug_fix
Some bug fixing
2 parents 3ad901c + e8410d6 commit 7194fc0

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "@oasp/ts-merger",
3-
"version": "2.0.0",
2+
"name": "@devonfw/ts-merger",
3+
"version": "2.1.1",
44
"description": "2-way TypeScript Merger",
55
"author": {
66
"name": "Capgemini",

src/components/classDeclaration/ClassDeclaration.ts

+16-10
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) => {
@@ -118,12 +123,6 @@ export class ClassDeclaration extends FileDeclaration {
118123

119124
toString(): String {
120125
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-
});
127126

128127
if (this.comments.length > 0) {
129128
this.comments.forEach((comment) => {
@@ -133,6 +132,13 @@ export class ClassDeclaration extends FileDeclaration {
133132
}
134133
classDeclaration.push('\n');
135134

135+
this.decorators.forEach((decorator) => {
136+
classDeclaration.push(decorator.toString(), '\n');
137+
});
138+
super.getModifiers().forEach((modifier) => {
139+
classDeclaration.push(modifier, ' ');
140+
});
141+
136142
classDeclaration.push('class ', this.getIdentifier());
137143
super.getHeritages().forEach((heritage) => {
138144
classDeclaration.push(heritage);

src/components/interfaceDeclaration/InterfaceDeclaration.ts

+13-7
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) => {
@@ -96,9 +101,6 @@ export class InterfaceDeclaration extends FileDeclaration {
96101

97102
toString(): String {
98103
let interfaceDeclaration: String[] = [];
99-
super.getModifiers().forEach((modifier) => {
100-
interfaceDeclaration.push(modifier, ' ');
101-
});
102104

103105
if (this.comments.length > 0) {
104106
this.comments.forEach((comment) => {
@@ -108,6 +110,10 @@ export class InterfaceDeclaration extends FileDeclaration {
108110
}
109111
interfaceDeclaration.push('\n');
110112

113+
super.getModifiers().forEach((modifier) => {
114+
interfaceDeclaration.push(modifier, ' ');
115+
});
116+
111117
interfaceDeclaration.push('interface ', this.getIdentifier());
112118
super.getHeritages().forEach((heritage) => {
113119
interfaceDeclaration.push(heritage);

0 commit comments

Comments
 (0)