Sometimes, a module exports the same thing as both a named and default export, e.g in Foo.js
:
export class Foo {}
export default Foo;
Run deno doc --json Foo.js
and the output is:
[
{
"kind": "class",
"name": "Foo",
"location": {
"filename": "file:///Users/jaydenseric/Sites/ruck/Foo.js",
"line": 1,
"col": 0
},
"jsDoc": null,
"classDef": {
"isAbstract": false,
"constructors": [],
"properties": [],
"indexSignatures": [],
"methods": [],
"extends": null,
"implements": [],
"typeParams": [],
"superTypeParams": []
}
},
{
"kind": "class",
"name": "default",
"location": {
"filename": "file:///Users/jaydenseric/Sites/ruck/Foo.js",
"line": 1,
"col": 0
},
"jsDoc": null,
"classDef": {
"isAbstract": false,
"constructors": [],
"properties": [],
"indexSignatures": [],
"methods": [],
"extends": null,
"implements": [],
"typeParams": [],
"superTypeParams": []
}
}
]
Note the documentation data for the same class is repeated twice.
Ideally generated docs for this data would not repeat all of the documentation for the same class twice, but it would either have one entry that explains the two ways it can be imported, or a second entry for either the named or default export would link to the main docs for the class.
Can this be achieved using the current JSON data? It looks like the location
is the same for both the named and default exports, is this a bug? It's not clear if the location should refer to the line of the export declaration or the source of an exported reference. Can location
be relied upon to detect the same member exported twice? Although dumb, theoretically the same member could also be exported multiple times under multiple named exports (a common use case is aliases for the same thing).
What if the JSON data structure were to be this instead:
[
{
+ "exports": ["Foo", "default"],
"kind": "class",
"name": "Foo",
"location": {
"filename": "file:///Users/jaydenseric/Sites/ruck/Foo.js",
"line": 1,
"col": 0
},
"jsDoc": null,
"classDef": {
"isAbstract": false,
"constructors": [],
"properties": [],
"indexSignatures": [],
"methods": [],
"extends": null,
"implements": [],
"typeParams": [],
"superTypeParams": []
}
},
- {
- "kind": "class",
- "name": "default",
- "location": {
- "filename": "file:///Users/jaydenseric/Sites/ruck/Foo.js",
- "line": 1,
- "col": 0
- },
- "jsDoc": null,
- "classDef": {
- "isAbstract": false,
- "constructors": [],
- "properties": [],
- "indexSignatures": [],
- "methods": [],
- "extends": null,
- "implements": [],
- "typeParams": [],
- "superTypeParams": []
- }
}
]