Skip to content

Commit b02821a

Browse files
author
Luca Forstner
authored
fix: Use magic-string appendLeft instead of replace (#303)
1 parent 2a22ed8 commit b02821a

File tree

1 file changed

+4
-2
lines changed
  • packages/bundler-plugin-core/src

1 file changed

+4
-2
lines changed

packages/bundler-plugin-core/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,11 @@ export function createRollupDebugIdInjectionHooks() {
346346
// Note: CodeQL complains that this regex potentially has n^2 runtime. This likely won't affect realistic files.
347347
/^(?:\s*|\/\*(?:.|\r|\n)*\*\/|\/\/.*[\n\r])*(?:"[^"]*";|'[^']*';)?/;
348348

349-
if (code.match(commentUseStrictRegex)?.[0]) {
349+
const match = code.match(commentUseStrictRegex)?.[0];
350+
351+
if (match) {
350352
// Add injected code after any comments or "use strict" at the beginning of the bundle.
351-
ms.replace(commentUseStrictRegex, (match) => `${match}${codeToInject}`);
353+
ms.appendLeft(match.length, codeToInject);
352354
} else {
353355
// ms.replace() doesn't work when there is an empty string match (which happens if
354356
// there is neither, a comment, nor a "use strict" at the top of the chunk) so we

0 commit comments

Comments
 (0)