From 5b0e1cb606dca470b7bd7df444431d70d4806988 Mon Sep 17 00:00:00 2001 From: Harry Porter-Mills Date: Thu, 23 Jun 2022 14:01:17 -0400 Subject: [PATCH] Prevent crash when the pad amount is negative If the start is less than the (count - lineLength) + 1 pad will be negative and cause the call to repeat on line 477 to crash with an uncaught RangeError. --- packages/vite/src/node/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 5967aadfc29f58..6eb3f4da440e5e 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -469,7 +469,7 @@ export function generateCodeFrame( const lineLength = lines[j].length if (j === i) { // push underline - const pad = start - (count - lineLength) + 1 + const pad = Math.max(start - (count - lineLength) + 1, 0) const length = Math.max( 1, end > count ? lineLength - pad : end - start