mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 12:03:44 -05:00
Merge pull request #3586 from vvakame/addEsModule
improve module loading interoperability for babel
This commit is contained in:
@@ -3012,6 +3012,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
return result;
|
||||
}
|
||||
|
||||
function emitEs6ExportDefaultCompat(node: Node) {
|
||||
if (node.parent.kind === SyntaxKind.SourceFile) {
|
||||
Debug.assert(!!(node.flags & NodeFlags.Default) || node.kind === SyntaxKind.ExportAssignment);
|
||||
// only allow export default at a source file level
|
||||
if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) {
|
||||
if (!currentSourceFile.symbol.exports["___esModule"]) {
|
||||
if (languageVersion === ScriptTarget.ES5) {
|
||||
// default value of configurable, enumerable, writable are `false`.
|
||||
write("Object.defineProperty(exports, \"__esModule\", { value: true });");
|
||||
writeLine();
|
||||
}
|
||||
else if (languageVersion === ScriptTarget.ES3) {
|
||||
write("exports.__esModule = true;");
|
||||
writeLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitExportMemberAssignment(node: FunctionLikeDeclaration | ClassDeclaration) {
|
||||
if (node.flags & NodeFlags.Export) {
|
||||
writeLine();
|
||||
@@ -3034,9 +3054,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
else {
|
||||
if (node.flags & NodeFlags.Default) {
|
||||
emitEs6ExportDefaultCompat(node);
|
||||
if (languageVersion === ScriptTarget.ES3) {
|
||||
write("exports[\"default\"]");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
write("exports.default");
|
||||
}
|
||||
}
|
||||
@@ -5538,6 +5560,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
write(")");
|
||||
}
|
||||
else {
|
||||
emitEs6ExportDefaultCompat(node);
|
||||
emitContainingModuleName(node);
|
||||
if (languageVersion === ScriptTarget.ES3) {
|
||||
write("[\"default\"] = ");
|
||||
|
||||
Reference in New Issue
Block a user