Skip to content

Commit 418f975

Browse files
Addressed small review issues.
1 parent a81b583 commit 418f975

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/compiler/transformers/declarations/emitBinder.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const knownFunctionMembers = new Set([
180180
export function bindSourceFileForDeclarationEmit(file: SourceFile) {
181181
const nodeLinks: EmitDeclarationNodeLinks[] = [];
182182
function tryGetNodeLinks(node: Node): EmitDeclarationNodeLinks | undefined {
183-
const id = (node as any).id;
183+
const id = node.id;
184184
if (!id) return undefined;
185185
return nodeLinks[id];
186186
}
@@ -274,7 +274,7 @@ export function bindSourceFileForDeclarationEmit(file: SourceFile) {
274274
/* eslint-disable no-var */
275275
var currentScope: Node = undefined!;
276276
var currentFunctionLocalSymbolTable: EmitDeclarationSymbolTable = undefined!;
277-
var currentSymbol: EmitDeclarationSymbol = undefined!;
277+
var currentParent: EmitDeclarationSymbol = undefined!;
278278
var currentLocalSymbolTable: EmitDeclarationSymbolTable = undefined!;
279279
var currentExportsSymbolTable: EmitDeclarationSymbolTable | undefined;
280280
var postBindingAction: (() => void)[] = [];
@@ -296,7 +296,7 @@ export function bindSourceFileForDeclarationEmit(file: SourceFile) {
296296
}
297297
function createEmitSymbol(): EmitDeclarationSymbol {
298298
return {
299-
parent: currentSymbol,
299+
parent: currentParent,
300300
declarations: [],
301301
flags: 0,
302302
};
@@ -353,24 +353,24 @@ export function bindSourceFileForDeclarationEmit(file: SourceFile) {
353353
return symbol;
354354
}
355355
function withScope(scope: Node, exports: EmitDeclarationSymbolTable | undefined, fn: () => void) {
356-
const old = [currentScope, currentSymbol, currentFunctionLocalSymbolTable, currentLocalSymbolTable, currentExportsSymbolTable] as const;
356+
const old = [currentScope, currentParent, currentFunctionLocalSymbolTable, currentLocalSymbolTable, currentExportsSymbolTable] as const;
357357
currentScope = scope;
358358
const links = getNodeLinks(scope);
359359
currentLocalSymbolTable = links.locals ??= new Map();
360-
currentSymbol = links.symbol ?? currentSymbol;
360+
currentParent = links.symbol ?? currentParent;
361361
currentExportsSymbolTable = exports;
362362
if (isBlockScopedContainerTopLevel(scope)) {
363363
currentFunctionLocalSymbolTable = currentLocalSymbolTable;
364364
}
365365
fn();
366-
[currentScope, currentSymbol, currentFunctionLocalSymbolTable, currentLocalSymbolTable, currentExportsSymbolTable] = old;
366+
[currentScope, currentParent, currentFunctionLocalSymbolTable, currentLocalSymbolTable, currentExportsSymbolTable] = old;
367367
}
368-
function withMembers(symbol: EmitDeclarationSymbol, table: "members" | "exports" = "members", fn: () => void) {
369-
const old = [currentLocalSymbolTable, currentSymbol] as const;
370-
currentSymbol = symbol;
371-
currentLocalSymbolTable = symbol[table] ??= new Map();
368+
function withMembers(symbol: EmitDeclarationSymbol, addToExports = false, fn: () => void) {
369+
const old = [currentLocalSymbolTable, currentParent] as const;
370+
currentParent = symbol;
371+
currentLocalSymbolTable = addToExports ? symbol.exports ??= new Map() : symbol.members ??= new Map();
372372
fn();
373-
[currentLocalSymbolTable, currentSymbol] = old;
373+
[currentLocalSymbolTable, currentParent] = old;
374374
}
375375

376376
interface LocalAndExportName {
@@ -492,7 +492,7 @@ export function bindSourceFileForDeclarationEmit(file: SourceFile) {
492492
function bindObjectLiteral(object: ObjectLiteralExpression) {
493493
const objectSymbol = createAnonymousEmitSymbol(object);
494494

495-
withMembers(objectSymbol, "members", () => {
495+
withMembers(objectSymbol, /*addToExports*/ false, () => {
496496
object.properties.forEach(m => {
497497
bindNode(m);
498498
});
@@ -687,7 +687,7 @@ export function bindSourceFileForDeclarationEmit(file: SourceFile) {
687687
}
688688
function bindTypeLiteralNode(node: TypeLiteralNode) {
689689
const objectSymbol = createAnonymousEmitSymbol(node);
690-
withMembers(objectSymbol, "members", () => {
690+
withMembers(objectSymbol, /*addToExports*/ false, () => {
691691
node.members.forEach(bindNode);
692692
});
693693
}
@@ -727,14 +727,14 @@ export function bindSourceFileForDeclarationEmit(file: SourceFile) {
727727
});
728728
});
729729
}
730-
elements.forEach(e => {
730+
for (const e of elements) {
731731
postBindingAction.push(() => {
732732
const resolvedSymbol = resolveName(e, (e.propertyName ?? e.name).escapedText, ~0);
733733
if (resolvedSymbol) {
734734
resolvedSymbol.declarations.forEach(d => getNodeLinks(d).isVisible = true);
735735
}
736736
});
737-
});
737+
}
738738
}
739739
}
740740
function bindEnumDeclaration(node: EnumDeclaration) {
@@ -777,7 +777,7 @@ export function bindSourceFileForDeclarationEmit(file: SourceFile) {
777777
withScope(interfaceDeclaration, /*exports*/ undefined, () => {
778778
bindTypeParameters(interfaceDeclaration.typeParameters);
779779
});
780-
withMembers(interfaceSymbol, "members", () => {
780+
withMembers(interfaceSymbol, /*addToExports*/ false, () => {
781781
interfaceDeclaration.members.forEach(m => {
782782
bindNode(m);
783783
});
@@ -790,15 +790,15 @@ export function bindSourceFileForDeclarationEmit(file: SourceFile) {
790790
withScope(classDeclaration, /*exports*/ undefined, () => {
791791
bindTypeParameters(classDeclaration.typeParameters);
792792
});
793-
withMembers(classSymbol, "members", () => {
793+
withMembers(classSymbol, /*addToExports*/ false, () => {
794794
classDeclaration.members.forEach(m => {
795795
if (hasSyntacticModifier(m, ModifierFlags.Static)) return;
796796
if (m.kind === SyntaxKind.SemicolonClassElement || m.kind === SyntaxKind.ClassStaticBlockDeclaration) return;
797797

798798
bindNode(m);
799799
});
800800
});
801-
withMembers(classSymbol, "exports", () => {
801+
withMembers(classSymbol, /*addToExports*/ true, () => {
802802
classDeclaration.members.forEach(m => {
803803
if (!hasSyntacticModifier(m, ModifierFlags.Static)) return;
804804
if (

0 commit comments

Comments
 (0)