@@ -17,17 +17,15 @@ function withDecorators(to, decorators = []) {
1717 * Creates a list of class decorators `tagName` and `classNames`
1818 *
1919 * @param {Object } j - jscodeshift lib reference
20- * @param {Property[] } classDecoratorProps
20+ * @param {Property } classDecoratorProp
2121 * @returns {Decorator[] }
2222 */
23- function createClassDecorators ( j , classDecoratorProps = [ ] ) {
24- return classDecoratorProps . map ( classDecoratorProp => {
25- return j . decorator (
26- j . callExpression ( j . identifier ( classDecoratorProp . key . name ) , [
27- classDecoratorProp . value
28- ] )
29- ) ;
30- } ) ;
23+ function createClassDecorator ( j , classDecoratorProp ) {
24+ return j . decorator (
25+ j . callExpression ( j . identifier ( classDecoratorProp . key . name ) , [
26+ classDecoratorProp . value
27+ ] )
28+ ) ;
3129}
3230
3331/**
@@ -40,7 +38,7 @@ function createClassDecorators(j, classDecoratorProps = []) {
4038 * @returns {Decorator[] }
4139 */
4240function createCallExpressionDecorators ( j , decoratorName , instanceProp ) {
43- if ( decoratorName === "computed" ) {
41+ if ( instanceProp . hasNonLiteralArg ) {
4442 const decoratorArgs = get ( instanceProp , "value.arguments" ) . slice ( 0 , - 1 ) ;
4543 return [
4644 j . decorator ( j . callExpression ( j . identifier ( decoratorName ) , decoratorArgs ) )
@@ -49,10 +47,7 @@ function createCallExpressionDecorators(j, decoratorName, instanceProp) {
4947 // clone the instance prop value
5048 const instancePropValue = JSON . parse ( JSON . stringify ( instanceProp . value ) ) ;
5149 instancePropValue . callee . name = decoratorName ;
52- if (
53- instanceProp . decoratorName &&
54- get ( instanceProp , "value.callee.object.callee.name" )
55- ) {
50+ if ( get ( instanceProp , "value.callee.object.callee.name" ) ) {
5651 const decoratorArgs = get ( instancePropValue , "callee.object.arguments" ) ;
5752 instancePropValue . callee . object = get (
5853 instancePropValue ,
@@ -101,19 +96,24 @@ function createBindingDecorators(j, decoratorName, instanceProp) {
10196 * @returns {Decorator[] }
10297 */
10398function createInstancePropDecorators ( j , instanceProp ) {
104- const decoratorName = instanceProp . decoratorName ;
105- if ( ! decoratorName ) {
106- return [ ] ;
107- }
108- if ( decoratorName === "className" || decoratorName === "attribute" ) {
109- return createBindingDecorators ( j , decoratorName , instanceProp ) ;
110- }
111- return createCallExpressionDecorators ( j , decoratorName , instanceProp ) ;
99+ return instanceProp . decoratorNames . reduce ( ( decorators , decoratorName ) => {
100+ if ( ! decoratorName ) {
101+ return decorators ;
102+ }
103+ if ( decoratorName === "className" || decoratorName === "attribute" ) {
104+ return decorators . concat (
105+ createBindingDecorators ( j , decoratorName , instanceProp )
106+ ) ;
107+ }
108+ return decorators . concat (
109+ createCallExpressionDecorators ( j , decoratorName , instanceProp )
110+ ) ;
111+ } , [ ] ) ;
112112}
113113
114114module . exports = {
115115 withDecorators,
116- createClassDecorators ,
116+ createClassDecorator ,
117117 createActionDecorators,
118118 createCallExpressionDecorators,
119119 createInstancePropDecorators
0 commit comments