@@ -65,14 +65,25 @@ function createCallExpressionDecorators(j, decoratorName, instanceProp) {
6565 ) ;
6666}
6767
68+ function createDecoratorsWithArgs ( j , identifier , args ) {
69+ return [
70+ j . decorator (
71+ j . callExpression (
72+ j . identifier ( identifier ) ,
73+ args . map ( arg => j . literal ( arg ) )
74+ )
75+ )
76+ ] ;
77+ }
78+
6879/**
6980 * Create `@action` decorator
7081 *
7182 * @param {Object } j - jscodeshift lib reference
7283 * @returns {Decorator[] }
7384 */
74- function createActionDecorators ( j ) {
75- return [ j . decorator ( j . identifier ( "action" ) ) ] ;
85+ function createIdentifierDecorators ( j , identifier = "action" ) {
86+ return [ j . decorator ( j . identifier ( identifier ) ) ] ;
7687}
7788
7889/**
@@ -102,25 +113,39 @@ function createBindingDecorators(j, decoratorName, instanceProp) {
102113 * @returns {Decorator[] }
103114 */
104115function createInstancePropDecorators ( j , instanceProp ) {
105- return instanceProp . decoratorNames . reduce ( ( decorators , decoratorName ) => {
106- if ( ! decoratorName ) {
116+ return instanceProp . decoratorNames . reduce ( ( decorators , decorator ) => {
117+ if ( ! decorator ) {
107118 return decorators ;
108119 }
109- if ( decoratorName === "className" || decoratorName === "attribute" ) {
120+ if ( decorator === "className" || decorator === "attribute" ) {
121+ return decorators . concat (
122+ createBindingDecorators ( j , decorator , instanceProp )
123+ ) ;
124+ }
125+ if ( decorator === "off" || decorator === "unobserves" ) {
110126 return decorators . concat (
111- createBindingDecorators ( j , decoratorName , instanceProp )
127+ createDecoratorsWithArgs (
128+ j ,
129+ decorator ,
130+ instanceProp . decoratorArgs [ decorator ]
131+ )
112132 ) ;
113133 }
114134 return decorators . concat (
115- createCallExpressionDecorators ( j , decoratorName , instanceProp )
135+ createCallExpressionDecorators (
136+ j ,
137+ decorator ,
138+ instanceProp ,
139+ instanceProp . decoratorArgs [ decorator ]
140+ )
116141 ) ;
117142 } , [ ] ) ;
118143}
119144
120145module . exports = {
121146 withDecorators,
122147 createClassDecorator,
123- createActionDecorators ,
148+ createIdentifierDecorators ,
124149 createCallExpressionDecorators,
125150 createInstancePropDecorators
126151} ;
0 commit comments