* Returns a proxy to a target with specific handling for the * `parent` property, as well has to handle the `app` property; * that is, the proxy should maintain correct local state in * closure scope for the `app` property if it happens to be set * by `ember-cli`. Other than `parent` & `app`, th
(targetCacheEntry, parent)
| 62 | * @return Proxy |
| 63 | */ |
| 64 | function getAddonProxy(targetCacheEntry, parent) { |
| 65 | let _app; |
| 66 | |
| 67 | // handle `preprocessJs` separately for Embroider |
| 68 | // |
| 69 | // some context here: |
| 70 | // |
| 71 | // Embroider patches `preprocessJs`, so we want to maintain local state within the |
| 72 | // proxy rather than allowing a patched `preprocessJs` set on the original addon |
| 73 | // instance itself |
| 74 | // |
| 75 | // for more info as to where this happens, see: |
| 76 | // https://github.com/embroider-build/embroider/blob/master/packages/compat/src/v1-addon.ts#L634 |
| 77 | let _preprocessJs; |
| 78 | |
| 79 | return new Proxy(targetCacheEntry, { |
| 80 | get(targetCacheEntry, property) { |
| 81 | if (property === 'parent') { |
| 82 | return parent; |
| 83 | } |
| 84 | |
| 85 | if (property === 'app') { |
| 86 | return _app; |
| 87 | } |
| 88 | |
| 89 | // only return `_preprocessJs` here if it was previously set to a patched version |
| 90 | if (property === 'preprocessJs' && _preprocessJs) { |
| 91 | return _preprocessJs; |
| 92 | } |
| 93 | |
| 94 | // keep proxies from even trying to set or initialize addons |
| 95 | if (property === 'initializeAddons') { |
| 96 | return undefined; |
| 97 | } |
| 98 | |
| 99 | // See the {@link index.js} file for a discussion of why the proxy 'addons' |
| 100 | // property returns an empty array. |
| 101 | if (property === 'addons') { |
| 102 | return []; |
| 103 | } |
| 104 | |
| 105 | // allow access to the property pointing to the real instance. |
| 106 | if (property === TARGET_INSTANCE) { |
| 107 | return targetCacheEntry[TARGET_INSTANCE]; |
| 108 | } |
| 109 | |
| 110 | // `included` will be called on the "real" addon, so there's no need for it to be |
| 111 | // called again; instead we return a no-op implementation here |
| 112 | if (property === 'included') { |
| 113 | return () => undefined; |
| 114 | } |
| 115 | |
| 116 | if (targetCacheEntry[TARGET_INSTANCE]) { |
| 117 | if (property !== 'constructor' && typeof targetCacheEntry[TARGET_INSTANCE][property] === 'function') { |
| 118 | // If we fall through to the Reflect.get just below, the 'this' context of the function when |
| 119 | // invoked is the proxy, not the original instance (so its local state is incorrect). |
| 120 | // Wrap the original methods to maintain the correct 'this' context. |
| 121 | return function _originalAddonPropMethodWrapper() { |
no outgoing calls
no test coverage detected
searching dependent graphs…