Skip to content

Commit

Permalink
fix(docgen): typescript: handle top level classes
Browse files Browse the repository at this point in the history
  • Loading branch information
drauggres committed Feb 6, 2020
1 parent b2e0251 commit 94111d0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/titanium-docgen/generators/typescript_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const skipApis = [
];

// List of modules that need to be generated as an interface instead of a namespace.
const knowInterfacesList = [
const forcedInterfaces = [
'Titanium.App.iOS.UserDefaults',
'Global.String',
'Global.JSON',
Expand Down Expand Up @@ -248,7 +248,7 @@ class DocsParser {
'pseudo',
];

return validSubtypes.includes(typeInfo.__subtype) || knowInterfacesList.includes(typeInfo.name);
return validSubtypes.includes(typeInfo.__subtype) || forcedInterfaces.includes(typeInfo.name);
}

isClass(typeInfo) {
Expand All @@ -257,7 +257,7 @@ class DocsParser {
'proxy',
'view'
];
return validSubtypes.includes(typeInfo.__subtype) && !knowInterfacesList.includes(typeInfo.name);
return validSubtypes.includes(typeInfo.__subtype) && !forcedInterfaces.includes(typeInfo.name);
}

/**
Expand All @@ -270,7 +270,7 @@ class DocsParser {
* @return {Boolean} True if the API type is considered a namespace in TypeScript, false if not.
*/
isNamespace(typeInfo) {
return (typeInfo.__subtype === 'module' || isConstantsOnlyProxy(typeInfo)) && !knowInterfacesList.includes(typeInfo.name);
return (typeInfo.__subtype === 'module' || isConstantsOnlyProxy(typeInfo)) && !forcedInterfaces.includes(typeInfo.name);
}

isModulesNamespace(typeInfo) {
Expand Down Expand Up @@ -470,7 +470,8 @@ class GlobalTemplateWriter {
return;
}
const parent = interfaceNode.extends ? 'extends ' + interfaceNode.extends + ' ' : '';
this.output += `${this.indent(nestingLevel)}${interfaceNode.keyWord} ${interfaceNode.name} ${parent}{\n`;
const isTopLevelClass = this instanceof ClassNode && nestingLevel === 0 ? 'declare ' : '';
this.output += `${this.indent(nestingLevel)}${isTopLevelClass}${interfaceNode.keyWord} ${interfaceNode.name} ${parent}{\n`;
if (interfaceNode.properties.length > 0) {
interfaceNode.properties.forEach(propertyNode => this.writePropertyNode(propertyNode, nestingLevel + 1));
}
Expand Down

0 comments on commit 94111d0

Please sign in to comment.