Skip to content

Commit 369bff1

Browse files
perf(runtime): drop the unreachable trailing-placeholder strip
No chunk filename template in the suite ends with a placeholder while starting with a literal, so the branch stripping the trailing empty string never ran — verified by counting its hits over every configCase under both its own config and the defaults `test:size` builds with. Removing it costs no bytes and leaves the helper with one branch, both outcomes exercised.
1 parent f09352c commit 369bff1

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

‎lib/runtime/GetChunkFilenameRuntimeModule.js‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -185,22 +185,14 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
185185
const dynamicUrlChunks = new Set();
186186

187187
/**
188-
* Drops the empty string a placeholder at either end of the template leaves
189-
* behind. Each strip requires a quoted operand at the other end, so the `+`
190-
* chain keeps yielding a string rather than a bare chunk id.
188+
* Drops the empty string a leading placeholder leaves behind. Only when a
189+
* quoted operand ends the expression, so the `+` chain keeps yielding a
190+
* string rather than a bare chunk id.
191191
* @param {string} expr concatenation expression
192-
* @returns {string} the expression without its dead empty strings
192+
* @returns {string} the expression without its dead empty string
193193
*/
194-
const dropDeadConcatOperands = (expr) => {
195-
let result = expr;
196-
if (result.startsWith('"" + ') && result.endsWith('"')) {
197-
result = result.slice(5);
198-
}
199-
if (result.endsWith(' + ""') && result.startsWith('"')) {
200-
result = result.slice(0, -5);
201-
}
202-
return result;
203-
};
194+
const dropDeadConcatOperand = (expr) =>
195+
expr.startsWith('"" + ') && expr.endsWith('"') ? expr.slice(5) : expr;
204196

205197
/**
206198
* @param {Chunk} c the chunk
@@ -273,7 +265,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
273265
},
274266
contentHashType: contentType
275267
});
276-
const url = dropDeadConcatOperands(staticChunkFilename);
268+
const url = dropDeadConcatOperand(staticChunkFilename);
277269
let set = staticUrls.get(url);
278270
if (set === undefined) {
279271
staticUrls.set(url, (set = new Set()));
@@ -373,7 +365,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
373365
},
374366
contentHashType: contentType
375367
});
376-
const url = dynamicUrl && dropDeadConcatOperands(dynamicUrl);
368+
const url = dynamicUrl && dropDeadConcatOperand(dynamicUrl);
377369

378370
const comment = `// This function allow to reference ${includedChunksMessages.join(
379371
" and "

0 commit comments

Comments
 (0)