Skip to content

Commit

Permalink
fix: Constructors did not have source information set
Browse files Browse the repository at this point in the history
Resolves #1626
  • Loading branch information
Gerrit0 committed Jul 12, 2021
1 parent 030cb1e commit 5dfe9de
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 34 deletions.
7 changes: 5 additions & 2 deletions src/lib/converter/plugins/SourcePlugin.ts
Expand Up @@ -94,10 +94,13 @@ export class SourcePlugin extends ConverterComponent {
if (isNamedNode(node)) {
position = ts.getLineAndCharacterOfPosition(
sourceFile,
node.name.end
node.name.getStart()
);
} else {
position = ts.getLineAndCharacterOfPosition(sourceFile, node.pos);
position = ts.getLineAndCharacterOfPosition(
sourceFile,
node.getStart()
);
}

if (reflection instanceof DeclarationReflection) {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/converter/symbols.ts
Expand Up @@ -466,7 +466,9 @@ function convertClassOrInterface(
context.trigger(
ConverterEvents.CREATE_DECLARATION,
constructMember,
classDeclaration.getChildren().find(ts.isConstructorDeclaration)
ts.isClassDeclaration(classDeclaration)
? classDeclaration.members.find(ts.isConstructorDeclaration)
: void 0
);

const constructContext = reflectionContext.withScope(constructMember);
Expand Down
38 changes: 26 additions & 12 deletions src/test/converter/class/specs-with-lump-categories.json
Expand Up @@ -753,6 +753,9 @@
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {
"shortText": "Constructor short text."
},
"signatures": [
{
"id": 27,
Expand Down Expand Up @@ -1025,6 +1028,9 @@
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {
"shortText": "Constructor short text."
},
"signatures": [
{
"id": 43,
Expand All @@ -1043,7 +1049,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Constructor param"
"shortText": "Constructor param"
},
"type": {
"type": "intrinsic",
Expand All @@ -1057,7 +1063,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Private string property"
"shortText": "Private string property"
},
"type": {
"type": "intrinsic",
Expand All @@ -1071,7 +1077,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Public number property"
"shortText": "Public number property"
},
"type": {
"type": "intrinsic",
Expand All @@ -1085,7 +1091,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Public implicit any property\n"
"shortText": "Public implicit any property\n"
},
"type": {
"type": "intrinsic",
Expand Down Expand Up @@ -1530,6 +1536,7 @@
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {},
"signatures": [
{
"id": 96,
Expand All @@ -1546,7 +1553,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "X component of the Vector"
"shortText": "X component of the Vector"
},
"type": {
"type": "intrinsic",
Expand All @@ -1560,7 +1567,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Y component of the Vector"
"shortText": "Y component of the Vector"
},
"type": {
"type": "intrinsic",
Expand All @@ -1574,7 +1581,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Vector name\n"
"shortText": "Vector name\n"
},
"type": {
"type": "intrinsic",
Expand Down Expand Up @@ -1672,6 +1679,7 @@
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {},
"signatures": [
{
"id": 105,
Expand All @@ -1688,7 +1696,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "X component of the Vector"
"shortText": "X component of the Vector"
},
"type": {
"type": "intrinsic",
Expand All @@ -1702,7 +1710,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Y component of the Vector"
"shortText": "Y component of the Vector"
},
"type": {
"type": "intrinsic",
Expand All @@ -1716,7 +1724,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Z component of the Vector"
"shortText": "Z component of the Vector"
},
"type": {
"type": "intrinsic",
Expand All @@ -1730,7 +1738,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Vector name\n"
"shortText": "Vector name\n"
},
"type": {
"type": "intrinsic",
Expand Down Expand Up @@ -2661,6 +2669,9 @@
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {
"shortText": "Constructor short text."
},
"signatures": [
{
"id": 168,
Expand Down Expand Up @@ -2688,7 +2699,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Constructor parameter.\n"
"shortText": "Constructor parameter.\n"
},
"type": {
"type": "reference",
Expand Down Expand Up @@ -2830,6 +2841,9 @@
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {
"shortText": "Constructor short text."
},
"signatures": [
{
"id": 178,
Expand Down
38 changes: 26 additions & 12 deletions src/test/converter/class/specs.json
Expand Up @@ -753,6 +753,9 @@
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {
"shortText": "Constructor short text."
},
"signatures": [
{
"id": 27,
Expand Down Expand Up @@ -1021,6 +1024,9 @@
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {
"shortText": "Constructor short text."
},
"signatures": [
{
"id": 43,
Expand All @@ -1039,7 +1045,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Constructor param"
"shortText": "Constructor param"
},
"type": {
"type": "intrinsic",
Expand All @@ -1053,7 +1059,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Private string property"
"shortText": "Private string property"
},
"type": {
"type": "intrinsic",
Expand All @@ -1067,7 +1073,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Public number property"
"shortText": "Public number property"
},
"type": {
"type": "intrinsic",
Expand All @@ -1081,7 +1087,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Public implicit any property\n"
"shortText": "Public implicit any property\n"
},
"type": {
"type": "intrinsic",
Expand Down Expand Up @@ -1526,6 +1532,7 @@
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {},
"signatures": [
{
"id": 96,
Expand All @@ -1542,7 +1549,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "X component of the Vector"
"shortText": "X component of the Vector"
},
"type": {
"type": "intrinsic",
Expand All @@ -1556,7 +1563,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Y component of the Vector"
"shortText": "Y component of the Vector"
},
"type": {
"type": "intrinsic",
Expand All @@ -1570,7 +1577,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Vector name\n"
"shortText": "Vector name\n"
},
"type": {
"type": "intrinsic",
Expand Down Expand Up @@ -1668,6 +1675,7 @@
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {},
"signatures": [
{
"id": 105,
Expand All @@ -1684,7 +1692,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "X component of the Vector"
"shortText": "X component of the Vector"
},
"type": {
"type": "intrinsic",
Expand All @@ -1698,7 +1706,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Y component of the Vector"
"shortText": "Y component of the Vector"
},
"type": {
"type": "intrinsic",
Expand All @@ -1712,7 +1720,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Z component of the Vector"
"shortText": "Z component of the Vector"
},
"type": {
"type": "intrinsic",
Expand All @@ -1726,7 +1734,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Vector name\n"
"shortText": "Vector name\n"
},
"type": {
"type": "intrinsic",
Expand Down Expand Up @@ -2657,6 +2665,9 @@
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {
"shortText": "Constructor short text."
},
"signatures": [
{
"id": 168,
Expand Down Expand Up @@ -2684,7 +2695,7 @@
"kindString": "Parameter",
"flags": {},
"comment": {
"text": "Constructor parameter.\n"
"shortText": "Constructor parameter.\n"
},
"type": {
"type": "reference",
Expand Down Expand Up @@ -2826,6 +2837,9 @@
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {
"shortText": "Constructor short text."
},
"signatures": [
{
"id": 178,
Expand Down
7 changes: 6 additions & 1 deletion src/test/converter2.test.ts
Expand Up @@ -224,6 +224,12 @@ const issueTests: Record<string, (project: ProjectReflection) => void> = {
"Property methods declared in interface should still allow comment inheritance"
);
},

gh1626(project) {
const ctor = query(project, "Foo.constructor");
equal(ctor.sources?.[0]?.line, 2);
equal(ctor.sources?.[0]?.character, 4);
},
};

describe("Converter2", () => {
Expand All @@ -233,7 +239,6 @@ describe("Converter2", () => {
app.bootstrap({
name: "typedoc",
excludeExternals: true,
disableSources: true,
tsconfig: join(base, "tsconfig.json"),
plugin: [],
});
Expand Down
3 changes: 3 additions & 0 deletions src/test/converter2/issues/gh1626.ts
@@ -0,0 +1,3 @@
export class Foo {
constructor() {}
}

0 comments on commit 5dfe9de

Please sign in to comment.