File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ module.exports = function(fileInfo, api) {
6
6
7
7
require ( './add-emit-declaration' ) ( context )
8
8
require ( './add-watch-deep' ) ( context )
9
+ require ( './rename-lifecycle' ) ( context )
9
10
10
11
return root . toSource ( { lineTerminator : '\n' } )
11
12
}
Original file line number Diff line number Diff line change
1
+ /** @type {import('jscodeshift').Transform } */
2
+
3
+ const DEPRECATED_LIFECYCLE = Object . create ( null )
4
+ DEPRECATED_LIFECYCLE . destroyed = 'unmounted'
5
+ DEPRECATED_LIFECYCLE . beforeDestroy = 'beforeUnmount'
6
+
7
+ module . exports = function renameLifecycle ( context ) {
8
+ const { j, root } = context
9
+
10
+ const renameDeprecatedLifecycle = path => {
11
+ const name = path . node . key . name
12
+
13
+ if (
14
+ DEPRECATED_LIFECYCLE [ name ] &&
15
+ path . parent &&
16
+ path . parent . parent &&
17
+ path . parent . parent . value . type === 'ExportDefaultDeclaration'
18
+ ) {
19
+ path . value . key . name = DEPRECATED_LIFECYCLE [ name ]
20
+ }
21
+ }
22
+
23
+ root . find ( j . ObjectProperty ) . forEach ( renameDeprecatedLifecycle )
24
+ root . find ( j . ObjectMethod ) . forEach ( renameDeprecatedLifecycle )
25
+ root . find ( j . ClassProperty ) . forEach ( renameDeprecatedLifecycle )
26
+
27
+ return root . toSource ( { lineTerminator : '\n' } )
28
+ }
You can’t perform that action at this time.
0 commit comments