File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { defineInlineTest } from 'jscodeshift/src/testUtils'
2
+
3
+ const renameLifeCycle = require ( '../rename-lifecycle' )
4
+
5
+ defineInlineTest (
6
+ renameLifeCycle ,
7
+ { } ,
8
+ `export default {
9
+ destroyed: function () {
10
+ console.log('foo')
11
+ },
12
+ beforeDestroy: function () {
13
+ console.log('bar')
14
+ },
15
+ methods: {
16
+ destroyed: function() {},
17
+ beforeDestroy: function() {}
18
+ }
19
+ }
20
+ ` ,
21
+ `export default {
22
+ unmounted: function () {
23
+ console.log('foo')
24
+ },
25
+ beforeUnmount: function () {
26
+ console.log('bar')
27
+ },
28
+ methods: {
29
+ destroyed: function() {},
30
+ beforeDestroy: function() {}
31
+ }
32
+ }` )
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ const transformationMap: {
17
17
'scoped-slots-to-slots' : require ( './scoped-slots-to-slots' ) ,
18
18
'new-directive-api' : require ( './new-directive-api' ) ,
19
19
'remove-vue-set-and-delete' : require ( './remove-vue-set-and-delete' ) ,
20
+ 'rename-lifecycle' : require ( './rename-lifecycle' ) ,
20
21
21
22
// atomic ones
22
23
'remove-contextual-h-from-render' : require ( './remove-contextual-h-from-render' ) ,
Original file line number Diff line number Diff line change
1
+ import wrap from '../src/wrapAstTransformation'
2
+ import type { ASTTransformation } from '../src/wrapAstTransformation'
3
+
4
+ const lifecycleMap : { [ key : string ] : string } = {
5
+ 'destroyed' : 'unmounted' ,
6
+ 'beforeDestroy' : 'beforeUnmount'
7
+ }
8
+
9
+ export const transformAST : ASTTransformation = ( { root, j } ) => {
10
+ const methodArray : any [ ] = [ j . ObjectProperty , j . ObjectMethod , j . ClassProperty ]
11
+ methodArray . forEach ( method => {
12
+ const methods = root . find ( method )
13
+ if ( methods . length ) {
14
+ methods . forEach ( ( path ) => {
15
+ // @ts -ignore
16
+ const beforeReplaceName = path . node . key . name
17
+ const afterReplaceName = lifecycleMap [ beforeReplaceName ]
18
+ if ( afterReplaceName && path . parent ?. parent ?. value ?. type === 'ExportDefaultDeclaration' ) {
19
+ // @ts -ignore
20
+ path . value . key . name = afterReplaceName
21
+ }
22
+ } )
23
+ }
24
+ } )
25
+ }
26
+
27
+ export default wrap ( transformAST )
28
+ export const parser = 'babylon'
You can’t perform that action at this time.
0 commit comments