Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tsc/internal/binder/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,9 +1081,11 @@ func (b *Binder) bindDeferredExpandoAssignment(node *ast.Node) {
b.bindAnonymousDeclaration(node, ast.SymbolFlagsProperty|ast.SymbolFlagsAssignment, ast.InternalSymbolNameComputed)
b.addLateBoundAssignmentDeclarationToSymbol(node, symbol)
} else {
// We declare expandos only when there are no non-expando declarations for that name.
// We declare expandos only when there are no non-expando declarations for that name that might have
// a value meaning. Expandos merge with type-only declarations (type aliases, interfaces, and
// uninstantiated namespaces), but not with aliases since those might resolve to values.
exports := ast.GetExports(symbol, &b.symbolExtraArena)
if existing := exports.Get(b.getDeclarationName(node)); existing == nil || existing.Flags()&ast.SymbolFlagsAssignment != 0 {
if existing := exports.Get(b.getDeclarationName(node)); existing == nil || existing.Flags()&ast.SymbolFlagsAssignment != 0 || existing.Flags()&(ast.SymbolFlagsValue|ast.SymbolFlagsAlias) == 0 {
b.declareSymbol(exports, symbol, node, ast.SymbolFlagsProperty|ast.SymbolFlagsAssignment, ast.SymbolFlagsPropertyExcludes)
}
}
Expand Down
7 changes: 5 additions & 2 deletions tsc/internal/transformers/declarations/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2908,7 +2908,9 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp

preexistingExpandoHasExport := core.Some(tx.expandoMembers[hostId], ast.IsExportDeclaration)

if ast.IsIdentifier(node.Right) {
// When the expando is merged with a type-only declaration (e.g. a type alias or uninstantiated namespace
// of the same name), an alias-like export would conflict with it, so we emit a variable declaration instead.
if ast.IsIdentifier(node.Right) && symbol.Flags()&(ast.SymbolFlagsType|ast.SymbolFlagsNamespace) == 0 {
if !preexistingExpandoHasExport {
tx.addExportModifierToExpandoMembers(hostId)
}
Expand All @@ -2920,7 +2922,8 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp

var varModifiers *ast.ModifierList

if preexistingExpandoHasExport {
// A renamed local stays private, since it's exported under the property name by the `export {}` added below
if preexistingExpandoHasExport && localName.Text() == exportName.Text() {
varModifiers = tx.Factory().NewModifierList(ast.CreateModifiersFromModifierFlags(ast.ModifierFlagsExport, tx.Factory().NewModifier))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//// [tests/cases/compiler/declarationEmitExpandoTypeOnlyNamespaceMember.ts] ////

//// [declarationEmitExpandoTypeOnlyNamespaceMember.ts]
export class C {}
export function f1() {}
f1.a = C;
f1.b = C;
export namespace f1 { export type a = 0; }

export enum E { A }
export function f2() {}
f2.a = E;
export namespace f2 { export interface a { x: string } }

export function g() {}
export function f3() {}
f3.a = g;
export namespace f3 { export namespace a { export type T = string; } }

export function Target() { return null; }
export namespace Target { export type Props = number; }

export function Popover() { return null; }
Popover.Target = Target;
export namespace Popover {
export namespace Target {
export type Extra = string;
}
}

export function Popover2() { return null; }
Popover2.b = C;
Popover2.Target = Target;
export namespace Popover2 {
export namespace Target {
export type Extra = string;
}
}


//// [declarationEmitExpandoTypeOnlyNamespaceMember.js]
export class C {
}
export function f1() { }
f1.a = C;
f1.b = C;
export var E;
(function (E) {
E[E["A"] = 0] = "A";
})(E || (E = {}));
export function f2() { }
f2.a = E;
export function g() { }
export function f3() { }
f3.a = g;
export function Target() { return null; }
export function Popover() { return null; }
Popover.Target = Target;
export function Popover2() { return null; }
Popover2.b = C;
Popover2.Target = Target;


//// [declarationEmitExpandoTypeOnlyNamespaceMember.d.ts]
export declare class C {
}
export declare function f1(): void;
export declare namespace f1 {
export var a: typeof C;
export { C as b };
}
export declare namespace f1 {
type a = 0;
}
export declare enum E {
A = 0
}
export declare function f2(): void;
export declare namespace f2 {
var a: typeof E;
}
export declare namespace f2 {
interface a {
x: string;
}
}
export declare function g(): void;
export declare function f3(): void;
export declare namespace f3 {
var a: typeof g;
}
export declare namespace f3 {
namespace a {
type T = string;
}
}
export declare function Target(): null;
export declare namespace Target {
type Props = number;
}
export declare function Popover(): null;
export declare namespace Popover {
var _a: typeof import("./declarationEmitExpandoTypeOnlyNamespaceMember").Target;
export { _a as Target };
}
export declare namespace Popover {
namespace Target {
type Extra = string;
}
}
export declare function Popover2(): null;
export declare namespace Popover2 {
export { C as b };
var _b: typeof import("./declarationEmitExpandoTypeOnlyNamespaceMember").Target;
export { _b as Target };
}
export declare namespace Popover2 {
namespace Target {
type Extra = string;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//// [tests/cases/compiler/declarationEmitExpandoTypeOnlyNamespaceMember.ts] ////

=== declarationEmitExpandoTypeOnlyNamespaceMember.ts ===
export class C {}
>C : Symbol(C, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 0, 0))

export function f1() {}
>f1 : Symbol(f1, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 0, 17), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 3, 9))

f1.a = C;
>f1.a : Symbol(f1.a, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 4, 21), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 1, 23))
>f1 : Symbol(f1, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 0, 17), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 3, 9))
>a : Symbol(f1.a, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 4, 21), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 1, 23))
>C : Symbol(C, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 0, 0))

