@@ -1592,18 +1592,34 @@ namespace ts {
1592
1592
if (declaration === undefined) return Debug.fail("Declaration to checkResolvedBlockScopedVariable is undefined");
1593
1593
1594
1594
if (!(declaration.flags & NodeFlags.Ambient) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
1595
+ let err;
1596
+ const declarationName = declarationNameToString(getNameOfDeclaration(declaration));
1595
1597
if (result.flags & SymbolFlags.BlockScopedVariable) {
1596
- error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationNameToString(getNameOfDeclaration(declaration)) );
1598
+ err = error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationName );
1597
1599
}
1598
1600
else if (result.flags & SymbolFlags.Class) {
1599
- error(errorLocation, Diagnostics.Class_0_used_before_its_declaration, declarationNameToString(getNameOfDeclaration(declaration)) );
1601
+ err = error(errorLocation, Diagnostics.Class_0_used_before_its_declaration, declarationName );
1600
1602
}
1601
1603
else if (result.flags & SymbolFlags.RegularEnum) {
1602
- error(errorLocation, Diagnostics.Enum_0_used_before_its_declaration, declarationNameToString(getNameOfDeclaration(declaration)));
1604
+ err = error(errorLocation, Diagnostics.Enum_0_used_before_its_declaration, declarationName);
1605
+ }
1606
+ else {
1607
+ Debug.assert(!!(result.flags & SymbolFlags.ConstEnum));
1608
+ }
1609
+
1610
+ if (err) {
1611
+ placeRelatedSpanOnLaterDeclaration(declarationName, declaration, err);
1603
1612
}
1604
1613
}
1605
1614
}
1606
1615
1616
+ function placeRelatedSpanOnLaterDeclaration(declarationName: string, declarationLocation: Declaration, diagnostic: Diagnostic) {
1617
+ Debug.assert(!diagnostic.relatedInformation);
1618
+ diagnostic.relatedInformation = [
1619
+ createDiagnosticForNode(declarationLocation, Diagnostics._0_was_declared_here, declarationName)
1620
+ ];
1621
+ }
1622
+
1607
1623
/* Starting from 'initial' node walk up the parent chain until 'stopAt' node is reached.
1608
1624
* If at any point current node is equal to 'parent' node - return true.
1609
1625
* Return false if 'stopAt' node is reached or isFunctionLike(current) === true.
@@ -17397,16 +17413,22 @@ namespace ts {
17397
17413
return;
17398
17414
}
17399
17415
17416
+ let err;
17417
+ const declarationName = idText(right);
17400
17418
if (isInPropertyInitializer(node) &&
17401
17419
!isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)
17402
17420
&& !isPropertyDeclaredInAncestorClass(prop)) {
17403
- error(right, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, idText(right) );
17421
+ err = error(right, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationName );
17404
17422
}
17405
17423
else if (valueDeclaration.kind === SyntaxKind.ClassDeclaration &&
17406
17424
node.parent.kind !== SyntaxKind.TypeReference &&
17407
17425
!(valueDeclaration.flags & NodeFlags.Ambient) &&
17408
17426
!isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)) {
17409
- error(right, Diagnostics.Class_0_used_before_its_declaration, idText(right));
17427
+ err = error(right, Diagnostics.Class_0_used_before_its_declaration, declarationName);
17428
+ }
17429
+
17430
+ if (err) {
17431
+ placeRelatedSpanOnLaterDeclaration(declarationName, valueDeclaration, err);
17410
17432
}
17411
17433
}
17412
17434
@@ -19020,8 +19042,8 @@ namespace ts {
19020
19042
if (importNode && !isImportCall(importNode)) {
19021
19043
const sigs = getSignaturesOfType(getTypeOfSymbol(getSymbolLinks(apparentType.symbol).target!), kind);
19022
19044
if (!sigs || !sigs.length) return;
19023
- diagnostic.relatedInformation = diagnostic.relatedInformation || [] ;
19024
- diagnostic.relatedInformation.push( createDiagnosticForNode(importNode, Diagnostics.Type_originates_at_this_import_A_namespace_style_import_cannot_be_called_or_constructed_and_will_cause_a_failure_at_runtime_Consider_using_a_default_import_or_import_require_here_instead)) ;
19045
+ Debug.assert(! diagnostic.relatedInformation) ;
19046
+ diagnostic.relatedInformation = [ createDiagnosticForNode(importNode, Diagnostics.Type_originates_at_this_import_A_namespace_style_import_cannot_be_called_or_constructed_and_will_cause_a_failure_at_runtime_Consider_using_a_default_import_or_import_require_here_instead)] ;
19025
19047
}
19026
19048
}
19027
19049
0 commit comments