@@ -2,10 +2,10 @@ import * as ts from "typescript";
22import * as lua from "../../../../LuaAST" ;
33import { AllAccessorDeclarations , TransformationContext } from "../../../context" ;
44import { createSelfIdentifier } from "../../../utils/lua-ast" ;
5- import { transformLuaLibFunction , LuaLibFeature } from "../../../utils/lualib" ;
5+ import { LuaLibFeature , transformLuaLibFunction } from "../../../utils/lualib" ;
66import { transformFunctionBody , transformParameters } from "../../function" ;
77import { transformPropertyName } from "../../literal" ;
8- import { getExtendedType , isStaticNode } from "../utils" ;
8+ import { isStaticNode } from "../utils" ;
99import { createPrototypeName } from "./constructor" ;
1010
1111function transformAccessor ( context : TransformationContext , node : ts . AccessorDeclaration ) : lua . FunctionExpression {
@@ -40,68 +40,3 @@ export function transformAccessorDeclarations(
4040 const call = transformLuaLibFunction ( context , feature , undefined , ...parameters ) ;
4141 return lua . createExpressionStatement ( call ) ;
4242}
43-
44- function * classWithAncestors (
45- context : TransformationContext ,
46- classDeclaration : ts . ClassLikeDeclarationBase
47- ) : Generator < ts . ClassLikeDeclarationBase > {
48- yield classDeclaration ;
49-
50- const extendsType = getExtendedType ( context , classDeclaration ) ;
51- if ( ! extendsType ) {
52- return false ;
53- }
54-
55- const symbol = extendsType . getSymbol ( ) ;
56- if ( symbol === undefined ) {
57- return false ;
58- }
59-
60- const symbolDeclarations = symbol . getDeclarations ( ) ;
61- if ( symbolDeclarations === undefined ) {
62- return false ;
63- }
64-
65- const declaration = symbolDeclarations . find ( ts . isClassLike ) ;
66- if ( ! declaration ) {
67- return false ;
68- }
69-
70- yield * classWithAncestors ( context , declaration ) ;
71- }
72-
73- export const hasMemberInClassOrAncestor = (
74- context : TransformationContext ,
75- classDeclaration : ts . ClassLikeDeclarationBase ,
76- callback : ( m : ts . ClassElement ) => boolean
77- ) => [ ...classWithAncestors ( context , classDeclaration ) ] . some ( c => c . members . some ( callback ) ) ;
78-
79- function getPropertyName ( propertyName : ts . PropertyName ) : string | number | undefined {
80- if ( ts . isIdentifier ( propertyName ) || ts . isStringLiteral ( propertyName ) || ts . isNumericLiteral ( propertyName ) ) {
81- return propertyName . text ;
82- } else {
83- return undefined ; // TODO: how to handle computed property names?
84- }
85- }
86-
87- function isSamePropertyName ( a : ts . PropertyName , b : ts . PropertyName ) : boolean {
88- const aName = getPropertyName ( a ) ;
89- const bName = getPropertyName ( b ) ;
90- return aName !== undefined && aName === bName ;
91- }
92-
93- export function isGetAccessorOverride (
94- context : TransformationContext ,
95- element : ts . ClassElement ,
96- classDeclaration : ts . ClassLikeDeclarationBase
97- ) : element is ts . GetAccessorDeclaration {
98- if ( ! ts . isGetAccessor ( element ) || isStaticNode ( element ) ) {
99- return false ;
100- }
101-
102- return hasMemberInClassOrAncestor (
103- context ,
104- classDeclaration ,
105- m => ts . isPropertyDeclaration ( m ) && m . initializer !== undefined && isSamePropertyName ( m . name , element . name )
106- ) ;
107- }
0 commit comments