f1.b = C;
>f1.b : Symbol(f1.b, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 2, 9))
>f1 : Symbol(f1, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 0, 17), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 3, 9))
>b : Symbol(f1.b, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 2, 9))
>C : Symbol(C, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 0, 0))

export namespace f1 { export type a = 0; }
>f1 : Symbol(f1, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 0, 17), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 3, 9))
>a : Symbol(a, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 4, 21), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 1, 23))

export enum E { A }
>E : Symbol(E, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 4, 42))
>A : Symbol(E.A, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 6, 15))

export function f2() {}
>f2 : Symbol(f2, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 6, 19), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 8, 9))

f2.a = E;
>f2.a : Symbol(f2.a, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 9, 21), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 7, 23))
>f2 : Symbol(f2, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 6, 19), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 8, 9))
>a : Symbol(f2.a, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 9, 21), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 7, 23))
>E : Symbol(E, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 4, 42))

export namespace f2 { export interface a { x: string } }
>f2 : Symbol(f2, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 6, 19), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 8, 9))
>a : Symbol(a, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 9, 21), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 7, 23))
>x : Symbol(a.x, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 9, 42))

export function g() {}
>g : Symbol(g, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 9, 56))

export function f3() {}
>f3 : Symbol(f3, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 11, 22), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 13, 9))

f3.a = g;
>f3.a : Symbol(f3.a, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 14, 21), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 12, 23))
>f3 : Symbol(f3, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 11, 22), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 13, 9))
>a : Symbol(f3.a, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 14, 21), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 12, 23))
>g : Symbol(g, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 9, 56))

export namespace f3 { export namespace a { export type T = string; } }
>f3 : Symbol(f3, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 11, 22), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 13, 9))
>a : Symbol(a, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 14, 21), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 12, 23))
>T : Symbol(T, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 14, 42))

export function Target() { return null; }
>Target : Symbol(Target, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 14, 70), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 16, 41))

export namespace Target { export type Props = number; }
>Target : Symbol(Target, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 14, 70), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 16, 41))
>Props : Symbol(Props, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 17, 25))

export function Popover() { return null; }
>Popover : Symbol(Popover, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 17, 55), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 20, 24))

