microsoft / microsoft/TypeScript
Proposal: `export as namespace` for UMD module output
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
La issue non indica alcun file sorgente, test o punto di ingresso. Inizia confrontando il comportamento proposto di NamespaceExportDeclaration e UMD con le issue correlate #8436, #10907 e #20990; il lavoro sarà considerato completato quando saranno disponibili un design concordato e criteri di implementazione per l’output dei namespace globali.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100