11import type {
2- CommentKind ,
32 Decorator ,
43 EOExpressionProp ,
54 EOMethod ,
@@ -23,23 +22,33 @@ type EOPropValue = EOProperty['value'] | EOMethod;
2322 * A wrapper object for ember object properties
2423 */
2524export default abstract class AbstractEOProp < P extends EOExpressionProp , B > {
26- readonly _prop : P & {
27- // ast-types missing these properties that exist on @babel/types
28- decorators ?: Decorator [ ] | null ;
29- } ;
25+ abstract readonly isClassDecorator : boolean ;
3026
31- protected decorators : DecoratorImportInfo [ ] = [ ] ;
27+ protected abstract readonly value : EOPropValue ;
28+
29+ protected readonly key = this . rawProp . key ;
30+
31+ protected readonly comments = this . rawProp . comments ?? null ;
3232
33- /** Runtime Data */
34- readonly runtimeData : RuntimeData ;
35- private readonly runtimeType : string | undefined ;
33+ protected readonly existingDecorators = this . rawProp . decorators ?? null ;
3634
37- constructor ( eoProp : P , protected readonly options : Options ) {
38- this . _prop = eoProp ;
35+ protected decorators : DecoratorImportInfo [ ] = [ ] ;
36+
37+ protected readonly runtimeData : RuntimeData ;
3938
39+ /** Override to `true` if the property type supports object literal decorators. */
40+ protected readonly supportsObjectLiteralDecorators : boolean = false ;
41+
42+ constructor (
43+ protected readonly rawProp : P & {
44+ // ast-types missing these properties that exist on @babel/types
45+ decorators ?: Decorator [ ] | null ;
46+ } ,
47+ protected readonly options : Options
48+ ) {
4049 this . runtimeData = options . runtimeData ;
4150 if ( this . runtimeData . type ) {
42- const { type , offProperties, unobservedProperties } = this . runtimeData ;
51+ const { offProperties, unobservedProperties } = this . runtimeData ;
4352
4453 const unobservedArgs = unobservedProperties [ this . name ] ;
4554 if ( unobservedArgs ) {
@@ -53,15 +62,12 @@ export default abstract class AbstractEOProp<P extends EOExpressionProp, B> {
5362 if ( offArgs ) {
5463 this . decorators . push ( { name : 'off' , args : offArgs } ) ;
5564 }
56- this . runtimeType = type ;
5765 }
5866 }
5967
60- // FIXME: Verify that everything on these classes is still needed
61- // FIXME: Verify access modifiers
62- abstract value : EOPropValue ;
63-
64- abstract build ( ) : B ;
68+ get name ( ) : string {
69+ return this . key . name ;
70+ }
6571
6672 /**
6773 * Get the map of decorators to import other than the computed props, services etc
@@ -81,75 +87,6 @@ export default abstract class AbstractEOProp<P extends EOExpressionProp, B> {
8187 } ;
8288 }
8389
84- get type ( ) : EOPropValue [ 'type' ] {
85- return this . value . type ;
86- }
87-
88- get key ( ) : P [ 'key' ] {
89- return this . _prop . key ;
90- }
91-
92- get name ( ) : string {
93- return this . _prop . key . name ;
94- }
95-
96- get comments ( ) : CommentKind [ ] | null {
97- return this . _prop . comments ?? null ;
98- }
99-
100- get computed ( ) : boolean {
101- return this . _prop . computed ?? false ;
102- }
103-
104- get isComputed ( ) : boolean {
105- return this . runtimeData . computedProperties . includes ( this . name ) ;
106- }
107-
108- get isOverridden ( ) : boolean {
109- return this . runtimeData . overriddenProperties . includes ( this . name ) ;
110- }
111-
112- get hasRuntimeData ( ) : boolean {
113- return ! ! this . runtimeType ;
114- }
115-
116- get replaceSuperWithUndefined ( ) : boolean {
117- return this . hasRuntimeData && ! this . isOverridden ;
118- }
119-
120- get existingDecorators ( ) : Decorator [ ] | null {
121- return this . _prop . decorators ?? null ;
122- }
123-
124- get hasDecorators ( ) : boolean {
125- return this . decorators . length > 0 ;
126- }
127-
128- get hasUnobservesDecorator ( ) : boolean {
129- return this . decorators . some ( ( d ) => d . name === 'unobserves' ) ;
130- }
131-
132- get hasOffDecorator ( ) : boolean {
133- return this . decorators . some ( ( d ) => d . name === 'off' ) ;
134- }
135-
136- get hasMetaDecorator ( ) : boolean {
137- return this . decorators . some ( ( d ) => d . isMetaDecorator ) ;
138- }
139-
140- /** Override to `true` if the property type supports object literal decorators. */
141- protected supportsObjectLiteralDecorators = false ;
142-
143- protected get needsDecorators ( ) : boolean {
144- return this . hasExistingDecorators || this . hasDecorators ;
145- }
146-
147- private get hasExistingDecorators ( ) : boolean {
148- return (
149- this . existingDecorators !== null && this . existingDecorators . length > 0
150- ) ;
151- }
152-
15390 get errors ( ) : string [ ] {
15491 let errors : string [ ] = [ ] ;
15592
@@ -164,7 +101,6 @@ export default abstract class AbstractEOProp<P extends EOExpressionProp, B> {
164101 ) ;
165102 }
166103
167- // FIXME: only include if existing decorators are supported?
168104 for ( const decorator of this . existingDecorators ) {
169105 const decoratorName = isNode ( decorator . expression , 'Identifier' )
170106 ? decorator . expression . name
@@ -205,17 +141,58 @@ export default abstract class AbstractEOProp<P extends EOExpressionProp, B> {
205141 ) ;
206142 }
207143
208- errors = [ ...errors , ...this . _errors ] ;
144+ errors = [ ...errors , ...this . typeErrors ] ;
209145
210146 return errors ;
211147 }
212148
149+ /** Returns the appropriate ClassBody member for the property type. */
150+ abstract build ( ) : B ;
151+
152+ protected makeError ( message : string ) : string {
153+ return `[${ this . name } ]: Transform not supported - ${ message } ` ;
154+ }
155+
213156 /** Override to add errors specific to the property type. */
214- protected get _errors ( ) : string [ ] {
157+ protected get typeErrors ( ) : string [ ] {
215158 return [ ] ;
216159 }
217160
218- protected makeError ( message : string ) : string {
219- return `[${ this . name } ]: Transform not supported - ${ message } ` ;
161+ protected get type ( ) : EOPropValue [ 'type' ] {
162+ return this . value . type ;
163+ }
164+
165+ protected get isOverridden ( ) : boolean {
166+ return this . runtimeData . overriddenProperties . includes ( this . name ) ;
167+ }
168+
169+ protected get replaceSuperWithUndefined ( ) : boolean {
170+ return this . hasRuntimeData && ! this . isOverridden ;
171+ }
172+
173+ private get hasRuntimeData ( ) : boolean {
174+ return ! ! this . runtimeData . type ;
175+ }
176+
177+ protected get hasDecorators ( ) : boolean {
178+ return this . decorators . length > 0 ;
179+ }
180+
181+ protected get needsDecorators ( ) : boolean {
182+ return this . hasExistingDecorators || this . hasDecorators ;
183+ }
184+
185+ private get hasUnobservesDecorator ( ) : boolean {
186+ return this . decorators . some ( ( d ) => d . name === 'unobserves' ) ;
187+ }
188+
189+ private get hasOffDecorator ( ) : boolean {
190+ return this . decorators . some ( ( d ) => d . name === 'off' ) ;
191+ }
192+
193+ private get hasExistingDecorators ( ) : boolean {
194+ return (
195+ this . existingDecorators !== null && this . existingDecorators . length > 0
196+ ) ;
220197 }
221198}
0 commit comments