File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed
Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -540,7 +540,7 @@ export class LuaTransformer {
540540 createClassPrototype ( ) ,
541541 tstl . createStringLiteral ( "__index" )
542542 ) ;
543- if ( statement . members . some ( ts . isGetAccessor ) ) {
543+ if ( tsHelper . hasGetAccessorInClassOrAncestor ( statement , this . checker ) ) {
544544 // className.prototype.____getters = {}
545545 const classPrototypeGetters = tstl . createTableIndexExpression (
546546 createClassPrototype ( ) ,
Original file line number Diff line number Diff line change @@ -385,6 +385,18 @@ export class TSHelper {
385385 ) !== undefined ;
386386 }
387387
388+ public static hasGetAccessorInClassOrAncestor (
389+ classDeclaration : ts . ClassLikeDeclarationBase ,
390+ checker : ts . TypeChecker
391+ ) : boolean
392+ {
393+ return TSHelper . findInClassOrAncestor (
394+ classDeclaration ,
395+ c => c . members . some ( ts . isGetAccessor ) ,
396+ checker
397+ ) !== undefined ;
398+ }
399+
388400 public static getPropertyName ( propertyName : ts . PropertyName ) : string | number | undefined {
389401 if ( ts . isIdentifier ( propertyName ) || ts . isStringLiteral ( propertyName ) || ts . isNumericLiteral ( propertyName ) ) {
390402 return propertyName . text ;
Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ export class AccessorTests {
66 public getAccessor ( ) : void {
77 const code =
88 `class Foo {
9- get foo() { return "foo"; }
9+ _foo;
10+ get foo() { return this._foo; }
11+ constructor(){ this._foo = "foo"; }
1012 }
1113 const f = new Foo();
1214 return f.foo;` ;
@@ -17,7 +19,9 @@ export class AccessorTests {
1719 public getAccessorInBaseClass ( ) : void {
1820 const code =
1921 `class Foo {
20- get foo() { return "foo"; }
22+ _foo;
23+ get foo() { return this._foo; }
24+ constructor(){ this._foo = "foo"; }
2125 }
2226 class Bar extends Foo {}
2327 const b = new Bar();
You can’t perform that action at this time.
0 commit comments