11import { ClassMirror , EnumMirror , InterfaceMirror , Type } from '@cparra/apex-reflection' ;
22import { ParsedFile , TopLevelType } from '../shared/types' ;
3- import { isApexType , isObjectType } from '../shared/utils' ;
3+ import { isApexType , isLwcType , isObjectType } from '../shared/utils' ;
44import { CustomObjectMetadata } from './sobject/reflect-custom-object-sources' ;
5+ import { LwcMetadata } from './lwc/reflect-lwc-source' ;
56
67type Named = { name : string } ;
78
@@ -23,10 +24,15 @@ export function sortTypesAndMembers(
2324 type : sortCustomObjectFields ( parsedFile . type , shouldSort ) ,
2425 } ;
2526 }
27+ if ( isLwcType ( parsedFile . type ) ) {
28+ return {
29+ ...parsedFile ,
30+ type : sortLwcMetadata ( parsedFile . type , shouldSort ) ,
31+ } ;
32+ }
33+
2634 // For TriggerMetadata or any other types, return the original parsedFile unchanged
2735 return parsedFile ;
28-
29- // TODO: Parsed LWC members (properties and methods)
3036 } )
3137 . sort ( ( a , b ) => sortByNames ( shouldSort , a . type , b . type ) ) ;
3238}
@@ -85,3 +91,37 @@ function sortClassMembers(shouldSort: boolean, classType: ClassMirror): ClassMir
8591 properties : sortNamed ( shouldSort , classType . properties ) ,
8692 } ;
8793}
94+
95+ function sortLwcMetadata ( type : LwcMetadata , shouldSort : boolean ) : LwcMetadata {
96+ if ( ! shouldSort ) {
97+ return type ;
98+ }
99+
100+ const sortedType = { ...type } ;
101+
102+ // Sort targets.
103+ if ( sortedType . targets ?. target ) {
104+ sortedType . targets = {
105+ ...sortedType . targets ,
106+ target : [ ...sortedType . targets . target ] . sort ( ) ,
107+ } ;
108+ }
109+
110+ // Sort targetConfigs.
111+ if ( sortedType . targetConfigs ?. targetConfig ) {
112+ sortedType . targetConfigs = {
113+ ...sortedType . targetConfigs ,
114+ targetConfig : sortedType . targetConfigs . targetConfig . map ( ( config ) => {
115+ if ( config . property ) {
116+ return {
117+ ...config ,
118+ property : [ ...config . property ] . sort ( ( a , b ) => a [ '@_name' ] . localeCompare ( b [ '@_name' ] ) ) ,
119+ } ;
120+ }
121+ return config ;
122+ } ) ,
123+ } ;
124+ }
125+
126+ return sortedType ;
127+ }
0 commit comments