Skip to content

Commit dc11196

Browse files
committed
Added handling defining class properties
Fixes #7
1 parent 027c497 commit dc11196

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/typescript-helpers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ export function getExportsForSourceFile(typeChecker: ts.TypeChecker, sourceFileS
101101
return result.map((symbol: ts.Symbol) => getActualSymbol(symbol, typeChecker));
102102
}
103103

104-
export type ClassMember = ts.MethodDeclaration | ts.PropertyDeclaration;
104+
export type ClassMember =
105+
| ts.MethodDeclaration
106+
| ts.PropertyDeclaration
107+
| ts.GetAccessorDeclaration
108+
| ts.SetAccessorDeclaration;
105109

106110
export function isClassMember(node: ts.Node): node is ClassMember {
107-
return ts.isMethodDeclaration(node) || ts.isPropertyDeclaration(node);
111+
return ts.isMethodDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isGetAccessor(node) || ts.isSetAccessor(node);
108112
}
109113

110114
export function hasPrivateKeyword(node: ClassMember | ts.ParameterDeclaration): boolean {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class TestProperties {
2+
private _salad: number = 0;
3+
public dressing: number = 0;
4+
public get salad(): number { return this._salad; }
5+
public set salad(val: number) { this._salad = val; }
6+
}
7+
8+
const test1 = new TestProperties();
9+
test1.salad = 0;
10+
test1.dressing = 0;
11+
const totalSalad = test1.salad + 1;
12+
const totalDressing = test1.dressing + 0;
13+
14+
export const temp = 1;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var TestProperties = /** @class */ (function () {
4+
function TestProperties() {
5+
this._private__salad = 0;
6+
this._internal_dressing = 0;
7+
}
8+
Object.defineProperty(TestProperties.prototype, "_internal_salad", {
9+
get: function () { return this._private__salad; },
10+
set: function (val) { this._private__salad = val; },
11+
enumerable: true,
12+
configurable: true
13+
});
14+
return TestProperties;
15+
}());
16+
var test1 = new TestProperties();
17+
test1._internal_salad = 0;
18+
test1._internal_dressing = 0;
19+
var totalSalad = test1._internal_salad + 1;
20+
var totalDressing = test1._internal_dressing + 0;
21+
exports.temp = 1;

0 commit comments

Comments
 (0)