Skip to content

Commit f3ffdda

Browse files
committed
Move some functionality around, small cleanup
1 parent 0007ec7 commit f3ffdda

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/compiler/checker.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,7 @@ namespace ts {
20692069
return links.target;
20702070
}
20712071

2072-
function markExportAsReferenced(node: ImportEqualsDeclaration | ExportAssignment | ExportSpecifier) {
2072+
function markExportAsReferenced(node: ImportEqualsDeclaration | ExportSpecifier) {
20732073
const symbol = getSymbolOfNode(node);
20742074
const target = resolveAlias(symbol);
20752075
if (target) {
@@ -2091,15 +2091,10 @@ namespace ts {
20912091
links.referenced = true;
20922092
const node = getDeclarationOfAliasSymbol(symbol);
20932093
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)) {
21032098
// import foo = <symbol>
21042099
checkExpressionCached(<Expression>node.moduleReference);
21052100
}
@@ -22472,7 +22467,7 @@ namespace ts {
2247222467
return result;
2247322468
}
2247422469

22475-
function checkExpressionCached(node: Expression, checkMode?: CheckMode): Type {
22470+
function checkExpressionCached(node: Expression | QualifiedName, checkMode?: CheckMode): Type {
2247622471
const links = getNodeLinks(node);
2247722472
if (!links.resolvedType) {
2247822473
if (checkMode) {
@@ -22664,7 +22659,8 @@ namespace ts {
2266422659
(node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).expression === node) ||
2266522660
(node.parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>node.parent).expression === node) ||
2266622661
((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
2266822664

2266922665
if (!ok) {
2267022666
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 {
2726027256
}
2726127257
else {
2726227258
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+
}
2726327263
}
2726427264
}
2726527265
}
@@ -27286,11 +27286,16 @@ namespace ts {
2728627286
grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers);
2728727287
}
2728827288
if (node.expression.kind === SyntaxKind.Identifier) {
27289-
markExportAsReferenced(node);
2729027289
const id = node.expression as Identifier;
2729127290
const sym = resolveEntityName(id, SymbolFlags.All, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, node);
2729227291
if (sym) {
2729327292
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+
}
2729427299
}
2729527300

2729627301
if (getEmitDeclarations(compilerOptions)) {

0 commit comments

Comments
 (0)