@@ -78,10 +78,11 @@ export class CubePropContextTranspiler implements TranspilerInterface {
7878 }
7979
8080 public static replaceValueWithArrowFunction ( resolveSymbol : SymbolResolver , value : NodePath < any > ) {
81- const knownIds = CubePropContextTranspiler . collectKnownIdentifiers (
81+ const knownIds = CubePropContextTranspiler . collectKnownIdentifiersAndTransform (
8282 resolveSymbol ,
8383 value ,
8484 ) ;
85+
8586 value . replaceWith (
8687 t . arrowFunctionExpression (
8788 knownIds . map ( i => t . identifier ( i ) ) ,
@@ -198,6 +199,25 @@ export class CubePropContextTranspiler implements TranspilerInterface {
198199 return R . uniq ( identifiers ) ;
199200 }
200201
202+ protected static collectKnownIdentifiersAndTransform ( resolveSymbol : SymbolResolver , path : NodePath ) : string [ ] {
203+ const identifiers : string [ ] = [ ] ;
204+
205+ if ( path . node . type === 'Identifier' ) {
206+ CubePropContextTranspiler . matchAndPushIdentifier ( path , resolveSymbol , identifiers ) ;
207+ }
208+
209+ path . traverse ( {
210+ Identifier : ( p ) => {
211+ CubePropContextTranspiler . matchAndTransformIdentifier ( p , resolveSymbol , identifiers ) ;
212+ } ,
213+ MemberExpression : ( p ) => {
214+ CubePropContextTranspiler . transformUserAttributesMemberExpression ( p ) ;
215+ }
216+ } ) ;
217+
218+ return R . uniq ( identifiers ) ;
219+ }
220+
201221 protected static matchAndPushIdentifier ( path , resolveSymbol : SymbolResolver , identifiers : string [ ] ) {
202222 if (
203223 ( ! path . parent ||
@@ -208,4 +228,33 @@ export class CubePropContextTranspiler implements TranspilerInterface {
208228 identifiers . push ( path . node . name ) ;
209229 }
210230 }
231+
232+ protected static matchAndTransformIdentifier ( path , resolveSymbol : SymbolResolver , identifiers : string [ ] ) {
233+ if (
234+ ( ! path . parent ||
235+ ( path . parent . type !== 'MemberExpression' || path . parent . type === 'MemberExpression' && path . key !== 'property' )
236+ ) &&
237+ resolveSymbol ( path . node . name )
238+ ) {
239+ // Special handling for userAttributes - replace in parameter list with securityContext
240+ if ( path . node . name === 'userAttributes' ) {
241+ identifiers . push ( 'securityContext' ) ;
242+ } else {
243+ identifiers . push ( path . node . name ) ;
244+ }
245+ }
246+ }
247+
248+ protected static transformUserAttributesMemberExpression ( path : NodePath < t . MemberExpression > ) {
249+ // Check if this is userAttributes.someProperty (object should be identifier named 'userAttributes')
250+ if ( t . isIdentifier ( path . node . object , { name : 'userAttributes' } ) ) {
251+ // Replace userAttributes with securityContext.cubeCloud.userAttributes
252+ const securityContext = t . identifier ( 'securityContext' ) ;
253+ const cubeCloud = t . memberExpression ( securityContext , t . identifier ( 'cubeCloud' ) ) ;
254+ const userAttributes = t . memberExpression ( cubeCloud , t . identifier ( 'userAttributes' ) ) ;
255+ const newMemberExpression = t . memberExpression ( userAttributes , path . node . property , path . node . computed ) ;
256+
257+ path . replaceWith ( newMemberExpression ) ;
258+ }
259+ }
211260}
0 commit comments