@@ -60,6 +60,12 @@ export interface DiffHunkItem extends DiffLineItem {
6060 unifiedInfo ?: HunkLineInfo & HunkInfo ;
6161}
6262
63+ type FileData = {
64+ oldFile ?: { fileName ?: string | null ; fileLang ?: string | null ; content ?: string | null } ;
65+ newFile ?: { fileName ?: string | null ; fileLang ?: string | null ; content ?: string | null } ;
66+ hunks ?: string [ ] ;
67+ } ;
68+
6369export class DiffFile {
6470 #oldFileResult?: File ;
6571
@@ -121,14 +127,20 @@ export class DiffFile {
121127
122128 _version_ = __VERSION__ ;
123129
130+ _oldFileName : string = "" ;
131+
124132 _oldFileContent : string = "" ;
125133
126134 _oldFileLang : string = "" ;
127135
136+ _newFileName : string = "" ;
137+
128138 _newFileContent : string = "" ;
129139
130140 _newFileLang : string = "" ;
131141
142+ _diffList : string [ ] = [ ] ;
143+
132144 diffLineLength : number = 0 ;
133145
134146 splitLineLength : number = 0 ;
@@ -147,14 +159,7 @@ export class DiffFile {
147159
148160 #clonedInstance = new Map < DiffFile , ( ) => void > ( ) ;
149161
150- static createInstance (
151- data : {
152- oldFile ?: { fileName ?: string | null ; fileLang ?: string | null ; content ?: string | null } ;
153- newFile ?: { fileName ?: string | null ; fileLang ?: string | null ; content ?: string | null } ;
154- hunks ?: string [ ] ;
155- } ,
156- bundle ?: ReturnType < DiffFile [ "getBundle" ] | DiffFile [ "_getFullBundle" ] >
157- ) {
162+ static createInstance ( data : FileData , bundle ?: ReturnType < DiffFile [ "getBundle" ] | DiffFile [ "_getFullBundle" ] > ) {
158163 const instance = new DiffFile (
159164 data ?. oldFile ?. fileName || "" ,
160165 data ?. oldFile ?. content || "" ,
@@ -176,34 +181,32 @@ export class DiffFile {
176181 }
177182
178183 constructor (
179- readonly _oldFileName : string ,
184+ _oldFileName : string ,
180185 _oldFileContent : string ,
181- readonly _newFileName : string ,
186+ _newFileName : string ,
182187 _newFileContent : string ,
183- readonly _diffList : string [ ] ,
188+ _diffList : string [ ] ,
184189 _oldFileLang ?: string ,
185190 _newFileLang ?: string ,
186191 readonly uuid ?: string
187192 ) {
188193 Object . defineProperty ( this , "__v_skip" , { value : true } ) ;
189- let oldContent = _oldFileContent ;
190- let newContent = _newFileContent ;
194+
191195 const diffList = Array . from ( new Set ( _diffList ) ) ;
192- Object . defineProperties ( this , {
193- _oldFileName : { get : ( ) => _oldFileName } ,
194- _newFileName : { get : ( ) => _newFileName } ,
195- _oldFileLang : { get : ( ) => getLang ( _oldFileLang || _oldFileName || _newFileLang || _newFileName ) || "txt" } ,
196- _newFileLang : { get : ( ) => getLang ( _newFileLang || _newFileName || _oldFileLang || _oldFileName ) || "txt" } ,
197- _oldFileContent : {
198- get : ( ) => oldContent ,
199- set : ( v : string ) => ( oldContent = v ) ,
200- } ,
201- _newFileContent : {
202- get : ( ) => newContent ,
203- set : ( v : string ) => ( newContent = v ) ,
204- } ,
205- _diffList : { get : ( ) => diffList } ,
206- } ) ;
196+
197+ this . _oldFileName = _oldFileName ;
198+
199+ this . _newFileName = _newFileName ;
200+
201+ this . _diffList = diffList ;
202+
203+ this . _oldFileLang = getLang ( _oldFileLang || _oldFileName || _newFileLang || _newFileName ) || "txt" ;
204+
205+ this . _newFileLang = getLang ( _newFileLang || _newFileName || _oldFileLang || _oldFileName ) || "txt" ;
206+
207+ this . _oldFileContent = _oldFileContent ;
208+
209+ this . _newFileContent = _newFileContent ;
207210
208211 this . initId ( ) ;
209212 }
@@ -1304,7 +1307,11 @@ export class DiffFile {
13041307 this . #composeByMerge = true ;
13051308
13061309 if ( __DEV__ && this . _version_ !== data . version ) {
1307- console . error ( "the version of the `diffInstance` is not match, some error may happen!" ) ;
1310+ console . error ( "the version of the `diffInstance` is not match, some error may happen" ) ;
1311+ }
1312+
1313+ if ( __DEV__ && ! data . hasInitRaw ) {
1314+ console . error ( `there are not a valid bundle data to merge, try to call 'initRaw' function before merge` ) ;
13081315 }
13091316
13101317 if ( notifyUpdate ) {
0 commit comments