Skip to content

Commit 0a9b218

Browse files
Report exact position of invalid characters in scanner (#44671)
1 parent 0e905be commit 0a9b218

10 files changed

+14
-13
lines changed

src/compiler/scanner.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,8 +2063,9 @@ namespace ts {
20632063
pos += charSize(ch);
20642064
continue;
20652065
}
2066-
error(Diagnostics.Invalid_character);
2067-
pos += charSize(ch);
2066+
const size = charSize(ch);
2067+
error(Diagnostics.Invalid_character, pos, size);
2068+
pos += size;
20682069
return token = SyntaxKind.Unknown;
20692070
}
20702071
}

tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration
1212
if (a) ¬ * bar;
1313
~
1414
!!! error TS2304: Cannot find name 'a'.
15-
15+
~
1616
!!! error TS1127: Invalid character.
1717
~
1818
!!! error TS1109: Expression expected.

tests/baselines/reference/emitBOM.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ tests/cases/compiler/emitBOM.js(1,3): error TS1127: Invalid character.
88

99
==== tests/cases/compiler/emitBOM.js (2 errors) ====
1010
// JS and d.ts output should have a BOM but not the sourcemap
11-
11+
~
1212
!!! error TS1127: Invalid character.
13-
13+
~
1414
!!! error TS1127: Invalid character.
1515
var x;
1616
//# sourceMappingURL=emitBOM.js.map

tests/baselines/reference/parseErrorInHeritageClause1.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ tests/cases/compiler/parseErrorInHeritageClause1.ts(1,19): error TS1127: Invalid
66
class C extends A ¬ {
77
~
88
!!! error TS2304: Cannot find name 'A'.
9-
9+
~
1010
!!! error TS1127: Invalid character.
1111
}

tests/baselines/reference/parserErrorRecovery_Block2.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecov
44
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts (1 errors) ====
55
function f() {
66
¬
7-
7+
~
88
!!! error TS1127: Invalid character.
99
return;
1010
}

tests/baselines/reference/parserErrorRecovery_ClassElement3.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErr
77
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts (4 errors) ====
88
module M {
99
¬
10-
10+
~
1111
!!! error TS1127: Invalid character.
1212
class C {
1313
}
@@ -16,7 +16,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErr
1616
~~~~
1717
!!! error TS1109: Expression expected.
1818
¬
19-
19+
~
2020
!!! error TS1127: Invalid character.
2121

2222
!!! error TS1005: '}' expected.

tests/baselines/reference/parserErrorRecovery_ParameterList4.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserEr
33

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

tests/baselines/reference/parserSkippedTokens16.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens16.t
2020
~
2121
!!! error TS1005: ';' expected.
2222
function Foo () ¬ { }
23-
23+
~
2424
!!! error TS1127: Invalid character.
2525
4+:5
2626
~
Binary file not shown.

tests/baselines/reference/unicodeIdentifierName2.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ tests/cases/compiler/unicodeIdentifierName2.ts(1,26): error TS1127: Invalid char
66

77
==== tests/cases/compiler/unicodeIdentifierName2.ts (4 errors) ====
88
var a₁ = "hello"; alert(a₁)
9-
9+
~
1010
!!! error TS1127: Invalid character.
1111
~
1212
!!! error TS1134: Variable declaration expected.
1313
~~~~~~~
1414
!!! error TS1134: Variable declaration expected.
15-
15+
~
1616
!!! error TS1127: Invalid character.

0 commit comments

Comments
 (0)