From aaa5f3559dd72e0f7a6ecfd5ac25150a8da89fc5 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Wed, 27 Dec 2023 09:30:45 -0700 Subject: [PATCH] Improve handling of function-namespaces --- CHANGELOG.md | 5 + src/lib/converter/symbols.ts | 66 +-- src/lib/models/reflections/kind.ts | 8 + .../assets/typedoc/components/Filter.ts | 1 + src/lib/utils/enum.ts | 6 + src/test/converter/function/specs.json | 382 ++++++++---------- src/test/issues.c2.test.ts | 29 +- 7 files changed, 249 insertions(+), 248 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7fdd6e60..4524b60ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,17 @@ - Added special cases for converting methods which are documented as returning `this` or accepting `this` as a parameter, #2458. Note: This will only happen if a method is declared as `method(): this`, it will not happen if the method implicitly returns `this` as the compiler strips that information when creating types for a class instance. +- Improved handling of functions with properties. Previous TypeDoc versions would always create a separate + namespace for properties, now, TypeDoc will create a separate namespace if the function is declaration merged + with a namespace. If the properties are added via `Object.assign` or via property assignment on the function + TypeDoc will now instead add the properties to the function's page, #2461. ### Bug Fixes - Navigation triangle markers should no longer display on a separate line with some font settings, #2457. - `@group` and `@category` organization is now applied later to allow inherited comments to create groups/categories, #2459. - Keyword syntax highlighting introduced in 0.25.4 was not always applied to keywords. +- If all members in a group are hidden from the page, the group will be hidden in the page index on page load. ## v0.25.4 (2023-11-26) diff --git a/src/lib/converter/symbols.ts b/src/lib/converter/symbols.ts index be4eb0ed3..bbceb26bb 100644 --- a/src/lib/converter/symbols.ts +++ b/src/lib/converter/symbols.ts @@ -74,7 +74,7 @@ const conversionOrder = [ ts.SymbolFlags.ExportValue, ts.SymbolFlags.TypeAlias, - ts.SymbolFlags.Function, + ts.SymbolFlags.Function, // Before NamespaceModule ts.SymbolFlags.Method, ts.SymbolFlags.Interface, ts.SymbolFlags.Property, @@ -161,6 +161,10 @@ export function convertSymbol( if (hasAllFlags(symbol.flags, ts.SymbolFlags.NamespaceModule)) { // This might be here if a namespace is declared several times. + // Or if it's a namespace-like thing defined on a function + // In the function case, it's important to remove ValueModule so that + // if we convert the children as properties of the function rather than as + // a separate namespace, we skip creating the namespace. flags = removeFlag(flags, ts.SymbolFlags.ValueModule); } @@ -460,11 +464,7 @@ function convertFunctionOrMethod( const signatures = type.getNonNullableType().getCallSignatures(); const reflection = context.createDeclarationReflection( - context.scope.kindOf( - ReflectionKind.ClassOrInterface | - ReflectionKind.VariableOrProperty | - ReflectionKind.TypeLiteral, - ) + context.scope.kindOf(ReflectionKind.MethodContainer) ? ReflectionKind.Method : ReflectionKind.Function, symbol, @@ -485,6 +485,10 @@ function convertFunctionOrMethod( for (const sig of signatures) { createSignature(scope, ReflectionKind.CallSignature, sig, symbol); } + + convertFunctionProperties(scope, symbol, type); + + return ts.SymbolFlags.NamespaceModule; } // getDeclaredTypeOfSymbol gets the INSTANCE type @@ -635,9 +639,7 @@ function convertProperty( ) { // This might happen if we're converting a function-module created with Object.assign // or `export default () => {}` - if ( - context.scope.kindOf(ReflectionKind.SomeModule | ReflectionKind.Project) - ) { + if (context.scope.kindOf(ReflectionKind.VariableContainer)) { return convertVariable(context, symbol, exportSymbol); } @@ -687,7 +689,7 @@ function convertProperty( } const reflection = context.createDeclarationReflection( - context.scope.kindOf(ReflectionKind.Namespace) + context.scope.kindOf(ReflectionKind.VariableContainer) ? ReflectionKind.Variable : ReflectionKind.Property, symbol, @@ -878,7 +880,9 @@ function convertVariable( } const reflection = context.createDeclarationReflection( - ReflectionKind.Variable, + context.scope.kindOf(ReflectionKind.VariableContainer) + ? ReflectionKind.Variable + : ReflectionKind.Property, symbol, exportSymbol, ); @@ -1000,7 +1004,9 @@ function convertVariableAsFunction( : context.checker.getDeclaredTypeOfSymbol(symbol); const reflection = context.createDeclarationReflection( - ReflectionKind.Function, + context.scope.kindOf(ReflectionKind.MethodContainer) + ? ReflectionKind.Method + : ReflectionKind.Function, symbol, exportSymbol, ); @@ -1020,25 +1026,31 @@ function convertVariableAsFunction( ); } - // #2436: Functions created with Object.assign on a function won't have a namespace flag - // but likely have properties that we should put into a namespace. + convertFunctionProperties(context.withScope(reflection), symbol, type); + + return ts.SymbolFlags.Property | ts.SymbolFlags.NamespaceModule; +} + +function convertFunctionProperties( + context: Context, + symbol: ts.Symbol, + type: ts.Type, +) { + // #2436/#2461: Functions created with Object.assign on a function likely have properties + // that we should document. We also add properties to the function if they are defined like: + // function f() {} + // f.x = 123; + // rather than creating a separate namespace. + // In the expando case, we'll have both namespace flags. + // In the Object.assign case, we'll have no namespace flags. + const nsFlags = ts.SymbolFlags.ValueModule | ts.SymbolFlags.NamespaceModule; if ( type.getProperties().length && - !hasAnyFlag( - symbol.flags, - ts.SymbolFlags.NamespaceModule | ts.SymbolFlags.ValueModule, - ) + (hasAllFlags(symbol.flags, nsFlags) || + !hasAnyFlag(symbol.flags, nsFlags)) ) { - const ns = context.createDeclarationReflection( - ReflectionKind.Namespace, - symbol, - exportSymbol, - ); - context.finalizeDeclarationReflection(ns); - convertSymbols(context.withScope(ns), type.getProperties()); + convertSymbols(context, type.getProperties()); } - - return ts.SymbolFlags.Property; } function convertAccessor( diff --git a/src/lib/models/reflections/kind.ts b/src/lib/models/reflections/kind.ts index 4540fe4f6..c816fe4fc 100644 --- a/src/lib/models/reflections/kind.ts +++ b/src/lib/models/reflections/kind.ts @@ -110,6 +110,14 @@ export namespace ReflectionKind { export const SignatureContainer = ContainsCallSignatures | ReflectionKind.Accessor; + export const VariableContainer = SomeModule | ReflectionKind.Project; + + export const MethodContainer = + ClassOrInterface | + VariableOrProperty | + FunctionOrMethod | + ReflectionKind.TypeLiteral; + const SINGULARS = { [ReflectionKind.Enum]: "Enumeration", [ReflectionKind.EnumMember]: "Enumeration Member", diff --git a/src/lib/output/themes/default/assets/typedoc/components/Filter.ts b/src/lib/output/themes/default/assets/typedoc/components/Filter.ts index dd027148c..d56a38227 100644 --- a/src/lib/output/themes/default/assets/typedoc/components/Filter.ts +++ b/src/lib/output/themes/default/assets/typedoc/components/Filter.ts @@ -30,6 +30,7 @@ export class Filter extends Component { this.setLocalStorage(this.fromLocalStorage()); style.innerHTML += `html:not(.${this.key}) .tsd-is-${this.el.name} { display: none; }\n`; + this.handleValueChange(); } /** diff --git a/src/lib/utils/enum.ts b/src/lib/utils/enum.ts index 98b6d1061..5b0ab7c94 100644 --- a/src/lib/utils/enum.ts +++ b/src/lib/utils/enum.ts @@ -22,6 +22,12 @@ export function hasAnyFlag(flags: number, check: number): boolean { return (flags & check) !== 0; } +export function debugFlags(Enum: {}, flags: number): string[] { + return getEnumKeys(Enum).filter( + (key) => ((Enum as any)[key] & flags) === (Enum as any)[key], + ); +} + // Note: String enums are not handled. export function getEnumKeys(Enum: {}): string[] { const E = Enum as any; diff --git a/src/test/converter/function/specs.json b/src/test/converter/function/specs.json index 99e4f1f90..6ef0333b4 100644 --- a/src/test/converter/function/specs.json +++ b/src/test/converter/function/specs.json @@ -12,73 +12,6 @@ "kind": 2, "flags": {}, "children": [ - { - "id": 80, - "name": "merged", - "variant": "declaration", - "kind": 4, - "flags": {}, - "children": [ - { - "id": 81, - "name": "nsFn", - "variant": "declaration", - "kind": 64, - "flags": {}, - "sources": [ - { - "fileName": "function.ts", - "line": 305, - "character": 7, - "url": "typedoc://function.ts#L305" - } - ], - "signatures": [ - { - "id": 82, - "name": "nsFn", - "variant": "signature", - "kind": 4096, - "flags": {}, - "sources": [ - { - "fileName": "function.ts", - "line": 305, - "character": 14, - "url": "typedoc://function.ts#L305" - } - ], - "type": { - "type": "intrinsic", - "name": "void" - } - } - ] - } - ], - "groups": [ - { - "title": "Functions", - "children": [ - 81 - ] - } - ], - "sources": [ - { - "fileName": "function.ts", - "line": 304, - "character": 16, - "url": "typedoc://function.ts#L304" - }, - { - "fileName": "function.ts", - "line": 305, - "character": 0, - "url": "typedoc://function.ts#L305" - } - ] - }, { "id": 55, "name": "moduleFunction", @@ -241,28 +174,28 @@ ] }, { - "id": 86, + "id": 85, "name": "Predicates", "variant": "declaration", "kind": 128, "flags": {}, "children": [ { - "id": 93, + "id": 92, "name": "constructor", "variant": "declaration", "kind": 512, "flags": {}, "signatures": [ { - "id": 94, + "id": 93, "name": "new Predicates", "variant": "signature", "kind": 16384, "flags": {}, "type": { "type": "reference", - "target": 86, + "target": 85, "name": "Predicates", "package": "typedoc" } @@ -270,7 +203,7 @@ ] }, { - "id": 97, + "id": 96, "name": "assertString", "variant": "declaration", "kind": 2048, @@ -285,7 +218,7 @@ ], "signatures": [ { - "id": 98, + "id": 97, "name": "assertString", "variant": "signature", "kind": 4096, @@ -311,7 +244,7 @@ ] }, { - "id": 95, + "id": 94, "name": "isString", "variant": "declaration", "kind": 2048, @@ -326,7 +259,7 @@ ], "signatures": [ { - "id": 96, + "id": 95, "name": "isString", "variant": "signature", "kind": 4096, @@ -352,7 +285,7 @@ ] }, { - "id": 90, + "id": 89, "name": "assert", "variant": "declaration", "kind": 2048, @@ -369,7 +302,7 @@ ], "signatures": [ { - "id": 91, + "id": 90, "name": "assert", "variant": "signature", "kind": 4096, @@ -384,7 +317,7 @@ ], "parameters": [ { - "id": 92, + "id": 91, "name": "x", "variant": "param", "kind": 32768, @@ -404,7 +337,7 @@ ] }, { - "id": 87, + "id": 86, "name": "isString", "variant": "declaration", "kind": 2048, @@ -421,7 +354,7 @@ ], "signatures": [ { - "id": 88, + "id": 87, "name": "isString", "variant": "signature", "kind": 4096, @@ -436,7 +369,7 @@ ], "parameters": [ { - "id": 89, + "id": 88, "name": "x", "variant": "param", "kind": 32768, @@ -464,16 +397,16 @@ { "title": "Constructors", "children": [ - 93 + 92 ] }, { "title": "Methods", "children": [ - 97, - 95, - 90, - 87 + 96, + 94, + 89, + 86 ] } ], @@ -487,7 +420,7 @@ ] }, { - "id": 99, + "id": 98, "name": "all", "variant": "declaration", "kind": 64, @@ -502,7 +435,7 @@ ], "signatures": [ { - "id": 100, + "id": 99, "name": "all", "variant": "signature", "kind": 4096, @@ -525,7 +458,7 @@ ], "typeParameter": [ { - "id": 101, + "id": 100, "name": "T", "variant": "typeParam", "kind": 131072, @@ -534,7 +467,7 @@ ], "parameters": [ { - "id": 102, + "id": 101, "name": "fn", "variant": "param", "kind": 32768, @@ -542,7 +475,7 @@ "type": { "type": "reflection", "declaration": { - "id": 103, + "id": 102, "name": "__type", "variant": "declaration", "kind": 65536, @@ -557,7 +490,7 @@ ], "signatures": [ { - "id": 104, + "id": 103, "name": "__type", "variant": "signature", "kind": 4096, @@ -572,7 +505,7 @@ ], "parameters": [ { - "id": 105, + "id": 104, "name": "item", "variant": "param", "kind": 32768, @@ -595,7 +528,7 @@ } }, { - "id": 106, + "id": 105, "name": "iterator", "variant": "param", "kind": 32768, @@ -625,7 +558,7 @@ } }, { - "id": 107, + "id": 106, "name": "all", "variant": "signature", "kind": 4096, @@ -648,7 +581,7 @@ ], "typeParameter": [ { - "id": 108, + "id": 107, "name": "T", "variant": "typeParam", "kind": 131072, @@ -657,7 +590,7 @@ ], "parameters": [ { - "id": 109, + "id": 108, "name": "fn", "variant": "param", "kind": 32768, @@ -665,7 +598,7 @@ "type": { "type": "reflection", "declaration": { - "id": 110, + "id": 109, "name": "__type", "variant": "declaration", "kind": 65536, @@ -680,7 +613,7 @@ ], "signatures": [ { - "id": 111, + "id": 110, "name": "__type", "variant": "signature", "kind": 4096, @@ -695,7 +628,7 @@ ], "parameters": [ { - "id": 112, + "id": 111, "name": "item", "variant": "param", "kind": 32768, @@ -721,7 +654,7 @@ "type": { "type": "reflection", "declaration": { - "id": 113, + "id": 112, "name": "__type", "variant": "declaration", "kind": 65536, @@ -736,7 +669,7 @@ ], "signatures": [ { - "id": 114, + "id": 113, "name": "__type", "variant": "signature", "kind": 4096, @@ -751,7 +684,7 @@ ], "parameters": [ { - "id": 115, + "id": 114, "name": "iterator", "variant": "param", "kind": 32768, @@ -2184,6 +2117,52 @@ "variant": "declaration", "kind": 64, "flags": {}, + "children": [ + { + "id": 80, + "name": "nsFn", + "variant": "declaration", + "kind": 2048, + "flags": {}, + "sources": [ + { + "fileName": "function.ts", + "line": 305, + "character": 7, + "url": "typedoc://function.ts#L305" + } + ], + "signatures": [ + { + "id": 81, + "name": "nsFn", + "variant": "signature", + "kind": 4096, + "flags": {}, + "sources": [ + { + "fileName": "function.ts", + "line": 305, + "character": 14, + "url": "typedoc://function.ts#L305" + } + ], + "type": { + "type": "intrinsic", + "name": "void" + } + } + ] + } + ], + "groups": [ + { + "title": "Methods", + "children": [ + 80 + ] + } + ], "sources": [ { "fileName": "function.ts", @@ -2468,7 +2447,7 @@ ] }, { - "id": 83, + "id": 82, "name": "variableFunction", "variant": "declaration", "kind": 64, @@ -2483,7 +2462,7 @@ ], "signatures": [ { - "id": 84, + "id": 83, "name": "variableFunction", "variant": "signature", "kind": 4096, @@ -2517,7 +2496,7 @@ ], "parameters": [ { - "id": 85, + "id": 84, "name": "someParam", "variant": "param", "kind": 32768, @@ -2548,20 +2527,19 @@ { "title": "Namespaces", "children": [ - 80, 55 ] }, { "title": "Classes", "children": [ - 86 + 85 ] }, { "title": "Functions", "children": [ - 99, + 98, 67, 61, 75, @@ -2578,7 +2556,7 @@ 78, 52, 45, - 83 + 82 ] } ], @@ -2592,14 +2570,14 @@ ] }, { - "id": 116, + "id": 115, "name": "generic-function", "variant": "declaration", "kind": 2, "flags": {}, "children": [ { - "id": 121, + "id": 120, "name": "functionWithGenericArrayParameter", "variant": "declaration", "kind": 64, @@ -2614,7 +2592,7 @@ ], "signatures": [ { - "id": 122, + "id": 121, "name": "functionWithGenericArrayParameter", "variant": "signature", "kind": 4096, @@ -2648,7 +2626,7 @@ ], "typeParameter": [ { - "id": 123, + "id": 122, "name": "T", "variant": "typeParam", "kind": 131072, @@ -2657,7 +2635,7 @@ ], "parameters": [ { - "id": 124, + "id": 123, "name": "param", "variant": "param", "kind": 32768, @@ -2678,7 +2656,7 @@ } }, { - "id": 125, + "id": 124, "name": "params", "variant": "param", "kind": 32768, @@ -2715,7 +2693,7 @@ ] }, { - "id": 126, + "id": 125, "name": "functionWithTemplate", "variant": "declaration", "kind": 64, @@ -2730,7 +2708,7 @@ ], "signatures": [ { - "id": 127, + "id": 126, "name": "functionWithTemplate", "variant": "signature", "kind": 4096, @@ -2745,7 +2723,7 @@ ], "typeParameter": [ { - "id": 128, + "id": 127, "name": "T", "variant": "typeParam", "kind": 131072, @@ -2762,7 +2740,7 @@ ], "parameters": [ { - "id": 129, + "id": 128, "name": "param", "variant": "param", "kind": 32768, @@ -2793,7 +2771,7 @@ ] }, { - "id": 117, + "id": 116, "name": "genericFunction", "variant": "declaration", "kind": 64, @@ -2808,7 +2786,7 @@ ], "signatures": [ { - "id": 118, + "id": 117, "name": "genericFunction", "variant": "signature", "kind": 4096, @@ -2842,7 +2820,7 @@ ], "typeParameter": [ { - "id": 119, + "id": 118, "name": "T", "variant": "typeParam", "kind": 131072, @@ -2868,7 +2846,7 @@ ], "parameters": [ { - "id": 120, + "id": 119, "name": "value", "variant": "param", "kind": 32768, @@ -2903,9 +2881,9 @@ { "title": "Functions", "children": [ - 121, - 126, - 117 + 120, + 125, + 116 ] } ], @@ -2919,21 +2897,21 @@ ] }, { - "id": 130, + "id": 129, "name": "implicit-types", "variant": "declaration", "kind": 2, "flags": {}, "children": [ { - "id": 139, + "id": 138, "name": "BreakpointRange", "variant": "declaration", "kind": 256, "flags": {}, "children": [ { - "id": 141, + "id": 140, "name": "end", "variant": "declaration", "kind": 1024, @@ -2952,7 +2930,7 @@ } }, { - "id": 140, + "id": 139, "name": "start", "variant": "declaration", "kind": 1024, @@ -2975,8 +2953,8 @@ { "title": "Properties", "children": [ - 141, - 140 + 140, + 139 ] } ], @@ -2990,7 +2968,7 @@ ] }, { - "id": 131, + "id": 130, "name": "getBreakpoints", "variant": "declaration", "kind": 64, @@ -3005,7 +2983,7 @@ ], "signatures": [ { - "id": 132, + "id": 131, "name": "getBreakpoints", "variant": "signature", "kind": 4096, @@ -3021,14 +2999,14 @@ "type": { "type": "reflection", "declaration": { - "id": 133, + "id": 132, "name": "__type", "variant": "declaration", "kind": 65536, "flags": {}, "children": [ { - "id": 136, + "id": 135, "name": "large", "variant": "declaration", "kind": 1024, @@ -3043,13 +3021,13 @@ ], "type": { "type": "reference", - "target": 139, + "target": 138, "name": "BreakpointRange", "package": "typedoc" } }, { - "id": 135, + "id": 134, "name": "medium", "variant": "declaration", "kind": 1024, @@ -3064,13 +3042,13 @@ ], "type": { "type": "reference", - "target": 139, + "target": 138, "name": "BreakpointRange", "package": "typedoc" } }, { - "id": 134, + "id": 133, "name": "small", "variant": "declaration", "kind": 1024, @@ -3085,13 +3063,13 @@ ], "type": { "type": "reference", - "target": 139, + "target": 138, "name": "BreakpointRange", "package": "typedoc" } }, { - "id": 137, + "id": 136, "name": "xlarge", "variant": "declaration", "kind": 1024, @@ -3106,13 +3084,13 @@ ], "type": { "type": "reference", - "target": 139, + "target": 138, "name": "BreakpointRange", "package": "typedoc" } }, { - "id": 138, + "id": 137, "name": "xxlarge", "variant": "declaration", "kind": 1024, @@ -3127,7 +3105,7 @@ ], "type": { "type": "reference", - "target": 139, + "target": 138, "name": "BreakpointRange", "package": "typedoc" } @@ -3137,11 +3115,11 @@ { "title": "Properties", "children": [ - 136, 135, 134, - 137, - 138 + 133, + 136, + 137 ] } ], @@ -3163,13 +3141,13 @@ { "title": "Interfaces", "children": [ - 139 + 138 ] }, { "title": "Functions", "children": [ - 131 + 130 ] } ], @@ -3188,8 +3166,8 @@ "title": "Modules", "children": [ 1, - 116, - 130 + 115, + 129 ] } ], @@ -3513,7 +3491,7 @@ }, "80": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "merged" + "qualifiedName": "merged.nsFn" }, "81": { "sourceFileName": "src/test/converter/function/function.ts", @@ -3521,7 +3499,7 @@ }, "82": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "merged.nsFn" + "qualifiedName": "variableFunction" }, "83": { "sourceFileName": "src/test/converter/function/function.ts", @@ -3529,15 +3507,15 @@ }, "84": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "variableFunction" + "qualifiedName": "someParam" }, "85": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "someParam" + "qualifiedName": "Predicates" }, "86": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "Predicates" + "qualifiedName": "Predicates.isString" }, "87": { "sourceFileName": "src/test/converter/function/function.ts", @@ -3545,11 +3523,11 @@ }, "88": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "Predicates.isString" + "qualifiedName": "x" }, "89": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "x" + "qualifiedName": "Predicates.assert" }, "90": { "sourceFileName": "src/test/converter/function/function.ts", @@ -3557,11 +3535,11 @@ }, "91": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "Predicates.assert" + "qualifiedName": "x" }, - "92": { + "94": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "x" + "qualifiedName": "Predicates.isString" }, "95": { "sourceFileName": "src/test/converter/function/function.ts", @@ -3569,7 +3547,7 @@ }, "96": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "Predicates.isString" + "qualifiedName": "Predicates.assertString" }, "97": { "sourceFileName": "src/test/converter/function/function.ts", @@ -3577,7 +3555,7 @@ }, "98": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "Predicates.assertString" + "qualifiedName": "all" }, "99": { "sourceFileName": "src/test/converter/function/function.ts", @@ -3585,15 +3563,15 @@ }, "100": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "all" + "qualifiedName": "T" }, "101": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "T" + "qualifiedName": "fn" }, "102": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "fn" + "qualifiedName": "__type" }, "103": { "sourceFileName": "src/test/converter/function/function.ts", @@ -3601,27 +3579,27 @@ }, "104": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "__type" + "qualifiedName": "item" }, "105": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "item" + "qualifiedName": "iterator" }, "106": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "iterator" + "qualifiedName": "all" }, "107": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "all" + "qualifiedName": "T" }, "108": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "T" + "qualifiedName": "fn" }, "109": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "fn" + "qualifiedName": "__type" }, "110": { "sourceFileName": "src/test/converter/function/function.ts", @@ -3629,11 +3607,11 @@ }, "111": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "__type" + "qualifiedName": "item" }, "112": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "item" + "qualifiedName": "__type" }, "113": { "sourceFileName": "src/test/converter/function/function.ts", @@ -3641,15 +3619,15 @@ }, "114": { "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "__type" + "qualifiedName": "iterator" }, "115": { - "sourceFileName": "src/test/converter/function/function.ts", - "qualifiedName": "iterator" + "sourceFileName": "src/test/converter/function/generic-function.ts", + "qualifiedName": "" }, "116": { "sourceFileName": "src/test/converter/function/generic-function.ts", - "qualifiedName": "" + "qualifiedName": "genericFunction" }, "117": { "sourceFileName": "src/test/converter/function/generic-function.ts", @@ -3657,15 +3635,15 @@ }, "118": { "sourceFileName": "src/test/converter/function/generic-function.ts", - "qualifiedName": "genericFunction" + "qualifiedName": "T" }, "119": { "sourceFileName": "src/test/converter/function/generic-function.ts", - "qualifiedName": "T" + "qualifiedName": "value" }, "120": { "sourceFileName": "src/test/converter/function/generic-function.ts", - "qualifiedName": "value" + "qualifiedName": "functionWithGenericArrayParameter" }, "121": { "sourceFileName": "src/test/converter/function/generic-function.ts", @@ -3673,81 +3651,77 @@ }, "122": { "sourceFileName": "src/test/converter/function/generic-function.ts", - "qualifiedName": "functionWithGenericArrayParameter" + "qualifiedName": "T" }, "123": { "sourceFileName": "src/test/converter/function/generic-function.ts", - "qualifiedName": "T" + "qualifiedName": "param" }, "124": { "sourceFileName": "src/test/converter/function/generic-function.ts", - "qualifiedName": "param" + "qualifiedName": "params" }, "125": { "sourceFileName": "src/test/converter/function/generic-function.ts", - "qualifiedName": "params" + "qualifiedName": "functionWithTemplate" }, "126": { "sourceFileName": "src/test/converter/function/generic-function.ts", "qualifiedName": "functionWithTemplate" }, "127": { - "sourceFileName": "src/test/converter/function/generic-function.ts", - "qualifiedName": "functionWithTemplate" - }, - "128": { "sourceFileName": "src/test/converter/function/generic-function.ts", "qualifiedName": "T" }, - "129": { + "128": { "sourceFileName": "src/test/converter/function/generic-function.ts", "qualifiedName": "param" }, - "130": { + "129": { "sourceFileName": "src/test/converter/function/implicit-types.ts", "qualifiedName": "" }, - "131": { + "130": { "sourceFileName": "src/test/converter/function/implicit-types.ts", "qualifiedName": "getBreakpoints" }, - "132": { + "131": { "sourceFileName": "src/test/converter/function/implicit-types.ts", "qualifiedName": "getBreakpoints" }, - "133": { + "132": { "sourceFileName": "src/test/converter/function/implicit-types.ts", "qualifiedName": "__type" }, - "134": { + "133": { "sourceFileName": "src/test/converter/function/implicit-types.ts", "qualifiedName": "__type.small" }, - "135": { + "134": { "sourceFileName": "src/test/converter/function/implicit-types.ts", "qualifiedName": "__type.medium" }, - "136": { + "135": { "sourceFileName": "src/test/converter/function/implicit-types.ts", "qualifiedName": "__type.large" }, - "137": { + "136": { "sourceFileName": "src/test/converter/function/implicit-types.ts", "qualifiedName": "__type.xlarge" }, - "138": { + "137": { "sourceFileName": "src/test/converter/function/implicit-types.ts", "qualifiedName": "__type.xxlarge" }, - "139": { + "138": { "sourceFileName": "src/test/converter/function/implicit-types.ts", "qualifiedName": "BreakpointRange" }, - "140": { + "139": { "sourceFileName": "src/test/converter/function/implicit-types.ts", "qualifiedName": "BreakpointRange.start" }, - "141": { + "140": { "sourceFileName": "src/test/converter/function/implicit-types.ts", "qualifiedName": "BreakpointRange.end" } diff --git a/src/test/issues.c2.test.ts b/src/test/issues.c2.test.ts index af957080d..5ca72e39d 100644 --- a/src/test/issues.c2.test.ts +++ b/src/test/issues.c2.test.ts @@ -253,7 +253,7 @@ describe("Issue Tests", () => { const project = convert(); equal( query(project, "gh1483.namespaceExport").kind, - ReflectionKind.Function, + ReflectionKind.Method, ); equal( query(project, "gh1483_2.staticMethod").kind, @@ -373,9 +373,9 @@ describe("Issue Tests", () => { equal(ctor.sources?.[0]?.character, 4); }); - it("#1651", () => { + it("Handles comment discovery with expando functions #1651", () => { const project = convert(); - equal(project.children?.map((c) => c.name), ["bar", "bar"]); + equal(project.children?.map((c) => c.name), ["bar"]); equal(project.children[0].children?.map((c) => c.name), [ "metadata", @@ -386,10 +386,10 @@ describe("Issue Tests", () => { project.children[0].comment?.summary, project.children[0].children[0].comment?.summary, project.children[0].children[1].signatures![0].comment?.summary, - project.children[1].signatures![0].comment?.summary, + project.children[0].signatures![0].comment?.summary, ].map(Comment.combineDisplayParts); - equal(comments, ["bar", "metadata", "fn", "bar"]); + equal(comments, ["", "metadata", "fn", "bar"]); }); it("#1660", () => { @@ -1199,18 +1199,13 @@ describe("Issue Tests", () => { it("Handles function-namespaces created with Object.assign #2436", () => { const project = convert(); - equal(project.children?.map((c) => c.kind), [ - ReflectionKind.Namespace, - ReflectionKind.Function, - ]); - equal( - project.children[0].getChildByName("bar")?.kind, - ReflectionKind.Variable, - ); - equal( - project.children[0].getChildByName("foo")?.kind, - ReflectionKind.Function, - ); + equal(query(project, "bug").kind, ReflectionKind.Function); + const foo = query(project, "bug.foo"); + const bar = query(project, "bug.bar"); + // It'd be kind of nice if foo became a method, but the symbol only has + // a Property flag, and there are other nicer ways to formulate this that do. + equal(foo.kind, ReflectionKind.Property, "method"); + equal(bar.kind, ReflectionKind.Property, "property"); }); it("Does not warn due to the diamond problem in comment discovery #2437", () => {