From 8232508db0f86d9cd71103cc820690e87bb9e6d6 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 22 Aug 2023 12:06:06 -0700 Subject: [PATCH 1/2] Avoid trying to emit anonymous classish/expando functions as assignments --- src/compiler/checker.ts | 29 +++++-- ...tionsFunctionClassesCjsExportAssignment.js | 16 ++-- .../jsDeclarationsGlobalFileConstFunction.js | 36 +++++++++ ...eclarationsGlobalFileConstFunction.symbols | 36 +++++++++ ...sDeclarationsGlobalFileConstFunction.types | 47 +++++++++++ ...eclarationsGlobalFileConstFunctionNamed.js | 50 ++++++++++++ ...ationsGlobalFileConstFunctionNamed.symbols | 58 ++++++++++++++ ...arationsGlobalFileConstFunctionNamed.types | 78 +++++++++++++++++++ .../jsDeclarationsGlobalFileConstFunction.ts | 16 ++++ ...eclarationsGlobalFileConstFunctionNamed.ts | 22 ++++++ 10 files changed, 374 insertions(+), 14 deletions(-) create mode 100644 tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.js create mode 100644 tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.symbols create mode 100644 tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.types create mode 100644 tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.js create mode 100644 tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.symbols create mode 100644 tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.types create mode 100644 tests/cases/compiler/jsDeclarationsGlobalFileConstFunction.ts create mode 100644 tests/cases/compiler/jsDeclarationsGlobalFileConstFunctionNamed.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9c6b8237a7f74..328b41f5abd96 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8525,11 +8525,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { ...oldcontext, usedSymbolNames: new Set(oldcontext.usedSymbolNames), remappedSymbolNames: new Map(), + remappedSymbolRefernces: new Map(oldcontext.remappedSymbolRefernces?.entries()), tracker: undefined!, }; const tracker: SymbolTracker = { ...oldcontext.tracker.inner, trackSymbol: (sym, decl, meaning) => { + if (context.remappedSymbolNames?.has(getSymbolId(sym))) return false; // If the context has a remapped name for the symbol, it *should* mean its been made visible const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*shouldComputeAliasesToMakeVisible*/ false); if (accessibleResult.accessibility === SymbolAccessibility.Accessible) { // Lookup the root symbol of the chain of refs we'll use to access it and serialize it @@ -8782,9 +8784,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // If it's a property: emit `export default _default` with a `_default` prop // If it's a class/interface/function: emit a class/interface/function with a `default` modifier // These forms can merge, eg (`export default 12; export default interface A {}`) - function serializeSymbolWorker(symbol: Symbol, isPrivate: boolean, propertyAsAlias: boolean): void { - const symbolName = unescapeLeadingUnderscores(symbol.escapedName); - const isDefault = symbol.escapedName === InternalSymbolName.Default; + function serializeSymbolWorker(symbol: Symbol, isPrivate: boolean, propertyAsAlias: boolean, escapedSymbolName = symbol.escapedName): void { + const symbolName = unescapeLeadingUnderscores(escapedSymbolName); + const isDefault = escapedSymbolName === InternalSymbolName.Default; if (isPrivate && !(context.flags & NodeBuilderFlags.AllowAnonymousIdentifier) && isStringANonContextualKeyword(symbolName) && !isDefault) { // Oh no. We cannot use this symbol's name as it's name... It's likely some jsdoc had an invalid name like `export` or `default` :( context.encounteredError = true; @@ -8803,7 +8805,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const modifierFlags = (!isPrivate ? ModifierFlags.Export : 0) | (isDefault && !needsPostExportDefault ? ModifierFlags.Default : 0); const isConstMergedWithNS = symbol.flags & SymbolFlags.Module && symbol.flags & (SymbolFlags.BlockScopedVariable | SymbolFlags.FunctionScopedVariable | SymbolFlags.Property) && - symbol.escapedName !== InternalSymbolName.ExportEquals; + escapedSymbolName !== InternalSymbolName.ExportEquals; const isConstMergedWithNSPrintableAsSignatureMerge = isConstMergedWithNS && isTypeRepresentableAsFunctionNamespaceMerge(getTypeOfSymbol(symbol), symbol); if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) || isConstMergedWithNSPrintableAsSignatureMerge) { serializeAsFunctionNamespaceMerge(getTypeOfSymbol(symbol), symbol, getInternalSymbolName(symbol, symbolName), modifierFlags); @@ -8815,7 +8817,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // symbol of name `export=` which needs to be handled like an alias. It's not great, but it is what it is. if ( symbol.flags & (SymbolFlags.BlockScopedVariable | SymbolFlags.FunctionScopedVariable | SymbolFlags.Property | SymbolFlags.Accessor) - && symbol.escapedName !== InternalSymbolName.ExportEquals + && escapedSymbolName !== InternalSymbolName.ExportEquals && !(symbol.flags & SymbolFlags.Prototype) && !(symbol.flags & SymbolFlags.Class) && !(symbol.flags & SymbolFlags.Method) @@ -8831,7 +8833,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else { const type = getTypeOfSymbol(symbol); const localName = getInternalSymbolName(symbol, symbolName); - if (!(symbol.flags & SymbolFlags.Function) && isTypeRepresentableAsFunctionNamespaceMerge(type, symbol)) { + if (type.symbol && type.symbol !== symbol && type.symbol.flags & SymbolFlags.Function && some(type.symbol.declarations, isFunctionExpressionOrArrowFunction) && (type.symbol.members?.size || type.symbol.exports?.size)) { + // assignment of a anonymous expando/class-like function, the func/ns/merge branch below won't trigger, + // and the assignment form has to reference the unreachable anonymous type so will error. + // Instead, serialzie the type's symbol, but with the current symbol's name, rather than the anonymous one. + if (!context.remappedSymbolRefernces) { + context.remappedSymbolRefernces = new Map(); + } + context.remappedSymbolRefernces.set(getSymbolId(type.symbol), symbol); // save name remapping as local name for target symbol + serializeSymbolWorker(type.symbol, isPrivate, propertyAsAlias, escapedSymbolName); + context.remappedSymbolRefernces.delete(getSymbolId(type.symbol)); + } + else if (!(symbol.flags & SymbolFlags.Function) && isTypeRepresentableAsFunctionNamespaceMerge(type, symbol)) { // If the type looks like a function declaration + ns could represent it, and it's type is sourced locally, rewrite it into a function declaration + ns serializeAsFunctionNamespaceMerge(type, symbol, localName, modifierFlags); } @@ -10134,6 +10147,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { * It will also use a representation of a number as written instead of a decimal form, e.g. `0o11` instead of `9`. */ function getNameOfSymbolAsWritten(symbol: Symbol, context?: NodeBuilderContext): string { + if (context?.remappedSymbolRefernces?.has(getSymbolId(symbol))) { + symbol = context.remappedSymbolRefernces.get(getSymbolId(symbol))!; + } if ( context && symbol.escapedName === InternalSymbolName.Default && !(context.flags & NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope) && // If it's not the first part of an entity name, it must print as `default` @@ -49929,6 +49945,7 @@ interface NodeBuilderContext { typeParameterNamesByTextNextNameCount?: Map; usedSymbolNames?: Set; remappedSymbolNames?: Map; + remappedSymbolRefernces?: Map; reverseMappedStack?: ReverseMappedSymbol[]; } diff --git a/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.js b/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.js index 04abac07a28a9..99070c882b9a5 100644 --- a/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.js +++ b/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.js @@ -228,6 +228,14 @@ type Input = { timer: Timer; hook: Hook; }; +/** + * Imports + */ +type Timer = import("./timer"); +/** + * Imports + */ +type Hook = import("./hook"); /** * Imports */ @@ -239,14 +247,6 @@ type State = { timer: Timer; hook: Hook; }; -/** - * Imports - */ -type Timer = import("./timer"); -/** - * Imports - */ -type Hook = import("./hook"); //// [hook.d.ts] export = Hook; /** diff --git a/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.js b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.js new file mode 100644 index 0000000000000..984ea0a483824 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.js @@ -0,0 +1,36 @@ +//// [tests/cases/compiler/jsDeclarationsGlobalFileConstFunction.ts] //// + +//// [file.js] +const SomeConstructor = function () { + this.x = 1; +}; + +const SomeConstructor2 = function () { +}; +SomeConstructor2.staticMember = "str"; + +const SomeConstructor3 = function () { + this.x = 1; +}; +SomeConstructor3.staticMember = "str"; + + + + +//// [file.d.ts] +declare function SomeConstructor(): void; +declare class SomeConstructor { + x: number; +} +declare function SomeConstructor2(): void; +declare namespace SomeConstructor2 { + let staticMember: string; +} +declare function SomeConstructor3(): void; +declare namespace SomeConstructor3 { + let staticMember_1: string; + export { staticMember_1 as staticMember }; +} +declare class SomeConstructor3 { + x: number; +} diff --git a/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.symbols b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.symbols new file mode 100644 index 0000000000000..a003ed2cbc09c --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.symbols @@ -0,0 +1,36 @@ +//// [tests/cases/compiler/jsDeclarationsGlobalFileConstFunction.ts] //// + +=== file.js === +const SomeConstructor = function () { +>SomeConstructor : Symbol(SomeConstructor, Decl(file.js, 0, 5)) + + this.x = 1; +>this.x : Symbol(SomeConstructor.x, Decl(file.js, 0, 37)) +>this : Symbol(SomeConstructor, Decl(file.js, 0, 23)) +>x : Symbol(SomeConstructor.x, Decl(file.js, 0, 37)) + +}; + +const SomeConstructor2 = function () { +>SomeConstructor2 : Symbol(SomeConstructor2, Decl(file.js, 4, 5), Decl(file.js, 5, 2)) + +}; +SomeConstructor2.staticMember = "str"; +>SomeConstructor2.staticMember : Symbol(SomeConstructor2.staticMember, Decl(file.js, 5, 2)) +>SomeConstructor2 : Symbol(SomeConstructor2, Decl(file.js, 4, 5), Decl(file.js, 5, 2)) +>staticMember : Symbol(SomeConstructor2.staticMember, Decl(file.js, 5, 2)) + +const SomeConstructor3 = function () { +>SomeConstructor3 : Symbol(SomeConstructor3, Decl(file.js, 8, 5), Decl(file.js, 10, 2)) + + this.x = 1; +>this.x : Symbol(SomeConstructor3.x, Decl(file.js, 8, 38)) +>this : Symbol(SomeConstructor3, Decl(file.js, 8, 24)) +>x : Symbol(SomeConstructor3.x, Decl(file.js, 8, 38)) + +}; +SomeConstructor3.staticMember = "str"; +>SomeConstructor3.staticMember : Symbol(SomeConstructor3.staticMember, Decl(file.js, 10, 2)) +>SomeConstructor3 : Symbol(SomeConstructor3, Decl(file.js, 8, 5), Decl(file.js, 10, 2)) +>staticMember : Symbol(SomeConstructor3.staticMember, Decl(file.js, 10, 2)) + diff --git a/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.types b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.types new file mode 100644 index 0000000000000..3e187f5c216db --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.types @@ -0,0 +1,47 @@ +//// [tests/cases/compiler/jsDeclarationsGlobalFileConstFunction.ts] //// + +=== file.js === +const SomeConstructor = function () { +>SomeConstructor : typeof SomeConstructor +>function () { this.x = 1;} : typeof SomeConstructor + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : this +>x : any +>1 : 1 + +}; + +const SomeConstructor2 = function () { +>SomeConstructor2 : { (): void; staticMember: string; } +>function () {} : { (): void; staticMember: string; } + +}; +SomeConstructor2.staticMember = "str"; +>SomeConstructor2.staticMember = "str" : "str" +>SomeConstructor2.staticMember : string +>SomeConstructor2 : { (): void; staticMember: string; } +>staticMember : string +>"str" : "str" + +const SomeConstructor3 = function () { +>SomeConstructor3 : typeof SomeConstructor3 +>function () { this.x = 1;} : typeof SomeConstructor3 + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : this +>x : any +>1 : 1 + +}; +SomeConstructor3.staticMember = "str"; +>SomeConstructor3.staticMember = "str" : "str" +>SomeConstructor3.staticMember : string +>SomeConstructor3 : typeof SomeConstructor3 +>staticMember : string +>"str" : "str" + diff --git a/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.js b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.js new file mode 100644 index 0000000000000..3d471e3615800 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.js @@ -0,0 +1,50 @@ +//// [tests/cases/compiler/jsDeclarationsGlobalFileConstFunctionNamed.ts] //// + +//// [file.js] +const SomeConstructor = function Named() { + this.x = 1; +}; + +const SomeConstructor2 = function Named() { +}; +SomeConstructor2.staticMember = "str"; + +const SomeConstructor3 = function Named() { + this.x = 1; +}; +SomeConstructor3.staticMember = "str"; + +const SelfReference = function Named() { + if (!(this instanceof Named)) return new Named(); + this.x = 1; +} +SelfReference.staticMember = "str"; + + + + +//// [file.d.ts] +declare function SomeConstructor(): void; +declare class SomeConstructor { + x: number; +} +declare function SomeConstructor2(): void; +declare namespace SomeConstructor2 { + let staticMember: string; +} +declare function SomeConstructor3(): void; +declare namespace SomeConstructor3 { + let staticMember_1: string; + export { staticMember_1 as staticMember }; +} +declare class SomeConstructor3 { + x: number; +} +declare function SelfReference(): SelfReference; +declare namespace SelfReference { + let staticMember_2: string; + export { staticMember_2 as staticMember }; +} +declare class SelfReference { + x: number; +} diff --git a/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.symbols b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.symbols new file mode 100644 index 0000000000000..50b29c337521a --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.symbols @@ -0,0 +1,58 @@ +//// [tests/cases/compiler/jsDeclarationsGlobalFileConstFunctionNamed.ts] //// + +=== file.js === +const SomeConstructor = function Named() { +>SomeConstructor : Symbol(SomeConstructor, Decl(file.js, 0, 5)) +>Named : Symbol(Named, Decl(file.js, 0, 23)) + + this.x = 1; +>this.x : Symbol(Named.x, Decl(file.js, 0, 42)) +>this : Symbol(Named, Decl(file.js, 0, 23)) +>x : Symbol(Named.x, Decl(file.js, 0, 42)) + +}; + +const SomeConstructor2 = function Named() { +>SomeConstructor2 : Symbol(SomeConstructor2, Decl(file.js, 4, 5), Decl(file.js, 5, 2)) +>Named : Symbol(Named, Decl(file.js, 4, 24)) + +}; +SomeConstructor2.staticMember = "str"; +>SomeConstructor2.staticMember : Symbol(SomeConstructor2.staticMember, Decl(file.js, 5, 2)) +>SomeConstructor2 : Symbol(SomeConstructor2, Decl(file.js, 4, 5), Decl(file.js, 5, 2)) +>staticMember : Symbol(SomeConstructor2.staticMember, Decl(file.js, 5, 2)) + +const SomeConstructor3 = function Named() { +>SomeConstructor3 : Symbol(SomeConstructor3, Decl(file.js, 8, 5), Decl(file.js, 10, 2)) +>Named : Symbol(Named, Decl(file.js, 8, 24)) + + this.x = 1; +>this.x : Symbol(Named.x, Decl(file.js, 8, 43)) +>this : Symbol(Named, Decl(file.js, 8, 24)) +>x : Symbol(Named.x, Decl(file.js, 8, 43)) + +}; +SomeConstructor3.staticMember = "str"; +>SomeConstructor3.staticMember : Symbol(SomeConstructor3.staticMember, Decl(file.js, 10, 2)) +>SomeConstructor3 : Symbol(SomeConstructor3, Decl(file.js, 8, 5), Decl(file.js, 10, 2)) +>staticMember : Symbol(SomeConstructor3.staticMember, Decl(file.js, 10, 2)) + +const SelfReference = function Named() { +>SelfReference : Symbol(SelfReference, Decl(file.js, 13, 5), Decl(file.js, 16, 1)) +>Named : Symbol(Named, Decl(file.js, 13, 21)) + + if (!(this instanceof Named)) return new Named(); +>this : Symbol(Named, Decl(file.js, 13, 21)) +>Named : Symbol(Named, Decl(file.js, 13, 21)) +>Named : Symbol(Named, Decl(file.js, 13, 21)) + + this.x = 1; +>this.x : Symbol(Named.x, Decl(file.js, 14, 53)) +>this : Symbol(Named, Decl(file.js, 13, 21)) +>x : Symbol(Named.x, Decl(file.js, 14, 53)) +} +SelfReference.staticMember = "str"; +>SelfReference.staticMember : Symbol(SelfReference.staticMember, Decl(file.js, 16, 1)) +>SelfReference : Symbol(SelfReference, Decl(file.js, 13, 5), Decl(file.js, 16, 1)) +>staticMember : Symbol(SelfReference.staticMember, Decl(file.js, 16, 1)) + diff --git a/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.types b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.types new file mode 100644 index 0000000000000..afd849a8bb55b --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.types @@ -0,0 +1,78 @@ +//// [tests/cases/compiler/jsDeclarationsGlobalFileConstFunctionNamed.ts] //// + +=== file.js === +const SomeConstructor = function Named() { +>SomeConstructor : typeof Named +>function Named() { this.x = 1;} : typeof Named +>Named : typeof Named + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : this +>x : any +>1 : 1 + +}; + +const SomeConstructor2 = function Named() { +>SomeConstructor2 : { (): void; staticMember: string; } +>function Named() {} : { (): void; staticMember: string; } +>Named : { (): void; staticMember: string; } + +}; +SomeConstructor2.staticMember = "str"; +>SomeConstructor2.staticMember = "str" : "str" +>SomeConstructor2.staticMember : string +>SomeConstructor2 : { (): void; staticMember: string; } +>staticMember : string +>"str" : "str" + +const SomeConstructor3 = function Named() { +>SomeConstructor3 : typeof Named +>function Named() { this.x = 1;} : typeof Named +>Named : typeof Named + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : this +>x : any +>1 : 1 + +}; +SomeConstructor3.staticMember = "str"; +>SomeConstructor3.staticMember = "str" : "str" +>SomeConstructor3.staticMember : string +>SomeConstructor3 : typeof Named +>staticMember : string +>"str" : "str" + +const SelfReference = function Named() { +>SelfReference : typeof Named +>function Named() { if (!(this instanceof Named)) return new Named(); this.x = 1;} : typeof Named +>Named : typeof Named + + if (!(this instanceof Named)) return new Named(); +>!(this instanceof Named) : boolean +>(this instanceof Named) : boolean +>this instanceof Named : boolean +>this : this +>Named : typeof Named +>new Named() : Named +>Named : typeof Named + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : this +>x : any +>1 : 1 +} +SelfReference.staticMember = "str"; +>SelfReference.staticMember = "str" : "str" +>SelfReference.staticMember : string +>SelfReference : typeof Named +>staticMember : string +>"str" : "str" + diff --git a/tests/cases/compiler/jsDeclarationsGlobalFileConstFunction.ts b/tests/cases/compiler/jsDeclarationsGlobalFileConstFunction.ts new file mode 100644 index 0000000000000..0ef68f6e91ad3 --- /dev/null +++ b/tests/cases/compiler/jsDeclarationsGlobalFileConstFunction.ts @@ -0,0 +1,16 @@ +// @checkJs: true +// @declaration: true +// @emitDeclarationOnly: true +// @filename: file.js +const SomeConstructor = function () { + this.x = 1; +}; + +const SomeConstructor2 = function () { +}; +SomeConstructor2.staticMember = "str"; + +const SomeConstructor3 = function () { + this.x = 1; +}; +SomeConstructor3.staticMember = "str"; diff --git a/tests/cases/compiler/jsDeclarationsGlobalFileConstFunctionNamed.ts b/tests/cases/compiler/jsDeclarationsGlobalFileConstFunctionNamed.ts new file mode 100644 index 0000000000000..2b40db86dbbdc --- /dev/null +++ b/tests/cases/compiler/jsDeclarationsGlobalFileConstFunctionNamed.ts @@ -0,0 +1,22 @@ +// @checkJs: true +// @declaration: true +// @emitDeclarationOnly: true +// @filename: file.js +const SomeConstructor = function Named() { + this.x = 1; +}; + +const SomeConstructor2 = function Named() { +}; +SomeConstructor2.staticMember = "str"; + +const SomeConstructor3 = function Named() { + this.x = 1; +}; +SomeConstructor3.staticMember = "str"; + +const SelfReference = function Named() { + if (!(this instanceof Named)) return new Named(); + this.x = 1; +} +SelfReference.staticMember = "str"; From 8b7279fd3c50beabdb0a59d8eddffaef38f0c0f2 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 28 Aug 2023 11:45:37 -0700 Subject: [PATCH 2/2] Fix spelling --- src/compiler/checker.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 41cf1b5838280..4dd46af4c769a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8533,13 +8533,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { ...oldcontext, usedSymbolNames: new Set(oldcontext.usedSymbolNames), remappedSymbolNames: new Map(), - remappedSymbolRefernces: new Map(oldcontext.remappedSymbolRefernces?.entries()), + remappedSymbolReferences: new Map(oldcontext.remappedSymbolReferences?.entries()), tracker: undefined!, }; const tracker: SymbolTracker = { ...oldcontext.tracker.inner, trackSymbol: (sym, decl, meaning) => { - if (context.remappedSymbolNames?.has(getSymbolId(sym))) return false; // If the context has a remapped name for the symbol, it *should* mean its been made visible + if (context.remappedSymbolNames?.has(getSymbolId(sym))) return false; // If the context has a remapped name for the symbol, it *should* mean it's been made visible const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*shouldComputeAliasesToMakeVisible*/ false); if (accessibleResult.accessibility === SymbolAccessibility.Accessible) { // Lookup the root symbol of the chain of refs we'll use to access it and serialize it @@ -8844,13 +8844,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (type.symbol && type.symbol !== symbol && type.symbol.flags & SymbolFlags.Function && some(type.symbol.declarations, isFunctionExpressionOrArrowFunction) && (type.symbol.members?.size || type.symbol.exports?.size)) { // assignment of a anonymous expando/class-like function, the func/ns/merge branch below won't trigger, // and the assignment form has to reference the unreachable anonymous type so will error. - // Instead, serialzie the type's symbol, but with the current symbol's name, rather than the anonymous one. - if (!context.remappedSymbolRefernces) { - context.remappedSymbolRefernces = new Map(); + // Instead, serialize the type's symbol, but with the current symbol's name, rather than the anonymous one. + if (!context.remappedSymbolReferences) { + context.remappedSymbolReferences = new Map(); } - context.remappedSymbolRefernces.set(getSymbolId(type.symbol), symbol); // save name remapping as local name for target symbol + context.remappedSymbolReferences.set(getSymbolId(type.symbol), symbol); // save name remapping as local name for target symbol serializeSymbolWorker(type.symbol, isPrivate, propertyAsAlias, escapedSymbolName); - context.remappedSymbolRefernces.delete(getSymbolId(type.symbol)); + context.remappedSymbolReferences.delete(getSymbolId(type.symbol)); } else if (!(symbol.flags & SymbolFlags.Function) && isTypeRepresentableAsFunctionNamespaceMerge(type, symbol)) { // If the type looks like a function declaration + ns could represent it, and it's type is sourced locally, rewrite it into a function declaration + ns @@ -10172,8 +10172,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { * It will also use a representation of a number as written instead of a decimal form, e.g. `0o11` instead of `9`. */ function getNameOfSymbolAsWritten(symbol: Symbol, context?: NodeBuilderContext): string { - if (context?.remappedSymbolRefernces?.has(getSymbolId(symbol))) { - symbol = context.remappedSymbolRefernces.get(getSymbolId(symbol))!; + if (context?.remappedSymbolReferences?.has(getSymbolId(symbol))) { + symbol = context.remappedSymbolReferences.get(getSymbolId(symbol))!; } if ( context && symbol.escapedName === InternalSymbolName.Default && !(context.flags & NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope) && @@ -50002,7 +50002,7 @@ interface NodeBuilderContext { typeParameterNamesByTextNextNameCount?: Map; usedSymbolNames?: Set; remappedSymbolNames?: Map; - remappedSymbolRefernces?: Map; + remappedSymbolReferences?: Map; reverseMappedStack?: ReverseMappedSymbol[]; }