Skip to content

Commit 5ac6eb2

Browse files
committed
PR feedback
1 parent 073b69a commit 5ac6eb2

File tree

4 files changed

+68
-62
lines changed

4 files changed

+68
-62
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12034,7 +12034,10 @@ namespace ts {
1203412034
const symbol = getSymbolOfNode(node);
1203512035
const localSymbol = node.localSymbol || symbol;
1203612036

12037-
const firstDeclaration = forEach(symbol.declarations,
12037+
// Since the javascript won't do semantic analysis like typescript,
12038+
// if the javascript file comes before the typescript file and both contain same name functions,
12039+
// checkFunctionOrConstructorSymbol wouldn't be called if we didnt ignore javascript function.
12040+
const firstDeclaration = forEach(localSymbol.declarations,
1203812041
// Get first non javascript function declaration
1203912042
declaration => declaration.kind === node.kind && !isSourceFileJavaScript(getSourceFile(declaration)) ?
1204012043
declaration : undefined);

src/compiler/declarationEmitter.ts

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -77,64 +77,67 @@ namespace ts {
7777
let addedGlobalFileReference = false;
7878
let allSourcesModuleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[] = [];
7979
forEach(sourceFiles, sourceFile => {
80-
if (!isSourceFileJavaScript(sourceFile)) {
81-
// Check what references need to be added
82-
if (!compilerOptions.noResolve) {
83-
forEach(sourceFile.referencedFiles, fileReference => {
84-
const referencedFile = tryResolveScriptReference(host, sourceFile, fileReference);
85-
86-
// Emit reference in dts, if the file reference was not already emitted
87-
if (referencedFile && !contains(emittedReferencedFiles, referencedFile)) {
88-
// Add a reference to generated dts file,
89-
// global file reference is added only
90-
// - if it is not bundled emit (because otherwise it would be self reference)
91-
// - and it is not already added
92-
if (writeReferencePath(referencedFile, !isBundledEmit && !addedGlobalFileReference)) {
93-
addedGlobalFileReference = true;
94-
}
95-
emittedReferencedFiles.push(referencedFile);
80+
// Dont emit for javascript file
81+
if (isSourceFileJavaScript(sourceFile)) {
82+
return;
83+
}
84+
85+
// Check what references need to be added
86+
if (!compilerOptions.noResolve) {
87+
forEach(sourceFile.referencedFiles, fileReference => {
88+
const referencedFile = tryResolveScriptReference(host, sourceFile, fileReference);
89+
90+
// Emit reference in dts, if the file reference was not already emitted
91+
if (referencedFile && !contains(emittedReferencedFiles, referencedFile)) {
92+
// Add a reference to generated dts file,
93+
// global file reference is added only
94+
// - if it is not bundled emit (because otherwise it would be self reference)
95+
// - and it is not already added
96+
if (writeReferencePath(referencedFile, !isBundledEmit && !addedGlobalFileReference)) {
97+
addedGlobalFileReference = true;
9698
}
97-
});
98-
}
99+
emittedReferencedFiles.push(referencedFile);
100+
}
101+
});
102+
}
99103

100-
if (!isBundledEmit || !isExternalModule(sourceFile)) {
101-
noDeclare = false;
102-
emitSourceFile(sourceFile);
103-
}
104-
else if (isExternalModule(sourceFile)) {
105-
noDeclare = true;
106-
write(`declare module "${getResolvedExternalModuleName(host, sourceFile)}" {`);
107-
writeLine();
108-
increaseIndent();
109-
emitSourceFile(sourceFile);
110-
decreaseIndent();
111-
write("}");
112-
writeLine();
113-
}
104+
if (!isBundledEmit || !isExternalModule(sourceFile)) {
105+
noDeclare = false;
106+
emitSourceFile(sourceFile);
107+
}
108+
else if (isExternalModule(sourceFile)) {
109+
noDeclare = true;
110+
write(`declare module "${getResolvedExternalModuleName(host, sourceFile)}" {`);
111+
writeLine();
112+
increaseIndent();
113+
emitSourceFile(sourceFile);
114+
decreaseIndent();
115+
write("}");
116+
writeLine();
117+
}
114118

115-
// create asynchronous output for the importDeclarations
116-
if (moduleElementDeclarationEmitInfo.length) {
117-
const oldWriter = writer;
118-
forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => {
119-
if (aliasEmitInfo.isVisible && !aliasEmitInfo.asynchronousOutput) {
120-
Debug.assert(aliasEmitInfo.node.kind === SyntaxKind.ImportDeclaration);
121-
createAndSetNewTextWriterWithSymbolWriter();
122-
Debug.assert(aliasEmitInfo.indent === 0 || (aliasEmitInfo.indent === 1 && isBundledEmit));
123-
for (let i = 0; i < aliasEmitInfo.indent; i++) {
124-
increaseIndent();
125-
}
126-
writeImportDeclaration(<ImportDeclaration>aliasEmitInfo.node);
127-
aliasEmitInfo.asynchronousOutput = writer.getText();
128-
for (let i = 0; i < aliasEmitInfo.indent; i++) {
129-
decreaseIndent();
130-
}
119+
// create asynchronous output for the importDeclarations
120+
if (moduleElementDeclarationEmitInfo.length) {
121+
const oldWriter = writer;
122+
forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => {
123+
if (aliasEmitInfo.isVisible && !aliasEmitInfo.asynchronousOutput) {
124+
Debug.assert(aliasEmitInfo.node.kind === SyntaxKind.ImportDeclaration);
125+
createAndSetNewTextWriterWithSymbolWriter();
126+
Debug.assert(aliasEmitInfo.indent === 0 || (aliasEmitInfo.indent === 1 && isBundledEmit));
127+
for (let i = 0; i < aliasEmitInfo.indent; i++) {
128+
increaseIndent();
131129
}
132-
});
133-
setWriter(oldWriter);
130+
writeImportDeclaration(<ImportDeclaration>aliasEmitInfo.node);
131+
aliasEmitInfo.asynchronousOutput = writer.getText();
132+
for (let i = 0; i < aliasEmitInfo.indent; i++) {
133+
decreaseIndent();
134+
}
135+
}
136+
});
137+
setWriter(oldWriter);
134138

135-
allSourcesModuleElementDeclarationEmitInfo = allSourcesModuleElementDeclarationEmitInfo.concat(moduleElementDeclarationEmitInfo);
136-
moduleElementDeclarationEmitInfo = [];
137-
}
139+
allSourcesModuleElementDeclarationEmitInfo = allSourcesModuleElementDeclarationEmitInfo.concat(moduleElementDeclarationEmitInfo);
140+
moduleElementDeclarationEmitInfo = [];
138141
}
139142
});
140143

src/compiler/program.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ namespace ts {
342342

343343
host = host || createCompilerHost(options);
344344
// Map storing if there is emit blocking diagnostics for given input
345-
const hasEmitBlockingDiagnostics = createFileMap<boolean>(!host.useCaseSensitiveFileNames() ? key => key.toLocaleLowerCase() : undefined);
345+
const hasEmitBlockingDiagnostics = createFileMap<boolean>(getCanonicalFileName);
346346

347347
const currentDirectory = host.getCurrentDirectory();
348348
const resolveModuleNamesWorker = host.resolveModuleNames
@@ -1287,14 +1287,14 @@ namespace ts {
12871287
if (emitFileName) {
12881288
const emitFilePath = toPath(emitFileName, currentDirectory, getCanonicalFileName);
12891289
// Report error if the output overwrites input file
1290-
if (forEach(files, file => toPath(file.fileName, currentDirectory, getCanonicalFileName) === emitFilePath)) {
1291-
createEmitBlockingDiagnostics(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file);
1290+
if (filesByName.contains(emitFilePath)) {
1291+
createEmitBlockingDiagnostics(emitFileName, emitFilePath, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file);
12921292
}
12931293

12941294
// Report error if multiple files write into same file
12951295
if (emitFilesSeen.contains(emitFilePath)) {
12961296
// Already seen the same emit file - report error
1297-
createEmitBlockingDiagnostics(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files);
1297+
createEmitBlockingDiagnostics(emitFileName, emitFilePath, Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files);
12981298
}
12991299
else {
13001300
emitFilesSeen.set(emitFilePath, true);
@@ -1303,7 +1303,7 @@ namespace ts {
13031303
}
13041304
}
13051305

1306-
function createEmitBlockingDiagnostics(emitFileName: string, message: DiagnosticMessage) {
1306+
function createEmitBlockingDiagnostics(emitFileName: string, emitFilePath: Path, message: DiagnosticMessage) {
13071307
hasEmitBlockingDiagnostics.set(toPath(emitFileName, currentDirectory, getCanonicalFileName), true);
13081308
programDiagnostics.add(createCompilerDiagnostic(message, emitFileName));
13091309
}

src/compiler/utilities.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,11 +1913,11 @@ namespace ts {
19131913
}
19141914
else {
19151915
const sourceFiles = targetSourceFile === undefined ? host.getSourceFiles() : [targetSourceFile];
1916-
forEach(sourceFiles, sourceFile => {
1916+
for (const sourceFile of sourceFiles) {
19171917
if (!isDeclarationFile(sourceFile)) {
19181918
onSingleFileEmit(host, sourceFile);
19191919
}
1920-
});
1920+
}
19211921
}
19221922

19231923
function onSingleFileEmit(host: EmitHost, sourceFile: SourceFile) {
@@ -1936,7 +1936,7 @@ namespace ts {
19361936
const bundledSources = filter(host.getSourceFiles(),
19371937
sourceFile => !isDeclarationFile(sourceFile) && // Not a declaration file
19381938
(!isExternalModule(sourceFile) || // non module file
1939-
(getEmitModuleKind(options) && isExternalModule(sourceFile)))); // module that can emit
1939+
(getEmitModuleKind(options) && isExternalModule(sourceFile)))); // module that can emit - note falsy value from getEmitModuleKind means the module kind that shouldn't be emitted
19401940
if (bundledSources.length) {
19411941
const jsFilePath = options.outFile || options.out;
19421942
const emitFileNames: EmitFileNames = {

0 commit comments

Comments
 (0)