Skip to content

Commit 50e941b

Browse files
committed
Merge branch 'release-2.1' of https://github.com/Microsoft/TypeScript into noEmitForJsFiles
2 parents 0c72309 + 182bc77 commit 50e941b

File tree

40 files changed

+123
-13
lines changed

40 files changed

+123
-13
lines changed

src/compiler/core.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,18 @@ namespace ts {
10631063
};
10641064
}
10651065

1066+
export function createCompilerDiagnosticFromMessageChain(chain: DiagnosticMessageChain): Diagnostic {
1067+
return {
1068+
file: undefined,
1069+
start: undefined,
1070+
length: undefined,
1071+
1072+
code: chain.code,
1073+
category: chain.category,
1074+
messageText: chain.next ? chain : chain.messageText
1075+
};
1076+
}
1077+
10661078
export function chainDiagnosticMessages(details: DiagnosticMessageChain, message: DiagnosticMessage, ...args: any[]): DiagnosticMessageChain;
10671079
export function chainDiagnosticMessages(details: DiagnosticMessageChain, message: DiagnosticMessage): DiagnosticMessageChain {
10681080
let text = getLocaleSpecificMessage(message);

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,5 +3118,9 @@
31183118
"Implement inherited abstract class": {
31193119
"category": "Message",
31203120
"code": 90007
3121+
},
3122+
"Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig": {
3123+
"category": "Error",
3124+
"code": 90009
31213125
}
31223126
}

src/compiler/program.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ namespace ts {
239239
const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
240240
const fileName = diagnostic.file.fileName;
241241
const relativeFileName = convertToRelativePath(fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName));
242-
output += `${ relativeFileName }(${ line + 1 },${ character + 1 }): `;
242+
output += `${relativeFileName}(${line + 1},${character + 1}): `;
243243
}
244244

245245
const category = DiagnosticCategory[diagnostic.category].toLowerCase();
246-
output += `${ category } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) }${ host.getNewLine() }`;
246+
output += `${category} TS${diagnostic.code}: ${flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine())}${host.getNewLine()}`;
247247
}
248248
return output;
249249
}
@@ -1316,11 +1316,11 @@ namespace ts {
13161316
}
13171317
else if (shouldAddFile) {
13181318
findSourceFile(resolution.resolvedFileName,
1319-
toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName),
1319+
toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName),
13201320
/*isDefaultLib*/ false,
1321-
file,
1322-
skipTrivia(file.text, file.imports[i].pos),
1323-
file.imports[i].end);
1321+
file,
1322+
skipTrivia(file.text, file.imports[i].pos),
1323+
file.imports[i].end);
13241324
}
13251325

