Skip to content
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

Merged
merged 36 commits into from
Nov 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7d06789
naive change
weswigham Sep 30, 2015
b6a57ea
Concatenated module emit fixes up all included paths
weswigham Oct 1, 2015
122753b
sourcemap correctness
weswigham Oct 2, 2015
8e409f3
new baselines for sourcemaps tests (given that modules can now get em…
weswigham Oct 2, 2015
4c4087c
Add compiler error for incompatible module formats
weswigham Oct 3, 2015
145fa0c
Accept baselines
weswigham Oct 3, 2015
03256e7
cusotm tests, forbid umd
weswigham Oct 3, 2015
3c73a66
removed umd as allowed, accepted new baselines
weswigham Oct 3, 2015
613c51d
Fix jakefile rules build
weswigham Oct 5, 2015
05dc9da
concatenated type emit
weswigham Oct 5, 2015
d8ec703
merge with master
weswigham Oct 5, 2015
d07e33d
Correct output, accept new baselines
weswigham Oct 5, 2015
6c1f3ef
m'lint
weswigham Oct 5, 2015
732ec34
update comment
weswigham Oct 5, 2015
1ae7b7c
Merge branch 'master' into out-module-concat
weswigham Oct 12, 2015
a83b858
Merge branch 'master' into out-module-concat
weswigham Oct 20, 2015
7a4e995
feedback form pr
weswigham Oct 20, 2015
79cf984
feedback form pr
weswigham Oct 20, 2015
d178945
rename variable
weswigham Oct 20, 2015
37bc277
feedback form pr
weswigham Oct 21, 2015
3f52686
cleanup a bit, think toward the future
weswigham Oct 21, 2015
2fcdb0f
bit more cleanup
weswigham Oct 21, 2015
d18facb
fix lint
weswigham Oct 21, 2015
255cde5
remove assertion
weswigham Oct 21, 2015
c165be8
change triple-slash ref emit critaera, add a new tests and accept new…
weswigham Oct 22, 2015
6c81242
Merge branch 'master' into out-module-concat
weswigham Oct 30, 2015
95a3fc7
feedback form pr, new baselines
weswigham Oct 30, 2015
70fba0b
Merge branch 'master' into out-module-concat
weswigham Oct 30, 2015
d4d6078
accept new baselines postmerge
weswigham Oct 30, 2015
f06627f
prevent absolutre paths from leaking through error baselines
weswigham Oct 30, 2015
6de5221
dont mutate
weswigham Nov 2, 2015
265fb51
feedback from CR
weswigham Nov 3, 2015
6f97021
Merge branch 'master' into out-module-concat
weswigham Nov 3, 2015
1baea88
shorten function
weswigham Nov 3, 2015
cadf543
Merge branch 'master' into out-module-concat
weswigham Nov 9, 2015
977c3ee
fix lints
weswigham Nov 9, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 4 additions & 1 deletion Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ var builtLocalCompiler = path.join(builtLocalDirectory, compilerFilename);
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, outDir, preserveConstEnums, keepComments, noResolve, stripInternal, callback) {
file(outFile, prereqs, function() {
var compilerPath = useBuiltCompiler ? builtLocalCompiler : LKGCompiler;
var options = "--module commonjs --noImplicitAny --noEmitOnError --pretty";
var options = "--noImplicitAny --noEmitOnError --pretty";

// Keep comments when specifically requested
// or when in debug mode.
Expand All @@ -251,6 +251,9 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
if (!noOutFile) {
options += " --out " + outFile;
}
else {
options += " --module commonjs"
}

if(noResolve) {
options += " --noResolve";
Expand Down
12 changes: 11 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14931,10 +14931,20 @@ namespace ts {
getReferencedValueDeclaration,
getTypeReferenceSerializationKind,
isOptionalParameter,
isArgumentsLocalBinding
isArgumentsLocalBinding,
getExternalModuleFileFromDeclaration
};
}

function getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration): SourceFile {
const specifier = getExternalModuleName(declaration);
const moduleSymbol = getSymbolAtLocation(specifier);
if (!moduleSymbol) {
return undefined;
}
return getDeclarationOfKind(moduleSymbol, SyntaxKind.SourceFile) as SourceFile;
}

function initializeTypeChecker() {
// Bind all source files and propagate errors
forEach(host.getSourceFiles(), file => {
Expand Down
63 changes: 56 additions & 7 deletions src/compiler/declarationEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ namespace ts {
let errorNameNode: DeclarationName;
const emitJsDocComments = compilerOptions.removeComments ? function (declaration: Node) { } : writeJsDocComments;
const emit = compilerOptions.stripInternal ? stripInternal : emitNode;
let noDeclare = !root;

const moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[] = [];
let moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[] = [];
let asynchronousSubModuleDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[];

// Contains the reference paths that needs to go in the declaration file.
Expand Down Expand Up @@ -107,26 +108,60 @@ namespace ts {
else {
// Emit references corresponding to this file
const emittedReferencedFiles: SourceFile[] = [];
let prevModuleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[] = [];
forEach(host.getSourceFiles(), sourceFile => {
if (!isExternalModuleOrDeclarationFile(sourceFile)) {
if (!isDeclarationFile(sourceFile)) {
// Check what references need to be added
if (!compilerOptions.noResolve) {
forEach(sourceFile.referencedFiles, fileReference => {
const referencedFile = tryResolveScriptReference(host, sourceFile, fileReference);

// If the reference file is a declaration file or an external module, emit that reference
if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) &&
// If the reference file is a declaration file, emit that reference
if (referencedFile && (isDeclarationFile(referencedFile) &&
!contains(emittedReferencedFiles, referencedFile))) { // If the file reference was not already emitted

writeReferencePath(referencedFile);
emittedReferencedFiles.push(referencedFile);
}
});
}
}

if (!isExternalModuleOrDeclarationFile(sourceFile)) {
noDeclare = false;
emitSourceFile(sourceFile);
}
else if (isExternalModule(sourceFile)) {
noDeclare = true;
write(`declare module "${getResolvedExternalModuleName(host, sourceFile)}" {`);
writeLine();
increaseIndent();
emitSourceFile(sourceFile);
decreaseIndent();
write("}");
writeLine();

// create asynchronous output for the importDeclarations
if (moduleElementDeclarationEmitInfo.length) {
const oldWriter = writer;
forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => {
if (aliasEmitInfo.isVisible && !aliasEmitInfo.asynchronousOutput) {
Debug.assert(aliasEmitInfo.node.kind === SyntaxKind.ImportDeclaration);
createAndSetNewTextWriterWithSymbolWriter();
Debug.assert(aliasEmitInfo.indent === 1);
increaseIndent();
writeImportDeclaration(<ImportDeclaration>aliasEmitInfo.node);
aliasEmitInfo.asynchronousOutput = writer.getText();
decreaseIndent();
}
});
setWriter(oldWriter);
}
prevModuleElementDeclarationEmitInfo = prevModuleElementDeclarationEmitInfo.concat(moduleElementDeclarationEmitInfo);
moduleElementDeclarationEmitInfo = [];
}
});
moduleElementDeclarationEmitInfo = moduleElementDeclarationEmitInfo.concat(prevModuleElementDeclarationEmitInfo);
}

return {
Expand Down Expand Up @@ -607,7 +642,7 @@ namespace ts {
if (node.flags & NodeFlags.Default) {
write("default ");
}
else if (node.kind !== SyntaxKind.InterfaceDeclaration) {
else if (node.kind !== SyntaxKind.InterfaceDeclaration && !noDeclare) {
write("declare ");
}
}
Expand Down Expand Up @@ -702,11 +737,25 @@ namespace ts {
}
write(" from ");
}
writeTextOfNode(currentText, node.moduleSpecifier);
emitExternalModuleSpecifier(node.moduleSpecifier);
write(";");
writer.writeLine();
}

function emitExternalModuleSpecifier(moduleSpecifier: Expression) {
if (moduleSpecifier.kind === SyntaxKind.StringLiteral && (!root) && (compilerOptions.out || compilerOptions.outFile)) {
const moduleName = getExternalModuleNameFromDeclaration(host, resolver, moduleSpecifier.parent as (ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration));
if (moduleName) {
write("\"");
write(moduleName);
write("\"");
return;
}
}

writeTextOfNode(currentText, moduleSpecifier);
}

function emitImportOrExportSpecifier(node: ImportOrExportSpecifier) {
if (node.propertyName) {
writeTextOfNode(currentText, node.propertyName);
Expand Down Expand Up @@ -738,7 +787,7 @@ namespace ts {
}
if (node.moduleSpecifier) {
write(" from ");
writeTextOfNode(currentText, node.moduleSpecifier);
emitExternalModuleSpecifier(node.moduleSpecifier);
}
write(";");
writer.writeLine();
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2310,7 +2310,6 @@
"category": "Message",
"code": 6078
},

"Specify JSX code generation: 'preserve' or 'react'": {
"category": "Message",
"code": 6080
Expand All @@ -2319,7 +2318,10 @@
"category": "Message",
"code": 6081
},

"Only 'amd' and 'system' modules are supported alongside --{0}.": {
"category": "Error",
"code": 6082
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
"code": 7005
Expand Down
Loading