(type, options, fn)
| 64 | } |
| 65 | |
| 66 | _tap(type, options, fn) { |
| 67 | if (typeof options === "string") { |
| 68 | // Fast path: a string options ("name") is by far the most common |
| 69 | // case. Build the final descriptor in a single allocation instead |
| 70 | // of creating `{ name }` and then `Object.assign`ing it. |
| 71 | const name = options.trim(); |
| 72 | if (name === "") { |
| 73 | throw new Error("Missing name for tap"); |
| 74 | } |
| 75 | options = { type, fn, name }; |
| 76 | } else { |
| 77 | if (typeof options !== "object" || options === null) { |
| 78 | throw new Error("Invalid tap options"); |
| 79 | } |
| 80 | let { name } = options; |
| 81 | if (typeof name === "string") { |
| 82 | name = name.trim(); |
| 83 | } |
| 84 | if (typeof name !== "string" || name === "") { |
| 85 | throw new Error("Missing name for tap"); |
| 86 | } |
| 87 | if (typeof options.context !== "undefined") { |
| 88 | deprecateContext(); |
| 89 | } |
| 90 | // Fast path: only `name` is set. Build the descriptor as a literal |
| 91 | // so `_insert` and downstream consumers see the same hidden class |
| 92 | // as the string-options path, avoiding a polymorphic call site. |
| 93 | // Scan with `for...in` (cheaper than allocating `Object.keys`) |
| 94 | // to verify no other user-provided properties exist - e.g. |
| 95 | // webpack's `additionalAssets` - otherwise they'd be dropped. |
| 96 | let onlyName = true; |
| 97 | for (const key in options) { |
| 98 | if (key !== "name") { |
| 99 | onlyName = false; |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | if (onlyName) { |
| 104 | options = { type, fn, name }; |
| 105 | } else { |
| 106 | options.name = name; |
| 107 | // Preserve previous precedence: user-provided keys win over the internal `type`/`fn`. |
| 108 | options = Object.assign({ type, fn }, options); |
| 109 | } |
| 110 | } |
| 111 | options = this._runRegisterInterceptors(options); |
| 112 | this._insert(options); |
| 113 | } |
| 114 | |
| 115 | tap(options, fn) { |
| 116 | this._tap("sync", options, fn); |
no test coverage detected