Skip to content

Commit 890d94c

Browse files
committed
fix diffErroredPatch erroring
1 parent b875046 commit 890d94c

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/webpack/patchWebpack.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,12 @@ function patchFactory(moduleId: PropertyKey, originalFactory: AnyModuleFactory):
650650
function diffErroredPatch(code: string, lastCode: string, match: RegExpMatchArray) {
651651
const changeSize = code.length - lastCode.length;
652652

653+
const matchIndex = match?.index ?? 0;
654+
const matchLength = match?.[0]?.length ?? 0;
655+
653656
// Use 200 surrounding characters of context
654-
const start = Math.max(0, match.index! - 200);
655-
const end = Math.min(lastCode.length, match.index! + match[0].length + 200);
657+
const start = Math.max(0, matchIndex - 200);
658+
const end = Math.min(lastCode.length, matchIndex + matchLength + 200);
656659
// (changeSize may be negative)
657660
const endPatched = end + changeSize;
658661

0 commit comments

Comments
 (0)