typedoc-plugin-typescript-declaration
Advanced tools
Comparing version 0.3.3 to 0.4.0
@@ -138,12 +138,16 @@ 'use strict'; | ||
class Indentor { | ||
constructor(indentString = ' ') { | ||
this._indentCache = []; | ||
constructor(indentString) { | ||
this._indentCache = {}; | ||
this._indentString = indentString; | ||
} | ||
getIndent(size) { | ||
var _a; | ||
if (size === 0) | ||
return ''; | ||
let indent = this._indentCache[size]; | ||
const indentString = (_a = this._indentString, (_a !== null && _a !== void 0 ? _a : Indentor.indentString)); | ||
const key = `${indentString}_${size}`; | ||
let indent = this._indentCache[key]; | ||
if (indent === undefined) { | ||
indent = new Array(size).fill(this._indentString).join(''); | ||
indent = new Array(size).fill(indentString).join(''); | ||
this._indentCache[key] = indent; | ||
} | ||
@@ -159,2 +163,3 @@ return indent; | ||
} | ||
Indentor.indentString = ' '; | ||
@@ -576,2 +581,60 @@ class ReflectionRenderer { | ||
class ModuleRenderer extends ContainerRenderer { | ||
constructor() { | ||
super('module'); | ||
} | ||
render(node) { | ||
var _a; | ||
if (this.isNamespace(node)) { | ||
let renderNode = node; | ||
const nodeNames = []; | ||
let latestComment; | ||
let currentComment; | ||
do { | ||
currentComment = this.renderComment(renderNode); | ||
// cannot combine modules into namespace because comments differ | ||
if (latestComment && currentComment && latestComment !== currentComment) { | ||
break; | ||
} | ||
if (currentComment) { | ||
latestComment = currentComment; | ||
} | ||
nodeNames.push(renderNode.name); | ||
if (((_a = renderNode.children) === null || _a === void 0 ? void 0 : _a.length) === 1 && renderNode.children[0].kindOf(models.ReflectionKind.SomeModule)) { | ||
const nextNode = renderNode.children[0]; | ||
const nextComment = this.renderComment(nextNode); | ||
// cannot combine modules into namespace because comments differ | ||
if (latestComment && nextComment && latestComment !== nextComment) { | ||
break; | ||
} | ||
renderNode = nextNode; | ||
} | ||
else { | ||
break; | ||
} | ||
} while (this.isNamespace(renderNode)); | ||
const lines = []; | ||
const declarationParts = [ | ||
this.isTop(node) ? 'declare' : '', | ||
'namespace', `${nodeNames.join('.')}` | ||
]; | ||
if (latestComment) { | ||
this.pushIfTruthy(lines, latestComment); | ||
} | ||
lines.push(join(' ', ...declarationParts, '{')); | ||
const body = this.renderBody(renderNode); | ||
if (body) { | ||
lines.push(body); | ||
} | ||
lines.push('}'); | ||
return lines.join('\n'); | ||
} | ||
return super.render(node); | ||
} | ||
isNamespace(node) { | ||
const hasSpecialCharacterExpression = /[^\w]/; | ||
return !hasSpecialCharacterExpression.test(node.name); | ||
} | ||
} | ||
class ObjectLiteralRenderer extends ContainerRenderer { | ||
@@ -787,3 +850,3 @@ constructor() { | ||
[models.ReflectionKind.Event]: new EventRenderer(), | ||
[models.ReflectionKind.ExternalModule]: new ContainerRenderer('module'), | ||
[models.ReflectionKind.ExternalModule]: new ModuleRenderer(), | ||
[models.ReflectionKind.Function]: new FunctionRenderer(), | ||
@@ -795,3 +858,3 @@ [models.ReflectionKind.GetSignature]: new GetSignatureRenderer(), | ||
[models.ReflectionKind.Method]: new MethodRenderer(), | ||
[models.ReflectionKind.Module]: new ContainerRenderer('module'), | ||
[models.ReflectionKind.Module]: new ModuleRenderer(), | ||
[models.ReflectionKind.ObjectLiteral]: new ObjectLiteralRenderer(), | ||
@@ -847,2 +910,3 @@ [models.ReflectionKind.Parameter]: new ParameterRenderer(), | ||
ReflectionFormatter.sortOption = ReflectionSortFlags.none; | ||
ReflectionFormatter.indentString = ' '; | ||
@@ -867,2 +931,8 @@ const declarationFileOption = { | ||
}; | ||
const indentStringOption = { | ||
name: 'indentString', | ||
type: declaration.ParameterType.String, | ||
help: 'Indent declarations using this string. Defaults to \' \'', | ||
defaultValue: ' ', | ||
}; | ||
class TypeScriptDeclarationPlugin extends components.RendererComponent { | ||
@@ -892,4 +962,5 @@ initialize() { | ||
} | ||
Indentor.indentString = app.options.getValue('indentString'); | ||
} | ||
veriftProject(project) { | ||
verifyProject(project) { | ||
if (this._declarationOnly && !this._declarationFile) { | ||
@@ -909,3 +980,3 @@ throw new Error('--declarationFile file must be specified when using the --declarationOnly option'); | ||
onRenderBegin(event) { | ||
this.veriftProject(event.project); | ||
this.verifyProject(event.project); | ||
} | ||
@@ -935,2 +1006,3 @@ static generateTypeDeclarations(project, sortOption, filename) { | ||
sortOptionOption, | ||
indentStringOption, | ||
]; | ||
@@ -937,0 +1009,0 @@ __decorate([ |
{ | ||
"name": "typedoc-plugin-typescript-declaration", | ||
"version": "0.3.3", | ||
"version": "0.4.0", | ||
"description": "Typedoc plugin to render to typescript declaration file", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67103
1536