Skip to content

Commit d35d490

Browse files
committed
Add support for ES5 classes and @classdesc with auto-generation of constructors
1 parent 3450c47 commit d35d490

File tree

14 files changed

+237
-46
lines changed

14 files changed

+237
-46
lines changed

.idea/misc.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/example.api.json

Lines changed: 101 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,17 @@
2828
"type": "ClassDoc",
2929
"scope": "static",
3030
"brief": "",
31-
"description": ""
31+
"description": "",
32+
"members": [
33+
{
34+
"name": "constructor",
35+
"type": "MethodDoc",
36+
"access": "public",
37+
"scope": "instance",
38+
"brief": "",
39+
"description": ""
40+
}
41+
]
3242
},
3343
{
3444
"name": "AbstractRenderer",
@@ -42,6 +52,14 @@
4252
"scope": "instance",
4353
"brief": "<p>The background color to fill if not transparent</p>",
4454
"description": ""
55+
},
56+
{
57+
"name": "constructor",
58+
"type": "MethodDoc",
59+
"access": "public",
60+
"scope": "instance",
61+
"brief": "",
62+
"description": ""
4563
}
4664
]
4765
},
@@ -475,13 +493,17 @@
475493
"name": "Road",
476494
"type": "ClassDoc",
477495
"brief": "<p>This is another road class.</p>",
478-
"description": ""
479-
},
480-
{
481-
"name": "Road",
482-
"type": "ClassDoc",
483-
"brief": "<p>Road represents a drivable 2D path for vehicles.</p>",
484-
"description": ""
496+
"description": "",
497+
"members": [
498+
{
499+
"name": "constructor",
500+
"type": "MethodDoc",
501+
"access": "public",
502+
"scope": "instance",
503+
"brief": "<p>This is another road class.</p>",
504+
"description": ""
505+
}
506+
]
485507
},
486508
{
487509
"name": "DEFAULT_LANES",
@@ -509,7 +531,17 @@
509531
"name": "Transaction",
510532
"type": "ClassDoc",
511533
"brief": "",
512-
"description": ""
534+
"description": "",
535+
"members": [
536+
{
537+
"name": "constructor",
538+
"type": "MethodDoc",
539+
"access": "public",
540+
"scope": "instance",
541+
"brief": "",
542+
"description": ""
543+
}
544+
]
513545
}
514546
]
515547
},
@@ -519,6 +551,14 @@
519551
"brief": "<p>Bean class</p>",
520552
"description": "",
521553
"members": [
554+
{
555+
"name": "constructor",
556+
"type": "MethodDoc",
557+
"access": "public",
558+
"scope": "instance",
559+
"brief": "<p>Bean class</p>",
560+
"description": ""
561+
},
522562
{
523563
"name": "roast",
524564
"type": "MethodDoc",
@@ -590,6 +630,14 @@
590630
"brief": "<p>Register a retail dealer for buying a car from</p>",
591631
"description": ""
592632
},
633+
{
634+
"name": "constructor",
635+
"type": "MethodDoc",
636+
"access": "public",
637+
"scope": "instance",
638+
"brief": "<p><em>Simulation</em> for a automobile that can drive on a manifold surface.</p>",
639+
"description": ""
640+
},
593641
{
594642
"name": "onCrash",
595643
"type": "MethodDoc",
@@ -635,12 +683,56 @@
635683
}
636684
]
637685
},
686+
{
687+
"name": "ExampleFactory",
688+
"type": "ClassDoc",
689+
"description": "<p>{@link ExampleFactory} can be used to build examples.</p>\n<pre><code class=\"hljs language-js\"><span class=\"hljs-comment\">// <span class=\"hljs-doctag\">TODO:</span> Make the API interesting</span>\nExampleFactory.getInstance()\n .build()\n</code></pre>",
690+
"members": [
691+
{
692+
"name": "getInstance",
693+
"type": "MethodDoc",
694+
"scope": "static",
695+
"brief": "<p>Gets a lazily-initialized, shared singleton instance of {@link ExampleFactory}.</p>",
696+
"description": ""
697+
},
698+
{
699+
"name": "build",
700+
"type": "MethodDoc",
701+
"scope": "instance",
702+
"brief": "<p>Build the road.</p>",
703+
"description": ""
704+
},
705+
{
706+
"name": "constructor",
707+
"type": "MethodDoc",
708+
"access": "public",
709+
"scope": "instance",
710+
"brief": "<p>This constructor should only be used for custom contexts.</p>",
711+
"description": ""
712+
},
713+
{
714+
"name": "getContext",
715+
"type": "MethodDoc",
716+
"scope": "instance",
717+
"brief": "<p>Get the context of this factory.</p>",
718+
"description": ""
719+
}
720+
]
721+
},
638722
{
639723
"name": "Gravity",
640724
"type": "ClassDoc",
641725
"brief": "<p>This class shouldn't be documented!</p>",
642726
"description": "",
643727
"members": [
728+
{
729+
"name": "constructor",
730+
"type": "MethodDoc",
731+
"access": "public",
732+
"scope": "instance",
733+
"brief": "<p>This class shouldn't be documented!</p>",
734+
"description": ""
735+
},
644736
{
645737
"name": "force",
646738
"type": "MethodDoc",

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"scripts": {
2525
"unit-test": "",
26-
"build": "webdoc --tutorials ./tutorials --site-root example-documentation --site-domain https://webdoc-labs.github.io",
26+
"build": "webdoc --tutorials ./tutorials --site-domain https://webdoc-labs.github.io",
2727
"build-next": "cd .. && webdoc && cd example",
2828
"build-pixi-api": "cd ../../pixi-api && webdoc && cd ../webdoc/example",
2929
"build-pixi-api-prod": "cd ../../pixi-api && webdoc --site-root pixi-api && cd ../webdoc/example",

example/src/ExampleFactory.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* A namespace dedicated to road manipulation utilites.
3+
*
4+
* @namespace
5+
*/
6+
const R = {
7+
/**
8+
* Builds a road
9+
*
10+
* @param {string} address
11+
* @return {ExampleFactory}
12+
*/
13+
buildRoad(address) {
14+
return null;
15+
},
16+
17+
/**
18+
* The default no. of lanes per one side of road
19+
*/
20+
DEFAULT_LANES: 4,
21+
};
22+
23+
/**
24+
* This constructor should only be used for custom contexts.
25+
*
26+
* @classdesc
27+
* {@link ExampleFactory} can be used to build examples.
28+
*
29+
* ```js
30+
* // TODO: Make the API interesting
31+
* ExampleFactory.getInstance()
32+
* .build()
33+
* ```
34+
*
35+
* @param {ExampleContext}[context=null] - A custom context for the factory.
36+
* @class
37+
*/
38+
export function ExampleFactory(context= null) {
39+
40+
}
41+
42+
/**
43+
* Get the context of this factory.
44+
*
45+
* @return {ExampleContext}
46+
*/
47+
ExampleFactory.prototype.getContext = function() {
48+
return null;
49+
}
50+
51+
/**
52+
* Build the road.
53+
*/
54+
ExampleFactory.prototype.build = function() {
55+
56+
}
57+
58+
/**
59+
* Gets a lazily-initialized, shared singleton instance of {@link ExampleFactory}.
60+
*
61+
* @returns {ExampleFactory}
62+
*/
63+
ExampleFactory.getInstance = function () {
64+
if (!ExampleFactory.__instance) {
65+
ExampleFactory.__instance = new ExampleFactory();
66+
}
67+
68+
return ExampleFactory.__instance;
69+
}

example/src/Road.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

packages/webdoc-default-template/static/scripts/default-template.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9466,7 +9466,6 @@ function makeIds(data, collector) {
94669466
};
94679467
})(function Explorer(_ref2) {
94689468
var isOpen = _ref2.isOpen,
9469-
setOpen = _ref2.setOpen,
94709469
expandedItems = _ref2.expandedItems,
94719470
setExpandedItems = _ref2.setExpandedItems,
94729471
toggleItem = _ref2.toggleItem,
@@ -9485,9 +9484,6 @@ function makeIds(data, collector) {
94859484
var _useExplorerStyles = useExplorerStyles(),
94869485
root = _useExplorerStyles.root;
94879486

9488-
var toggleOpen = external_React_default.a.useCallback(function () {
9489-
return setOpen(!isOpen);
9490-
}, [isOpen]);
94919487
var children = [];
94929488
var explorerTree = window.appData.explorerTree;
94939489

packages/webdoc-parser/src/symbols-babel/extract-symbol.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,13 @@ export default function extractSymbol(
229229
nodeSymbol.meta.type = "PropertyDoc";
230230
}
231231

232+
let isExpression = false;
233+
232234
if (isExpressionStatement(node)) {
233235
// Literal property
234236

237+
isExpression = true;
238+
235239
const object = resolveObject(node.expression.left);
236240
const scope = isInstancePropertyAssignment(node.expression.left) ?
237241
"instance" : "static";
@@ -251,7 +255,7 @@ export default function extractSymbol(
251255
}
252256

253257
if (isFunctionExpression(init) || isArrowFunctionExpression(init)) {
254-
nodeSymbol.meta.type = isObjectProperty(node) ? "MethodDoc" : "FunctionDoc";
258+
nodeSymbol.meta.type = isObjectProperty(node) || isExpression ? "MethodDoc" : "FunctionDoc";
255259

256260
nodeSymbol.meta.params = extractParams(init);
257261
nodeSymbol.meta.returns = extractReturns(init);

packages/webdoc-parser/src/tag-parsers/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export {parseExtends, parseImplements, parseMixes} from "./parseExtendsImplement
1111
export {
1212
parseAbstract,
1313
parseAuthor,
14+
parseClassDesc,
1415
parseCopyright,
1516
parseDefault,
1617
parseDeprecated,

packages/webdoc-parser/src/tag-parsers/parseSimple.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
AbstractTag,
55
AuthorTag,
66
BaseDoc,
7+
ClassDescTag,
78
CopyrightTag,
89
DataType,
910
DefaultTag,
@@ -58,6 +59,13 @@ export function parseAuthor(value: string, doc: $Shape<BaseDoc>): $Shape<AuthorT
5859
};
5960
}
6061

62+
export function parseClassDesc(value: string, _doc: $Shape<BaseDoc>): $Shape<ClassDescTag> {
63+
return {
64+
value,
65+
type: "ClassDescTag",
66+
};
67+
}
68+
6169
export function parseCopyright(value: string, doc: $Shape<BaseDoc>): $Shape<CopyrightTag> {
6270
doc.copyright = value;
6371

packages/webdoc-parser/src/transformer/document-tree-modifiers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import type {Doc, RootDoc} from "@webdoc/types";
44
import modDiscoverMembers from "./mod-discover-members";
5+
import modES5Constructor from './mod-es5-constructor';
56
import modPackageApi from "./mod-package-api";
67
import modPrune from "./mod-prune";// Next line is f'd up b/c the compiler ran on that file
78
import modResolveMemberof from "./mod-resolve-memberof"; // eslint-disable-line
@@ -52,7 +53,7 @@ export const STAGE_AST_LIKE = 100;
5253

5354
/**
5455
* The doctree-mod should run when symbols are placed in their documented parents. The
55-
* `@modResolveMemberof` tag is resolved in this stage. This occurs after {@code STAGE_AST_LIKE}.
56+
* `@memberof` tag is resolved in this stage. This occurs after {@code STAGE_AST_LIKE}.
5657
*
5758
* Example:
5859
* ```js
@@ -125,6 +126,7 @@ export function registerDoctreeMod(
125126
}
126127

127128
// These are the in-built doctree-mods.
129+
registerDoctreeMod("ASTMemberResolution", STAGE_AST_LIKE, modES5Constructor);
128130
registerDoctreeMod("ASTMemberResolution", STAGE_AST_LIKE, modResolveMembers);
129131
registerDoctreeMod("MemberOfResolution", STAGE_SYMBOLS_RESOLVED, modResolveMemberof);
130132
registerDoctreeMod("ExtendsImplementsMixesResolution", STAGE_SYMBOLS_RESOLVED, modResolveRelated);

0 commit comments

Comments
 (0)