Report exact position of invalid characters in scanner (#44671)

This commit is contained in:
Josh Goldberg 2021-06-21 17:23:14 -04:00 committed by GitHub
parent 0e905be42b
commit 0a9b218b11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 14 additions and 13 deletions

View file

@ -2063,8 +2063,9 @@ namespace ts {
pos += charSize(ch);
continue;
}
error(Diagnostics.Invalid_character);
pos += charSize(ch);
const size = charSize(ch);
error(Diagnostics.Invalid_character, pos, size);
pos += size;
return token = SyntaxKind.Unknown;
}
}

View file

@ -12,7 +12,7 @@ tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration
if (a) ¬ * bar;
~
!!! error TS2304: Cannot find name 'a'.
~
!!! error TS1127: Invalid character.
~
!!! error TS1109: Expression expected.

View file

@ -8,9 +8,9 @@ tests/cases/compiler/emitBOM.js(1,3): error TS1127: Invalid character.
==== tests/cases/compiler/emitBOM.js (2 errors) ====
// JS and d.ts output should have a BOM but not the sourcemap
~
!!! error TS1127: Invalid character.
~
!!! error TS1127: Invalid character.
var x;
//# sourceMappingURL=emitBOM.js.map

View file

@ -6,6 +6,6 @@ tests/cases/compiler/parseErrorInHeritageClause1.ts(1,19): error TS1127: Invalid
class C extends A ¬ {
~
!!! error TS2304: Cannot find name 'A'.
~
!!! error TS1127: Invalid character.
}

View file

@ -4,7 +4,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecov
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts (1 errors) ====
function f() {
¬
~
!!! error TS1127: Invalid character.
return;
}

View file

@ -7,7 +7,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErr
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts (4 errors) ====
module M {
¬
~
!!! error TS1127: Invalid character.
class C {
}
@ -16,7 +16,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErr
~~~~
!!! error TS1109: Expression expected.
¬
~
!!! error TS1127: Invalid character.
!!! error TS1005: '}' expected.

View file

@ -3,6 +3,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserEr
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts (1 errors) ====
function f(a,¬) {
~
!!! error TS1127: Invalid character.
}

View file

@ -20,7 +20,7 @@ tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens16.t
~
!!! error TS1005: ';' expected.
function Foo () ¬ { }
~
!!! error TS1127: Invalid character.
4+:5
~

View file

@ -6,11 +6,11 @@ tests/cases/compiler/unicodeIdentifierName2.ts(1,26): error TS1127: Invalid char
==== tests/cases/compiler/unicodeIdentifierName2.ts (4 errors) ====
var a₁ = "hello"; alert(a₁)
~
!!! error TS1127: Invalid character.
~
!!! error TS1134: Variable declaration expected.
~~~~~~~
!!! error TS1134: Variable declaration expected.
~
!!! error TS1127: Invalid character.