Popover.Target = Target;
>Popover.Target : Symbol(Popover.Target, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 21, 26), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 19, 42))
>Popover : Symbol(Popover, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 17, 55), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 20, 24))
>Target : Symbol(Popover.Target, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 21, 26), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 19, 42))
>Target : Symbol(Target, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 14, 70), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 16, 41))

export namespace Popover {
>Popover : Symbol(Popover, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 17, 55), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 20, 24))

export namespace Target {
>Target : Symbol(Target, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 21, 26), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 19, 42))

export type Extra = string;
>Extra : Symbol(Extra, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 22, 27))
}
}

export function Popover2() { return null; }
>Popover2 : Symbol(Popover2, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 25, 1), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 29, 25))

Popover2.b = C;
>Popover2.b : Symbol(Popover2.b, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 27, 43))
>Popover2 : Symbol(Popover2, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 25, 1), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 29, 25))
>b : Symbol(Popover2.b, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 27, 43))
>C : Symbol(C, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 0, 0))

Popover2.Target = Target;
>Popover2.Target : Symbol(Popover2.Target, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 30, 27), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 28, 15))
>Popover2 : Symbol(Popover2, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 25, 1), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 29, 25))
>Target : Symbol(Popover2.Target, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 30, 27), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 28, 15))
>Target : Symbol(Target, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 14, 70), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 16, 41))

export namespace Popover2 {
>Popover2 : Symbol(Popover2, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 25, 1), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 29, 25))

export namespace Target {
>Target : Symbol(Target, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 30, 27), Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 28, 15))

export type Extra = string;
>Extra : Symbol(Extra, Decl(declarationEmitExpandoTypeOnlyNamespaceMember.ts, 31, 27))
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//// [tests/cases/compiler/declarationEmitExpandoTypeOnlyNamespaceMember.ts] ////

=== declarationEmitExpandoTypeOnlyNamespaceMember.ts ===
export class C {}
>C : C

export function f1() {}
>f1 : { (): void; b: typeof C; a: typeof C; }

f1.a = C;
>f1.a = C : typeof C
>f1.a : typeof C
>f1 : { (): void; b: typeof C; a: typeof C; }
>a : typeof C
>C : typeof C

f1.b = C;
>f1.b = C : typeof C
>f1.b : typeof C
>f1 : { (): void; b: typeof C; a: typeof C; }
>b : typeof C
>C : typeof C

export namespace f1 { export type a = 0; }
>a : 0

export enum E { A }
>E : E
>A : E.A

export function f2() {}
>f2 : { (): void; a: typeof E; }

f2.a = E;
>f2.a = E : typeof E
>f2.a : typeof E
>f2 : { (): void; a: typeof E; }
>a : typeof E
>E : typeof E

export namespace f2 { export interface a { x: string } }
>x : string

export function g() {}
>g : () => void

export function f3() {}
>f3 : { (): void; a: () => void; }

f3.a = g;
>f3.a = g : () => void
>f3.a : () => void
>f3 : { (): void; a: () => void; }
>a : () => void
>g : () => void

export namespace f3 { export namespace a { export type T = string; } }
>T : string

export function Target() { return null; }
>Target : () => null

export namespace Target { export type Props = number; }
>Props : number

export function Popover() { return null; }
>Popover : { (): null; Target: () => null; }

Popover.Target = Target;
>Popover.Target = Target : () => null
>Popover.Target : () => null
>Popover : { (): null; Target: () => null; }
>Target : () => null
>Target : () => null

export namespace Popover {
export namespace Target {
export type Extra = string;
>Extra : string
}
}

export function Popover2() { return null; }
>Popover2 : { (): null; b: typeof C; Target: () => null; }

Popover2.b = C;
>Popover2.b = C : typeof C
>Popover2.b : typeof C
>Popover2 : { (): null; b: typeof C; Target: () => null; }
>b : typeof C
>C : typeof C

Popover2.Target = Target;
>Popover2.Target = Target : () => null
>Popover2.Target : () => null
>Popover2 : { (): null; b: typeof C; Target: () => null; }
>Target : () => null
>Target : () => null

export namespace Popover2 {
export namespace Target {
export type Extra = string;
>Extra : string
}
}

Loading