@@ -2069,7 +2069,7 @@ namespace ts {
2069
2069
return links.target;
2070
2070
}
2071
2071
2072
- function markExportAsReferenced(node: ImportEqualsDeclaration | ExportAssignment | ExportSpecifier) {
2072
+ function markExportAsReferenced(node: ImportEqualsDeclaration | ExportSpecifier) {
2073
2073
const symbol = getSymbolOfNode(node);
2074
2074
const target = resolveAlias(symbol);
2075
2075
if (target) {
@@ -2091,15 +2091,10 @@ namespace ts {
2091
2091
links.referenced = true;
2092
2092
const node = getDeclarationOfAliasSymbol(symbol);
2093
2093
if (!node) return Debug.fail();
2094
- if (node.kind === SyntaxKind.ExportAssignment) {
2095
- // export default <symbol>
2096
- checkExpressionCached((<ExportAssignment>node).expression);
2097
- }
2098
- else if (node.kind === SyntaxKind.ExportSpecifier) {
2099
- // export { <symbol> } or export { <symbol> as foo }
2100
- checkExpressionCached((<ExportSpecifier>node).propertyName || (<ExportSpecifier>node).name);
2101
- }
2102
- else if (isInternalModuleImportEqualsDeclaration(node)) {
2094
+ // We defer checking of the reference of an `import =` until the import itself is referenced,
2095
+ // This way a chain of imports can be elided if ultimately the final input is only used in a type
2096
+ // position.
2097
+ if (isInternalModuleImportEqualsDeclaration(node)) {
2103
2098
// import foo = <symbol>
2104
2099
checkExpressionCached(<Expression>node.moduleReference);
2105
2100
}
@@ -22472,7 +22467,7 @@ namespace ts {
22472
22467
return result;
22473
22468
}
22474
22469
22475
- function checkExpressionCached(node: Expression, checkMode?: CheckMode): Type {
22470
+ function checkExpressionCached(node: Expression | QualifiedName , checkMode?: CheckMode): Type {
22476
22471
const links = getNodeLinks(node);
22477
22472
if (!links.resolvedType) {
22478
22473
if (checkMode) {
@@ -22664,7 +22659,8 @@ namespace ts {
22664
22659
(node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).expression === node) ||
22665
22660
(node.parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>node.parent).expression === node) ||
22666
22661
((node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName) && isInRightSideOfImportOrExportAssignment(<Identifier>node) ||
22667
- (node.parent.kind === SyntaxKind.TypeQuery && (<TypeQueryNode>node.parent).exprName === node));
22662
+ (node.parent.kind === SyntaxKind.TypeQuery && (<TypeQueryNode>node.parent).exprName === node)) ||
22663
+ (node.parent.kind === SyntaxKind.ExportSpecifier); // We allow reexporting const enums
22668
22664
22669
22665
if (!ok) {
22670
22666
error(node, Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment_or_type_query);
@@ -27260,6 +27256,10 @@ namespace ts {
27260
27256
}
27261
27257
else {
27262
27258
markExportAsReferenced(node);
27259
+ const target = symbol && (symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol);
27260
+ if (!target || target === unknownSymbol || target.flags & SymbolFlags.Value) {
27261
+ checkExpressionCached(node.propertyName || node.name);
27262
+ }
27263
27263
}
27264
27264
}
27265
27265
}
@@ -27286,11 +27286,16 @@ namespace ts {
27286
27286
grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers);
27287
27287
}
27288
27288
if (node.expression.kind === SyntaxKind.Identifier) {
27289
- markExportAsReferenced(node);
27290
27289
const id = node.expression as Identifier;
27291
27290
const sym = resolveEntityName(id, SymbolFlags.All, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, node);
27292
27291
if (sym) {
27293
27292
markAliasReferenced(sym, id);
27293
+ // If not a value, we're interpreting the identifier as a type export, along the lines of (`export { Id as default }`)
27294
+ const target = sym.flags & SymbolFlags.Alias ? resolveAlias(sym) : sym;
27295
+ if (target === unknownSymbol || target.flags & SymbolFlags.Value) {
27296
+ // However if it is a value, we need to check it's being used correctly
27297
+ checkExpressionCached(node.expression);
27298
+ }
27294
27299
}
27295
27300
27296
27301
if (getEmitDeclarations(compilerOptions)) {
0 commit comments