@@ -979,10 +979,7 @@ namespace ts {
979
979
}
980
980
981
981
function parseErrorAtCurrentToken ( message : DiagnosticMessage , arg0 ?: any ) : void {
982
- const start = scanner . getTokenPos ( ) ;
983
- const length = scanner . getTextPos ( ) - start ;
984
-
985
- parseErrorAtPosition ( start , length , message , arg0 ) ;
982
+ parseErrorAt ( scanner . getTokenPos ( ) , scanner . getTextPos ( ) , message , arg0 ) ;
986
983
}
987
984
988
985
function parseErrorAtPosition ( start : number , length : number , message : DiagnosticMessage , arg0 ?: any ) : void {
@@ -997,9 +994,16 @@ namespace ts {
997
994
parseErrorBeforeNextFinishedNode = true ;
998
995
}
999
996
1000
- function scanError ( message : DiagnosticMessage , length ?: number ) {
1001
- const pos = scanner . getTextPos ( ) ;
1002
- parseErrorAtPosition ( pos , length || 0 , message ) ;
997
+ function parseErrorAt ( start : number , end : number , message : DiagnosticMessage , arg0 ?: any ) : void {
998
+ parseErrorAtPosition ( start , end - start , message , arg0 ) ;
999
+ }
1000
+
1001
+ function parseErrorAtRange ( range : TextRange , message : DiagnosticMessage , arg0 ?: any ) : void {
1002
+ parseErrorAt ( range . pos , range . end , message , arg0 ) ;
1003
+ }
1004
+
1005
+ function scanError ( message : DiagnosticMessage , length : number ) : void {
1006
+ parseErrorAtPosition ( scanner . getTextPos ( ) , length , message ) ;
1003
1007
}
1004
1008
1005
1009
function getNodePos ( ) : number {
@@ -3809,12 +3813,13 @@ namespace ts {
3809
3813
const unaryOperator = token ( ) ;
3810
3814
const simpleUnaryExpression = parseSimpleUnaryExpression ( ) ;
3811
3815
if ( token ( ) === SyntaxKind . AsteriskAsteriskToken ) {
3812
- const start = skipTrivia ( sourceText , simpleUnaryExpression . pos ) ;
3816
+ const pos = skipTrivia ( sourceText , simpleUnaryExpression . pos ) ;
3817
+ const { end } = simpleUnaryExpression ;
3813
3818
if ( simpleUnaryExpression . kind === SyntaxKind . TypeAssertionExpression ) {
3814
- parseErrorAtPosition ( start , simpleUnaryExpression . end - start , Diagnostics . A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses ) ;
3819
+ parseErrorAt ( pos , end , Diagnostics . A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses ) ;
3815
3820
}
3816
3821
else {
3817
- parseErrorAtPosition ( start , simpleUnaryExpression . end - start , Diagnostics . An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses , tokenToString ( unaryOperator ) ) ;
3822
+ parseErrorAt ( pos , end , Diagnostics . An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses , tokenToString ( unaryOperator ) ) ;
3818
3823
}
3819
3824
}
3820
3825
return simpleUnaryExpression ;
@@ -4085,7 +4090,7 @@ namespace ts {
4085
4090
node . closingElement = parseJsxClosingElement ( inExpressionContext ) ;
4086
4091
4087
4092
if ( ! tagNamesAreEquivalent ( node . openingElement . tagName , node . closingElement . tagName ) ) {
4088
- parseErrorAtPosition ( node . closingElement . pos , node . closingElement . end - node . closingElement . pos , Diagnostics . Expected_corresponding_JSX_closing_tag_for_0 , getTextOfNodeFromSourceText ( sourceText , node . openingElement . tagName ) ) ;
4093
+ parseErrorAtRange ( node . closingElement , Diagnostics . Expected_corresponding_JSX_closing_tag_for_0 , getTextOfNodeFromSourceText ( sourceText , node . openingElement . tagName ) ) ;
4089
4094
}
4090
4095
4091
4096
result = finishNode ( node ) ;
@@ -4141,11 +4146,10 @@ namespace ts {
4141
4146
// If we hit EOF, issue the error at the tag that lacks the closing element
4142
4147
// rather than at the end of the file (which is useless)
4143
4148
if ( isJsxOpeningFragment ( openingTag ) ) {
4144
- parseErrorAtPosition ( openingTag . pos , openingTag . end - openingTag . pos , Diagnostics . JSX_fragment_has_no_corresponding_closing_tag ) ;
4149
+ parseErrorAtRange ( openingTag , Diagnostics . JSX_fragment_has_no_corresponding_closing_tag ) ;
4145
4150
}
4146
4151
else {
4147
- const openingTagName = openingTag . tagName ;
4148
- parseErrorAtPosition ( openingTagName . pos , openingTagName . end - openingTagName . pos , Diagnostics . JSX_element_0_has_no_corresponding_closing_tag , getTextOfNodeFromSourceText ( sourceText , openingTagName ) ) ;
4152
+ parseErrorAtRange ( openingTag . tagName , Diagnostics . JSX_element_0_has_no_corresponding_closing_tag , getTextOfNodeFromSourceText ( sourceText , openingTag . tagName ) ) ;
4149
4153
}
4150
4154
return undefined ;
4151
4155
case SyntaxKind . LessThanSlashToken :
@@ -4317,8 +4321,7 @@ namespace ts {
4317
4321
const node = < JsxClosingFragment > createNode ( SyntaxKind . JsxClosingFragment ) ;
4318
4322
parseExpected ( SyntaxKind . LessThanSlashToken ) ;
4319
4323
if ( tokenIsIdentifierOrKeyword ( token ( ) ) ) {
4320
- const unexpectedTagName = parseJsxElementName ( ) ;
4321
- parseErrorAtPosition ( unexpectedTagName . pos , unexpectedTagName . end - unexpectedTagName . pos , Diagnostics . Expected_corresponding_closing_tag_for_JSX_fragment ) ;
4324
+ parseErrorAtRange ( parseJsxElementName ( ) , Diagnostics . Expected_corresponding_closing_tag_for_JSX_fragment ) ;
4322
4325
}
4323
4326
if ( inExpressionContext ) {
4324
4327
parseExpected ( SyntaxKind . GreaterThanToken ) ;
@@ -6066,8 +6069,7 @@ namespace ts {
6066
6069
node . name = identifierName ;
6067
6070
}
6068
6071
if ( kind === SyntaxKind . ImportSpecifier && checkIdentifierIsKeyword ) {
6069
- // Report error identifier expected
6070
- parseErrorAtPosition ( checkIdentifierStart , checkIdentifierEnd - checkIdentifierStart , Diagnostics . Identifier_expected ) ;
6072
+ parseErrorAt ( checkIdentifierStart , checkIdentifierEnd , Diagnostics . Identifier_expected ) ;
6071
6073
}
6072
6074
return finishNode ( node ) ;
6073
6075
}
@@ -6591,7 +6593,7 @@ namespace ts {
6591
6593
6592
6594
function parseReturnTag ( atToken : AtToken , tagName : Identifier ) : JSDocReturnTag {
6593
6595
if ( forEach ( tags , t => t . kind === SyntaxKind . JSDocReturnTag ) ) {
6594
- parseErrorAtPosition ( tagName . pos , scanner . getTokenPos ( ) - tagName . pos , Diagnostics . _0_tag_already_specified , tagName . escapedText ) ;
6596
+ parseErrorAt ( tagName . pos , scanner . getTokenPos ( ) , Diagnostics . _0_tag_already_specified , tagName . escapedText ) ;
6595
6597
}
6596
6598
6597
6599
const result = < JSDocReturnTag > createNode ( SyntaxKind . JSDocReturnTag , atToken . pos ) ;
@@ -6603,7 +6605,7 @@ namespace ts {
6603
6605
6604
6606
function parseTypeTag ( atToken : AtToken , tagName : Identifier ) : JSDocTypeTag {
6605
6607
if ( forEach ( tags , t => t . kind === SyntaxKind . JSDocTypeTag ) ) {
6606
- parseErrorAtPosition ( tagName . pos , scanner . getTokenPos ( ) - tagName . pos , Diagnostics . _0_tag_already_specified , tagName . escapedText ) ;
6608
+ parseErrorAt ( tagName . pos , scanner . getTokenPos ( ) , Diagnostics . _0_tag_already_specified , tagName . escapedText ) ;
6607
6609
}
6608
6610
6609
6611
const result = < JSDocTypeTag > createNode ( SyntaxKind . JSDocTypeTag , atToken . pos ) ;
@@ -6813,7 +6815,7 @@ namespace ts {
6813
6815
6814
6816
function parseTemplateTag ( atToken : AtToken , tagName : Identifier ) : JSDocTemplateTag | undefined {
6815
6817
if ( some ( tags , isJSDocTemplateTag ) ) {
6816
- parseErrorAtPosition ( tagName . pos , scanner . getTokenPos ( ) - tagName . pos , Diagnostics . _0_tag_already_specified , tagName . escapedText ) ;
6818
+ parseErrorAt ( tagName . pos , scanner . getTokenPos ( ) , Diagnostics . _0_tag_already_specified , tagName . escapedText ) ;
6817
6819
}
6818
6820
6819
6821
// Type parameter list looks like '@template T,U,V'
0 commit comments