Report bind diagnostics, program diagnostics and file pre processing diagnostics in javascript file
Handles #5785
This commit is contained in:
parent
acedf3c247
commit
6b42712eb2
|
@ -661,19 +661,17 @@ namespace ts {
|
|||
}
|
||||
|
||||
function getSemanticDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
|
||||
// For JavaScript files, we don't want to report the normal typescript semantic errors.
|
||||
// Instead, we just report errors for using TypeScript-only constructs from within a
|
||||
// JavaScript file.
|
||||
if (isSourceFileJavaScript(sourceFile)) {
|
||||
return getJavaScriptSemanticDiagnosticsForFile(sourceFile, cancellationToken);
|
||||
}
|
||||
|
||||
return runWithCancellationToken(() => {
|
||||
const typeChecker = getDiagnosticsProducingTypeChecker();
|
||||
|
||||
Debug.assert(!!sourceFile.bindDiagnostics);
|
||||
const bindDiagnostics = sourceFile.bindDiagnostics;
|
||||
const checkDiagnostics = typeChecker.getDiagnostics(sourceFile, cancellationToken);
|
||||
// For JavaScript files, we don't want to report the normal typescript semantic errors.
|
||||
// Instead, we just report errors for using TypeScript-only constructs from within a
|
||||
// JavaScript file.
|
||||
const checkDiagnostics = isSourceFileJavaScript(sourceFile) ?
|
||||
getJavaScriptSemanticDiagnosticsForFile(sourceFile, cancellationToken) :
|
||||
typeChecker.getDiagnostics(sourceFile, cancellationToken);
|
||||
const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName);
|
||||
const programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName);
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
tests/cases/compiler/a.js(1,5): error TS2451: Cannot redeclare block-scoped variable 'C'.
|
||||
tests/cases/compiler/a.js(2,5): error TS2451: Cannot redeclare block-scoped variable 'C'.
|
||||
tests/cases/compiler/a.js(6,5): error TS7027: Unreachable code detected.
|
||||
tests/cases/compiler/a.js(11,9): error TS1100: Invalid use of 'arguments' in strict mode.
|
||||
|
||||
|
||||
==== tests/cases/compiler/a.js (4 errors) ====
|
||||
let C = "sss";
|
||||
~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'C'.
|
||||
let C = 0; // Error: Cannot redeclare block-scoped variable 'C'.
|
||||
~
|
||||
!!! error TS2451: Cannot redeclare block-scoped variable 'C'.
|
||||
|
||||
function f() {
|
||||
return;
|
||||
return; // Error: Unreachable code detected.
|
||||
~~~~~~
|
||||
!!! error TS7027: Unreachable code detected.
|
||||
}
|
||||
|
||||
function b() {
|
||||
"use strict";
|
||||
var arguments = 0; // Error: Invalid use of 'arguments' in strict mode.
|
||||
~~~~~~~~~
|
||||
!!! error TS1100: Invalid use of 'arguments' in strict mode.
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
=== tests/cases/compiler/a.js ===
|
||||
let C = "sss";
|
||||
>C : Symbol(C, Decl(a.js, 0, 3))
|
||||
|
||||
let C = 0; // Error: Cannot redeclare block-scoped variable 'C'.
|
||||
>C : Symbol(C, Decl(a.js, 1, 3))
|
||||
|
||||
function f() {
|
||||
>f : Symbol(f, Decl(a.js, 1, 10))
|
||||
|
||||
return;
|
||||
return; // Error: Unreachable code detected.
|
||||
}
|
||||
|
||||
function b() {
|
||||
>b : Symbol(b, Decl(a.js, 6, 1))
|
||||
|
||||
"use strict";
|
||||
var arguments = 0; // Error: Invalid use of 'arguments' in strict mode.
|
||||
>arguments : Symbol(arguments, Decl(a.js, 10, 7))
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
=== tests/cases/compiler/a.js ===
|
||||
let C = "sss";
|
||||
>C : string
|
||||
>"sss" : string
|
||||
|
||||
let C = 0; // Error: Cannot redeclare block-scoped variable 'C'.
|
||||
>C : number
|
||||
>0 : number
|
||||
|
||||
function f() {
|
||||
>f : () => void
|
||||
|
||||
return;
|
||||
return; // Error: Unreachable code detected.
|
||||
}
|
||||
|
||||
function b() {
|
||||
>b : () => void
|
||||
|
||||
"use strict";
|
||||
>"use strict" : string
|
||||
|
||||
var arguments = 0; // Error: Invalid use of 'arguments' in strict mode.
|
||||
>arguments : number
|
||||
>0 : number
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
|
||||
tests/cases/compiler/a.js(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided.
|
||||
tests/cases/compiler/a.js(1,1): error TS8003: 'export=' can only be used in a .ts file.
|
||||
|
||||
|
||||
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
|
||||
==== tests/cases/compiler/a.js (1 errors) ====
|
||||
==== tests/cases/compiler/a.js (2 errors) ====
|
||||
export = b;
|
||||
~~~~~~~~~~~
|
||||
!!! error TS1148: Cannot compile modules unless the '--module' flag is provided.
|
||||
~~~~~~~~~~~
|
||||
!!! error TS8003: 'export=' can only be used in a .ts file.
|
|
@ -11,5 +11,12 @@ verify.getSemanticDiagnostics(`[
|
|||
"length": 11,
|
||||
"category": "error",
|
||||
"code": 8003
|
||||
},
|
||||
{
|
||||
"message": "Cannot compile modules unless the '--module' flag is provided.",
|
||||
"start": 0,
|
||||
"length": 11,
|
||||
"category": "error",
|
||||
"code": 1148
|
||||
}
|
||||
]`);
|
Loading…
Reference in a new issue