Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add detecting read-only properties #1268

Merged
merged 1 commit into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/converter/factories/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ function setupDeclaration(context: Context, reflection: DeclarationReflection, n
reflection.setFlag(ReflectionFlag.Protected, !!(modifiers & ts.ModifierFlags.Protected));
reflection.setFlag(ReflectionFlag.Public, !!(modifiers & ts.ModifierFlags.Public));
reflection.setFlag(ReflectionFlag.Optional, !!(node['questionToken']));
reflection.setFlag(ReflectionFlag.Readonly, !!(modifiers & ts.ModifierFlags.Readonly));

if (
context.isInherit &&
Expand Down
4 changes: 2 additions & 2 deletions src/lib/converter/nodes/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ export class VariableConverter extends ConverterNodeComponent<ts.VariableDeclara
break;
case ReflectionKind.Property:
if (node.modifiers
&& node.modifiers.some( m => m.kind === ts.SyntaxKind.AbstractKeyword )) {
variable.setFlag(ReflectionFlag.Abstract, true);
&& node.modifiers.some( m => m.kind === ts.SyntaxKind.AbstractKeyword)) {
variable.setFlag(ReflectionFlag.Abstract, true);
}
break;
}
Expand Down
10 changes: 8 additions & 2 deletions src/lib/models/reflections/abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export enum ReflectionFlag {
ConstructorProperty = 1024,
Abstract = 2048,
Const = 4096,
Let = 8192
Let = 8192,
Readonly = 16384
}

const relevantFlags: ReflectionFlag[] = [
Expand All @@ -99,7 +100,8 @@ const relevantFlags: ReflectionFlag[] = [
ReflectionFlag.Rest,
ReflectionFlag.Abstract,
ReflectionFlag.Let,
ReflectionFlag.Const
ReflectionFlag.Const,
ReflectionFlag.Readonly
];

/**
Expand Down Expand Up @@ -201,6 +203,10 @@ export class ReflectionFlags extends Array<string> {
return this.hasFlag(ReflectionFlag.Let);
}

get isReadonly() {
return this.hasFlag(ReflectionFlag.Readonly);
}

setFlag(flag: ReflectionFlag, set: boolean) {
switch (flag) {
case ReflectionFlag.Private:
Expand Down
6 changes: 4 additions & 2 deletions src/test/converter/class/specs-with-lump-categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,8 @@
"kind": 1024,
"kindString": "Property",
"flags": {
"isConstructorProperty": true
"isConstructorProperty": true,
"isReadonly": true
},
"comment": {
"shortText": "Vector name\n"
Expand Down Expand Up @@ -1807,7 +1808,8 @@
"kind": 1024,
"kindString": "Property",
"flags": {
"isConstructorProperty": true
"isConstructorProperty": true,
"isReadonly": true
},
"comment": {
"shortText": "Vector name\n"
Expand Down
6 changes: 4 additions & 2 deletions src/test/converter/class/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,8 @@
"kind": 1024,
"kindString": "Property",
"flags": {
"isConstructorProperty": true
"isConstructorProperty": true,
"isReadonly": true
},
"comment": {
"shortText": "Vector name\n"
Expand Down Expand Up @@ -1803,7 +1804,8 @@
"kind": 1024,
"kindString": "Property",
"flags": {
"isConstructorProperty": true
"isConstructorProperty": true,
"isReadonly": true
},
"comment": {
"shortText": "Vector name\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> p4</h3>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
<a name="p5" class="tsd-anchor"></a>
<h3>p5</h3>
<h3><span class="tsd-flag ts-flagReadonly">Readonly</span> p5</h3>
<div class="tsd-signature tsd-kind-icon">p5<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
</aside>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ <h3>p3</h3>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-inherited">
<a name="p5" class="tsd-anchor"></a>
<h3>p5</h3>
<h3><span class="tsd-flag ts-flagReadonly">Readonly</span> p5</h3>
<div class="tsd-signature tsd-kind-icon">p5<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<p>Inherited from <a href="_classes_.genericclass.html">GenericClass</a>.<a href="_classes_.genericclass.html#p5">p5</a></p>
Expand Down