Skip to content

Report exact position of invalid characters in scanner #44671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2056,8 +2056,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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/emitBOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
Expand All @@ -16,7 +16,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErr
~~~~
!!! error TS1109: Expression expected.
¬

~
!!! error TS1127: Invalid character.

!!! error TS1005: '}' expected.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserSkippedTokens16.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens16.t
~
!!! error TS1005: ';' expected.
function Foo () ¬ { }

~
!!! error TS1127: Invalid character.
4+:5
~
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/baselines/reference/unicodeIdentifierName2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.