@@ -2361,7 +2361,7 @@ namespace ts {
2361
2361
return links.target;
2362
2362
}
2363
2363
2364
- function markExportAsReferenced(node: ImportEqualsDeclaration | ExportAssignment | ExportSpecifier) {
2364
+ function markExportAsReferenced(node: ImportEqualsDeclaration | ExportSpecifier) {
2365
2365
const symbol = getSymbolOfNode(node);
2366
2366
const target = resolveAlias(symbol);
2367
2367
if (target) {
@@ -2383,15 +2383,10 @@ namespace ts {
2383
2383
links.referenced = true;
2384
2384
const node = getDeclarationOfAliasSymbol(symbol);
2385
2385
if (!node) return Debug.fail();
2386
- if (node.kind === SyntaxKind.ExportAssignment) {
2387
- // export default <symbol>
2388
- checkExpressionCached((<ExportAssignment>node).expression);
2389
- }
2390
- else if (node.kind === SyntaxKind.ExportSpecifier) {
2391
- // export { <symbol> } or export { <symbol> as foo }
2392
- checkExpressionCached((<ExportSpecifier>node).propertyName || (<ExportSpecifier>node).name);
2393
- }
2394
- else if (isInternalModuleImportEqualsDeclaration(node)) {
2386
+ // We defer checking of the reference of an `import =` until the import itself is referenced,
2387
+ // This way a chain of imports can be elided if ultimately the final input is only used in a type
2388
+ // position.
2389
+ if (isInternalModuleImportEqualsDeclaration(node)) {
2395
2390
// import foo = <symbol>
2396
2391
checkExpressionCached(<Expression>node.moduleReference);
2397
2392
}
@@ -17815,7 +17810,7 @@ namespace ts {
17815
17810
}
17816
17811
17817
17812
function markAliasReferenced(symbol: Symbol, location: Node) {
17818
- if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(location) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) {
17813
+ if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(location) && (compilerOptions.preserveConstEnums || !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol) ))) {
17819
17814
markAliasSymbolAsReferenced(symbol);
17820
17815
}
17821
17816
}
@@ -20326,8 +20321,8 @@ namespace ts {
20326
20321
// if jsx emit was not react as there wont be error being emitted
20327
20322
reactSym.isReferenced = SymbolFlags.All;
20328
20323
20329
- // If react symbol is alias, mark it as referenced
20330
- if (reactSym.flags & SymbolFlags.Alias && !isConstEnumOrConstEnumOnlyModule(resolveAlias(reactSym)) ) {
20324
+ // If react symbol is alias, mark it as refereced
20325
+ if (reactSym.flags & SymbolFlags.Alias) {
20331
20326
markAliasSymbolAsReferenced(reactSym);
20332
20327
}
20333
20328
}
@@ -24878,7 +24873,7 @@ namespace ts {
24878
24873
return result;
24879
24874
}
24880
24875
24881
- function checkExpressionCached(node: Expression, checkMode?: CheckMode): Type {
24876
+ function checkExpressionCached(node: Expression | QualifiedName , checkMode?: CheckMode): Type {
24882
24877
const links = getNodeLinks(node);
24883
24878
if (!links.resolvedType) {
24884
24879
if (checkMode && checkMode !== CheckMode.Normal) {
@@ -25206,7 +25201,8 @@ namespace ts {
25206
25201
(node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).expression === node) ||
25207
25202
(node.parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>node.parent).expression === node) ||
25208
25203
((node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName) && isInRightSideOfImportOrExportAssignment(<Identifier>node) ||
25209
- (node.parent.kind === SyntaxKind.TypeQuery && (<TypeQueryNode>node.parent).exprName === node));
25204
+ (node.parent.kind === SyntaxKind.TypeQuery && (<TypeQueryNode>node.parent).exprName === node)) ||
25205
+ (node.parent.kind === SyntaxKind.ExportSpecifier); // We allow reexporting const enums
25210
25206
25211
25207
if (!ok) {
25212
25208
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);
@@ -30145,6 +30141,10 @@ namespace ts {
30145
30141
}
30146
30142
else {
30147
30143
markExportAsReferenced(node);
30144
+ const target = symbol && (symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol);
30145
+ if (!target || target === unknownSymbol || target.flags & SymbolFlags.Value) {
30146
+ checkExpressionCached(node.propertyName || node.name);
30147
+ }
30148
30148
}
30149
30149
}
30150
30150
}
@@ -30171,7 +30171,17 @@ namespace ts {
30171
30171
grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers);
30172
30172
}
30173
30173
if (node.expression.kind === SyntaxKind.Identifier) {
30174
- markExportAsReferenced(node);
30174
+ const id = node.expression as Identifier;
30175
+ const sym = resolveEntityName(id, SymbolFlags.All, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, node);
30176
+ if (sym) {
30177
+ markAliasReferenced(sym, id);
30178
+ // If not a value, we're interpreting the identifier as a type export, along the lines of (`export { Id as default }`)
30179
+ const target = sym.flags & SymbolFlags.Alias ? resolveAlias(sym) : sym;
30180
+ if (target === unknownSymbol || target.flags & SymbolFlags.Value) {
30181
+ // However if it is a value, we need to check it's being used correctly
30182
+ checkExpressionCached(node.expression);
30183
+ }
30184
+ }
30175
30185
30176
30186
if (getEmitDeclarations(compilerOptions)) {
30177
30187
collectLinkedAliases(node.expression as Identifier, /*setVisibility*/ true);
0 commit comments