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B;AAlDlB,SAAS;IADrB,qBAAS,CAAC,EAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,+BAAkB,EAAC,CAAC;GAClE,SAAS,CAyZrB;AAzZY,8BAAS","sourcesContent":["import * as ts from 'typescript';\nimport * as _ts from '../ts-internal';\nimport * as _ from 'lodash';\n\nimport { Application } from '../application';\nimport { ParameterType } from '../utils/options/declaration';\nimport { Reflection, Type, ProjectReflection } from '../models/index';\nimport { Context } from './context';\nimport { ConverterComponent, ConverterNodeComponent, ConverterTypeComponent, TypeTypeConverter, TypeNodeConverter } from './components';\nimport { Component, Option, ChildableComponent, ComponentClass } from '../utils/component';\nimport { normalizePath } from '../utils/fs';\nimport { createMinimatch } from '../utils/paths';\n\n/**\n * Result structure of the [[Converter.convert]] method.\n */\nexport interface ConverterResult {\n /**\n * An array containing all errors generated by the TypeScript compiler.\n */\n errors: ReadonlyArray<ts.Diagnostic>;\n\n /**\n * The resulting project reflection.\n */\n project: ProjectReflection;\n}\n\n/**\n * Compiles source files using TypeScript and converts compiler symbols to reflections.\n */\n@Component({name: 'converter', internal: true, childClass: ConverterComponent})\nexport class Converter extends ChildableComponent<Application, ConverterComponent> {\n /**\n * The human readable name of the project. Used within the templates to set the title of the document.\n */\n @Option({\n name: 'name',\n help: 'Set the name of the project that will be used in the header of the template.'\n })\n name!: string;\n\n @Option({\n name: 'externalPattern',\n help: 'Define patterns for files that should be considered being external.',\n type: ParameterType.Array\n })\n externalPattern!: Array<string>;\n\n @Option({\n name: 'includeDeclarations',\n help: 'Turn on parsing of .d.ts declaration files.',\n type: ParameterType.Boolean\n })\n includeDeclarations!: boolean;\n\n @Option({\n name: 'excludeExternals',\n help: 'Prevent externally resolved TypeScript files from being documented.',\n type: ParameterType.Boolean\n })\n excludeExternals!: boolean;\n\n @Option({\n name: 'excludeNotExported',\n help: 'Prevent symbols that are not exported from being documented.',\n type: ParameterType.Boolean\n })\n excludeNotExported!: boolean;\n\n @Option({\n name: 'excludePrivate',\n help: 'Ignores private variables and methods',\n type: ParameterType.Boolean\n })\n excludePrivate!: boolean;\n\n @Option({\n name: 'excludeProtected',\n help: 'Ignores protected variables and methods',\n type: ParameterType.Boolean\n })\n excludeProtected!: boolean;\n\n /**\n * Defined in the initialize method\n */\n private nodeConverters!: {[syntaxKind: number]: ConverterNodeComponent<ts.Node>};\n\n /**\n * Defined in the initialize method\n */\n private typeNodeConverters!: TypeNodeConverter<ts.Type, ts.Node>[];\n\n /**\n * Defined in the initialize method\n */\n private typeTypeConverters!: TypeTypeConverter<ts.Type>[];\n\n /**\n * General events\n */\n\n /**\n * Triggered when the converter begins converting a project.\n * The listener should implement [[IConverterCallback]].\n * @event\n */\n static EVENT_BEGIN = 'begin';\n\n /**\n * Triggered when the converter has finished converting a project.\n * The listener should implement [[IConverterCallback]].\n * @event\n */\n static EVENT_END = 'end';\n\n /**\n * Factory events\n */\n\n /**\n * Triggered when the converter begins converting a source file.\n * The listener should implement [[IConverterNodeCallback]].\n * @event\n */\n static EVENT_FILE_BEGIN = 'fileBegin';\n\n /**\n * Triggered when the converter has created a declaration reflection.\n * The listener should implement [[IConverterNodeCallback]].\n * @event\n */\n static EVENT_CREATE_DECLARATION = 'createDeclaration';\n\n /**\n * Triggered when the converter has created a signature reflection.\n * The listener should implement [[IConverterNodeCallback]].\n * @event\n */\n static EVENT_CREATE_SIGNATURE = 'createSignature';\n\n /**\n * Triggered when the converter has created a parameter reflection.\n * The listener should implement [[IConverterNodeCallback]].\n * @event\n */\n static EVENT_CREATE_PARAMETER = 'createParameter';\n\n /**\n * Triggered when the converter has created a type parameter reflection.\n * The listener should implement [[IConverterNodeCallback]].\n * @event\n */\n static EVENT_CREATE_TYPE_PARAMETER = 'createTypeParameter';\n\n /**\n * Triggered when the converter has found a function implementation.\n * The listener should implement [[IConverterNodeCallback]].\n * @event\n */\n static EVENT_FUNCTION_IMPLEMENTATION = 'functionImplementation';\n\n /**\n * Resolve events\n */\n\n /**\n * Triggered when the converter begins resolving a project.\n * The listener should implement [[IConverterCallback]].\n * @event\n */\n static EVENT_RESOLVE_BEGIN = 'resolveBegin';\n\n /**\n * Triggered when the converter resolves a reflection.\n * The listener should implement [[IConverterResolveCallback]].\n * @event\n */\n static EVENT_RESOLVE = 'resolveReflection';\n\n /**\n * Triggered when the converter has finished resolving a project.\n * The listener should implement [[IConverterCallback]].\n * @event\n */\n static EVENT_RESOLVE_END = 'resolveEnd';\n\n /**\n * Create a new Converter instance.\n *\n * @param application The application instance this converter relies on. The application\n * must expose the settings that should be used and serves as a global logging endpoint.\n */\n initialize() {\n this.nodeConverters = {};\n this.typeTypeConverters = [];\n this.typeNodeConverters = [];\n }\n\n addComponent<T extends ConverterComponent & Component>(name: string, componentClass: T | ComponentClass<T>): T {\n const component = super.addComponent(name, componentClass);\n if (component instanceof ConverterNodeComponent) {\n this.addNodeConverter(component);\n } else if (component instanceof ConverterTypeComponent) {\n this.addTypeConverter(component);\n }\n\n return component;\n }\n\n private addNodeConverter(converter: ConverterNodeComponent<any>) {\n for (let supports of converter.supports) {\n this.nodeConverters[supports] = converter;\n }\n }\n\n private addTypeConverter(converter: ConverterTypeComponent) {\n if ('supportsNode' in converter && 'convertNode' in converter) {\n this.typeNodeConverters.push(<TypeNodeConverter<any, any>> converter);\n this.typeNodeConverters.sort((a, b) => (b.priority || 0) - (a.priority || 0));\n }\n\n if ('supportsType' in converter && 'convertType' in converter) {\n this.typeTypeConverters.push(<TypeTypeConverter<any>> converter);\n this.typeTypeConverters.sort((a, b) => (b.priority || 0) - (a.priority || 0));\n }\n }\n\n removeComponent(name: string): ConverterComponent | undefined {\n const component = super.removeComponent(name);\n if (component instanceof ConverterNodeComponent) {\n this.removeNodeConverter(component);\n } else if (component instanceof ConverterTypeComponent) {\n this.removeTypeConverter(component);\n }\n\n return component;\n }\n\n private removeNodeConverter(converter: ConverterNodeComponent<any>) {\n const converters = this.nodeConverters;\n const keys = _.keys(this.nodeConverters);\n for (let key of keys) {\n if (converters[key] === converter) {\n delete converters[key];\n }\n }\n }\n\n private removeTypeConverter(converter: ConverterTypeComponent) {\n const typeIndex = this.typeTypeConverters.indexOf(<any> converter);\n if (typeIndex !== -1) {\n this.typeTypeConverters.splice(typeIndex, 1);\n }\n\n const nodeIndex = this.typeNodeConverters.indexOf(<any> converter);\n if (nodeIndex !== -1) {\n this.typeNodeConverters.splice(nodeIndex, 1);\n }\n }\n\n removeAllComponents() {\n super.removeAllComponents();\n\n this.nodeConverters = {};\n this.typeTypeConverters = [];\n this.typeNodeConverters = [];\n }\n\n /**\n * Compile the given source files and create a project reflection for them.\n *\n * @param fileNames Array of the file names that should be compiled.\n */\n convert(fileNames: string[]): ConverterResult {\n const normalizedFiles = fileNames.map(normalizePath);\n\n const program = ts.createProgram(normalizedFiles, this.application.options.getCompilerOptions());\n const checker = program.getTypeChecker();\n const context = new Context(this, normalizedFiles, checker, program);\n\n this.trigger(Converter.EVENT_BEGIN, context);\n\n const errors = this.compile(context);\n const project = this.resolve(context);\n\n this.trigger(Converter.EVENT_END, context);\n\n return {\n errors: errors,\n project: project\n };\n }\n\n /**\n * Analyze the given node and create a suitable reflection.\n *\n * This function checks the kind of the node and delegates to the matching function implementation.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The compiler node that should be analyzed.\n * @return The resulting reflection or undefined.\n */\n convertNode(context: Context, node: ts.Node): Reflection | undefined {\n if (context.visitStack.includes(node)) {\n return;\n }\n\n const oldVisitStack = context.visitStack;\n context.visitStack = oldVisitStack.slice();\n context.visitStack.push(node);\n\n let result: Reflection | undefined;\n if (node.kind in this.nodeConverters) {\n result = this.nodeConverters[node.kind].convert(context, node);\n }\n\n context.visitStack = oldVisitStack;\n return result;\n }\n\n /**\n * Convert the given TypeScript type into its TypeDoc type reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The node whose type should be reflected.\n * @param type The type of the node if already known.\n * @returns The TypeDoc type reflection representing the given node and type.\n */\n convertType(context: Context, node?: ts.Node, type?: ts.Type): Type | undefined {\n // Run all node based type conversions\n if (node) {\n type = type || context.getTypeAtLocation(node);\n\n for (let converter of this.typeNodeConverters) {\n if (converter.supportsNode(context, node, type)) {\n return converter.convertNode(context, node, type);\n }\n }\n }\n\n // Run all type based type conversions\n if (type) {\n for (let converter of this.typeTypeConverters) {\n if (converter.supportsType(context, type)) {\n return converter.convertType(context, type);\n }\n }\n }\n }\n\n /**\n * Helper function to convert multiple types at once, filtering out types which fail to convert.\n *\n * @param context\n * @param nodes\n */\n convertTypes(context: Context, nodes: ReadonlyArray<ts.Node> = [], types: ReadonlyArray<ts.Type> = []): Type[] {\n const result: Type[] = [];\n _.zip(nodes, types).forEach(([node, type]) => {\n const converted = this.convertType(context, node, type);\n if (converted) {\n result.push(converted);\n }\n });\n return result;\n }\n\n /**\n * Compile the files within the given context and convert the compiler symbols to reflections.\n *\n * @param context The context object describing the current state the converter is in.\n * @returns An array containing all errors generated by the TypeScript compiler.\n */\n private compile(context: Context): ReadonlyArray<ts.Diagnostic> {\n const program = context.program;\n\n const exclude = createMinimatch(this.application.exclude || []);\n const isExcluded = (file: ts.SourceFile) => exclude.some(mm => mm.match(file.fileName));\n\n const includedSourceFiles = program.getSourceFiles()\n .filter(file => !isExcluded(file));\n const isRelevantError = ({ file }: ts.Diagnostic) => !file || includedSourceFiles.includes(file);\n\n includedSourceFiles.forEach((sourceFile) => {\n this.convertNode(context, sourceFile);\n });\n\n let diagnostics = program.getOptionsDiagnostics().filter(isRelevantError);\n if (diagnostics.length) {\n return diagnostics;\n }\n\n diagnostics = program.getSyntacticDiagnostics().filter(isRelevantError);\n if (diagnostics.length) {\n return diagnostics;\n }\n\n diagnostics = program.getGlobalDiagnostics().filter(isRelevantError);\n if (diagnostics.length) {\n return diagnostics;\n }\n\n diagnostics = program.getSemanticDiagnostics().filter(isRelevantError);\n if (diagnostics.length) {\n return diagnostics;\n }\n\n return [];\n }\n\n /**\n * Resolve the project within the given context.\n *\n * @param context The context object describing the current state the converter is in.\n * @returns The final project reflection.\n */\n private resolve(context: Context): ProjectReflection {\n this.trigger(Converter.EVENT_RESOLVE_BEGIN, context);\n const project = context.project;\n\n for (let id in project.reflections) {\n if (!project.reflections.hasOwnProperty(id)) {\n continue;\n }\n this.trigger(Converter.EVENT_RESOLVE, context, project.reflections[id]);\n }\n\n this.trigger(Converter.EVENT_RESOLVE_END, context);\n return project;\n }\n\n /**\n * Return the basename of the default library that should be used.\n *\n * @returns The basename of the default library.\n */\n getDefaultLib(): string {\n return ts.getDefaultLibFileName(this.application.options.getCompilerOptions());\n }\n}\n"]}
\No newline at end of file