Skip to content

Commit 024bf4a

Browse files
committed
Relax errors, fix nested property resolution for MongoDB codebase compat
1 parent 7c1a615 commit 024bf4a

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

example/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
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",
30-
"build-pixi-api-gcp": "cd ../../pixi-api && webdoc --tutorials ./projects/guides --verbose && cd ../webdoc/example"
30+
"build-pixi-api-gcp": "cd ../../pixi-api && webdoc --tutorials ./projects/guides --verbose && cd ../webdoc/example",
31+
"build-mongodb": "cd ../../node-mongodb-native && webdoc --verbose && cd ../webdoc/example"
3132
},
3233
"bugs": {
3334
"url": "https://github.com/SukantPal/webdoc/issues"

packages/webdoc-model/src/doc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
} from "@webdoc/types";
1212
import {nanoid} from "nanoid";
1313

14-
const CANONICAL_SEPARATOR = /([.#~$])/g;
14+
export const CANONICAL_SEPARATOR = /([.#~$])/g;
1515

1616
function updateScope(doc: Doc, scopeStack: string[], scopePath: string): void {
1717
if (scopePath) {
@@ -75,7 +75,7 @@ export const createDoc = (
7575

7676
// Sad: splitting will include the separators so filter them
7777
const path = doc.name.split(CANONICAL_SEPARATOR)
78-
.filter((ch) => ch !== "." && ch !== "#" && ch !== "#");
78+
.filter((ch) => ch !== "." && ch !== "#" && ch !== "~");
7979
const parserOpts = doc.parserOpts || {};
8080

8181
doc.name = path[path.length - 1];

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22
import type {BaseDoc, PropertyTag} from "@webdoc/types";
33
import {StringUtils, matchDataTypeClosure, matchDefaultValueClosure} from "./helper";
4-
import {createDoc} from "@webdoc/model";
4+
import {createDoc, findDoc, CANONICAL_SEPARATOR} from "@webdoc/model";
55
import {parseDataType} from "@webdoc/model";
66

77
// @property {<DATA_TYPE>} <NAME> - <DESC>
@@ -103,7 +103,7 @@ export function parseProperty(value: string, doc: $Shape<BaseDoc>): PropertyTag
103103
doc.members = [];
104104
}
105105

106-
doc.members.push(createDoc(name, "PropertyDoc", {
106+
const propertyDoc = createDoc(name, "PropertyDoc", {
107107
object: null,
108108
constant: !!dataValue,
109109
dataType: dataType ? parseDataType(dataType) : undefined,
@@ -113,7 +113,21 @@ export function parseProperty(value: string, doc: $Shape<BaseDoc>): PropertyTag
113113
optional,
114114
scope: "default", // related-resolution doctree-mod will resolve this
115115
loc: doc.loc,
116-
}));
116+
});
117+
let parent = doc;
118+
119+
// Properties cannot be relocated. Attempt to do it locally
120+
if (propertyDoc.parserOpts && propertyDoc.parserOpts.memberof) {
121+
delete propertyDoc.parserOpts.memberof;
122+
123+
parent = findDoc(name.split(CANONICAL_SEPARATOR).slice(0, -2).join("."), doc);
124+
}
125+
126+
if (parent) {
127+
doc.members.push(propertyDoc);
128+
} else {
129+
throw new Error('Property ' + name + '\'s parent cannot be located. Did you declare parent properties?');
130+
}
117131

118132
return {
119133
name: "property",

packages/webdoc-parser/src/validators/validate-parameters.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function validateParameters(doc: DocShape, meta: SymbolSignature): void {
2020
const name = param.identifier;
2121

2222
if (!name) {
23-
throw new Error("Anonymous documented parameters are not supported");
23+
console.warn("Anonymous documented parameters are not supported");
2424
}
2525

2626
const dotIndex = name.indexOf(".");
@@ -33,14 +33,14 @@ function validateParameters(doc: DocShape, meta: SymbolSignature): void {
3333
// @param {string} string
3434
// @param {string} options.title
3535
if (firstId !== lastParam) {
36-
throw new Error(`Object property ${name} parameter must be placed` +
36+
console.warn(`Object property ${name} parameter must be placed` +
3737
`directly after object parameter ${firstId}`);
3838
}
3939

4040
continue;
4141
}
4242
if (j >= metaParams.length) {
43-
throw new Error(`"${name}" is not a parameter & cannot` +
43+
console.warn(`"${name}" is not a parameter & cannot` +
4444
` come after the last parameter "${lastParam || ""}"`);
4545
}
4646

0 commit comments

Comments
 (0)