13261326
if (isFromNodeModulesSearch) {
@@ -1538,13 +1538,24 @@ namespace ts {
15381538
// Report error if the output overwrites input file
15391539
if (filesByName.contains(emitFilePath)) {
15401540
const sourceFile = filesByName.get(emitFilePath);
1541-
blockEmittingOfFile(emitFileName, !(options.noEmitOverwriteForJsFiles && isSourceFileJavaScript(sourceFile)) && Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file);
1541+
if (options.noEmitOverwriteForJsFiles && isSourceFileJavaScript(sourceFile)) {
1542+
blockEmittingOfFile(emitFileName);
1543+
}
1544+
else {
1545+
let chain: DiagnosticMessageChain;
1546+
if (!options.configFilePath) {
1547+
// The program is from either an inferred project or an external project
1548+
chain = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Adding_a_tsconfig_json_file_will_help_organize_projects_that_contain_both_TypeScript_and_JavaScript_files_Learn_more_at_https_Colon_Slash_Slashaka_ms_Slashtsconfig);
1549+
}
1550+
chain = chainDiagnosticMessages(chain, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file, emitFileName);
1551+
blockEmittingOfFile(emitFileName, createCompilerDiagnosticFromMessageChain(chain));
1552+
}
15421553
}
15431554

15441555
// Report error if multiple files write into same file
15451556
if (emitFilesSeen.contains(emitFilePath)) {
15461557
// Already seen the same emit file - report error
1547-
blockEmittingOfFile(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files);
1558+
blockEmittingOfFile(emitFileName, createCompilerDiagnostic(Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files, emitFileName));
15481559
}
15491560
else {
15501561
emitFilesSeen.set(emitFilePath, true);
@@ -1553,10 +1564,10 @@ namespace ts {
15531564
}
15541565
}
15551566

1556-
function blockEmittingOfFile(emitFileName: string, message?: DiagnosticMessage) {
1567+
function blockEmittingOfFile(emitFileName: string, diag?: Diagnostic) {
15571568
hasEmitBlockingDiagnostics.set(toPath(emitFileName, currentDirectory, getCanonicalFileName), true);
1558-
if (message) {
1559-
programDiagnostics.add(createCompilerDiagnostic(message, emitFileName));
1569+
if (diag) {
1570+
programDiagnostics.add(diag);
15601571
}
15611572
}
15621573
}

src/harness/fourslash.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,19 @@ namespace FourSlash {
12741274
resultString += "Diagnostics:" + Harness.IO.newLine();
12751275
const diagnostics = ts.getPreEmitDiagnostics(this.languageService.getProgram());
12761276
for (let i = 0, n = diagnostics.length; i < n; i++) {
1277-
resultString += " " + diagnostics[0].messageText + Harness.IO.newLine();
1277+
const diagnostic = diagnostics[i];
1278+
if (typeof diagnostic.messageText !== "string") {
1279+
let chainedMessage = <ts.DiagnosticMessageChain>diagnostic.messageText;
1280+
let indentation = " ";
1281+
while (chainedMessage) {
1282+
resultString += indentation + chainedMessage.messageText + Harness.IO.newLine();
1283+
chainedMessage = chainedMessage.next;
1284+
indentation = indentation + " ";
1285+
}
1286+
}
1287+
else {
1288+
resultString += " " + diagnostic.messageText + Harness.IO.newLine();
1289+
}
12781290
}
12791291
}
12801292

tests/baselines/reference/compileOnSaveWorksWhenEmitBlockingErrorOnOtherFile.baseline

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
EmitSkipped: true
22
Diagnostics:
3-
Cannot write file '/tests/cases/fourslash/b.js' because it would overwrite input file.
3+
Cannot write file '/tests/cases/fourslash/b.js' because it would overwrite input file.
4+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
45

56
EmitSkipped: false
67
FileName : /tests/cases/fourslash/a.js

tests/baselines/reference/declarationFileOverwriteError.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.d.ts' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23

34

45
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.d.ts' because it would overwrite input file.
6+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
57
==== tests/cases/compiler/a.d.ts (0 errors) ====
68

79
declare class c {

tests/baselines/reference/declarationFileOverwriteErrorWithOut.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/out.d.ts' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23

34

45
!!! error TS5055: Cannot write file 'tests/cases/compiler/out.d.ts' because it would overwrite input file.
6+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
57
==== tests/cases/compiler/out.d.ts (0 errors) ====
68

79
declare class c {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile01.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23

34

45
!!! error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile01.js' because it would overwrite input file.
6+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
57
==== tests/cases/conformance/salsa/myFile01.js (0 errors) ====
68

79
export default "hello";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile02.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23

34

45
!!! error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile02.js' because it would overwrite input file.
6+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
57
==== tests/cases/conformance/salsa/myFile02.js (0 errors) ====
68

79
export default "hello";

tests/baselines/reference/jsFileCompilationAmbientVarDeclarationSyntax.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23
tests/cases/compiler/a.js(1,1): error TS8009: 'declare' can only be used in a .ts file.
34

45

56
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
7+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
68
==== tests/cases/compiler/a.js (1 errors) ====
79
declare var v;
810
~~~~~~~

tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23
error TS5056: Cannot write file 'tests/cases/compiler/a.js' because it would be overwritten by multiple input files.
34

45

56
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
7+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
68
!!! error TS5056: Cannot write file 'tests/cases/compiler/a.js' because it would be overwritten by multiple input files.
79
==== tests/cases/compiler/a.ts (0 errors) ====
810
class c {

tests/baselines/reference/jsFileCompilationEnumSyntax.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23
tests/cases/compiler/a.js(1,6): error TS8015: 'enum declarations' can only be used in a .ts file.
34

45

56
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
7+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
68
==== tests/cases/compiler/a.js (1 errors) ====
79
enum E { }
810
~

tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
error TS5053: Option 'allowJs' cannot be specified with option 'declaration'.
22
error TS5055: Cannot write file 'tests/cases/compiler/c.js' because it would overwrite input file.
3+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
34

45

56
!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'.
67
!!! error TS5055: Cannot write file 'tests/cases/compiler/c.js' because it would overwrite input file.
8+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
79
==== tests/cases/compiler/a.ts (0 errors) ====
810
class c {
911
}

tests/baselines/reference/jsFileCompilationExportAssignmentSyntax.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23
tests/cases/compiler/a.js(1,1): error TS8003: 'export=' can only be used in a .ts file.
34

45

56
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
7+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
68
==== tests/cases/compiler/a.js (1 errors) ====
79
export = b;
810
~~~~~~~~~~~

tests/baselines/reference/jsFileCompilationHeritageClauseSyntaxOfClass.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23
tests/cases/compiler/a.js(1,9): error TS8005: 'implements clauses' can only be used in a .ts file.
34

45

56
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
7+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
68
==== tests/cases/compiler/a.js (1 errors) ====
79
class C implements D { }
810
~~~~~~~~~~~~

tests/baselines/reference/jsFileCompilationImportEqualsSyntax.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23
tests/cases/compiler/a.js(1,1): error TS8002: 'import ... =' can only be used in a .ts file.
34

45

56
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
7+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
68
==== tests/cases/compiler/a.js (1 errors) ====
79
import a = b;
810
~~~~~~~~~~~~~

tests/baselines/reference/jsFileCompilationInterfaceSyntax.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23
tests/cases/compiler/a.js(1,11): error TS8006: 'interface declarations' can only be used in a .ts file.
34

45

56
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
7+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
68
==== tests/cases/compiler/a.js (1 errors) ====
79
interface I { }
810
~

tests/baselines/reference/jsFileCompilationModuleSyntax.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23
tests/cases/compiler/a.js(1,8): error TS8007: 'module declarations' can only be used in a .ts file.
34

45

56
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
7+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
68
==== tests/cases/compiler/a.js (1 errors) ====
79
module M { }
810
~

tests/baselines/reference/jsFileCompilationNoErrorWithoutDeclarationsWithJsFileReferenceWithNoOut.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/c.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23

34

45
!!! error TS5055: Cannot write file 'tests/cases/compiler/c.js' because it would overwrite input file.
6+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
57
==== tests/cases/compiler/a.ts (0 errors) ====
68
class c {
79
}

tests/baselines/reference/jsFileCompilationOptionalParameter.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23
tests/cases/compiler/a.js(1,13): error TS8009: '?' can only be used in a .ts file.
34

45

56
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
7+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
68
==== tests/cases/compiler/a.js (1 errors) ====
79
function F(p?) { }
810
~

tests/baselines/reference/jsFileCompilationPublicMethodSyntaxOfClass.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23
tests/cases/compiler/a.js(2,5): error TS8009: 'public' can only be used in a .ts file.
34

45

56
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
7+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
68
==== tests/cases/compiler/a.js (1 errors) ====
79
class C {
810
public foo() {

tests/baselines/reference/jsFileCompilationPublicParameterModifier.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
2+
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
23
tests/cases/compiler/a.js(1,23): error TS8012: 'parameter modifiers' can only be used in a .ts file.
34

45

56
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
7+
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig
68
==== tests/cases/compiler/a.js (1 errors) ====
79
class C { constructor(public x) { }}
810
~~~~~~

0 commit comments

Comments
 (0)