mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Do not emit declarations for javascript files
This commit is contained in:
parent
b217b8b620
commit
94a647b72b
@ -33,7 +33,9 @@ namespace ts {
|
||||
export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] {
|
||||
let diagnostics: Diagnostic[] = [];
|
||||
let { declarationFilePath } = getEmitFileNames(targetSourceFile, host);
|
||||
emitDeclarations(host, resolver, diagnostics, declarationFilePath, targetSourceFile);
|
||||
if (declarationFilePath) {
|
||||
emitDeclarations(host, resolver, diagnostics, declarationFilePath, targetSourceFile);
|
||||
}
|
||||
return diagnostics;
|
||||
}
|
||||
|
||||
@ -105,7 +107,7 @@ namespace ts {
|
||||
// Emit references corresponding to this file
|
||||
let emittedReferencedFiles: SourceFile[] = [];
|
||||
forEach(host.getSourceFiles(), sourceFile => {
|
||||
if (!isExternalModuleOrDeclarationFile(sourceFile)) {
|
||||
if (!isExternalModuleOrDeclarationFile(sourceFile) && !isJavaScript(sourceFile.fileName)) {
|
||||
// Check what references need to be added
|
||||
if (!compilerOptions.noResolve) {
|
||||
forEach(sourceFile.referencedFiles, fileReference => {
|
||||
@ -1590,9 +1592,17 @@ namespace ts {
|
||||
}
|
||||
|
||||
function writeReferencePath(referencedFile: SourceFile) {
|
||||
let declFileName = referencedFile.flags & NodeFlags.DeclarationFile
|
||||
? referencedFile.fileName // Declaration file, use declaration file name
|
||||
: getEmitFileNames(referencedFile, host).declarationFilePath; // declaration file name
|
||||
let declFileName: string;
|
||||
if (referencedFile.flags & NodeFlags.DeclarationFile) {
|
||||
// Declaration file, use declaration file name
|
||||
declFileName = referencedFile.fileName;
|
||||
}
|
||||
else {
|
||||
// declaration file name
|
||||
let { declarationFilePath, jsFilePath } = getEmitFileNames(referencedFile, host);
|
||||
Debug.assert(!!declarationFilePath || isJavaScript(referencedFile.fileName), "Declaration file is not present only for javascript files");
|
||||
declFileName = declarationFilePath || jsFilePath;
|
||||
}
|
||||
|
||||
declFileName = getRelativePathToDirectoryOrUrl(
|
||||
getDirectoryPath(normalizeSlashes(declarationFilePath)),
|
||||
|
||||
@ -8158,7 +8158,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emitJavaScript(jsFilePath, sourceMapFilePath, sourceFile);
|
||||
}
|
||||
|
||||
if (compilerOptions.declaration) {
|
||||
if (declarationFilePath) {
|
||||
emitSkipped = writeDeclarationFile(declarationFilePath, sourceFile, host, resolver, diagnostics) || emitSkipped;
|
||||
}
|
||||
|
||||
|
||||
@ -1272,7 +1272,7 @@ namespace ts {
|
||||
if (sourceMapFilePath) {
|
||||
emitFilesSeen[sourceMapFilePath] = [file];
|
||||
}
|
||||
if (options.declaration) {
|
||||
if (declarationFilePath) {
|
||||
emitFilesSeen[declarationFilePath] = [file];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1797,7 +1797,7 @@ namespace ts {
|
||||
return {
|
||||
jsFilePath,
|
||||
sourceMapFilePath: getSourceMapFilePath(jsFilePath, options),
|
||||
declarationFilePath: getDeclarationEmitFilePath(jsFilePath, options)
|
||||
declarationFilePath: !isJavaScript(sourceFile.fileName) ? getDeclarationEmitFilePath(jsFilePath, options) : undefined
|
||||
};
|
||||
}
|
||||
else if (options.outFile || options.out) {
|
||||
|
||||
@ -13,4 +13,3 @@ var x = "hello"; // No error is recorded here and declaration file will show thi
|
||||
|
||||
//// [out.d.ts]
|
||||
declare var x: number;
|
||||
declare var x: number;
|
||||
|
||||
@ -13,4 +13,3 @@ var x = 10; // Error reported so no declaration file generated?
|
||||
|
||||
//// [out.d.ts]
|
||||
declare var x: string;
|
||||
declare var x: string;
|
||||
|
||||
@ -22,4 +22,3 @@ function foo() {
|
||||
//// [out.d.ts]
|
||||
declare class c {
|
||||
}
|
||||
declare function foo(): void;
|
||||
|
||||
@ -29,5 +29,3 @@ function foo() {
|
||||
//// [out.d.ts]
|
||||
declare class c {
|
||||
}
|
||||
declare function bar(): void;
|
||||
declare function foo(): void;
|
||||
|
||||
@ -8,7 +8,7 @@ error TS5055: Cannot write file 'tests/cases/compiler/c.js' which is one of the
|
||||
|
||||
==== tests/cases/compiler/b.ts (0 errors) ====
|
||||
/// <reference path="c.js"/>
|
||||
// error on above reference path when emitting declarations
|
||||
// b.d.ts should have c.js as the reference path since we dont emit declarations for js files
|
||||
function foo() {
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ class c {
|
||||
|
||||
//// [b.ts]
|
||||
/// <reference path="c.js"/>
|
||||
// error on above reference path when emitting declarations
|
||||
// b.d.ts should have c.js as the reference path since we dont emit declarations for js files
|
||||
function foo() {
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ var c = (function () {
|
||||
})();
|
||||
//// [b.js]
|
||||
/// <reference path="c.js"/>
|
||||
// error on above reference path when emitting declarations
|
||||
// b.d.ts should have c.js as the reference path since we dont emit declarations for js files
|
||||
function foo() {
|
||||
}
|
||||
|
||||
@ -30,8 +30,6 @@ function foo() {
|
||||
//// [a.d.ts]
|
||||
declare class c {
|
||||
}
|
||||
//// [c.d.ts]
|
||||
declare function bar(): void;
|
||||
//// [b.d.ts]
|
||||
/// <reference path="c.d.ts" />
|
||||
/// <reference path="c.js" />
|
||||
declare function foo(): void;
|
||||
|
||||
@ -31,5 +31,4 @@ function foo() {
|
||||
//// [out.d.ts]
|
||||
declare class c {
|
||||
}
|
||||
declare function bar(): void;
|
||||
declare function foo(): void;
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
class c {
|
||||
>c : Symbol(c, Decl(a.ts, 0, 0))
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
/// <reference path="c.js"/>
|
||||
// b.d.ts should have c.js as the reference path since we dont emit declarations for js files
|
||||
function foo() {
|
||||
>foo : Symbol(foo, Decl(b.ts, 0, 0))
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/c.js ===
|
||||
function bar() {
|
||||
>bar : Symbol(bar, Decl(c.js, 0, 0))
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
class c {
|
||||
>c : c
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
/// <reference path="c.js"/>
|
||||
// b.d.ts should have c.js as the reference path since we dont emit declarations for js files
|
||||
function foo() {
|
||||
>foo : () => void
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/c.js ===
|
||||
function bar() {
|
||||
>bar : () => void
|
||||
}
|
||||
@ -17,5 +17,4 @@ a = 10;
|
||||
|
||||
|
||||
//// [out.d.ts]
|
||||
declare let a: number;
|
||||
declare let b: number;
|
||||
|
||||
@ -17,4 +17,3 @@ b = 30;
|
||||
|
||||
//// [out.d.ts]
|
||||
declare let b: number;
|
||||
declare let a: number;
|
||||
|
||||
@ -1,2 +1 @@
|
||||
declare var test: number;
|
||||
declare var test2: number;
|
||||
|
||||
@ -1,2 +1 @@
|
||||
declare var test: number;
|
||||
declare var test2: number;
|
||||
|
||||
@ -1,2 +1 @@
|
||||
declare var test: number;
|
||||
declare var test2: number;
|
||||
|
||||
@ -1,2 +1 @@
|
||||
declare var test: number;
|
||||
declare var test2: number;
|
||||
|
||||
@ -6,7 +6,7 @@ class c {
|
||||
|
||||
// @filename: b.ts
|
||||
/// <reference path="c.js"/>
|
||||
// error on above reference path when emitting declarations
|
||||
// b.d.ts should have c.js as the reference path since we dont emit declarations for js files
|
||||
function foo() {
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
// @allowJs: true
|
||||
// @declaration: true
|
||||
// @outDir: outDir
|
||||
// @filename: a.ts
|
||||
class c {
|
||||
}
|
||||
|
||||
// @filename: b.ts
|
||||
/// <reference path="c.js"/>
|
||||
// b.d.ts should have c.js as the reference path since we dont emit declarations for js files
|
||||
function foo() {
|
||||
}
|
||||
|
||||
// @filename: c.js
|
||||
function bar() {
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user