angular / clutz

Closure to TypeScript `.d.ts` generator
MIT License
162 stars 60 forks source link

follow local aliases in the clutz alias map #974

Closed tsjs-copybara-bot closed 4 years ago

tsjs-copybara-bot commented 4 years ago

follow local aliases in the clutz alias map

Consider Clutzing code like: const x = goog.require('mod'); exports.y = x;

Where 'mod' is not visible to Clutz due to it getting only partial input. By default, Clutz wants to look up the type of x and emit y as having the same type, which here would be {?} because x isn't known.

Instead, the correct emit for this is to emit 'y' as a straight alias of 'x', whatever it happens to end up as later. To do this Clutz builds an "alias map", that attempts to track which locals refer to imports.

This change extends the alias map to support one level of indirection through a local, e.g.

const x = goog.require('mod'); const y = x; exports.z = y;