@@ -223,7 +223,8 @@ function parseObjectExpression(
223223 } else if (
224224 property . key . type !== 'Identifier' &&
225225 property . key . type !== 'StringLiteral' &&
226- property . key . type !== 'NumericLiteral'
226+ property . key . type !== 'NumericLiteral' &&
227+ property . key . type !== 'Computed'
227228 ) {
228229 return errorLeft ( `Unimplemented property key type ${ property . key . type } ` ) ;
229230 }
@@ -235,7 +236,41 @@ function parseObjectExpression(
235236 commentEndIdx ,
236237 ) ;
237238 commentStartIdx = ( property . value as swc . HasSpan ) . span . end ;
238- const name = property . key . value ;
239+
240+ let name : string = '' ;
241+ if ( property . key . type === 'Computed' ) {
242+ if ( property . key . expression . type !== 'Identifier' ) {
243+ return errorLeft (
244+ `Unimplemented computed property value type ${ property . value . type } ` ,
245+ ) ;
246+ }
247+
248+ const initE = findSymbolInitializer (
249+ project ,
250+ source ,
251+ property . key . expression . value ,
252+ ) ;
253+ if ( E . isLeft ( initE ) ) {
254+ return initE ;
255+ }
256+ const [ newSourceFile , init ] = initE . right ;
257+ const valueE = parsePlainInitializer ( project , newSourceFile , init ) ;
258+ if ( E . isLeft ( valueE ) ) {
259+ return valueE ;
260+ }
261+ const schema = valueE . right ;
262+ if (
263+ ( schema . type === 'string' || schema . type === 'number' ) &&
264+ schema . enum !== undefined
265+ ) {
266+ name = String ( schema . enum [ 0 ] ) ;
267+ } else {
268+ return errorLeft ( 'Computed property must be string or number literal' ) ;
269+ }
270+ } else {
271+ name = String ( property . key . value ) ;
272+ }
273+
239274 const valueE = parsePlainInitializer ( project , source , property . value ) ;
240275 if ( E . isLeft ( valueE ) ) {
241276 return valueE ;
0 commit comments