-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--outFile & --module concatenation #5090
Changes from 19 commits
7d06789
b6a57ea
122753b
8e409f3
4c4087c
145fa0c
03256e7
3c73a66
613c51d
05dc9da
d8ec703
d07e33d
6c1f3ef
732ec34
1ae7b7c
a83b858
7a4e995
79cf984
d178945
37bc277
3f52686
2fcdb0f
d18facb
255cde5
c165be8
6c81242
95a3fc7
70fba0b
d4d6078
f06627f
6de5221
265fb51
6f97021
1baea88
cadf543
977c3ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -446,14 +446,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi | |
/** If removeComments is true, no leading-comments needed to be emitted **/ | ||
let emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos: number) { } : emitLeadingCommentsOfPositionWorker; | ||
|
||
let moduleEmitDelegates: Map<(node: SourceFile) => void> = { | ||
let moduleEmitDelegates: Map<(node: SourceFile, resolvePath?: boolean) => void> = { | ||
[ModuleKind.ES6]: emitES6Module, | ||
[ModuleKind.AMD]: emitAMDModule, | ||
[ModuleKind.System]: emitSystemModule, | ||
[ModuleKind.UMD]: emitUMDModule, | ||
[ModuleKind.CommonJS]: emitCommonJSModule, | ||
}; | ||
|
||
let bundleEmitDelegates: Map<(node: SourceFile, resolvePath?: boolean) => void> = { | ||
[ModuleKind.ES6]() {}, | ||
[ModuleKind.AMD]: emitAMDModule, | ||
[ModuleKind.System]: emitSystemModule, | ||
[ModuleKind.UMD]() {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only the amd compat part of umd would work - trying to load the concatenated umd file in a commonjs environment would only lead to sadness. So there's no point in allowing it. |
||
[ModuleKind.CommonJS]() {}, | ||
}; | ||
|
||
if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) { | ||
initializeEmitterWithSourceMaps(); | ||
} | ||
|
@@ -463,10 +471,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi | |
emitSourceFile(root); | ||
} | ||
else { | ||
if (modulekind) { | ||
forEach(host.getSourceFiles(), emitEmitHelpers); | ||
} | ||
forEach(host.getSourceFiles(), sourceFile => { | ||
if (!isExternalModuleOrDeclarationFile(sourceFile)) { | ||
emitSourceFile(sourceFile); | ||
} | ||
else if (modulekind && isExternalModule(sourceFile)) { | ||
emitConcatenatedModule(sourceFile); | ||
} | ||
}); | ||
} | ||
|
||
|
@@ -480,6 +494,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi | |
emit(sourceFile); | ||
} | ||
|
||
function emitConcatenatedModule(sourceFile: SourceFile): void { | ||
currentSourceFile = sourceFile; | ||
exportFunctionForFile = undefined; | ||
let canonicalName = resolveToSemiabsolutePath(host, sourceFile.fileName); | ||
sourceFile.moduleName = sourceFile.moduleName || canonicalName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would capture this in a variable instead of mutating it. the tree should be immutable post parsing (modulo intentional breaks to the previous rule :D) |
||
emit(sourceFile); | ||
} | ||
|
||
function isUniqueName(name: string): boolean { | ||
return !resolver.hasGlobalName(name) && | ||
!hasProperty(currentSourceFile.identifiers, name) && | ||
|
@@ -6703,7 +6725,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi | |
write("}"); // execute | ||
} | ||
|
||
function emitSystemModule(node: SourceFile): void { | ||
function emitSystemModule(node: SourceFile, resolvePath?: boolean): void { | ||
collectExternalModuleInfo(node); | ||
// System modules has the following shape | ||
// System.register(['dep-1', ... 'dep-n'], function(exports) {/* module body function */}) | ||
|
@@ -6743,6 +6765,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi | |
write(", "); | ||
} | ||
|
||
if (resolvePath) { | ||
text = makeModulePathSemiAbsolute(host, currentSourceFile, text); | ||
} | ||
write(text); | ||
} | ||
write(`], function(${exportFunctionForFile}) {`); | ||
|
@@ -6763,7 +6788,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi | |
importAliasNames: string[]; | ||
} | ||
|
||
function getAMDDependencyNames(node: SourceFile, includeNonAmdDependencies: boolean): AMDDependencyNames { | ||
function getAMDDependencyNames(node: SourceFile, includeNonAmdDependencies: boolean, resolvePath?: boolean): AMDDependencyNames { | ||
// names of modules with corresponding parameter in the factory function | ||
let aliasedModuleNames: string[] = []; | ||
// names of modules with no corresponding parameters in factory function | ||
|
@@ -6787,6 +6812,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi | |
// Find the name of the external module | ||
let externalModuleName = getExternalModuleNameText(importNode); | ||
|
||
if (resolvePath) { | ||
externalModuleName = makeModulePathSemiAbsolute(host, currentSourceFile, externalModuleName); | ||
} | ||
|
||
// Find the name of the module alias, if there is one | ||
let importAliasName = getLocalNameForExternalImport(importNode); | ||
if (includeNonAmdDependencies && importAliasName) { | ||
|
@@ -6801,7 +6830,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi | |
return { aliasedModuleNames, unaliasedModuleNames, importAliasNames }; | ||
} | ||
|
||
function emitAMDDependencies(node: SourceFile, includeNonAmdDependencies: boolean) { | ||
function emitAMDDependencies(node: SourceFile, includeNonAmdDependencies: boolean, resolvePath?: boolean) { | ||
// An AMD define function has the following shape: | ||
// define(id?, dependencies?, factory); | ||
// | ||
|
@@ -6814,7 +6843,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi | |
// `import "module"` or `<amd-dependency path= "a.css" />` | ||
// we need to add modules without alias names to the end of the dependencies list | ||
|
||
let dependencyNames = getAMDDependencyNames(node, includeNonAmdDependencies); | ||
let dependencyNames = getAMDDependencyNames(node, includeNonAmdDependencies, resolvePath); | ||
emitAMDDependencyList(dependencyNames); | ||
write(", "); | ||
emitAMDFactoryHeader(dependencyNames); | ||
|
@@ -6842,7 +6871,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi | |
write(") {"); | ||
} | ||
|
||
function emitAMDModule(node: SourceFile) { | ||
function emitAMDModule(node: SourceFile, resolvePath?: boolean) { | ||
emitEmitHelpers(node); | ||
collectExternalModuleInfo(node); | ||
|
||
|
@@ -6851,7 +6880,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi | |
if (node.moduleName) { | ||
write("\"" + node.moduleName + "\", "); | ||
} | ||
emitAMDDependencies(node, /*includeNonAmdDependencies*/ true); | ||
emitAMDDependencies(node, /*includeNonAmdDependencies*/ true, resolvePath); | ||
increaseIndent(); | ||
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true); | ||
emitExportStarHelper(); | ||
|
@@ -7100,8 +7129,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi | |
emitDetachedComments(node); | ||
|
||
if (isExternalModule(node) || compilerOptions.isolatedModules) { | ||
let emitModule = moduleEmitDelegates[modulekind] || moduleEmitDelegates[ModuleKind.CommonJS]; | ||
emitModule(node); | ||
if (root || (!isExternalModule(node) && compilerOptions.isolatedModules)) { | ||
let emitModule = moduleEmitDelegates[modulekind] || moduleEmitDelegates[ModuleKind.CommonJS]; | ||
emitModule(node); | ||
} | ||
else { | ||
bundleEmitDelegates[modulekind](node, /*resolvePath*/true); | ||
} | ||
} | ||
else { | ||
// emit prologue directives prior to __extends | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it took me a while to figure out what resolvePath realy does, and i am not sure what is a better name here.