Skip to content

Commit 08226d2

Browse files
author
benzhai
committed
fix bug.
1 parent eb2bc37 commit 08226d2

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

components/convert-component.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,17 @@ export class ConvertComponent extends ConverterComponent {
166166
const funcInstance = this.instanceBuilder(reflection.kind, reflection.name);
167167
funcInstance.buildObjectStructure(funcData);
168168
if (!funcInstance.isEmpty()) {
169-
this.globalFuncsJson = Object.assign(funcInstance.getJsonContent(), this.globalFuncsJson);
169+
let storage = this.prepareStorage(reflection);
170+
Object.assign(storage, funcInstance.getJsonContent());
170171
}
171172
break;
172173
case ReflectionKind.Variable:
173174
const variableData = this.getCommentInfo(reflection);
174175
const variableInstance = this.instanceBuilder(reflection.kind, reflection.name);
175176
variableInstance.buildObjectStructure(variableData);
176177
if (!variableInstance.isEmpty()){
177-
this.globalFuncsJson = Object.assign(variableInstance.getJsonContent(), this.globalFuncsJson);
178+
let storage = this.prepareStorage(reflection);
179+
Object.assign(storage, variableInstance.getJsonContent());
178180
}
179181
break;
180182
case ReflectionKind.GetSignature:
@@ -189,6 +191,23 @@ export class ConvertComponent extends ConverterComponent {
189191
}
190192
}
191193

194+
private prepareStorage(reflection){
195+
let ref = reflection.parent;
196+
let paths = [];
197+
do{
198+
paths.unshift(ref.name);
199+
ref = ref.parent;
200+
}while(ref.kind != ReflectionKind.Global);
201+
let obj = this.globalFuncsJson;
202+
paths.forEach(p => {
203+
if(!obj[p]){
204+
obj[p] = {};
205+
}
206+
obj = obj[p];
207+
});
208+
return obj;
209+
}
210+
192211
/**
193212
* Returns all comment info including tags and parameters.
194213
* @param reflection

components/render-component.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,14 @@ export class RenderComponenet extends RendererComponent {
101101
if (!this.globalFuncsData) {
102102
break;
103103
}
104-
const funcName = reflection.name;
105-
const funcData = this.globalFuncsData[funcName];
104+
const funcData = this.getGlobalComment(reflection);
106105
this.updateComment(reflection.signatures[0], funcData);
107106
break;
108107
case ReflectionKind.Variable:
109108
if (!this.globalFuncsData) {
110109
break;
111110
}
112-
const variableName = reflection.name;
113-
const variableData = this.globalFuncsData[variableName];
111+
const variableData = this.getGlobalComment(reflection);
114112
this.updateComment(reflection, variableData);
115113
break;
116114
case ReflectionKind.GetSignature:
@@ -133,6 +131,21 @@ export class RenderComponenet extends RendererComponent {
133131
}
134132
}
135133

134+
private getGlobalComment(reflection){
135+
let ref = reflection;
136+
let paths = [];
137+
do{
138+
paths.unshift(ref.name);
139+
ref = ref.parent;
140+
}while(ref.kind != ReflectionKind.Global);
141+
let p = paths.shift();
142+
let storage = this.globalFuncsData[p];
143+
while(storage && paths.length){
144+
storage = storage[paths.shift()];
145+
}
146+
return storage;
147+
}
148+
136149
private getAttribute(parentName, attribute) {
137150
if (this.data && this.data[parentName]) {
138151
return this.data[parentName][attribute];

0 commit comments

Comments
 (0)