Skip to content

Commit 5b0a4a5

Browse files
fix: maintain context of the original method name as a fallback type prefix
1 parent 429ce10 commit 5b0a4a5

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

src/dynamic-param-interfaces.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const ignoreDescriptions = <T extends EventParameterDocumentation>(
4848
// Given a parameter create a new interface and return it's name
4949
// IName is the proposed interface name prefix
5050
// backupIName is a slightly longer IName in case IName is already taken
51-
const createParamInterface = (param: ParamInterface, IName = '', backupIName = ''): string => {
51+
const createParamInterface = (param: ParamInterface, IName = '', backupIName = '', finalBackupIName = ''): string => {
5252
let argType = polite(IName) + _.upperFirst(_.camelCase(param.name));
5353
let argName = param.name;
5454
// TODO: Note. It is still possible for even backupIName to be already used
@@ -79,17 +79,15 @@ const createParamInterface = (param: ParamInterface, IName = '', backupIName = '
7979
)
8080
) {
8181
if (backupIName) {
82-
return createParamInterface(param, backupIName);
82+
return createParamInterface(param, backupIName, finalBackupIName);
8383
}
84-
// console.log('ISSUE', param.properties)
85-
// FIXME: Wut...
86-
return argType;
87-
// console.error(
88-
// ignoreDescriptions(paramInterfacesToDeclare[argType].properties),
89-
// '\n',
90-
// ignoreDescriptions(param.properties),
91-
// );
92-
// throw Error(`Interface "${argType}" has already been declared`);
84+
console.error(
85+
argType, IName, backupIName, finalBackupIName,
86+
ignoreDescriptions(paramInterfacesToDeclare[argType].properties),
87+
'\n',
88+
ignoreDescriptions(param.properties),
89+
);
90+
throw Error(`Interface "${argType}" has already been declared`);
9391
}
9492
// Update the params interfaces we still have to define
9593
paramInterfacesToDeclare[argType] = param;

src/utils.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ export const genMethodString = (
295295
moduleMethod: MethodDocumentationBlock,
296296
includeType = true,
297297
paramTypePrefix = '',
298+
topLevelModuleMethod?: MethodDocumentationBlock,
298299
): string => {
299300
const createMethodObjectParamType = (
300301
objectParam: DetailedObjectType & TypeInformation & DocumentationBlock & { required: boolean },
@@ -304,7 +305,7 @@ export const genMethodString = (
304305
}
305306
if (objectParam.name === 'options') {
306307
if (
307-
['show', 'hide', 'open', 'close', 'start', 'stop', 'constructor'].includes(
308+
['show', 'hide', 'open', 'close', 'start', 'stop', 'constructor', 'print'].includes(
308309
moduleMethod.name.toLowerCase(),
309310
)
310311
) {
@@ -317,7 +318,18 @@ export const genMethodString = (
317318
return paramInterfaces.createParamInterface(objectParam, _.upperFirst(moduleMethod.name));
318319
}
319320

320-
return paramInterfaces.createParamInterface(objectParam, '', _.upperFirst(moduleMethod.name));
321+
if (
322+
['set', 'get'].includes(
323+
moduleMethod.name.toLowerCase(),
324+
)
325+
) {
326+
return paramInterfaces.createParamInterface(
327+
objectParam,
328+
_.upperFirst(module.name) + _.upperFirst(moduleMethod.name),
329+
);
330+
}
331+
332+
return paramInterfaces.createParamInterface(objectParam, '', _.upperFirst(moduleMethod.name), topLevelModuleMethod ? _.upperFirst(topLevelModuleMethod.name) : '');
321333
};
322334
return `${includeType ? '(' : ''}${(moduleMethod.parameters || [])
323335
.map(param => {
@@ -346,6 +358,9 @@ export const genMethodString = (
346358
name: _.upperFirst(moduleMethod.name) + _.upperFirst(param.name),
347359
...functionParam,
348360
} as any /* FIXME: */,
361+
true,
362+
'',
363+
moduleMethod
349364
),
350365
});
351366
} else if (paramType.type === 'Object' && objectParam.properties) {
@@ -359,7 +374,9 @@ export const genMethodString = (
359374
}
360375
const functionParam = param as DetailedFunctionType;
361376
if (param.type === 'Function' && functionParam.parameters) {
362-
paramType = genMethodString(paramInterfaces, module, functionParam as any /* FIXME: */);
377+
paramType = genMethodString(paramInterfaces, module, functionParam as any /* FIXME: */, true,
378+
'',
379+
moduleMethod);
363380
}
364381
365382
const name = paramify(param.name);

0 commit comments

Comments
 (0)