Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON output missing "sources" node for constructors (HTML source info also incorrect) #1626

Closed
immcintosh opened this issue Jul 11, 2021 · 1 comment
Labels
bug Functionality does not match expectation

Comments

@immcintosh
Copy link

Search terms

json, sources, constructor

Expected Behavior

I'm reporting this bug specifically due to this issue causing a compatibility issue with sphinx_js documentation generator, and after reviewing what's going on, this does not seems like correct behavior.

The "Constructor" node should include the same "sources" node as a "Function" node does, being that it's a specialized type of function and logically has a source file location. For example, a function node appears as; I would expect the Constructor to have the same source info:

"id": 2,
"name": "default",
"kind": 64,
"kindString": "Function",
"flags": {},
"sources": [
{
	"fileName": "app.tsx",
	"line": 13,
	"character": 12
}

Corollary

The HTML documentation generated for constructors displays an incorrect line number (while functions have correct line numbers).

Actual Behavior

{
	"id": 2,
	"name": "constructor",
	"kind": 512,
	"kindString": "Constructor",
	"flags": {},
	"signatures": [
		{
			"id": 3,
			"name": "new default",
			"kind": 16384,
			"kindString": "Constructor signature",
			"flags": {},
			"type": {
				"type": "reference",
				"id": 1,
				"name": "TestClass"
			}
		}
	]
}

Steps to reproduce the bug

Run typedoc on any file containing a class with a constructor. This problem seems to be universal and I have never seen a constructor node generated with the correct file/line information. For example:

src/test/test.ts

class TestClass {
    public foo() {}
    public bar() {}
    constructor() {}
}

export default TestClass;

tsconfig.json

{
    "compilerOptions": {
        "jsx": "react",
        "allowJs": true,
        "module": "commonjs",
        "skipLibCheck": true,
        "esModuleInterop": true,
        "noImplicitAny": true,
        "sourceMap": true,
        "baseUrl": ".",
        "outDir": "dist",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "paths": {
            "*": ["node_modules/*"]
        }
    },
    "include": ["src/**/*"],
    "typedocOptions": {
        "entryPoints": ["src/test"],
        "out": "build/typedoc",
        "json": "build/docs.json"
    }
}

Environment

  • Typedoc version: 0.21.3
  • TypeScript version: 4.3.5
  • Node.js version: 15.8.0
  • OS: Windows 10
@immcintosh immcintosh added the bug Functionality does not match expectation label Jul 11, 2021
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jul 12, 2021

Thanks for the bug report! Yeah... that broke in 0.20. I thought constructorNode.getChildren().find(ts.isConstructorDeclaration) would get the constructor declaration, but that apparently wasn't right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality does not match expectation
Projects
None yet
Development

No branches or pull requests

2 participants