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
32 changes: 16 additions & 16 deletions tsc/internal/checker/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,22 @@ func getDeclarationModifierFlagsFromSymbol(s *ast.Symbol) ast.ModifierFlags {
}

func getDeclarationModifierFlagsFromSymbolEx(s *ast.Symbol, isWrite bool) ast.ModifierFlags {
if s.CheckFlags&ast.CheckFlagsSynthetic != 0 {
var accessModifier ast.ModifierFlags
switch {
case s.CheckFlags&ast.CheckFlagsContainsPrivate != 0:
accessModifier = ast.ModifierFlagsPrivate
case s.CheckFlags&ast.CheckFlagsContainsPublic != 0:
accessModifier = ast.ModifierFlagsPublic
default:
accessModifier = ast.ModifierFlagsProtected
}
var staticModifier ast.ModifierFlags
if s.CheckFlags&ast.CheckFlagsContainsStatic != 0 {
staticModifier = ast.ModifierFlagsStatic
}
return accessModifier | staticModifier
}
if s.ValueDeclaration != nil {
var declaration *ast.Node
if isWrite {
Expand All @@ -732,22 +748,6 @@ func getDeclarationModifierFlagsFromSymbolEx(s *ast.Symbol, isWrite bool) ast.Mo
}
return flags & ^ast.ModifierFlagsAccessibilityModifier
}
if s.CheckFlags&ast.CheckFlagsSynthetic != 0 {
var accessModifier ast.ModifierFlags
switch {
case s.CheckFlags&ast.CheckFlagsContainsPrivate != 0:
accessModifier = ast.ModifierFlagsPrivate
case s.CheckFlags&ast.CheckFlagsContainsPublic != 0:
accessModifier = ast.ModifierFlagsPublic
default:
accessModifier = ast.ModifierFlagsProtected
}
var staticModifier ast.ModifierFlags
if s.CheckFlags&ast.CheckFlagsContainsStatic != 0 {
staticModifier = ast.ModifierFlagsStatic
}
return accessModifier | staticModifier
}
if s.Flags&ast.SymbolFlagsPrototype != 0 {
return ast.ModifierFlagsPublic | ast.ModifierFlagsStatic
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//// [tests/cases/compiler/syntheticProtectedProperties.ts] ////

=== syntheticProtectedProperties.ts ===
// https://github.com/microsoft/TypeScript/issues/63749

declare class Dummy {
>Dummy : Symbol(Dummy, Decl(syntheticProtectedProperties.ts, 0, 0))

a: number;
>a : Symbol(Dummy.a, Decl(syntheticProtectedProperties.ts, 2, 21))
}

type Public = Base | Dummy;
>Public : Symbol(Public, Decl(syntheticProtectedProperties.ts, 4, 1))
>Base : Symbol(Base, Decl(syntheticProtectedProperties.ts, 6, 27))
>Dummy : Symbol(Dummy, Decl(syntheticProtectedProperties.ts, 0, 0))

declare class Base {
>Base : Symbol(Base, Decl(syntheticProtectedProperties.ts, 6, 27))

protected get content(): string;
>content : Symbol(Base.content, Decl(syntheticProtectedProperties.ts, 8, 20), Decl(syntheticProtectedProperties.ts, 9, 36))

protected set content(value: string);
>content : Symbol(Base.content, Decl(syntheticProtectedProperties.ts, 8, 20), Decl(syntheticProtectedProperties.ts, 9, 36))
>value : Symbol(value, Decl(syntheticProtectedProperties.ts, 10, 26))
}

declare class Mock {
>Mock : Symbol(Mock, Decl(syntheticProtectedProperties.ts, 11, 1))

get content(): string;
>content : Symbol(Mock.content, Decl(syntheticProtectedProperties.ts, 13, 20), Decl(syntheticProtectedProperties.ts, 14, 26))

set content(value: string);
>content : Symbol(Mock.content, Decl(syntheticProtectedProperties.ts, 13, 20), Decl(syntheticProtectedProperties.ts, 14, 26))
>value : Symbol(value, Decl(syntheticProtectedProperties.ts, 15, 16))
}

declare const w: Public
>w : Symbol(w, Decl(syntheticProtectedProperties.ts, 18, 13))
>Public : Symbol(Public, Decl(syntheticProtectedProperties.ts, 4, 1))

if (w instanceof Mock) {
>w : Symbol(w, Decl(syntheticProtectedProperties.ts, 18, 13))
>Mock : Symbol(Mock, Decl(syntheticProtectedProperties.ts, 11, 1))

w.content;
>w.content : Symbol(Mock.content, Decl(syntheticProtectedProperties.ts, 8, 20), Decl(syntheticProtectedProperties.ts, 9, 36), Decl(syntheticProtectedProperties.ts, 13, 20), Decl(syntheticProtectedProperties.ts, 14, 26), Decl(syntheticProtectedProperties.ts, 13, 20) ... and 1 more)
>w : Symbol(w, Decl(syntheticProtectedProperties.ts, 18, 13))
>content : Symbol(Mock.content, Decl(syntheticProtectedProperties.ts, 8, 20), Decl(syntheticProtectedProperties.ts, 9, 36), Decl(syntheticProtectedProperties.ts, 13, 20), Decl(syntheticProtectedProperties.ts, 14, 26), Decl(syntheticProtectedProperties.ts, 13, 20) ... and 1 more)
}
declare const w2: Mock & Public
>w2 : Symbol(w2, Decl(syntheticProtectedProperties.ts, 22, 13))
>Mock : Symbol(Mock, Decl(syntheticProtectedProperties.ts, 11, 1))
>Public : Symbol(Public, Decl(syntheticProtectedProperties.ts, 4, 1))

w2.content;
>w2.content : Symbol(Mock.content, Decl(syntheticProtectedProperties.ts, 13, 20), Decl(syntheticProtectedProperties.ts, 14, 26), Decl(syntheticProtectedProperties.ts, 8, 20), Decl(syntheticProtectedProperties.ts, 9, 36), Decl(syntheticProtectedProperties.ts, 13, 20) ... and 1 more)
>w2 : Symbol(w2, Decl(syntheticProtectedProperties.ts, 22, 13))
>content : Symbol(Mock.content, Decl(syntheticProtectedProperties.ts, 13, 20), Decl(syntheticProtectedProperties.ts, 14, 26), Decl(syntheticProtectedProperties.ts, 8, 20), Decl(syntheticProtectedProperties.ts, 9, 36), Decl(syntheticProtectedProperties.ts, 13, 20) ... and 1 more)


declare const w3: Public & Mock
>w3 : Symbol(w3, Decl(syntheticProtectedProperties.ts, 26, 13))
>Public : Symbol(Public, Decl(syntheticProtectedProperties.ts, 4, 1))
>Mock : Symbol(Mock, Decl(syntheticProtectedProperties.ts, 11, 1))

w3.content;
>w3.content : Symbol(Mock.content, Decl(syntheticProtectedProperties.ts, 8, 20), Decl(syntheticProtectedProperties.ts, 9, 36), Decl(syntheticProtectedProperties.ts, 13, 20), Decl(syntheticProtectedProperties.ts, 14, 26), Decl(syntheticProtectedProperties.ts, 13, 20) ... and 1 more)
>w3 : Symbol(w3, Decl(syntheticProtectedProperties.ts, 26, 13))
>content : Symbol(Mock.content, Decl(syntheticProtectedProperties.ts, 8, 20), Decl(syntheticProtectedProperties.ts, 9, 36), Decl(syntheticProtectedProperties.ts, 13, 20), Decl(syntheticProtectedProperties.ts, 14, 26), Decl(syntheticProtectedProperties.ts, 13, 20) ... and 1 more)

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

=== syntheticProtectedProperties.ts ===
// https://github.com/microsoft/TypeScript/issues/63749

declare class Dummy {
>Dummy : Dummy

a: number;
>a : number
}

type Public = Base | Dummy;
>Public : Public

declare class Base {
>Base : Base

protected get content(): string;
>content : string

protected set content(value: string);
>content : string
>value : string
}

declare class Mock {
>Mock : Mock

get content(): string;
>content : string

set content(value: string);
>content : string
>value : string
}

declare const w: Public
>w : Public

if (w instanceof Mock) {
>w instanceof Mock : boolean
>w : Public
>Mock : typeof Mock

w.content;
>w.content : string
>w : Public & Mock
>content : string
}
declare const w2: Mock & Public
>w2 : Mock & Public

w2.content;
>w2.content : string
>w2 : Mock & Public
>content : string


declare const w3: Public & Mock
>w3 : Public & Mock

w3.content;
>w3.content : string
>w3 : Public & Mock
>content : string

30 changes: 30 additions & 0 deletions tsc/testdata/tests/cases/compiler/syntheticProtectedProperties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @noEmit: true

// https://github.com/microsoft/TypeScript/issues/63749

declare class Dummy {
a: number;
}

type Public = Base | Dummy;

declare class Base {
protected get content(): string;
protected set content(value: string);
}

declare class Mock {
get content(): string;
set content(value: string);
}

declare const w: Public
if (w instanceof Mock) {
w.content;
}
declare const w2: Mock & Public
w2.content;


declare const w3: Public & Mock
w3.content;