@@ -4,31 +4,43 @@ import { TransformationContext } from "../../../context";
44import { createSelfIdentifier } from "../../../utils/lua-ast" ;
55import { transformFunctionBody , transformParameters } from "../../function" ;
66import { transformIdentifier } from "../../identifier" ;
7- import { findInClassOrAncestor , isStaticNode } from "../utils" ;
7+ import { getExtendedType , isStaticNode } from "../utils" ;
88
9- export function hasSetAccessorInClassOrAncestor (
9+ // TODO: Inline to `hasMemberInClassOrAncestor`?
10+ function * classWithAncestors (
1011 context : TransformationContext ,
11- classDeclaration : ts . ClassLikeDeclarationBase ,
12- isStatic : boolean
13- ) : boolean {
14- return (
15- findInClassOrAncestor ( context , classDeclaration , c =>
16- c . members . some ( m => ts . isSetAccessor ( m ) && isStaticNode ( m ) === isStatic )
17- ) !== undefined
18- ) ;
12+ classDeclaration : ts . ClassLikeDeclarationBase
13+ ) : Generator < ts . ClassLikeDeclarationBase > {
14+ yield classDeclaration ;
15+
16+ const extendsType = getExtendedType ( context , classDeclaration ) ;
17+ if ( ! extendsType ) {
18+ return false ;
19+ }
20+
21+ const symbol = extendsType . getSymbol ( ) ;
22+ if ( symbol === undefined ) {
23+ return false ;
24+ }
25+
26+ const symbolDeclarations = symbol . getDeclarations ( ) ;
27+ if ( symbolDeclarations === undefined ) {
28+ return false ;
29+ }
30+
31+ const declaration = symbolDeclarations . find ( ts . isClassLike ) ;
32+ if ( ! declaration ) {
33+ return false ;
34+ }
35+
36+ yield * classWithAncestors ( context , declaration ) ;
1937}
2038
21- export function hasGetAccessorInClassOrAncestor (
39+ export const hasMemberInClassOrAncestor = (
2240 context : TransformationContext ,
2341 classDeclaration : ts . ClassLikeDeclarationBase ,
24- isStatic : boolean
25- ) : boolean {
26- return (
27- findInClassOrAncestor ( context , classDeclaration , c =>
28- c . members . some ( m => ts . isGetAccessor ( m ) && isStaticNode ( m ) === isStatic )
29- ) !== undefined
30- ) ;
31- }
42+ callback : ( m : ts . ClassElement ) => boolean
43+ ) => [ ...classWithAncestors ( context , classDeclaration ) ] . some ( c => c . members . some ( callback ) ) ;
3244
3345function getPropertyName ( propertyName : ts . PropertyName ) : string | number | undefined {
3446 if ( ts . isIdentifier ( propertyName ) || ts . isStringLiteral ( propertyName ) || ts . isNumericLiteral ( propertyName ) ) {
@@ -53,10 +65,11 @@ export function isGetAccessorOverride(
5365 return false ;
5466 }
5567
56- const hasInitializedField = ( e : ts . ClassElement ) =>
57- ts . isPropertyDeclaration ( e ) && e . initializer !== undefined && isSamePropertyName ( e . name , element . name ) ;
58-
59- return findInClassOrAncestor ( context , classDeclaration , c => c . members . some ( hasInitializedField ) ) !== undefined ;
68+ return hasMemberInClassOrAncestor (
69+ context ,
70+ classDeclaration ,
71+ m => ts . isPropertyDeclaration ( m ) && m . initializer !== undefined && isSamePropertyName ( m . name , element . name )
72+ ) ;
6073}
6174
6275export function transformAccessorDeclaration (
0 commit comments