1
1
import equal from 'fast-deep-equal'
2
2
import {
3
3
ProcessedRefDiffRefactoring ,
4
- RefDiffCommit ,
5
4
RefDiffLocation ,
6
5
RefDiffLocationWithLines ,
7
6
RefDiffNode ,
8
7
RefDiffNodeWithLines ,
9
- RefDiffOutput ,
10
8
RefDiffRefactoring ,
11
9
} from '../../../../common/refdiff.js'
12
- import { commitPlaceholder , RefactoringMeta , RefactoringType , RefactoringTypes } from '../../../../common/common.js'
13
- import { commitUrl } from '../../utils.js'
10
+ import {
11
+ PureRefactoringMeta ,
12
+ RefactoringType ,
13
+ RefactoringTypes ,
14
+ } from '../../../../common/common.js'
14
15
import { refDiffToolName } from '../runner/refdiff.js'
15
16
16
- type R = RefactoringMeta & ProcessedRefDiffRefactoring
17
+ type R = PureRefactoringMeta & ProcessedRefDiffRefactoring
17
18
18
19
const formatTypeAndDescription = ( ref : RefDiffRefactoring ) : [ typ : RefactoringType , desc : string ] => {
19
20
switch ( ref . type ) {
@@ -62,8 +63,8 @@ const formatTypeAndDescription = (ref: RefDiffRefactoring): [typ: RefactoringTyp
62
63
}
63
64
}
64
65
65
- const extractedMethods = ( c : RefDiffCommit ) : RefDiffRefactoring [ ] => {
66
- return c . refactorings
66
+ const extractedMethods = ( refs : RefDiffRefactoring [ ] ) : RefDiffRefactoring [ ] => {
67
+ return refs
67
68
. filter ( ( r ) => r . type === 'EXTRACT' && r . after . type === 'Method' )
68
69
}
69
70
@@ -83,75 +84,68 @@ const process = (ref: RefDiffRefactoring): ProcessedRefDiffRefactoring => ({
83
84
after : processNode ( ref . after ) ,
84
85
} )
85
86
86
- export const processRefDiffOutput = ( repoUrl : string , output : RefDiffOutput ) : R [ ] => {
87
- return output . map ( ( c ) : RefDiffCommit => {
88
- c . refactorings = c . refactorings . flatMap ( ( ref ) : RefDiffRefactoring [ ] => {
89
- switch ( ref . type ) {
90
- case 'INTERNAL_MOVE_RENAME' :
91
- return [
92
- { ...ref , type : 'INTERNAL_MOVE' } ,
93
- { ...ref , type : 'RENAME' } ,
94
- ref ,
95
- ]
96
- case 'MOVE_RENAME' :
97
- return [
98
- { ...ref , type : 'MOVE' } ,
99
- { ...ref , type : 'RENAME' } ,
100
- ref ,
101
- ]
102
- case 'EXTRACT_MOVE' :
103
- return [
104
- { ...ref , type : 'EXTRACT' } ,
105
- { ...ref , type : 'MOVE' } ,
106
- ref ,
107
- ]
108
- default :
109
- return [ ref ]
110
- }
111
- } )
112
- return c
113
- } ) . flatMap ( ( c ) : R [ ] => {
114
- const extractMethodRefactorings = extractedMethods ( c )
87
+ export const processRefDiffOutput = ( refs : RefDiffRefactoring [ ] ) : R [ ] => {
88
+ // Expand some composite refactorings
89
+ const refactorings = refs . flatMap ( ( ref ) : RefDiffRefactoring [ ] => {
90
+ switch ( ref . type ) {
91
+ case 'INTERNAL_MOVE_RENAME' :
92
+ return [
93
+ { ...ref , type : 'INTERNAL_MOVE' } ,
94
+ { ...ref , type : 'RENAME' } ,
95
+ ref ,
96
+ ]
97
+ case 'MOVE_RENAME' :
98
+ return [
99
+ { ...ref , type : 'MOVE' } ,
100
+ { ...ref , type : 'RENAME' } ,
101
+ ref ,
102
+ ]
103
+ case 'EXTRACT_MOVE' :
104
+ return [
105
+ { ...ref , type : 'EXTRACT' } ,
106
+ { ...ref , type : 'MOVE' } ,
107
+ ref ,
108
+ ]
109
+ default :
110
+ return [ ref ]
111
+ }
112
+ } )
115
113
116
- return c . refactorings . map ( ( ref ) : R => {
117
- const [ typ , description ] = formatTypeAndDescription ( ref )
114
+ const extractMethodRefactorings = extractedMethods ( refs )
118
115
119
- const ret : R = {
120
- type : typ ,
121
- description,
116
+ return refactorings . map ( ( ref ) : R => {
117
+ const [ typ , description ] = formatTypeAndDescription ( ref )
122
118
123
- sha1 : c . sha1 ,
124
- repository : repoUrl ,
125
- url : commitUrl ( repoUrl , c . sha1 ) ,
119
+ const ret : R = {
120
+ type : typ ,
121
+ description ,
126
122
127
- meta : {
128
- tool : refDiffToolName ,
129
- } ,
130
- commit : commitPlaceholder ( ) ,
123
+ meta : {
124
+ tool : refDiffToolName ,
125
+ } ,
131
126
132
- ...process ( ref ) ,
133
- }
127
+ ...process ( ref ) ,
128
+ }
134
129
135
- // Pre-compute needed information
136
- if ( typ === RefactoringTypes . ExtractMethod ) {
137
- ret . extractMethod = {
138
- // Use-case 1: 重複の処理が無い / あるextract
139
- sourceMethodsCount : extractSourceMethodsCount ( ref , extractMethodRefactorings ) ,
140
- // Use-case 2: 数行のみのextract, extractする前の行数
141
- sourceMethodLines : ret . before . location . lines ,
142
- extractedLines : ret . after . location . lines ,
143
- }
130
+ // Pre-compute needed information
131
+ if ( typ === RefactoringTypes . ExtractMethod ) {
132
+ ret . extractMethod = {
133
+ // Use-case 1: 重複の処理が無い / あるextract
134
+ sourceMethodsCount : extractSourceMethodsCount ( ref , extractMethodRefactorings ) ,
135
+ // Use-case 2: 数行のみのextract, extractする前の行数
136
+ sourceMethodLines : ret . before . location . lines ,
137
+ extractedLines : ret . after . location . lines ,
144
138
}
139
+ }
145
140
146
- // Use-case 3: 具体的なrenameした単語
147
- if ( ref . type === 'RENAME' ) {
148
- ret . rename = {
149
- from : ref . before . name ,
150
- to : ref . after . name ,
151
- }
141
+ // Use-case 3: 具体的なrenameした単語
142
+ if ( ref . type === 'RENAME' ) {
143
+ ret . rename = {
144
+ from : ref . before . name ,
145
+ to : ref . after . name ,
152
146
}
147
+ }
153
148
154
- return ret
155
- } )
149
+ return ret
156
150
} )
157
151
}
0 commit comments