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

+15-27
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

-4
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

+1-2
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

+3-3
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

+2
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

+2
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

+2
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

+3
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

+7
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

+2
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
~

tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.errors.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
tests/cases/compiler/b.ts(1,1): error TS8018: .js file cannot be referenced in .ts file when emitting declarations.
1+
error TS5055: Cannot write file 'tests/cases/compiler/c.js' which is one of the input files.
22

33

4+
!!! error TS5055: Cannot write file 'tests/cases/compiler/c.js' which is one of the input files.
45
==== tests/cases/compiler/a.ts (0 errors) ====
56
class c {
67
}
78

8-
==== tests/cases/compiler/b.ts (1 errors) ====
9+
==== tests/cases/compiler/b.ts (0 errors) ====
910
/// <reference path="c.js"/>
10-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11-
!!! error TS8018: .js file cannot be referenced in .ts file when emitting declarations.
1211
// error on above reference path when emitting declarations
1312
function foo() {
1413
}

tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.js

+5
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ function foo() {
3030
//// [a.d.ts]
3131
declare class c {
3232
}
33+
//// [c.d.ts]
34+
declare function bar(): void;
35+
//// [b.d.ts]
36+
/// <reference path="c.d.ts" />
37+
declare function foo(): void;

tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.errors.txt

-18
This file was deleted.

tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.js

+9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ var c = (function () {
2020
}
2121
return c;
2222
})();
23+
function bar() {
24+
}
2325
/// <reference path="c.js"/>
2426
// error on above reference when emitting declarations
2527
function foo() {
2628
}
29+
30+
31+
//// [out.d.ts]
32+
declare class c {
33+
}
34+
declare function bar(): void;
35+
declare function foo(): void;
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class c {
55

66
=== tests/cases/compiler/b.ts ===
77
/// <reference path="c.js"/>
8-
// no error on above reference path since not emitting declarations
8+
// error on above reference when emitting declarations
99
function foo() {
1010
>foo : Symbol(foo, Decl(b.ts, 0, 0))
1111
}
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class c {
55

66
=== tests/cases/compiler/b.ts ===
77
/// <reference path="c.js"/>
8-
// no error on above reference path since not emitting declarations
8+
// error on above reference when emitting declarations
99
function foo() {
1010
>foo : () => void
1111
}

tests/baselines/reference/jsFileCompilationExportAssignmentSyntax.errors.txt

+2
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 TS8003: 'export=' 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
export = b;
68
~~~~~~~~~~~

tests/baselines/reference/jsFileCompilationHeritageClauseSyntaxOfClass.errors.txt

+2
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,9): error TS8005: 'implements clauses' 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
class C implements D { }
68
~~~~~~~~~~~~

tests/baselines/reference/jsFileCompilationImportEqualsSyntax.errors.txt

+2
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 TS8002: 'import ... =' 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
import a = b;
68
~~~~~~~~~~~~~

tests/baselines/reference/jsFileCompilationInterfaceSyntax.errors.txt

+2
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,11): error TS8006: 'interface 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
interface I { }
68
~

tests/baselines/reference/jsFileCompilationModuleSyntax.errors.txt

+2
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,8): error TS8007: 'module 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
module M { }
68
~
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error TS5055: Cannot write file 'tests/cases/compiler/c.js' which is one of the input files.
2+
3+
4+
!!! error TS5055: Cannot write file 'tests/cases/compiler/c.js' which is one of the input files.
5+
==== tests/cases/compiler/a.ts (0 errors) ====
6+
class c {
7+
}
8+
9+
==== tests/cases/compiler/b.ts (0 errors) ====
10+
/// <reference path="c.js"/>
11+
// no error on above reference path since not emitting declarations
12+
function foo() {
13+
}
14+
15+
==== tests/cases/compiler/c.js (0 errors) ====
16+
function bar() {
17+
}

tests/baselines/reference/jsFileCompilationNoErrorWithoutDeclarationsWithJsFileReferenceWithOut.js

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ var c = (function () {
2020
}
2121
return c;
2222
})();
23+
function bar() {
24+
}
2325
/// <reference path="c.js"/>
2426
//no error on above reference since not emitting declarations
2527
function foo() {

tests/baselines/reference/jsFileCompilationOptionalParameter.errors.txt

+2
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,13): error TS8009: '?' 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
function F(p?) { }
68
~

tests/baselines/reference/jsFileCompilationPropertySyntaxOfClass.errors.txt

+2
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,11): error TS8014: 'property 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
class C { v }
68
~

tests/baselines/reference/jsFileCompilationPublicMethodSyntaxOfClass.errors.txt

+2
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(2,5): error TS8009: 'public' 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
class C {
68
public foo() {

tests/baselines/reference/jsFileCompilationPublicParameterModifier.errors.txt

+2
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,23): error TS8012: 'parameter modifiers' 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
class C { constructor(public x) { }}
68
~~~~~~

tests/baselines/reference/jsFileCompilationRestParameter.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
function foo(...a) { }
33

44
//// [b.js]
5+
function foo(...a) { }

tests/baselines/reference/jsFileCompilationReturnTypeSyntaxOfFunction.errors.txt

+2
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,15): error TS8010: 'types' 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
function F(): number { }
68
~~~~~~

tests/baselines/reference/jsFileCompilationSyntaxError.errors.txt

+2
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(3,6): error TS1223: 'type' tag already specified.
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
/**
68
* @type {number}

0 commit comments

Comments
 (0)