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

Constructor parameters with readonly flag define properties. #584

Merged
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
5 changes: 3 additions & 2 deletions examples/basic/src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ export class GenericClass<T extends BaseClass>
* @param p2 Private string property
* @param p3 Public number property
* @param p4 Public implicit any property
* @param p5 Readonly property
*/
constructor(p1, protected p2:T, public p3:number, private p4:number) {
constructor(p1, protected p2:T, public p3:number, private p4:number, readonly p5: string) {
}


Expand All @@ -311,4 +312,4 @@ export class GenericClass<T extends BaseClass>
export class NonGenericClass extends GenericClass<SubClassB>
{

}
}
3 changes: 2 additions & 1 deletion src/lib/converter/nodes/constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export class ConstructorConverter extends ConverterNodeComponent<ts.ConstructorD
*/
private addParameterProperty(context: Context, parameter: ts.ParameterDeclaration, comment: Comment) {
const modifiers = ts.getCombinedModifierFlags(parameter);
const visibility = modifiers & (ts.ModifierFlags.Public | ts.ModifierFlags.Protected | ts.ModifierFlags.Private);
const visibility = modifiers & (ts.ModifierFlags.Public | ts.ModifierFlags.Protected |
ts.ModifierFlags.Private | ts.ModifierFlags.Readonly);
if (!visibility) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ class Vector2
/**
* @param x X component of the Vector
* @param y Y component of the Vector
* @param name Vector name
*/
constructor(public x:number, public y:number) {
constructor(public x:number, public y:number,
readonly name: string) {
}
}

Expand All @@ -21,8 +23,10 @@ class Vector3 extends Vector2
* @param x X component of the Vector
* @param y Y component of the Vector
* @param z Z component of the Vector
* @param name Vector name
*/
constructor(x:number, public y:number, public z:number) {
super(x, y);
constructor(x:number, public y:number, public z:number,
readonly name: string) {
super(x, y, name);
}
}
141 changes: 111 additions & 30 deletions src/test/converter/constructor-properties/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
"comment": {},
"signatures": [
{
"id": 6,
"id": 7,
"name": "new Vector2",
"kind": 16384,
"kindString": "Constructor signature",
"flags": {},
"comment": {},
"parameters": [
{
"id": 7,
"id": 8,
"name": "x",
"kind": 32768,
"kindString": "Parameter",
Expand All @@ -55,18 +55,32 @@
}
},
{
"id": 8,
"id": 9,
"name": "y",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"comment": {
"shortText": "Y component of the Vector\n"
"shortText": "Y component of the Vector"
},
"type": {
"type": "intrinsic",
"name": "number"
}
},
{
"id": 10,
"name": "name",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"comment": {
"shortText": "Vector name\n"
},
"type": {
"type": "intrinsic",
"name": "string"
}
}
],
"type": {
Expand All @@ -84,6 +98,29 @@
}
]
},
{
"id": 6,
"name": "name",
"kind": 1024,
"kindString": "Property",
"flags": {
"isConstructorProperty": true
},
"comment": {
"shortText": "Vector name\n"
},
"sources": [
{
"fileName": "constructor-properties.ts",
"line": 12,
"character": 29
}
],
"type": {
"type": "intrinsic",
"name": "string"
}
},
{
"id": 4,
"name": "x",
Expand All @@ -99,7 +136,7 @@
"sources": [
{
"fileName": "constructor-properties.ts",
"line": 10,
"line": 11,
"character": 24
}
],
Expand All @@ -118,12 +155,12 @@
"isPublic": true
},
"comment": {
"shortText": "Y component of the Vector\n"
"shortText": "Y component of the Vector"
},
"sources": [
{
"fileName": "constructor-properties.ts",
"line": 10,
"line": 11,
"character": 41
}
],
Expand All @@ -145,6 +182,7 @@
"title": "Properties",
"kind": 1024,
"children": [
6,
4,
5
]
Expand All @@ -161,12 +199,12 @@
{
"type": "reference",
"name": "Vector3",
"id": 9
"id": 11
}
]
},
{
"id": 9,
"id": 11,
"name": "Vector3",
"kind": 128,
"kindString": "Class",
Expand All @@ -176,23 +214,23 @@
},
"children": [
{
"id": 10,
"id": 12,
"name": "constructor",
"kind": 512,
"kindString": "Constructor",
"flags": {},
"comment": {},
"signatures": [
{
"id": 13,
"id": 16,
"name": "new Vector3",
"kind": 16384,
"kindString": "Constructor signature",
"flags": {},
"comment": {},
"parameters": [
{
"id": 14,
"id": 17,
"name": "x",
"kind": 32768,
"kindString": "Parameter",
Expand All @@ -206,7 +244,7 @@
}
},
{
"id": 15,
"id": 18,
"name": "y",
"kind": 32768,
"kindString": "Parameter",
Expand All @@ -220,24 +258,38 @@
}
},
{
"id": 16,
"id": 19,
"name": "z",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"comment": {
"shortText": "Z component of the Vector\n"
"shortText": "Z component of the Vector"
},
"type": {
"type": "intrinsic",
"name": "number"
}
},
{
"id": 20,
"name": "name",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"comment": {
"shortText": "Vector name\n"
},
"type": {
"type": "intrinsic",
"name": "string"
}
}
],
"type": {
"type": "reference",
"name": "Vector3",
"id": 9
"id": 11
},
"overwrites": {
"type": "reference",
Expand All @@ -249,7 +301,7 @@
"sources": [
{
"fileName": "constructor-properties.ts",
"line": 19,
"line": 21,
"character": 1
}
],
Expand All @@ -260,7 +312,35 @@
}
},
{
"id": 17,
"id": 15,
"name": "name",
"kind": 1024,
"kindString": "Property",
"flags": {
"isConstructorProperty": true
},
"comment": {
"shortText": "Vector name\n"
},
"sources": [
{
"fileName": "constructor-properties.ts",
"line": 29,
"character": 29
}
],
"type": {
"type": "intrinsic",
"name": "string"
},
"overwrites": {
"type": "reference",
"name": "Vector2.name",
"id": 6
}
},
{
"id": 21,
"name": "x",
"kind": 1024,
"kindString": "Property",
Expand All @@ -274,7 +354,7 @@
"sources": [
{
"fileName": "constructor-properties.ts",
"line": 10,
"line": 11,
"character": 24
}
],
Expand All @@ -289,7 +369,7 @@
}
},
{
"id": 11,
"id": 13,
"name": "y",
"kind": 1024,
"kindString": "Property",
Expand All @@ -303,7 +383,7 @@
"sources": [
{
"fileName": "constructor-properties.ts",
"line": 25,
"line": 28,
"character": 34
}
],
Expand All @@ -318,7 +398,7 @@
}
},
{
"id": 12,
"id": 14,
"name": "z",
"kind": 1024,
"kindString": "Property",
Expand All @@ -327,12 +407,12 @@
"isPublic": true
},
"comment": {
"shortText": "Z component of the Vector\n"
"shortText": "Z component of the Vector"
},
"sources": [
{
"fileName": "constructor-properties.ts",
"line": 25,
"line": 28,
"character": 51
}
],
Expand All @@ -347,23 +427,24 @@
"title": "Constructors",
"kind": 512,
"children": [
10
12
]
},
{
"title": "Properties",
"kind": 1024,
"children": [
17,
11,
12
15,
21,
13,
14
]
}
],
"sources": [
{
"fileName": "constructor-properties.ts",
"line": 18,
"line": 20,
"character": 13
}
],
Expand All @@ -382,7 +463,7 @@
"kind": 128,
"children": [
2,
9
11
]
}
],
Expand Down
Loading