Repository: GoogleChrome/workbox (language: javascript)

Issue:
Dynamic method calls in Queue.ts could fail with minification
There are some dynamic method calls in `Queue.ts` along the lines of:

https://github.com/GoogleChrome/workbox/blob/48f53f790ce7f0aa1a8431bdc605d589b648e329/packages/workbox-background-sync/src/Queue.ts#L279

(and a few more similar ones).

These method calls can fail if minification changes the names of the methods on the underlying `QueueStore` object.

I think it might be possible (via `declare` in TypeScript?) to give hints to various minifiers that they shouldn't do renaming, but honestly it might be easier just to use `if()`/`else()` conditionals to find the right method name to call, since there are usually only a couple to choose from for each code path.


Discussion / hints:

Fix patch:
diff --git a/packages/workbox-background-sync/src/Queue.ts b/packages/workbox-background-sync/src/Queue.ts
index d98aff23a..97dd895f1 100644
--- a/packages/workbox-background-sync/src/Queue.ts
+++ b/packages/workbox-background-sync/src/Queue.ts
@@ -11,7 +11,7 @@ import {logger} from 'workbox-core/_private/logger.js';
 import {assert} from 'workbox-core/_private/assert.js';
 import {getFriendlyURL} from 'workbox-core/_private/getFriendlyURL.js';
 import {QueueStore} from './lib/QueueStore.js';
-import {UnidentifiedQueueStoreEntry} from './lib/QueueDb.js';
+import {QueueStoreEntry, UnidentifiedQueueStoreEntry} from './lib/QueueDb.js';
 import {StorableRequest} from './lib/StorableRequest.js';
 import './_version.js';
 
@@ -276,7 +276,14 @@ class Queue {
       entry.metadata = metadata;
     }
 
-    await this._queueStore[`${operation}Entry`](entry);
+    switch (operation) {
+      case 'push':
+        await this._queueStore.pushEntry(entry);
+        break;
+      case 'unshift':
+        await this._queueStore.unshiftEntry(entry);
+        break;
+    }
 
     if (process.env.NODE_ENV !== 'production') {
       logger.log(
@@ -307,7 +314,15 @@ class Queue {
     operation: 'pop' | 'shift',
   ): Promise<QueueEntry | undefined> {
     const now = Date.now();
-    const entry = await this._queueStore[`${operation}Entry`]();
+    let entry: QueueStoreEntry | undefined;
+    switch (operation) {
+      case 'pop':
+        entry = await this._queueStore.popEntry();
+        break;
+      case 'shift':
+        entry = await this._queueStore.shiftEntry();
+        break;
+    }
 
     if (entry) {
       // Ignore requests older than maxRetentionTime. Call this function


Test patch: