microsoft / microsoft/TypeScript
Proposal: `export as namespace` for UMD module output
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Current problem
TypeScript supports UMD output but does not support exporting as a global namespace.
Syntax
NamespaceExportDeclaration:
export as namespace IdentifierPath
Behavior
export var x = 0;
export function y() {}
export default {};
export as namespace My.Custom.Namespace;
// emits:
(function (global, factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
else {
global.My = global.My || {};
global.My.Custom = global.My.Custom || {};
global.My.Custom.Namespace = global.My.Custom.Namespace || {};
var exports = global.My.Custom.Namespace;
factory(global.require, exports);
}
})(this, function (require, exports) {
"use strict";
exports.__esModule = true;
exports.x = 0;
function y() { }
exports.y = y;
exports["default"] = {};
});
Note
- This proposal basically follows Babel behavior.
- Importing any module without a module loader will throw in this proposal. A further extension may use global namespaces as Babel does.
- Babel overwrites on the existing namespace whereas this proposal extends the existing one, as TS
namespacedoes. - Rollup has a special behavior where
export default Xworks like CommonJSmodule.exports = Xwhereas this proposal does not.
Prior arts: Babel exactGlobals, Webpack multi part library, Rollup output.name option with namespace support
See also
#8436
#10907
#20990
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Der Issue nennt keine Quelldateien, Tests oder Einstiegspunkte. Beginne damit, das vorgeschlagene Verhalten von NamespaceExportDeclaration und UMD mit den verwandten Issues #8436, #10907 und #20990 zu vergleichen; als abgeschlossen gilt die Aufgabe, wenn ein abgestimmtes Design und Implementierungskriterien für die Ausgabe globaler Namespaces vorliegen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100