Skip to content

Commit

Permalink
Remove Const flag for function-variables and fix 1734 test
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Feb 13, 2022
1 parent 44bf2ec commit f5e52c2
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 154 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- `reflection.decorates`, `reflection.decorators`, and their corresponding interfaces have been removed as no code in TypeDoc used them.
- The shape of the `Comment` class has changed significantly to support multiple tag kinds.
- Listeners to `Converter.EVENT_CREATE_TYPE_PARAMETER` and `Converter.EVENT_CREATE_DECLARATION` will now never be passed a `ts.Node` as their third argument.
- Constant variables which are interpreted as functions will no longer have the `ReflectionFlag.Const` flag set.

### Features

Expand Down
25 changes: 18 additions & 7 deletions src/lib/converter/plugins/CommentPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,24 +249,35 @@ export class CommentPlugin extends ConverterComponent {
}

if (reflection.type instanceof ReflectionType) {
// GERRIT: This is problematic. Need to revisit and try to stop having nested reflections.
reflection.type.declaration.comment ||= reflection.comment?.clone();

this.processSignatureComments(
this.moveCommentToSignatures(
reflection,
reflection.type.declaration.getNonIndexSignatures()
);
} else {
this.processSignatureComments(reflection.getNonIndexSignatures());
this.moveCommentToSignatures(
reflection,
reflection.getNonIndexSignatures()
);
}
}

private processSignatureComments(signatures: SignatureReflection[]) {
private moveCommentToSignatures(
reflection: DeclarationReflection,
signatures: SignatureReflection[]
) {
if (!signatures.length) {
return;
}

const comment = reflection.comment;

// Since this reflection has signatures, remove the comment from the parent
// reflection. This is important so that in type aliases we don't end up with
// a comment rendered twice.
delete reflection.comment;

for (const signature of signatures) {
const childComment = signature.comment;
const childComment = (signature.comment ||= comment?.clone());
if (!childComment) continue;

signature.parameters?.forEach((parameter, index) => {
Expand Down
13 changes: 0 additions & 13 deletions src/lib/converter/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -910,19 +910,6 @@ function convertVariableAsFunction(
exportSymbol
);
setModifiers(symbol, accessDeclaration, reflection);
// Does anyone care about this? I doubt it...
if (
declaration &&
hasAllFlags(symbol.flags, ts.SymbolFlags.BlockScopedVariable)
) {
reflection.setFlag(
ReflectionFlag.Const,
hasAllFlags(
(declaration || symbol.valueDeclaration).parent.flags,
ts.NodeFlags.Const
)
);
}

context.finalizeDeclarationReflection(reflection);

Expand Down
24 changes: 8 additions & 16 deletions src/test/converter/alias/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@
"kind": 4194304,
"kindString": "Type alias",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "A type that describes a compare function, e.g. for array.sort()."
}
]
},
"sources": [
{
"fileName": "alias.ts",
Expand All @@ -154,14 +146,6 @@
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "A type that describes a compare function, e.g. for array.sort()."
}
]
},
"sources": [
{
"fileName": "alias.ts",
Expand All @@ -176,6 +160,14 @@
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "A type that describes a compare function, e.g. for array.sort()."
}
]
},
"parameters": [
{
"id": 4,
Expand Down
8 changes: 2 additions & 6 deletions src/test/converter/function/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,7 @@
"name": "all",
"kind": 64,
"kindString": "Function",
"flags": {
"isConst": true
},
"flags": {},
"sources": [
{
"fileName": "function.ts",
Expand Down Expand Up @@ -2157,9 +2155,7 @@
"name": "variableFunction",
"kind": 64,
"kindString": "Function",
"flags": {
"isConst": true
},
"flags": {},
"sources": [
{
"fileName": "function.ts",
Expand Down
8 changes: 0 additions & 8 deletions src/test/converter/interface/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1620,14 +1620,6 @@
"kind": 256,
"kindString": "Interface",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "Function signature of an event listener callback"
}
]
},
"sources": [
{
"fileName": "interface-implementation.ts",
Expand Down
40 changes: 10 additions & 30 deletions src/test/converter/js/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
"name": "export=",
"kind": 64,
"kindString": "Function",
"flags": {
"isConst": true
},
"flags": {},
"sources": [
{
"fileName": "export-eq-type.js",
Expand Down Expand Up @@ -582,14 +580,6 @@
"kind": 4194304,
"kindString": "Type alias",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "even though in the same comment block"
}
]
},
"sources": [
{
"fileName": "index.js",
Expand All @@ -605,14 +595,6 @@
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "even though in the same comment block"
}
]
},
"sources": [
{
"fileName": "index.js",
Expand All @@ -627,6 +609,14 @@
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "even though in the same comment block"
}
]
},
"type": {
"type": "intrinsic",
"name": "any"
Expand Down Expand Up @@ -800,14 +790,6 @@
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "enum comment"
}
]
},
"children": [
{
"id": 13,
Expand Down Expand Up @@ -874,9 +856,7 @@
"name": "usedFoo",
"kind": 64,
"kindString": "Function",
"flags": {
"isConst": true
},
"flags": {},
"sources": [
{
"fileName": "index.js",
Expand Down
60 changes: 19 additions & 41 deletions src/test/converter/mixin/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1037,14 +1037,6 @@
"kind": 4194304,
"kindString": "Type alias",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "Any constructor function"
}
]
},
"sources": [
{
"fileName": "mixin.ts",
Expand Down Expand Up @@ -1073,21 +1065,21 @@
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "Any constructor function"
}
]
},
"signatures": [
{
"id": 8,
"name": "__type",
"kind": 16384,
"kindString": "Constructor signature",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "Any constructor function"
}
]
},
"parameters": [
{
"id": 9,
Expand Down Expand Up @@ -1122,14 +1114,6 @@
"kind": 4194304,
"kindString": "Type alias",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "Any function"
}
]
},
"sources": [
{
"fileName": "mixin.ts",
Expand Down Expand Up @@ -1158,14 +1142,6 @@
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "Any function"
}
]
},
"sources": [
{
"fileName": "mixin.ts",
Expand All @@ -1180,6 +1156,14 @@
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "Any function"
}
]
},
"parameters": [
{
"id": 4,
Expand Down Expand Up @@ -1324,9 +1308,7 @@
"name": "Mixin1Func",
"kind": 64,
"kindString": "Function",
"flags": {
"isConst": true
},
"flags": {},
"sources": [
{
"fileName": "mixin.ts",
Expand Down Expand Up @@ -1440,9 +1422,7 @@
"name": "Mixin2",
"kind": 64,
"kindString": "Function",
"flags": {
"isConst": true
},
"flags": {},
"sources": [
{
"fileName": "mixin.ts",
Expand Down Expand Up @@ -1566,9 +1546,7 @@
"name": "Mixin3",
"kind": 64,
"kindString": "Function",
"flags": {
"isConst": true
},
"flags": {},
"sources": [
{
"fileName": "mixin.ts",
Expand Down
16 changes: 0 additions & 16 deletions src/test/converter/variables/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1007,14 +1007,6 @@
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "An object literal."
}
]
},
"children": [
{
"id": 89,
Expand Down Expand Up @@ -1439,14 +1431,6 @@
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "A typed literal without an initializer."
}
]
},
"children": [
{
"id": 48,
Expand Down

0 comments on commit f5e52c2

Please sign in to comment.