Skip to content
Merged
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
29 changes: 16 additions & 13 deletions packages/typescript/src/enums/checkFlags.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ export enum CheckFlags {
ContainsPublic = 1 << 8,
ContainsProtected = 1 << 9,
ContainsPrivate = 1 << 10,
ContainsStatic = 1 << 11,
Late = 1 << 12,
ReverseMapped = 1 << 13,
OptionalParameter = 1 << 14,
RestParameter = 1 << 15,
DeferredType = 1 << 16,
HasNeverType = 1 << 17,
Mapped = 1 << 18,
StripOptional = 1 << 19,
Unresolved = 1 << 20,
IsDiscriminantComputed = 1 << 21,
IsDiscriminant = 1 << 22,
IndexSymbol = 1 << 23,
ContainsWritePublic = 1 << 11,
ContainsWriteProtected = 1 << 12,
ContainsWritePrivate = 1 << 13,
ContainsStatic = 1 << 14,
Late = 1 << 15,
ReverseMapped = 1 << 16,
OptionalParameter = 1 << 17,
RestParameter = 1 << 18,
DeferredType = 1 << 19,
HasNeverType = 1 << 20,
Mapped = 1 << 21,
StripOptional = 1 << 22,
Unresolved = 1 << 23,
IsDiscriminantComputed = 1 << 24,
IsDiscriminant = 1 << 25,
IndexSymbol = 1 << 26,
Synthetic = SyntheticProperty | SyntheticMethod,
NonUniformAndLiteral = HasNonUniformType | HasLiteralType,
Partial = ReadPartial | WritePartial,
Expand Down
29 changes: 16 additions & 13 deletions packages/typescript/src/enums/checkFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ export var CheckFlags: any;
CheckFlags[CheckFlags["ContainsPublic"] = 256] = "ContainsPublic";
CheckFlags[CheckFlags["ContainsProtected"] = 512] = "ContainsProtected";
CheckFlags[CheckFlags["ContainsPrivate"] = 1024] = "ContainsPrivate";
CheckFlags[CheckFlags["ContainsStatic"] = 2048] = "ContainsStatic";
CheckFlags[CheckFlags["Late"] = 4096] = "Late";
CheckFlags[CheckFlags["ReverseMapped"] = 8192] = "ReverseMapped";
CheckFlags[CheckFlags["OptionalParameter"] = 16384] = "OptionalParameter";
CheckFlags[CheckFlags["RestParameter"] = 32768] = "RestParameter";
CheckFlags[CheckFlags["DeferredType"] = 65536] = "DeferredType";
CheckFlags[CheckFlags["HasNeverType"] = 131072] = "HasNeverType";
CheckFlags[CheckFlags["Mapped"] = 262144] = "Mapped";
CheckFlags[CheckFlags["StripOptional"] = 524288] = "StripOptional";
CheckFlags[CheckFlags["Unresolved"] = 1048576] = "Unresolved";
CheckFlags[CheckFlags["IsDiscriminantComputed"] = 2097152] = "IsDiscriminantComputed";
CheckFlags[CheckFlags["IsDiscriminant"] = 4194304] = "IsDiscriminant";
CheckFlags[CheckFlags["IndexSymbol"] = 8388608] = "IndexSymbol";
CheckFlags[CheckFlags["ContainsWritePublic"] = 2048] = "ContainsWritePublic";
CheckFlags[CheckFlags["ContainsWriteProtected"] = 4096] = "ContainsWriteProtected";
CheckFlags[CheckFlags["ContainsWritePrivate"] = 8192] = "ContainsWritePrivate";
CheckFlags[CheckFlags["ContainsStatic"] = 16384] = "ContainsStatic";
CheckFlags[CheckFlags["Late"] = 32768] = "Late";
CheckFlags[CheckFlags["ReverseMapped"] = 65536] = "ReverseMapped";
CheckFlags[CheckFlags["OptionalParameter"] = 131072] = "OptionalParameter";
CheckFlags[CheckFlags["RestParameter"] = 262144] = "RestParameter";
CheckFlags[CheckFlags["DeferredType"] = 524288] = "DeferredType";
CheckFlags[CheckFlags["HasNeverType"] = 1048576] = "HasNeverType";
CheckFlags[CheckFlags["Mapped"] = 2097152] = "Mapped";
CheckFlags[CheckFlags["StripOptional"] = 4194304] = "StripOptional";
CheckFlags[CheckFlags["Unresolved"] = 8388608] = "Unresolved";
CheckFlags[CheckFlags["IsDiscriminantComputed"] = 16777216] = "IsDiscriminantComputed";
CheckFlags[CheckFlags["IsDiscriminant"] = 33554432] = "IsDiscriminant";
CheckFlags[CheckFlags["IndexSymbol"] = 67108864] = "IndexSymbol";
CheckFlags[CheckFlags["Synthetic"] = 6] = "Synthetic";
CheckFlags[CheckFlags["NonUniformAndLiteral"] = 192] = "NonUniformAndLiteral";
CheckFlags[CheckFlags["Partial"] = 48] = "Partial";
Expand Down
29 changes: 16 additions & 13 deletions tsc/internal/ast/checkflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ const (
CheckFlagsContainsPublic CheckFlags = 1 << 8 // Synthetic property with public constituent(s)
CheckFlagsContainsProtected CheckFlags = 1 << 9 // Synthetic property with protected constituent(s)
CheckFlagsContainsPrivate CheckFlags = 1 << 10 // Synthetic property with private constituent(s)
CheckFlagsContainsStatic CheckFlags = 1 << 11 // Synthetic property with static constituent(s)
CheckFlagsLate CheckFlags = 1 << 12 // Late-bound symbol for a computed property with a dynamic name
CheckFlagsReverseMapped CheckFlags = 1 << 13 // Property of reverse-inferred homomorphic mapped type
CheckFlagsOptionalParameter CheckFlags = 1 << 14 // Optional parameter
CheckFlagsRestParameter CheckFlags = 1 << 15 // Rest parameter
CheckFlagsDeferredType CheckFlags = 1 << 16 // Calculation of the type of this symbol is deferred due to processing costs, should be fetched with `getTypeOfSymbolWithDeferredType`
CheckFlagsHasNeverType CheckFlags = 1 << 17 // Synthetic property with at least one never type in constituents
CheckFlagsMapped CheckFlags = 1 << 18 // Property of mapped type
CheckFlagsStripOptional CheckFlags = 1 << 19 // Strip optionality in mapped property
CheckFlagsUnresolved CheckFlags = 1 << 20 // Unresolved type alias symbol
CheckFlagsIsDiscriminantComputed CheckFlags = 1 << 21 // IsDiscriminant flags has been computed
CheckFlagsIsDiscriminant CheckFlags = 1 << 22 // Discriminant property
CheckFlagsIndexSymbol CheckFlags = 1 << 23 // Synthetic property created from index signature
CheckFlagsContainsWritePublic CheckFlags = 1 << 11 // Synthetic property with public set accessors(s)
CheckFlagsContainsWriteProtected CheckFlags = 1 << 12 // Synthetic property with protected set accessors(s)
CheckFlagsContainsWritePrivate CheckFlags = 1 << 13 // Synthetic property with private set accessors(s)
CheckFlagsContainsStatic CheckFlags = 1 << 14 // Synthetic property with static constituent(s)
CheckFlagsLate CheckFlags = 1 << 15 // Late-bound symbol for a computed property with a dynamic name
CheckFlagsReverseMapped CheckFlags = 1 << 16 // Property of reverse-inferred homomorphic mapped type
CheckFlagsOptionalParameter CheckFlags = 1 << 17 // Optional parameter
CheckFlagsRestParameter CheckFlags = 1 << 18 // Rest parameter
CheckFlagsDeferredType CheckFlags = 1 << 19 // Calculation of the type of this symbol is deferred due to processing costs, should be fetched with `getTypeOfSymbolWithDeferredType`
CheckFlagsHasNeverType CheckFlags = 1 << 20 // Synthetic property with at least one never type in constituents
CheckFlagsMapped CheckFlags = 1 << 21 // Property of mapped type
CheckFlagsStripOptional CheckFlags = 1 << 22 // Strip optionality in mapped property
CheckFlagsUnresolved CheckFlags = 1 << 23 // Unresolved type alias symbol
CheckFlagsIsDiscriminantComputed CheckFlags = 1 << 24 // IsDiscriminant flags has been computed
CheckFlagsIsDiscriminant CheckFlags = 1 << 25 // Discriminant property
CheckFlagsIndexSymbol CheckFlags = 1 << 26 // Synthetic property created from index signature
CheckFlagsSynthetic = CheckFlagsSyntheticProperty | CheckFlagsSyntheticMethod
CheckFlagsNonUniformAndLiteral = CheckFlagsHasNonUniformType | CheckFlagsHasLiteralType
CheckFlagsPartial = CheckFlagsReadPartial | CheckFlagsWritePartial
Expand Down
57 changes: 39 additions & 18 deletions tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11922,10 +11922,14 @@ func (c *Checker) checkPropertyAccessibilityAtLocation(location *ast.Node, isSup
// Property is known to be private or protected at this point
// Private property is accessible if the property is within the declaring class
if flags&ast.ModifierFlagsPrivate != 0 {
declaringClassDeclaration := ast.GetClassLikeDeclarationOfSymbol(c.getParentOfSymbol(prop))
if !c.isNodeWithinClass(location, declaringClassDeclaration) {
var declaringClassDeclaration *ast.Node
if parent := c.getParentOfSymbol(prop); parent != nil {
declaringClassDeclaration = ast.GetClassLikeDeclarationOfSymbol(parent)
}
if declaringClassDeclaration == nil || !c.isNodeWithinClass(location, declaringClassDeclaration) {
if errorNode != nil {
c.error(errorNode, diagnostics.Property_0_is_private_and_only_accessible_within_class_1, c.symbolToString(prop), c.TypeToString(c.getDeclaringClass(prop)))
class := core.OrElse(c.getDeclaringClass(prop), containingType)
c.error(errorNode, diagnostics.Property_0_is_private_and_only_accessible_within_class_1, c.symbolToString(prop), c.TypeToString(class))
}
return false
}
Expand Down Expand Up @@ -11958,10 +11962,7 @@ func (c *Checker) checkPropertyAccessibilityAtLocation(location *ast.Node, isSup
}
if flags&ast.ModifierFlagsStatic != 0 || enclosingClass == nil {
if errorNode != nil {
class := c.getDeclaringClass(prop)
if class == nil {
class = containingType
}
class := core.OrElse(c.getDeclaringClass(prop), containingType)
c.error(errorNode, diagnostics.Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses, c.symbolToString(prop), c.TypeToString(class))
}
return false
Expand Down Expand Up @@ -21585,6 +21586,7 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s
var modifiers ast.ModifierFlags
if prop != nil {
modifiers = getDeclarationModifierFlagsFromSymbol(prop)
writeModifiers := getDeclarationModifierFlagsFromSymbolEx(prop, true /*isWrite*/)
if prop.Flags&ast.SymbolFlagsClassMember != 0 {
if isUnion {
optionalFlag |= prop.Flags & ast.SymbolFlagsOptional
Expand Down Expand Up @@ -21624,14 +21626,19 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s
} else if !isUnion && !c.isReadonlySymbol(prop) {
checkFlags &^= ast.CheckFlagsReadonly
}
if modifiers&ast.ModifierFlagsNonPublicAccessibilityModifier == 0 {
checkFlags |= ast.CheckFlagsContainsPublic
}
if modifiers&ast.ModifierFlagsProtected != 0 {
if modifiers&ast.ModifierFlagsProtected != 0 && modifiers&ast.ModifierFlagsPublic == 0 {
checkFlags |= ast.CheckFlagsContainsProtected
}
if modifiers&ast.ModifierFlagsPrivate != 0 {
} else if modifiers&ast.ModifierFlagsPrivate != 0 && modifiers&ast.ModifierFlagsPublic == 0 {
checkFlags |= ast.CheckFlagsContainsPrivate
} else {
checkFlags |= ast.CheckFlagsContainsPublic
}
if writeModifiers&ast.ModifierFlagsProtected != 0 && writeModifiers&ast.ModifierFlagsPublic == 0 {
checkFlags |= ast.CheckFlagsContainsWriteProtected
} else if writeModifiers&ast.ModifierFlagsPrivate != 0 && writeModifiers&ast.ModifierFlagsPublic == 0 {
checkFlags |= ast.CheckFlagsContainsWritePrivate
} else {
checkFlags |= ast.CheckFlagsContainsWritePublic
}
if modifiers&ast.ModifierFlagsStatic != 0 {
checkFlags |= ast.CheckFlagsContainsStatic
Expand Down Expand Up @@ -21665,13 +21672,27 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s
}
}
}
if singleProp == nil || isUnion &&
if singleProp == nil {
// No property was found
return nil
}
if isUnion &&
(propSet.Size() != 0 || checkFlags&ast.CheckFlagsPartial != 0) &&
checkFlags&(ast.CheckFlagsContainsPrivate|ast.CheckFlagsContainsProtected) != 0 &&
checkFlags&(ast.CheckFlagsContainsPrivate|ast.CheckFlagsContainsProtected|ast.CheckFlagsContainsWritePrivate|ast.CheckFlagsContainsWriteProtected) != 0 &&
!(propSet.Size() != 0 && c.hasCommonDeclaration(&propSet)) {
// No property was found, or, in a union, a property has a private or protected declaration in one
// constituent, but is missing or has a different declaration in another constituent.
return nil
// A property in a union has a private or protected declaration in one constituent, but is missing
// or has a different declaration in another constituent. If the private or protected declaration is
// for reading, we don't create a property.
if checkFlags&(ast.CheckFlagsContainsPrivate|ast.CheckFlagsContainsProtected) != 0 {
return nil
}
// Otherwise, if the private or protected declaration is for writing, reduce accessibility to that of
// the most restricted constituent.
if checkFlags&ast.CheckFlagsContainsWritePrivate != 0 {
checkFlags &^= ast.CheckFlagsContainsWritePublic | ast.CheckFlagsContainsWriteProtected
} else if checkFlags&ast.CheckFlagsContainsWriteProtected != 0 {
checkFlags &^= ast.CheckFlagsContainsWritePublic
}
}
if propSet.Size() == 0 && checkFlags&ast.CheckFlagsReadPartial == 0 && len(indexTypes) == 0 {
if !mergedInstantiations {
Expand Down
31 changes: 15 additions & 16 deletions tsc/internal/checker/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,21 @@ func getDeclarationModifierFlagsFromSymbol(s *ast.Symbol) ast.ModifierFlags {
}

func getDeclarationModifierFlagsFromSymbolEx(s *ast.Symbol, isWrite bool) ast.ModifierFlags {
if s.CheckFlags&ast.CheckFlagsSynthetic != 0 {
Comment thread
ahejlsberg marked this conversation as resolved.
var accessModifier ast.ModifierFlags
switch {
case !isWrite && s.CheckFlags&ast.CheckFlagsContainsPublic != 0 || isWrite && s.CheckFlags&ast.CheckFlagsContainsWritePublic != 0:
accessModifier = ast.ModifierFlagsPublic
case !isWrite && s.CheckFlags&ast.CheckFlagsContainsProtected != 0 || isWrite && s.CheckFlags&ast.CheckFlagsContainsWriteProtected != 0:
accessModifier = ast.ModifierFlagsProtected
case !isWrite && s.CheckFlags&ast.CheckFlagsContainsPrivate != 0 || isWrite && s.CheckFlags&ast.CheckFlagsContainsWritePrivate != 0:
accessModifier = ast.ModifierFlagsPrivate
}
if s.CheckFlags&ast.CheckFlagsContainsStatic != 0 {
return accessModifier | ast.ModifierFlagsStatic
}
return accessModifier
}
if s.ValueDeclaration != nil {
var declaration *ast.Node
if isWrite {
Expand All @@ -732,22 +747,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
Loading