| 76 | } |
| 77 | |
| 78 | function processCode(asset, obj) { |
| 79 | let application; |
| 80 | let paramStack = []; |
| 81 | let keyStack = []; |
| 82 | let fn = (t, k) => { |
| 83 | if (t && t.type === 'reference') { |
| 84 | let dep = bundleGraph |
| 85 | .getDependencies(asset) |
| 86 | .find(d => d.specifier === t.specifier && !bundleGraph.isDependencySkipped(d)); |
| 87 | let res = bundleGraph.getResolvedAsset(dep, bundle); |
| 88 | let result = res ? processAsset(res)[t.imported] : null; |
| 89 | if (result) { |
| 90 | t = result; |
| 91 | } else { |
| 92 | return { |
| 93 | type: 'identifier', |
| 94 | name: t.local |
| 95 | }; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if (t && t.type === 'application') { |
| 100 | application = t.typeParameters.map(item => fn(item, 'typeParameters')); |
| 101 | } |
| 102 | |
| 103 | let hasParams = false; |
| 104 | if ( |
| 105 | t && |
| 106 | (t.type === 'alias' || t.type === 'interface') && |
| 107 | t.typeParameters && |
| 108 | application && |
| 109 | shouldMerge(t, k, keyStack) |
| 110 | ) { |
| 111 | let params = Object.assign({}, paramStack[paramStack.length - 1]); |
| 112 | t.typeParameters.forEach((p, i) => { |
| 113 | let v = application[i] || p.default; |
| 114 | params[p.name] = v; |
| 115 | }); |
| 116 | paramStack.push(params); |
| 117 | // so we don't replace the type parameters in the extended interface |
| 118 | application = null; |
| 119 | hasParams = true; |
| 120 | } else if ( |
| 121 | t && |
| 122 | (t.type === 'alias' || t.type === 'interface' || t.type === 'component') && |
| 123 | t.typeParameters && |
| 124 | keyStack.length === 0 |
| 125 | ) { |
| 126 | // If we are at a root export, replace type parameters with constraints if possible. |
| 127 | // Seeing `DateValue` (as in `T extends DateValue`) is nicer than just `T`. |
| 128 | let typeParameters = t.typeParameters.map(item => fn(item, 'typeParameters')); |
| 129 | let params = Object.assign({}, paramStack[paramStack.length - 1]); |
| 130 | typeParameters.forEach(p => { |
| 131 | if (!params[p.name] && p.constraint) { |
| 132 | params[p.name] = p.constraint; |
| 133 | } |
| 134 | }); |
| 135 | paramStack.push(params); |