Skip to content

Commit 777e7be

Browse files
committed
refactor
1 parent 7909d87 commit 777e7be

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

‎src/compiler/binder.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import {
8787
getElementOrPropertyAccessName,
8888
getEmitScriptTarget,
8989
getEnclosingBlockScopeContainer,
90+
getEnclosingContainer,
9091
getErrorSpanForNode,
9192
getEscapedTextOfIdentifierOrLiteral,
9293
getEscapedTextOfJsxNamespacedName,
@@ -2357,7 +2358,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
23572358
const saveCurrentFlow = currentFlow;
23582359
for (const typeAlias of delayedTypeAliases) {
23592360
const host = typeAlias.parent.parent;
2360-
container = (findAncestor(host.parent, n => !!(getContainerFlags(n) & ContainerFlags.IsContainer)) as IsContainer | undefined) || file;
2361+
container = (getEnclosingContainer(host) as IsContainer | undefined) || file;
23612362
blockScopeContainer = (getEnclosingBlockScopeContainer(host) as IsBlockScopedContainer | undefined) || file;
23622363
currentFlow = initFlowNode({ flags: FlowFlags.Start });
23632364
parent = typeAlias;

‎src/compiler/checker.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39026,8 +39026,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3902639026
n.parent.kind !== SyntaxKind.ClassExpression &&
3902739027
n.flags & NodeFlags.Ambient) {
3902839028
const container = getEnclosingContainer(n);
39029-
if ((container.flags & NodeFlags.ExportContext) && !(flags & ModifierFlags.Ambient) && !(isModuleBlock(n.parent) && isModuleDeclaration(n.parent.parent) && isGlobalScopeAugmentation(n.parent.parent))) {
39030-
// It is nested in an ambient context, which means it is automatically exported
39029+
if ((container && container.flags & NodeFlags.ExportContext) && !(flags & ModifierFlags.Ambient) && !(isModuleBlock(n.parent) && isModuleDeclaration(n.parent.parent) && isGlobalScopeAugmentation(n.parent.parent))) {
39030+
// It is nested in an ambient export context, which means it is automatically exported
3903139031
flags |= ModifierFlags.Export;
3903239032
}
3903339033
flags |= ModifierFlags.Ambient;

‎src/compiler/utilities.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,8 +2025,8 @@ export function isAnyImportOrReExport(node: Node): node is AnyImportOrReExport {
20252025
}
20262026

20272027
/** @internal */
2028-
export function getEnclosingContainer(node: Node): Node {
2029-
return findAncestor(node.parent, n => !!(getContainerFlags(n) & ContainerFlags.IsContainer))!;
2028+
export function getEnclosingContainer(node: Node): Node | undefined {
2029+
return findAncestor(node.parent, n => !!(getContainerFlags(n) & ContainerFlags.IsContainer));
20302030
}
20312031

20322032
// Gets the nearest enclosing block scope container that has the provided node

0 commit comments

Comments
 (0)