@@ -1655,18 +1655,34 @@ namespace ts {
1655
1655
if (declaration === undefined) return Debug.fail("Declaration to checkResolvedBlockScopedVariable is undefined");
1656
1656
1657
1657
if (!(declaration.flags & NodeFlags.Ambient) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
1658
+ let err;
1659
+ const declarationName = declarationNameToString(getNameOfDeclaration(declaration));
1658
1660
if (result.flags & SymbolFlags.BlockScopedVariable) {
1659
- error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationNameToString(getNameOfDeclaration(declaration)) );
1661
+ err = error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationName );
1660
1662
}
1661
1663
else if (result.flags & SymbolFlags.Class) {
1662
- error(errorLocation, Diagnostics.Class_0_used_before_its_declaration, declarationNameToString(getNameOfDeclaration(declaration)) );
1664
+ err = error(errorLocation, Diagnostics.Class_0_used_before_its_declaration, declarationName );
1663
1665
}
1664
1666
else if (result.flags & SymbolFlags.RegularEnum) {
1665
- error(errorLocation, Diagnostics.Enum_0_used_before_its_declaration, declarationNameToString(getNameOfDeclaration(declaration)));
1667
+ err = error(errorLocation, Diagnostics.Enum_0_used_before_its_declaration, declarationName);
1668
+ }
1669
+ else {
1670
+ Debug.assert(!!(result.flags & SymbolFlags.ConstEnum));
1671
+ }
1672
+
1673
+ if (err) {
1674
+ placeRelatedSpanOnLaterDeclaration(declarationName, declaration, err);
1666
1675
}
1667
1676
}
1668
1677
}
1669
1678
1679
+ function placeRelatedSpanOnLaterDeclaration(declarationName: string, declarationLocation: Declaration, diagnostic: Diagnostic) {
1680
+ Debug.assert(!diagnostic.relatedInformation);
1681
+ diagnostic.relatedInformation = [
1682
+ createDiagnosticForNode(declarationLocation, Diagnostics._0_was_declared_here, declarationName)
1683
+ ];
1684
+ }
1685
+
1670
1686
/* Starting from 'initial' node walk up the parent chain until 'stopAt' node is reached.
1671
1687
* If at any point current node is equal to 'parent' node - return true.
1672
1688
* Return false if 'stopAt' node is reached or isFunctionLike(current) === true.
@@ -17460,16 +17476,22 @@ namespace ts {
17460
17476
return;
17461
17477
}
17462
17478
17479
+ let err;
17480
+ const declarationName = idText(right);
17463
17481
if (isInPropertyInitializer(node) &&
17464
17482
!isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)
17465
17483
&& !isPropertyDeclaredInAncestorClass(prop)) {
17466
- error(right, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, idText(right) );
17484
+ err = error(right, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationName );
17467
17485
}
17468
17486
else if (valueDeclaration.kind === SyntaxKind.ClassDeclaration &&
17469
17487
node.parent.kind !== SyntaxKind.TypeReference &&
17470
17488
!(valueDeclaration.flags & NodeFlags.Ambient) &&
17471
17489
!isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)) {
17472
- error(right, Diagnostics.Class_0_used_before_its_declaration, idText(right));
17490
+ err = error(right, Diagnostics.Class_0_used_before_its_declaration, declarationName);
17491
+ }
17492
+
17493
+ if (err) {
17494
+ placeRelatedSpanOnLaterDeclaration(declarationName, valueDeclaration, err);
17473
17495
}
17474
17496
}
17475
17497
@@ -19083,8 +19105,8 @@ namespace ts {
19083
19105
if (importNode && !isImportCall(importNode)) {
19084
19106
const sigs = getSignaturesOfType(getTypeOfSymbol(getSymbolLinks(apparentType.symbol).target!), kind);
19085
19107
if (!sigs || !sigs.length) return;
19086
- diagnostic.relatedInformation = diagnostic.relatedInformation || [] ;
19087
- 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)) ;
19108
+ Debug.assert(! diagnostic.relatedInformation) ;
19109
+ 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)] ;
19088
19110
}
19089
19111
}
19090
19112
0 commit comments