Skip to content

Commit b38a81b

Browse files
committed
Emit enabled for JS files
1 parent 286fb3e commit b38a81b

File tree

50 files changed

+136
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+136
-80
lines changed

src/compiler/declarationEmitter.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,16 @@ namespace ts {
6969
if (!compilerOptions.noResolve) {
7070
let addedGlobalFileReference = false;
7171
forEach(root.referencedFiles, fileReference => {
72-
if (isJavaScript(fileReference.fileName)) {
73-
reportedDeclarationError = true;
74-
diagnostics.push(createFileDiagnostic(root, fileReference.pos, fileReference.end - fileReference.pos, Diagnostics.js_file_cannot_be_referenced_in_ts_file_when_emitting_declarations));
75-
}
76-
else {
77-
let referencedFile = tryResolveScriptReference(host, root, fileReference);
72+
let referencedFile = tryResolveScriptReference(host, root, fileReference);
7873

79-
// All the references that are not going to be part of same file
80-
if (referencedFile && ((referencedFile.flags & NodeFlags.DeclarationFile) || // This is a declare file reference
81-
shouldEmitToOwnFile(referencedFile, compilerOptions) || // This is referenced file is emitting its own js file
82-
!addedGlobalFileReference)) { // Or the global out file corresponding to this reference was not added
74+
// All the references that are not going to be part of same file
75+
if (referencedFile && ((referencedFile.flags & NodeFlags.DeclarationFile) || // This is a declare file reference
76+
shouldEmitToOwnFile(referencedFile, compilerOptions) || // This is referenced file is emitting its own js file
77+
!addedGlobalFileReference)) { // Or the global out file corresponding to this reference was not added
8378

84-
writeReferencePath(referencedFile);
85-
if (!isExternalModuleOrDeclarationFile(referencedFile)) {
86-
addedGlobalFileReference = true;
87-
}
79+
writeReferencePath(referencedFile);
80+
if (!isExternalModuleOrDeclarationFile(referencedFile)) {
81+
addedGlobalFileReference = true;
8882
}
8983
}
9084
});
@@ -111,24 +105,18 @@ namespace ts {
111105
// Emit references corresponding to this file
112106
let emittedReferencedFiles: SourceFile[] = [];
113107
forEach(host.getSourceFiles(), sourceFile => {
114-
if (!isExternalModuleOrDeclarationFile(sourceFile) && !isJavaScript(sourceFile.fileName)) {
108+
if (!isExternalModuleOrDeclarationFile(sourceFile)) {
115109
// Check what references need to be added
116110
if (!compilerOptions.noResolve) {
117111
forEach(sourceFile.referencedFiles, fileReference => {
118-
if (isJavaScript(fileReference.fileName)) {
119-
reportedDeclarationError = true;
120-
diagnostics.push(createFileDiagnostic(sourceFile, fileReference.pos, fileReference.end - fileReference.pos, Diagnostics.js_file_cannot_be_referenced_in_ts_file_when_emitting_declarations));
121-
}
122-
else {
123-
let referencedFile = tryResolveScriptReference(host, sourceFile, fileReference);
112+
let referencedFile = tryResolveScriptReference(host, sourceFile, fileReference);
124113

125-
// If the reference file is a declaration file or an external module, emit that reference
126-
if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) &&
127-
!contains(emittedReferencedFiles, referencedFile))) { // If the file reference was not already emitted
114+
// If the reference file is a declaration file or an external module, emit that reference
115+
if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) &&
116+
!contains(emittedReferencedFiles, referencedFile))) { // If the file reference was not already emitted
128117

129-
writeReferencePath(referencedFile);
130-
emittedReferencedFiles.push(referencedFile);
131-
}
118+
writeReferencePath(referencedFile);
119+
emittedReferencedFiles.push(referencedFile);
132120
}
133121
});
134122
}

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,10 +2465,6 @@
24652465
"category": "Error",
24662466
"code": 8017
24672467
},
2468-
".js file cannot be referenced in .ts file when emitting declarations.": {
2469-
"category": "Error",
2470-
"code": 8018
2471-
},
24722468

24732469
"Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses.": {
24742470
"category": "Error",

src/compiler/emitter.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
342342
emitFile(getEmitFileNames(targetSourceFile, host), targetSourceFile);
343343
}
344344
else if (!isDeclarationFile(targetSourceFile) &&
345-
!isJavaScript(targetSourceFile.fileName) &&
346345
(compilerOptions.outFile || compilerOptions.out)) {
347346
emitFile(getBundledEmitFileNames(compilerOptions));
348347
}
@@ -462,7 +461,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
462461
}
463462
else {
464463
forEach(host.getSourceFiles(), sourceFile => {
465-
if (!isJavaScript(sourceFile.fileName) && !isExternalModuleOrDeclarationFile(sourceFile)) {
464+
if (!isExternalModuleOrDeclarationFile(sourceFile)) {
466465
emitSourceFile(sourceFile);
467466
}
468467
});

src/compiler/utilities.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ namespace ts {
17691769
}
17701770

17711771
export function getEmitFileNames(sourceFile: SourceFile, host: EmitHost) {
1772-
if (!isDeclarationFile(sourceFile) && !isJavaScript(sourceFile.fileName)) {
1772+
if (!isDeclarationFile(sourceFile)) {
17731773
let options = host.getCompilerOptions();
17741774
let jsFilePath: string;
17751775
if (shouldEmitToOwnFile(sourceFile, options)) {
@@ -1835,12 +1835,12 @@ namespace ts {
18351835
}
18361836

18371837
export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean {
1838-
if (!isDeclarationFile(sourceFile) && !isJavaScript(sourceFile.fileName)) {
1838+
if (!isDeclarationFile(sourceFile)) {
18391839
if ((isExternalModule(sourceFile) || !(compilerOptions.outFile || compilerOptions.out))) {
18401840
// 1. in-browser single file compilation scenario
18411841
// 2. non supported extension file
18421842
return compilerOptions.isolatedModules ||
1843-
forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(sourceFile.fileName, extension));
1843+
forEach(getSupportedExtensions(compilerOptions), extension => fileExtensionIs(sourceFile.fileName, extension));
18441844
}
18451845
return false;
18461846
}

tests/baselines/reference/jsFileCompilationAmbientVarDeclarationSyntax.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
error TS5055: Cannot write file 'tests/cases/compiler/a.js' which is one of the input files.
12
tests/cases/compiler/a.js(1,1): error TS8009: 'declare' can only be used in a .ts file.
23

34

5+
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' which is one of the input files.
46
==== tests/cases/compiler/a.js (1 errors) ====
57
declare var v;
68
~~~~~~~

tests/baselines/reference/jsFileCompilationDecoratorSyntax.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
error TS5055: Cannot write file 'tests/cases/compiler/a.js' which is one of the input files.
12
tests/cases/compiler/a.js(1,1): error TS8017: 'decorators' can only be used in a .ts file.
23

34

5+
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' which is one of the input files.
46
==== tests/cases/compiler/a.js (1 errors) ====
57
@internal class C { }
68
~~~~~~~~~

tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.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.js' which is one of the input files.
2+
error TS5056: Cannot write file 'tests/cases/compiler/a.js' since one or more input files would emit into it.
23

34

45
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' which is one of the input files.
6+
!!! error TS5056: Cannot write file 'tests/cases/compiler/a.js' since one or more input files would emit into it.
57
==== tests/cases/compiler/a.ts (0 errors) ====
68
class c {
79
}

tests/baselines/reference/jsFileCompilationEmitDeclarations.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ var c = (function () {
1515
}
1616
return c;
1717
})();
18+
function foo() {
19+
}
1820

1921

2022
//// [out.d.ts]
2123
declare class c {
2224
}
25+
declare function foo(): void;

tests/baselines/reference/jsFileCompilationEmitTrippleSlashReference.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ var c = (function () {
1919
}
2020
return c;
2121
})();
22+
function bar() {
23+
}
24+
/// <reference path="c.js"/>
25+
function foo() {
26+
}
2227

2328

2429
//// [out.d.ts]
2530
declare class c {
2631
}
32+
declare function bar(): void;
33+
declare function foo(): void;

tests/baselines/reference/jsFileCompilationEnumSyntax.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
error TS5055: Cannot write file 'tests/cases/compiler/a.js' which is one of the input files.
12
tests/cases/compiler/a.js(1,6): error TS8015: 'enum declarations' can only be used in a .ts file.
23

34

5+
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' which is one of the input files.
46
==== tests/cases/compiler/a.js (1 errors) ====
57
enum E { }
68
~

0 commit comments

Comments
 (0)