Description
Hallo!
I came across this issue today which got me stuck for a while. Exporting a function named "toString" (a name coincidentally present in the Object prototype...) lead to my builds crashing.
TypeScript Version: 1.8.10 / nightly (2.1.0-dev.20160714)
Sample Triggering the Effect
function toString() {}
export { toString as foo }
Expected behavior:
This should compile to a valid module, e.g. using tsc --module commonjs foo.ts.
Actual behavior:
The TS compiler fails throwing TypeError: undefined is not a function. The code in TS causing this issue looks like this:
let name = (specifier.propertyName || specifier.name).text;
(exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier);
Since name is present in the prototype of exportSpecifiers, this won't create an empty array as it should, but rather invokes push on the prototype member (which is undefined).
This could be fixable by pre- or postfixing names making sure they're not interfering with prototype properties.