Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25740,9 +25740,7 @@ namespace ts {
return getTypeOfSymbol(symbol);
}

// We should only mark aliases as referenced if there isn't a local value declaration
// for the symbol. Also, don't mark any property access expression LHS - checkPropertyAccessExpression will handle that
if (!(node.parent && isPropertyAccessExpression(node.parent) && node.parent.expression === node)) {
if (shouldMarkIdentifierAliasReferenced(node)) {
markAliasReferenced(symbol, node);
}

Expand Down Expand Up @@ -25890,6 +25888,25 @@ namespace ts {
return assignmentKind ? getBaseTypeOfLiteralType(flowType) : flowType;
}

function shouldMarkIdentifierAliasReferenced(node: Identifier): boolean {
const parent = node.parent;
if (parent) {
// A property access expression LHS? checkPropertyAccessExpression will handle that.
if (isPropertyAccessExpression(parent) && parent.expression === node) {
return false;
}
// Next two check for an identifier inside a type only export.
if (isExportSpecifier(parent) && parent.isTypeOnly) {
return false;
}
const greatGrandparent = parent.parent?.parent;
if (greatGrandparent && isExportDeclaration(greatGrandparent) && greatGrandparent.isTypeOnly) {
return false;
}
}
return true;
}

function isInsideFunctionOrInstancePropertyInitializer(node: Node, threshold: Node): boolean {
return !!findAncestor(node, n => n === threshold ? "quit" : isFunctionLike(n) || (
n.parent && isPropertyDeclaration(n.parent) && !hasStaticModifier(n.parent) && n.parent.initializer === n
Expand Down Expand Up @@ -41225,7 +41242,9 @@ namespace ts {
error(exportedName, Diagnostics.Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module, idText(exportedName));
}
else {
markExportAsReferenced(node);
if (!node.isTypeOnly && !node.parent.parent.isTypeOnly) {
markExportAsReferenced(node);
}
const target = symbol && (symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol);
if (!target || target === unknownSymbol || target.flags & SymbolFlags.Value) {
checkExpressionCached(node.propertyName || node.name);
Expand Down
14 changes: 14 additions & 0 deletions src/testRunner/unittests/services/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,5 +485,19 @@ export { a as alias };
export * as alias from './file';`, {
noSetFileName: true
});

transpilesCorrectly("Elides import equals referenced only by export type",
`import IFoo = Namespace.IFoo;` +
`export type { IFoo };`, {
options: { compilerOptions: { module: ModuleKind.CommonJS } }
}
);

transpilesCorrectly("Elides import equals referenced only by type only export specifier",
`import IFoo = Namespace.IFoo;` +
`export { type IFoo };`, {
options: { compilerOptions: { module: ModuleKind.CommonJS } }
}
);
});
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.