mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 11:54:44 -06:00
Merge pull request #15229 from Microsoft/Fix15220
Fix #15220: Check for file on diagnostics before getting line map
This commit is contained in:
commit
e6ecfa46f0
@ -20487,7 +20487,7 @@ namespace ts {
|
||||
errorMessage = Diagnostics.Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function;
|
||||
}
|
||||
|
||||
error(derived.valueDeclaration.name, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type));
|
||||
error(derived.valueDeclaration.name || derived.valueDeclaration, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -930,20 +930,22 @@ namespace ts {
|
||||
*/
|
||||
function shouldReportDiagnostic(diagnostic: Diagnostic) {
|
||||
const { file, start } = diagnostic;
|
||||
const lineStarts = getLineStarts(file);
|
||||
let { line } = computeLineAndCharacterOfPosition(lineStarts, start);
|
||||
while (line > 0) {
|
||||
const previousLineText = file.text.slice(lineStarts[line - 1], lineStarts[line]);
|
||||
const result = ignoreDiagnosticCommentRegEx.exec(previousLineText);
|
||||
if (!result) {
|
||||
// non-empty line
|
||||
return true;
|
||||
if (file) {
|
||||
const lineStarts = getLineStarts(file);
|
||||
let { line } = computeLineAndCharacterOfPosition(lineStarts, start);
|
||||
while (line > 0) {
|
||||
const previousLineText = file.text.slice(lineStarts[line - 1], lineStarts[line]);
|
||||
const result = ignoreDiagnosticCommentRegEx.exec(previousLineText);
|
||||
if (!result) {
|
||||
// non-empty line
|
||||
return true;
|
||||
}
|
||||
if (result[3]) {
|
||||
// @ts-ignore
|
||||
return false;
|
||||
}
|
||||
line--;
|
||||
}
|
||||
if (result[3]) {
|
||||
// @ts-ignore
|
||||
return false;
|
||||
}
|
||||
line--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
tests/cases/compiler/a.js(14,5): error TS2424: Class 'A' defines instance member function 'foo', but extended class 'B' defines it as instance member property.
|
||||
|
||||
|
||||
==== tests/cases/compiler/a.js (1 errors) ====
|
||||
// @ts-check
|
||||
class A {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
foo() {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor() {
|
||||
super();
|
||||
this.foo = () => 3;
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2424: Class 'A' defines instance member function 'foo', but extended class 'B' defines it as instance member property.
|
||||
}
|
||||
}
|
||||
|
||||
const i = new B();
|
||||
i.foo();
|
||||
24
tests/cases/compiler/checkJsFiles_noErrorLocation.ts
Normal file
24
tests/cases/compiler/checkJsFiles_noErrorLocation.ts
Normal file
@ -0,0 +1,24 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
|
||||
// @fileName: a.js
|
||||
// @ts-check
|
||||
class A {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
foo() {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor() {
|
||||
super();
|
||||
this.foo = () => 3;
|
||||
}
|
||||
}
|
||||
|
||||
const i = new B();
|
||||
i.foo();
|
||||
Loading…
x
Reference in New Issue
Block a user