Skip to content

Commit a30cf18

Browse files
committed
Infer readonly from class properties
1 parent c9f4515 commit a30cf18

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export default function extractSymbol(
101101
name = node.key.name;
102102

103103
nodeSymbol.meta.access = node.access || node.accessibility;
104+
nodeSymbol.meta.readonly = node.readonly;
104105
nodeSymbol.meta.dataType = extractType(node);
105106
nodeSymbol.meta.scope = node.static ? "static" : "instance";
106107
nodeSymbol.meta.type = "PropertyDoc";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ 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;
11+
private readonly initProperty: number = 11;
1212
1313
constructor() {
1414
/**
1515
* This is a property whose data-type & access should be inferred.
16-
* @default 9
1716
*/
1817
this.initProperty = 9;
1918
}
@@ -50,6 +49,7 @@ describe("@webdoc/parser.LanguageIntegration{@lang ts}", function() {
5049
expect(symbolInitProperty.meta.access).to.equal("private");
5150
expect(symbolInitProperty.meta.defaultValue).to.equal(11);
5251
expect(symbolInitProperty.comment).to.not.equal("");
52+
expect(symbolInitProperty.meta.readonly).to.equal(true);
5353
});
5454

5555
it("should be able to parse type-casted objects for property symbols", function() {

packages/webdoc-types/index.js.flow

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export type BaseDoc = {
7070
fires?: [],
7171
license?: string,
7272
loc?: SymbolLocation,
73+
readonly?: boolean,
7374
scope?: "static" | "instance" | "inner" | "default",
7475
see?: DocLink[],
7576
since?: string,
@@ -258,6 +259,7 @@ export type TagType =
258259
"NSTag" |
259260
"LicenseTag" |
260261
"ParamTag" |
262+
"ReadonlyTag" |
261263
"ReturnTag" |
262264
"SeeTag" |
263265
"SinceTag" |
@@ -286,6 +288,7 @@ export type Tag =
286288
NSTag |
287289
LicenseTag |
288290
ParamTag |
291+
ReadonlyTag |
289292
ReturnTag |
290293
SeeTag |
291294
SinceTag |
@@ -314,6 +317,7 @@ export type TagShape =
314317
$Shape<NSTag> |
315318
$Shape<LicenseTag> |
316319
$Shape<ParamTag> |
320+
$Shape<ReadonlyTag> |
317321
$Shape<ReturnTag> |
318322
$Shape<SeeTag> |
319323
$Shape<SinceTag> |
@@ -455,6 +459,11 @@ export type ParamTag = {
455459
type: "ParamTag"
456460
};
457461

462+
export type ReadonlyTag = {
463+
...BaseTag,
464+
type: "ReadonlyTag"
465+
};
466+
458467
export type ReturnTag = {
459468
...TypedTag,
460469
type: "ReturnTag"

0 commit comments

Comments
 (0)