-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TypeScript Version: 1.8.10
Code
An AMD module with re-exports:
export * from "a/b";
export * from "a/c";
Generates the following code:
define(["require", "exports", "a/b", "a/c"], function (require, exports, b_1, c_1) {
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
__export(b_1);
__export(c_1);
});
Problem:
The emitted helper '__export' function will fail if the exports object has an empty prototype (due to custom module loading system) and thus does not inherit the 'hasOwnProperty' method. It will also not handle correctly exported readonly properties (created by custom decorators).
Workaround:
As a workaround, i currently override the emitted function in my TypeScript code like so:
function __export(m: any) {
Object.getOwnPropertyNames(m).forEach(p => Object.defineProperty(exports, p, Object.getOwnPropertyDescriptor(m, p)));
}
export * from "a/b";
export * from "a/c";
Please fix the emitted '__exports' function to code similar to the above workaround (at least for ES5/ES6 targets).
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript