mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Make the implicitly exported rule consistent between checker and binder (#54659)
This commit is contained in:
@@ -87,6 +87,7 @@ import {
|
||||
getElementOrPropertyAccessName,
|
||||
getEmitScriptTarget,
|
||||
getEnclosingBlockScopeContainer,
|
||||
getEnclosingContainer,
|
||||
getErrorSpanForNode,
|
||||
getEscapedTextOfIdentifierOrLiteral,
|
||||
getEscapedTextOfJsxNamespacedName,
|
||||
@@ -455,7 +456,8 @@ function getModuleInstanceStateForAliasTarget(specifier: ExportSpecifier, visite
|
||||
return ModuleInstanceState.Instantiated; // Couldn't locate, assume could refer to a value
|
||||
}
|
||||
|
||||
const enum ContainerFlags {
|
||||
/** @internal */
|
||||
export const enum ContainerFlags {
|
||||
// The current node is not a container, and no container manipulation should happen before
|
||||
// recursing into it.
|
||||
None = 0,
|
||||
@@ -2356,7 +2358,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
|
||||
const saveCurrentFlow = currentFlow;
|
||||
for (const typeAlias of delayedTypeAliases) {
|
||||
const host = typeAlias.parent.parent;
|
||||
container = (findAncestor(host.parent, n => !!(getContainerFlags(n) & ContainerFlags.IsContainer)) as IsContainer | undefined) || file;
|
||||
container = (getEnclosingContainer(host) as IsContainer | undefined) || file;
|
||||
blockScopeContainer = (getEnclosingBlockScopeContainer(host) as IsBlockScopedContainer | undefined) || file;
|
||||
currentFlow = initFlowNode({ flags: FlowFlags.Start });
|
||||
parent = typeAlias;
|
||||
@@ -3768,7 +3770,8 @@ export function isExportsOrModuleExportsOrAlias(sourceFile: SourceFile, node: Ex
|
||||
return false;
|
||||
}
|
||||
|
||||
function getContainerFlags(node: Node): ContainerFlags {
|
||||
/** @internal */
|
||||
export function getContainerFlags(node: Node): ContainerFlags {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
|
||||
@@ -274,6 +274,7 @@ import {
|
||||
getEmitModuleResolutionKind,
|
||||
getEmitScriptTarget,
|
||||
getEnclosingBlockScopeContainer,
|
||||
getEnclosingContainer,
|
||||
getEntityNameFromTypeNode,
|
||||
getErrorSpanForNode,
|
||||
getEscapedTextOfIdentifierOrLiteral,
|
||||
@@ -39038,8 +39039,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
n.parent.kind !== SyntaxKind.ClassDeclaration &&
|
||||
n.parent.kind !== SyntaxKind.ClassExpression &&
|
||||
n.flags & NodeFlags.Ambient) {
|
||||
if (!(flags & ModifierFlags.Ambient) && !(isModuleBlock(n.parent) && isModuleDeclaration(n.parent.parent) && isGlobalScopeAugmentation(n.parent.parent))) {
|
||||
// It is nested in an ambient context, which means it is automatically exported
|
||||
const container = getEnclosingContainer(n);
|
||||
if ((container && container.flags & NodeFlags.ExportContext) && !(flags & ModifierFlags.Ambient) && !(isModuleBlock(n.parent) && isModuleDeclaration(n.parent.parent) && isGlobalScopeAugmentation(n.parent.parent))) {
|
||||
// It is nested in an ambient export context, which means it is automatically exported
|
||||
flags |= ModifierFlags.Export;
|
||||
}
|
||||
flags |= ModifierFlags.Ambient;
|
||||
|
||||
@@ -73,6 +73,7 @@ import {
|
||||
ConditionalExpression,
|
||||
ConstructorDeclaration,
|
||||
ConstructSignatureDeclaration,
|
||||
ContainerFlags,
|
||||
contains,
|
||||
containsPath,
|
||||
createGetCanonicalFileName,
|
||||
@@ -162,6 +163,7 @@ import {
|
||||
GetCanonicalFileName,
|
||||
getCombinedModifierFlags,
|
||||
getCombinedNodeFlags,
|
||||
getContainerFlags,
|
||||
getDirectoryPath,
|
||||
getJSDocAugmentsTag,
|
||||
getJSDocDeprecatedTagNoCache,
|
||||
@@ -2022,6 +2024,11 @@ export function isAnyImportOrReExport(node: Node): node is AnyImportOrReExport {
|
||||
return isAnyImportSyntax(node) || isExportDeclaration(node);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getEnclosingContainer(node: Node): Node | undefined {
|
||||
return findAncestor(node.parent, n => !!(getContainerFlags(n) & ContainerFlags.IsContainer));
|
||||
}
|
||||
|
||||
// Gets the nearest enclosing block scope container that has the provided node
|
||||
// as a descendant, that is not the provided node.
|
||||
/** @internal */
|
||||
|
||||
Reference in New Issue
Block a user