mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Don’t create expando declarations on alias symbols (#39558)
* Don’t create expando declarations on alias symbols * Update other baseline * Fix brace nesting refactor mistake
This commit is contained in:
@@ -2980,6 +2980,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
function bindPotentiallyMissingNamespaces(namespaceSymbol: Symbol | undefined, entityName: BindableStaticNameExpression, isToplevel: boolean, isPrototypeProperty: boolean, containerIsClass: boolean) {
|
||||
if (namespaceSymbol?.flags! & SymbolFlags.Alias) {
|
||||
return namespaceSymbol;
|
||||
}
|
||||
if (isToplevel && !isPrototypeProperty) {
|
||||
// make symbols or add declarations for intermediate containers
|
||||
const flags = SymbolFlags.Module | SymbolFlags.Assignment;
|
||||
|
||||
@@ -35217,39 +35217,36 @@ namespace ts {
|
||||
const target = resolveAlias(symbol);
|
||||
|
||||
if (target !== unknownSymbol) {
|
||||
const shouldSkipWithJSExpandoTargets = symbol.flags & SymbolFlags.Assignment;
|
||||
if (!shouldSkipWithJSExpandoTargets) {
|
||||
// For external modules symbol represents local symbol for an alias.
|
||||
// This local symbol will merge any other local declarations (excluding other aliases)
|
||||
// and symbol.flags will contains combined representation for all merged declaration.
|
||||
// Based on symbol.flags we can compute a set of excluded meanings (meaning that resolved alias should not have,
|
||||
// otherwise it will conflict with some local declaration). Note that in addition to normal flags we include matching SymbolFlags.Export*
|
||||
// in order to prevent collisions with declarations that were exported from the current module (they still contribute to local names).
|
||||
symbol = getMergedSymbol(symbol.exportSymbol || symbol);
|
||||
const excludedMeanings =
|
||||
(symbol.flags & (SymbolFlags.Value | SymbolFlags.ExportValue) ? SymbolFlags.Value : 0) |
|
||||
(symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : 0) |
|
||||
(symbol.flags & SymbolFlags.Namespace ? SymbolFlags.Namespace : 0);
|
||||
if (target.flags & excludedMeanings) {
|
||||
const message = node.kind === SyntaxKind.ExportSpecifier ?
|
||||
Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 :
|
||||
Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0;
|
||||
error(node, message, symbolToString(symbol));
|
||||
}
|
||||
// For external modules, `symbol` represents the local symbol for an alias.
|
||||
// This local symbol will merge any other local declarations (excluding other aliases)
|
||||
// and symbol.flags will contains combined representation for all merged declaration.
|
||||
// Based on symbol.flags we can compute a set of excluded meanings (meaning that resolved alias should not have,
|
||||
// otherwise it will conflict with some local declaration). Note that in addition to normal flags we include matching SymbolFlags.Export*
|
||||
// in order to prevent collisions with declarations that were exported from the current module (they still contribute to local names).
|
||||
symbol = getMergedSymbol(symbol.exportSymbol || symbol);
|
||||
const excludedMeanings =
|
||||
(symbol.flags & (SymbolFlags.Value | SymbolFlags.ExportValue) ? SymbolFlags.Value : 0) |
|
||||
(symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : 0) |
|
||||
(symbol.flags & SymbolFlags.Namespace ? SymbolFlags.Namespace : 0);
|
||||
if (target.flags & excludedMeanings) {
|
||||
const message = node.kind === SyntaxKind.ExportSpecifier ?
|
||||
Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 :
|
||||
Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0;
|
||||
error(node, message, symbolToString(symbol));
|
||||
}
|
||||
|
||||
// Don't allow to re-export something with no value side when `--isolatedModules` is set.
|
||||
if (compilerOptions.isolatedModules
|
||||
&& node.kind === SyntaxKind.ExportSpecifier
|
||||
&& !node.parent.parent.isTypeOnly
|
||||
&& !(target.flags & SymbolFlags.Value)
|
||||
&& !(node.flags & NodeFlags.Ambient)) {
|
||||
error(node, Diagnostics.Re_exporting_a_type_when_the_isolatedModules_flag_is_provided_requires_using_export_type);
|
||||
}
|
||||
// Don't allow to re-export something with no value side when `--isolatedModules` is set.
|
||||
if (compilerOptions.isolatedModules
|
||||
&& node.kind === SyntaxKind.ExportSpecifier
|
||||
&& !node.parent.parent.isTypeOnly
|
||||
&& !(target.flags & SymbolFlags.Value)
|
||||
&& !(node.flags & NodeFlags.Ambient)) {
|
||||
error(node, Diagnostics.Re_exporting_a_type_when_the_isolatedModules_flag_is_provided_requires_using_export_type);
|
||||
}
|
||||
|
||||
if (isImportSpecifier(node) &&
|
||||
(target.valueDeclaration && target.valueDeclaration.flags & NodeFlags.Deprecated
|
||||
|| every(target.declarations, d => !!(d.flags & NodeFlags.Deprecated)))) {
|
||||
|| every(target.declarations, d => !!(d.flags & NodeFlags.Deprecated)))) {
|
||||
errorOrSuggestion(/* isError */ false, node.name, Diagnostics._0_is_deprecated, symbol.escapedName as string);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user