mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
Fix #3245: ensure transpile diagnostics only include syntactic and compiler options diagnostics
This commit is contained in:
@@ -10,9 +10,6 @@ module ts {
|
||||
/** The version of the TypeScript compiler release */
|
||||
export const version = "1.5.3";
|
||||
|
||||
const carriageReturnLineFeed = "\r\n";
|
||||
const lineFeed = "\n";
|
||||
|
||||
export function findConfigFile(searchPath: string): string {
|
||||
var fileName = "tsconfig.json";
|
||||
while (true) {
|
||||
@@ -94,10 +91,7 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
let newLine =
|
||||
options.newLine === NewLineKind.CarriageReturnLineFeed ? carriageReturnLineFeed :
|
||||
options.newLine === NewLineKind.LineFeed ? lineFeed :
|
||||
sys.newLine;
|
||||
const newLine = getNewLineCharacter(options);
|
||||
|
||||
return {
|
||||
getSourceFile,
|
||||
@@ -175,6 +169,7 @@ module ts {
|
||||
getGlobalDiagnostics,
|
||||
getSemanticDiagnostics,
|
||||
getDeclarationDiagnostics,
|
||||
getCompilerOptionsDiagnostics,
|
||||
getTypeChecker,
|
||||
getDiagnosticsProducingTypeChecker,
|
||||
getCommonSourceDirectory: () => commonSourceDirectory,
|
||||
@@ -291,6 +286,12 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getCompilerOptionsDiagnostics(): Diagnostic[]{
|
||||
let allDiagnostics: Diagnostic[] = [];
|
||||
addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
|
||||
return sortAndDeduplicateDiagnostics(allDiagnostics);
|
||||
}
|
||||
|
||||
function getGlobalDiagnostics(): Diagnostic[] {
|
||||
let typeChecker = getDiagnosticsProducingTypeChecker();
|
||||
|
||||
|
||||
@@ -1064,6 +1064,7 @@ module ts {
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
/* @internal */ getCompilerOptionsDiagnostics(): Diagnostic[];
|
||||
|
||||
/**
|
||||
* Gets a type checker that can be used to semantically analyze source fils in the program.
|
||||
|
||||
@@ -1774,6 +1774,21 @@ module ts {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const carriageReturnLineFeed = "\r\n";
|
||||
const lineFeed = "\n";
|
||||
export function getNewLineCharacter(options: CompilerOptions): string {
|
||||
if (options.newLine === NewLineKind.CarriageReturnLineFeed) {
|
||||
return carriageReturnLineFeed;
|
||||
}
|
||||
else if (options.newLine === NewLineKind.LineFeed) {
|
||||
return lineFeed;
|
||||
}
|
||||
else if (sys) {
|
||||
return sys.newLine
|
||||
}
|
||||
return carriageReturnLineFeed;
|
||||
}
|
||||
}
|
||||
|
||||
module ts {
|
||||
|
||||
@@ -1772,15 +1772,24 @@ module ts {
|
||||
// Filename can be non-ts file.
|
||||
options.allowNonTsExtensions = true;
|
||||
|
||||
// We are not returning a lib file when asked, so pass this flag to
|
||||
// avoid reporting a file not found error
|
||||
options.noLib = true;
|
||||
|
||||
// Similar to the library, we are not returning any refrenced files
|
||||
options.noResolve = true;
|
||||
|
||||
// Parse
|
||||
var inputFileName = fileName || "module.ts";
|
||||
var sourceFile = createSourceFile(inputFileName, input, options.target);
|
||||
let inputFileName = fileName || "module.ts";
|
||||
let sourceFile = createSourceFile(inputFileName, input, options.target);
|
||||
|
||||
// Store syntactic diagnostics
|
||||
if (diagnostics && sourceFile.parseDiagnostics) {
|
||||
diagnostics.push(...sourceFile.parseDiagnostics);
|
||||
}
|
||||
|
||||
let newLine = getNewLineCharacter(options);
|
||||
|
||||
// Output
|
||||
let outputText: string;
|
||||
|
||||
@@ -1795,13 +1804,13 @@ module ts {
|
||||
useCaseSensitiveFileNames: () => false,
|
||||
getCanonicalFileName: fileName => fileName,
|
||||
getCurrentDirectory: () => "",
|
||||
getNewLine: () => (sys && sys.newLine) || "\r\n"
|
||||
getNewLine: () => newLine
|
||||
};
|
||||
|
||||
var program = createProgram([inputFileName], options, compilerHost);
|
||||
|
||||
if (diagnostics) {
|
||||
diagnostics.push(...program.getGlobalDiagnostics());
|
||||
diagnostics.push(...program.getCompilerOptionsDiagnostics());
|
||||
}
|
||||
|
||||
// Emit
|
||||
|
||||
Reference in New Issue
Block a user