Skip to content

Commit 514a354

Browse files
error log
1 parent cc50592 commit 514a354

File tree

6 files changed

+106
-94
lines changed

6 files changed

+106
-94
lines changed

packages/core/index.d.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,23 @@ declare const lowlight: {
4545
};
4646
export declare class DiffFile {
4747

48-
readonly _oldFileName: string;
49-
readonly _newFileName: string;
50-
readonly _diffList: string[];
5148
readonly uuid?: string;
5249
_version_: string;
50+
_oldFileName: string;
5351
_oldFileContent: string;
5452
_oldFileLang: string;
53+
_newFileName: string;
5554
_newFileContent: string;
5655
_newFileLang: string;
56+
_diffList: string[];
5757
diffLineLength: number;
5858
splitLineLength: number;
5959
unifiedLineLength: number;
6060
fileLineLength: number;
6161
hasExpandSplitAll: boolean;
6262
hasExpandUnifiedAll: boolean;
6363
hasSomeLineCollapsed: boolean;
64-
static createInstance(data: {
65-
oldFile?: {
66-
fileName?: string | null;
67-
fileLang?: string | null;
68-
content?: string | null;
69-
};
70-
newFile?: {
71-
fileName?: string | null;
72-
fileLang?: string | null;
73-
content?: string | null;
74-
};
75-
hunks?: string[];
76-
}, bundle?: ReturnType<DiffFile["getBundle"] | DiffFile["_getFullBundle"]>): DiffFile;
64+
static createInstance(data: FileData, bundle?: ReturnType<DiffFile["getBundle"] | DiffFile["_getFullBundle"]>): DiffFile;
7765
constructor(_oldFileName: string, _oldFileContent: string, _newFileName: string, _newFileContent: string, _diffList: string[], _oldFileLang?: string, _newFileLang?: string, uuid?: string);
7866
initId(): void;
7967
getId(): string;
@@ -561,6 +549,19 @@ export type DiffUnifiedLineItem = {
561549
index: number;
562550
lineNumber: number;
563551
};
552+
export type FileData = {
553+
oldFile?: {
554+
fileName?: string | null;
555+
fileLang?: string | null;
556+
content?: string | null;
557+
};
558+
newFile?: {
559+
fileName?: string | null;
560+
fileLang?: string | null;
561+
content?: string | null;
562+
};
563+
hunks?: string[];
564+
};
564565
export type HunkInfo = {
565566
oldStartIndex: number;
566567
newStartIndex: number;

packages/core/src/diff-file.ts

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
6369
export 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) {

packages/file/index.d.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,23 @@ declare const lowlight: {
4444
registered: (aliasOrName: string) => boolean;
4545
};
4646
export declare class DiffFile {
47-
readonly _oldFileName: string;
48-
readonly _newFileName: string;
49-
readonly _diffList: string[];
5047
readonly uuid?: string;
5148
_version_: string;
49+
_oldFileName: string;
5250
_oldFileContent: string;
5351
_oldFileLang: string;
52+
_newFileName: string;
5453
_newFileContent: string;
5554
_newFileLang: string;
55+
_diffList: string[];
5656
diffLineLength: number;
5757
splitLineLength: number;
5858
unifiedLineLength: number;
5959
fileLineLength: number;
6060
hasExpandSplitAll: boolean;
6161
hasExpandUnifiedAll: boolean;
6262
hasSomeLineCollapsed: boolean;
63-
static createInstance(data: {
64-
oldFile?: {
65-
fileName?: string | null;
66-
fileLang?: string | null;
67-
content?: string | null;
68-
};
69-
newFile?: {
70-
fileName?: string | null;
71-
fileLang?: string | null;
72-
content?: string | null;
73-
};
74-
hunks?: string[];
75-
}, bundle?: ReturnType<DiffFile["getBundle"] | DiffFile["_getFullBundle"]>): DiffFile;
63+
static createInstance(data: FileData, bundle?: ReturnType<DiffFile["getBundle"] | DiffFile["_getFullBundle"]>): DiffFile;
7664
constructor(_oldFileName: string, _oldFileContent: string, _newFileName: string, _newFileContent: string, _diffList: string[], _oldFileLang?: string, _newFileLang?: string, uuid?: string);
7765
initId(): void;
7866
getId(): string;
@@ -560,6 +548,19 @@ export type DiffUnifiedLineItem = {
560548
index: number;
561549
lineNumber: number;
562550
};
551+
export type FileData = {
552+
oldFile?: {
553+
fileName?: string | null;
554+
fileLang?: string | null;
555+
content?: string | null;
556+
};
557+
newFile?: {
558+
fileName?: string | null;
559+
fileLang?: string | null;
560+
content?: string | null;
561+
};
562+
hunks?: string[];
563+
};
563564
export type HunkInfo = {
564565
oldStartIndex: number;
565566
newStartIndex: number;

packages/react/index.d.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,23 @@ declare const lowlight: {
4444
registered: (aliasOrName: string) => boolean;
4545
};
4646
export declare class DiffFile {
47-
readonly _oldFileName: string;
48-
readonly _newFileName: string;
49-
readonly _diffList: string[];
5047
readonly uuid?: string;
5148
_version_: string;
49+
_oldFileName: string;
5250
_oldFileContent: string;
5351
_oldFileLang: string;
52+
_newFileName: string;
5453
_newFileContent: string;
5554
_newFileLang: string;
55+
_diffList: string[];
5656
diffLineLength: number;
5757
splitLineLength: number;
5858
unifiedLineLength: number;
5959
fileLineLength: number;
6060
hasExpandSplitAll: boolean;
6161
hasExpandUnifiedAll: boolean;
6262
hasSomeLineCollapsed: boolean;
63-
static createInstance(data: {
64-
oldFile?: {
65-
fileName?: string | null;
66-
fileLang?: string | null;
67-
content?: string | null;
68-
};
69-
newFile?: {
70-
fileName?: string | null;
71-
fileLang?: string | null;
72-
content?: string | null;
73-
};
74-
hunks?: string[];
75-
}, bundle?: ReturnType<DiffFile["getBundle"] | DiffFile["_getFullBundle"]>): DiffFile;
63+
static createInstance(data: FileData, bundle?: ReturnType<DiffFile["getBundle"] | DiffFile["_getFullBundle"]>): DiffFile;
7664
constructor(_oldFileName: string, _oldFileContent: string, _newFileName: string, _newFileContent: string, _diffList: string[], _oldFileLang?: string, _newFileLang?: string, uuid?: string);
7765
initId(): void;
7866
getId(): string;
@@ -560,6 +548,19 @@ export type DiffUnifiedLineItem = {
560548
index: number;
561549
lineNumber: number;
562550
};
551+
export type FileData = {
552+
oldFile?: {
553+
fileName?: string | null;
554+
fileLang?: string | null;
555+
content?: string | null;
556+
};
557+
newFile?: {
558+
fileName?: string | null;
559+
fileLang?: string | null;
560+
content?: string | null;
561+
};
562+
hunks?: string[];
563+
};
563564
export type HunkInfo = {
564565
oldStartIndex: number;
565566
newStartIndex: number;

packages/react/src/components/DiffView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ const DiffViewWithRef = <T extends unknown>(
199199
const diffFile = useMemo(() => {
200200
if (_diffFile) {
201201
// missing data for plain file render
202-
// TODO next release update
202+
// TODO next release update ?
203+
// will cause more complex for diffFile flow control, keep current
203204
const diffFile = DiffFile.createInstance({});
204205
diffFile._mergeFullBundle(_diffFile._getFullBundle());
205206
return diffFile;

packages/vue/index.d.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,23 @@ declare const lowlight: {
4444
registered: (aliasOrName: string) => boolean;
4545
};
4646
export declare class DiffFile {
47-
readonly _oldFileName: string;
48-
readonly _newFileName: string;
49-
readonly _diffList: string[];
5047
readonly uuid?: string;
5148
_version_: string;
49+
_oldFileName: string;
5250
_oldFileContent: string;
5351
_oldFileLang: string;
52+
_newFileName: string;
5453
_newFileContent: string;
5554
_newFileLang: string;
55+
_diffList: string[];
5656
diffLineLength: number;
5757
splitLineLength: number;
5858
unifiedLineLength: number;
5959
fileLineLength: number;
6060
hasExpandSplitAll: boolean;
6161
hasExpandUnifiedAll: boolean;
6262
hasSomeLineCollapsed: boolean;
63-
static createInstance(data: {
64-
oldFile?: {
65-
fileName?: string | null;
66-
fileLang?: string | null;
67-
content?: string | null;
68-
};
69-
newFile?: {
70-
fileName?: string | null;
71-
fileLang?: string | null;
72-
content?: string | null;
73-
};
74-
hunks?: string[];
75-
}, bundle?: ReturnType<DiffFile["getBundle"] | DiffFile["_getFullBundle"]>): DiffFile;
63+
static createInstance(data: FileData, bundle?: ReturnType<DiffFile["getBundle"] | DiffFile["_getFullBundle"]>): DiffFile;
7664
constructor(_oldFileName: string, _oldFileContent: string, _newFileName: string, _newFileContent: string, _diffList: string[], _oldFileLang?: string, _newFileLang?: string, uuid?: string);
7765
initId(): void;
7866
getId(): string;
@@ -560,6 +548,19 @@ export type DiffUnifiedLineItem = {
560548
index: number;
561549
lineNumber: number;
562550
};
551+
export type FileData = {
552+
oldFile?: {
553+
fileName?: string | null;
554+
fileLang?: string | null;
555+
content?: string | null;
556+
};
557+
newFile?: {
558+
fileName?: string | null;
559+
fileLang?: string | null;
560+
content?: string | null;
561+
};
562+
hunks?: string[];
563+
};
563564
export type HunkInfo = {
564565
oldStartIndex: number;
565566
newStartIndex: number;

0 commit comments

Comments
 (0)