Skip to content

Commit c9f4515

Browse files
authored
Merge pull request #68 from webdoc-labs/fix/fields
Fix: Inference for types and default values in fields
2 parents 42fd9fa + acf10dc commit c9f4515

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

packages/webdoc-parser/src/transformer/symbol-to-doc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ export default function symbolToDoc(symbol: Symbol): ?Doc {
133133

134134
options.abstract = symbol.meta.abstract;
135135
options.access = symbol.meta.access;
136+
options.dataType = symbol.meta.dataType;
137+
options.defaultValue = symbol.meta.defaultValue;
136138
options.scope = symbol.meta.scope;
137139
options.loc = symbol.loc;
138140

packages/webdoc-parser/test/lang-ts.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe("@webdoc/parser.LanguageIntegration{@lang ts}", function() {
88
it("should parse classes correctly", function() {
99
let symtree = buildSymbolTree(`
1010
class ClassName {
11-
private initProperty: number;
11+
private initProperty: number = 11;
1212
1313
constructor() {
1414
/**
@@ -48,6 +48,7 @@ describe("@webdoc/parser.LanguageIntegration{@lang ts}", function() {
4848
expect(symbolInitProperty.meta.dataType).to.not.equal(undefined);
4949
expect(symbolInitProperty.meta.dataType[0]).to.equal("number");
5050
expect(symbolInitProperty.meta.access).to.equal("private");
51+
expect(symbolInitProperty.meta.defaultValue).to.equal(11);
5152
expect(symbolInitProperty.comment).to.not.equal("");
5253
});
5354

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const {createPackageDoc} = require("@webdoc/model");
2+
const {parse} = require("../lib/parse");
3+
4+
const expect = require("chai").expect;
5+
6+
describe("@webdoc/parser.parser", function() {
7+
it("should infer access, default value, and type for fields", function() {
8+
const docs = parse([{
9+
content: `
10+
/** Example class */
11+
class Example {
12+
/**
13+
* Field description
14+
*/
15+
protected field: boolean = true;
16+
}
17+
`,
18+
path: ".ts",
19+
package: createPackageDoc(),
20+
}]);
21+
22+
expect(docs.members.length).to.equal(1);
23+
expect(docs.members[0].members.length).to.equal(1);
24+
25+
const fieldDoc = docs.members[0].members[0];
26+
27+
expect(fieldDoc.access).to.equal("protected");
28+
expect(fieldDoc.dataType && fieldDoc.dataType[0]).to.equal("boolean");
29+
expect(fieldDoc.defaultValue).to.equal(true);
30+
31+
// TODO: Fix this. No space should be there (added/not-fixed b/c this was
32+
// in a PR for different issue)
33+
expect(fieldDoc.brief).to.equal(" Field description");
34+
});
35+
});

0 commit comments

Comments
 (0)