Move const enums and typeof facts maps out of createTypeChecker (#32691)

This commit is contained in:
Ron Buckton
2019-08-03 13:09:11 -07:00
committed by GitHub
parent e82d0af554
commit 3c690f1264

View File

@@ -57,6 +57,187 @@ namespace ts {
GeneratorYield
}
const enum TypeFacts {
None = 0,
TypeofEQString = 1 << 0, // typeof x === "string"
TypeofEQNumber = 1 << 1, // typeof x === "number"
TypeofEQBigInt = 1 << 2, // typeof x === "bigint"
TypeofEQBoolean = 1 << 3, // typeof x === "boolean"
TypeofEQSymbol = 1 << 4, // typeof x === "symbol"
TypeofEQObject = 1 << 5, // typeof x === "object"
TypeofEQFunction = 1 << 6, // typeof x === "function"
TypeofEQHostObject = 1 << 7, // typeof x === "xxx"
TypeofNEString = 1 << 8, // typeof x !== "string"
TypeofNENumber = 1 << 9, // typeof x !== "number"
TypeofNEBigInt = 1 << 10, // typeof x !== "bigint"
TypeofNEBoolean = 1 << 11, // typeof x !== "boolean"
TypeofNESymbol = 1 << 12, // typeof x !== "symbol"
TypeofNEObject = 1 << 13, // typeof x !== "object"
TypeofNEFunction = 1 << 14, // typeof x !== "function"
TypeofNEHostObject = 1 << 15, // typeof x !== "xxx"
EQUndefined = 1 << 16, // x === undefined
EQNull = 1 << 17, // x === null
EQUndefinedOrNull = 1 << 18, // x === undefined / x === null
NEUndefined = 1 << 19, // x !== undefined
NENull = 1 << 20, // x !== null
NEUndefinedOrNull = 1 << 21, // x != undefined / x != null
Truthy = 1 << 22, // x
Falsy = 1 << 23, // !x
All = (1 << 24) - 1,
// The following members encode facts about particular kinds of types for use in the getTypeFacts function.
// The presence of a particular fact means that the given test is true for some (and possibly all) values
// of that kind of type.
BaseStringStrictFacts = TypeofEQString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull,
BaseStringFacts = BaseStringStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
StringStrictFacts = BaseStringStrictFacts | Truthy | Falsy,
StringFacts = BaseStringFacts | Truthy,
EmptyStringStrictFacts = BaseStringStrictFacts | Falsy,
EmptyStringFacts = BaseStringFacts,
NonEmptyStringStrictFacts = BaseStringStrictFacts | Truthy,
NonEmptyStringFacts = BaseStringFacts | Truthy,
BaseNumberStrictFacts = TypeofEQNumber | TypeofNEString | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull,
BaseNumberFacts = BaseNumberStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
NumberStrictFacts = BaseNumberStrictFacts | Truthy | Falsy,
NumberFacts = BaseNumberFacts | Truthy,
ZeroNumberStrictFacts = BaseNumberStrictFacts | Falsy,
ZeroNumberFacts = BaseNumberFacts,
NonZeroNumberStrictFacts = BaseNumberStrictFacts | Truthy,
NonZeroNumberFacts = BaseNumberFacts | Truthy,
BaseBigIntStrictFacts = TypeofEQBigInt | TypeofNEString | TypeofNENumber | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull,
BaseBigIntFacts = BaseBigIntStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
BigIntStrictFacts = BaseBigIntStrictFacts | Truthy | Falsy,
BigIntFacts = BaseBigIntFacts | Truthy,
ZeroBigIntStrictFacts = BaseBigIntStrictFacts | Falsy,
ZeroBigIntFacts = BaseBigIntFacts,
NonZeroBigIntStrictFacts = BaseBigIntStrictFacts | Truthy,
NonZeroBigIntFacts = BaseBigIntFacts | Truthy,
BaseBooleanStrictFacts = TypeofEQBoolean | TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull,
BaseBooleanFacts = BaseBooleanStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
BooleanStrictFacts = BaseBooleanStrictFacts | Truthy | Falsy,
BooleanFacts = BaseBooleanFacts | Truthy,
FalseStrictFacts = BaseBooleanStrictFacts | Falsy,
FalseFacts = BaseBooleanFacts,
TrueStrictFacts = BaseBooleanStrictFacts | Truthy,
TrueFacts = BaseBooleanFacts | Truthy,
SymbolStrictFacts = TypeofEQSymbol | TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull | Truthy,
SymbolFacts = SymbolStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
ObjectStrictFacts = TypeofEQObject | TypeofEQHostObject | TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEFunction | NEUndefined | NENull | NEUndefinedOrNull | Truthy,
ObjectFacts = ObjectStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
FunctionStrictFacts = TypeofEQFunction | TypeofEQHostObject | TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | NEUndefined | NENull | NEUndefinedOrNull | Truthy,
FunctionFacts = FunctionStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
UndefinedFacts = TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | EQUndefined | EQUndefinedOrNull | NENull | Falsy,
NullFacts = TypeofEQObject | TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEFunction | TypeofNEHostObject | EQNull | EQUndefinedOrNull | NEUndefined | Falsy,
EmptyObjectStrictFacts = All & ~(EQUndefined | EQNull | EQUndefinedOrNull),
EmptyObjectFacts = All,
}
const typeofEQFacts: ReadonlyMap<TypeFacts> = createMapFromTemplate({
string: TypeFacts.TypeofEQString,
number: TypeFacts.TypeofEQNumber,
bigint: TypeFacts.TypeofEQBigInt,
boolean: TypeFacts.TypeofEQBoolean,
symbol: TypeFacts.TypeofEQSymbol,
undefined: TypeFacts.EQUndefined,
object: TypeFacts.TypeofEQObject,
function: TypeFacts.TypeofEQFunction
});
const typeofNEFacts: ReadonlyMap<TypeFacts> = createMapFromTemplate({
string: TypeFacts.TypeofNEString,
number: TypeFacts.TypeofNENumber,
bigint: TypeFacts.TypeofNEBigInt,
boolean: TypeFacts.TypeofNEBoolean,
symbol: TypeFacts.TypeofNESymbol,
undefined: TypeFacts.NEUndefined,
object: TypeFacts.TypeofNEObject,
function: TypeFacts.TypeofNEFunction
});
type TypeSystemEntity = Node | Symbol | Type | Signature;
const enum TypeSystemPropertyName {
Type,
ResolvedBaseConstructorType,
DeclaredType,
ResolvedReturnType,
ImmediateBaseConstraint,
EnumTagType,
JSDocTypeReference,
}
const enum CheckMode {
Normal = 0, // Normal type checking
Contextual = 1 << 0, // Explicitly assigned contextual type, therefore not cacheable
Inferential = 1 << 1, // Inferential typing
SkipContextSensitive = 1 << 2, // Skip context sensitive function expressions
SkipGenericFunctions = 1 << 3, // Skip single signature generic functions
IsForSignatureHelp = 1 << 4, // Call resolution for purposes of signature help
}
const enum ContextFlags {
None = 0,
Signature = 1 << 0, // Obtaining contextual signature
}
const enum AccessFlags {
None = 0,
NoIndexSignatures = 1 << 0,
Writing = 1 << 1,
CacheSymbol = 1 << 2,
NoTupleBoundsCheck = 1 << 3,
}
const enum CallbackCheck {
None,
Bivariant,
Strict,
}
const enum MappedTypeModifiers {
IncludeReadonly = 1 << 0,
ExcludeReadonly = 1 << 1,
IncludeOptional = 1 << 2,
ExcludeOptional = 1 << 3,
}
const enum ExpandingFlags {
None = 0,
Source = 1,
Target = 1 << 1,
Both = Source | Target,
}
const enum MembersOrExportsResolutionKind {
resolvedExports = "resolvedExports",
resolvedMembers = "resolvedMembers"
}
const enum UnusedKind {
Local,
Parameter,
}
/** @param containingNode Node to check for parse error */
type AddUnusedDiagnostic = (containingNode: Node, type: UnusedKind, diagnostic: DiagnosticWithLocation) => void;
const isNotOverloadAndNotAccessor = and(isNotOverload, isNotAccessor);
const enum DeclarationMeaning {
GetAccessor = 1,
SetAccessor = 2,
PropertyAssignment = 4,
Method = 8,
GetOrSetAccessor = GetAccessor | SetAccessor,
PropertyAssignmentOrMethod = PropertyAssignment | Method,
}
const enum DeclarationSpaces {
None = 0,
ExportValue = 1 << 0,
ExportType = 1 << 1,
ExportNamespace = 1 << 2,
}
export function getNodeId(node: Node): number {
if (!node.id) {
node.id = nextNodeId;
@@ -670,101 +851,7 @@ namespace ts {
// Suggestion diagnostics must have a file. Keyed by source file name.
const suggestionDiagnostics = createMultiMap<DiagnosticWithLocation>();
const enum TypeFacts {
None = 0,
TypeofEQString = 1 << 0, // typeof x === "string"
TypeofEQNumber = 1 << 1, // typeof x === "number"
TypeofEQBigInt = 1 << 2, // typeof x === "bigint"
TypeofEQBoolean = 1 << 3, // typeof x === "boolean"
TypeofEQSymbol = 1 << 4, // typeof x === "symbol"
TypeofEQObject = 1 << 5, // typeof x === "object"
TypeofEQFunction = 1 << 6, // typeof x === "function"
TypeofEQHostObject = 1 << 7, // typeof x === "xxx"
TypeofNEString = 1 << 8, // typeof x !== "string"
TypeofNENumber = 1 << 9, // typeof x !== "number"
TypeofNEBigInt = 1 << 10, // typeof x !== "bigint"
TypeofNEBoolean = 1 << 11, // typeof x !== "boolean"
TypeofNESymbol = 1 << 12, // typeof x !== "symbol"
TypeofNEObject = 1 << 13, // typeof x !== "object"
TypeofNEFunction = 1 << 14, // typeof x !== "function"
TypeofNEHostObject = 1 << 15, // typeof x !== "xxx"
EQUndefined = 1 << 16, // x === undefined
EQNull = 1 << 17, // x === null
EQUndefinedOrNull = 1 << 18, // x === undefined / x === null
NEUndefined = 1 << 19, // x !== undefined
NENull = 1 << 20, // x !== null
NEUndefinedOrNull = 1 << 21, // x != undefined / x != null
Truthy = 1 << 22, // x
Falsy = 1 << 23, // !x
All = (1 << 24) - 1,
// The following members encode facts about particular kinds of types for use in the getTypeFacts function.
// The presence of a particular fact means that the given test is true for some (and possibly all) values
// of that kind of type.
BaseStringStrictFacts = TypeofEQString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull,
BaseStringFacts = BaseStringStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
StringStrictFacts = BaseStringStrictFacts | Truthy | Falsy,
StringFacts = BaseStringFacts | Truthy,
EmptyStringStrictFacts = BaseStringStrictFacts | Falsy,
EmptyStringFacts = BaseStringFacts,
NonEmptyStringStrictFacts = BaseStringStrictFacts | Truthy,
NonEmptyStringFacts = BaseStringFacts | Truthy,
BaseNumberStrictFacts = TypeofEQNumber | TypeofNEString | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull,
BaseNumberFacts = BaseNumberStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
NumberStrictFacts = BaseNumberStrictFacts | Truthy | Falsy,
NumberFacts = BaseNumberFacts | Truthy,
ZeroNumberStrictFacts = BaseNumberStrictFacts | Falsy,
ZeroNumberFacts = BaseNumberFacts,
NonZeroNumberStrictFacts = BaseNumberStrictFacts | Truthy,
NonZeroNumberFacts = BaseNumberFacts | Truthy,
BaseBigIntStrictFacts = TypeofEQBigInt | TypeofNEString | TypeofNENumber | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull,
BaseBigIntFacts = BaseBigIntStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
BigIntStrictFacts = BaseBigIntStrictFacts | Truthy | Falsy,
BigIntFacts = BaseBigIntFacts | Truthy,
ZeroBigIntStrictFacts = BaseBigIntStrictFacts | Falsy,
ZeroBigIntFacts = BaseBigIntFacts,
NonZeroBigIntStrictFacts = BaseBigIntStrictFacts | Truthy,
NonZeroBigIntFacts = BaseBigIntFacts | Truthy,
BaseBooleanStrictFacts = TypeofEQBoolean | TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull,
BaseBooleanFacts = BaseBooleanStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
BooleanStrictFacts = BaseBooleanStrictFacts | Truthy | Falsy,
BooleanFacts = BaseBooleanFacts | Truthy,
FalseStrictFacts = BaseBooleanStrictFacts | Falsy,
FalseFacts = BaseBooleanFacts,
TrueStrictFacts = BaseBooleanStrictFacts | Truthy,
TrueFacts = BaseBooleanFacts | Truthy,
SymbolStrictFacts = TypeofEQSymbol | TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull | Truthy,
SymbolFacts = SymbolStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
ObjectStrictFacts = TypeofEQObject | TypeofEQHostObject | TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEFunction | NEUndefined | NENull | NEUndefinedOrNull | Truthy,
ObjectFacts = ObjectStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
FunctionStrictFacts = TypeofEQFunction | TypeofEQHostObject | TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | NEUndefined | NENull | NEUndefinedOrNull | Truthy,
FunctionFacts = FunctionStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
UndefinedFacts = TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | EQUndefined | EQUndefinedOrNull | NENull | Falsy,
NullFacts = TypeofEQObject | TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEFunction | TypeofNEHostObject | EQNull | EQUndefinedOrNull | NEUndefined | Falsy,
EmptyObjectStrictFacts = All & ~(EQUndefined | EQNull | EQUndefinedOrNull),
EmptyObjectFacts = All,
}
const typeofEQFacts = createMapFromTemplate({
string: TypeFacts.TypeofEQString,
number: TypeFacts.TypeofEQNumber,
bigint: TypeFacts.TypeofEQBigInt,
boolean: TypeFacts.TypeofEQBoolean,
symbol: TypeFacts.TypeofEQSymbol,
undefined: TypeFacts.EQUndefined,
object: TypeFacts.TypeofEQObject,
function: TypeFacts.TypeofEQFunction
});
const typeofNEFacts = createMapFromTemplate({
string: TypeFacts.TypeofNEString,
number: TypeFacts.TypeofNENumber,
bigint: TypeFacts.TypeofNEBigInt,
boolean: TypeFacts.TypeofNEBoolean,
symbol: TypeFacts.TypeofNESymbol,
undefined: TypeFacts.NEUndefined,
object: TypeFacts.TypeofNEObject,
function: TypeFacts.TypeofNEFunction
});
const typeofTypesByName = createMapFromTemplate<Type>({
const typeofTypesByName: ReadonlyMap<Type> = createMapFromTemplate<Type>({
string: stringType,
number: numberType,
bigint: bigintType,
@@ -784,77 +871,9 @@ namespace ts {
const identityRelation = createMap<RelationComparisonResult>();
const enumRelation = createMap<RelationComparisonResult>();
type TypeSystemEntity = Node | Symbol | Type | Signature;
const enum TypeSystemPropertyName {
Type,
ResolvedBaseConstructorType,
DeclaredType,
ResolvedReturnType,
ImmediateBaseConstraint,
EnumTagType,
JSDocTypeReference,
}
const enum CheckMode {
Normal = 0, // Normal type checking
Contextual = 1 << 0, // Explicitly assigned contextual type, therefore not cacheable
Inferential = 1 << 1, // Inferential typing
SkipContextSensitive = 1 << 2, // Skip context sensitive function expressions
SkipGenericFunctions = 1 << 3, // Skip single signature generic functions
IsForSignatureHelp = 1 << 4, // Call resolution for purposes of signature help
}
const enum ContextFlags {
None = 0,
Signature = 1 << 0, // Obtaining contextual signature
}
const enum AccessFlags {
None = 0,
NoIndexSignatures = 1 << 0,
Writing = 1 << 1,
CacheSymbol = 1 << 2,
NoTupleBoundsCheck = 1 << 3,
}
const enum CallbackCheck {
None,
Bivariant,
Strict,
}
const enum MappedTypeModifiers {
IncludeReadonly = 1 << 0,
ExcludeReadonly = 1 << 1,
IncludeOptional = 1 << 2,
ExcludeOptional = 1 << 3,
}
const enum ExpandingFlags {
None = 0,
Source = 1,
Target = 1 << 1,
Both = Source | Target,
}
const enum MembersOrExportsResolutionKind {
resolvedExports = "resolvedExports",
resolvedMembers = "resolvedMembers"
}
const enum UnusedKind {
Local,
Parameter,
}
/** @param containingNode Node to check for parse error */
type AddUnusedDiagnostic = (containingNode: Node, type: UnusedKind, diagnostic: DiagnosticWithLocation) => void;
const builtinGlobals = createSymbolTable();
builtinGlobals.set(undefinedSymbol.escapedName, undefinedSymbol);
const isNotOverloadAndNotAccessor = and(isNotOverload, isNotAccessor);
initializeTypeChecker();
return checker;
@@ -25570,20 +25589,13 @@ namespace ts {
}
function checkClassForDuplicateDeclarations(node: ClassLikeDeclaration) {
const enum Declaration {
Getter = 1,
Setter = 2,
Method = 4,
Property = Getter | Setter
}
const instanceNames = createUnderscoreEscapedMap<Declaration>();
const staticNames = createUnderscoreEscapedMap<Declaration>();
const instanceNames = createUnderscoreEscapedMap<DeclarationMeaning>();
const staticNames = createUnderscoreEscapedMap<DeclarationMeaning>();
for (const member of node.members) {
if (member.kind === SyntaxKind.Constructor) {
for (const param of (member as ConstructorDeclaration).parameters) {
if (isParameterPropertyDeclaration(param) && !isBindingPattern(param.name)) {
addName(instanceNames, param.name, param.name.escapedText, Declaration.Property);
addName(instanceNames, param.name, param.name.escapedText, DeclarationMeaning.GetOrSetAccessor);
}
}
}
@@ -25596,30 +25608,30 @@ namespace ts {
if (name && memberName) {
switch (member.kind) {
case SyntaxKind.GetAccessor:
addName(names, name, memberName, Declaration.Getter);
addName(names, name, memberName, DeclarationMeaning.GetAccessor);
break;
case SyntaxKind.SetAccessor:
addName(names, name, memberName, Declaration.Setter);
addName(names, name, memberName, DeclarationMeaning.SetAccessor);
break;
case SyntaxKind.PropertyDeclaration:
addName(names, name, memberName, Declaration.Property);
addName(names, name, memberName, DeclarationMeaning.GetOrSetAccessor);
break;
case SyntaxKind.MethodDeclaration:
addName(names, name, memberName, Declaration.Method);
addName(names, name, memberName, DeclarationMeaning.Method);
break;
}
}
}
}
function addName(names: UnderscoreEscapedMap<Declaration>, location: Node, name: __String, meaning: Declaration) {
function addName(names: UnderscoreEscapedMap<DeclarationMeaning>, location: Node, name: __String, meaning: DeclarationMeaning) {
const prev = names.get(name);
if (prev) {
if (prev & Declaration.Method) {
if (meaning !== Declaration.Method) {
if (prev & DeclarationMeaning.Method) {
if (meaning !== DeclarationMeaning.Method) {
error(location, Diagnostics.Duplicate_identifier_0, getTextOfNode(location));
}
}
@@ -26333,12 +26345,6 @@ namespace ts {
}
}
const enum DeclarationSpaces {
None = 0,
ExportValue = 1 << 0,
ExportType = 1 << 1,
ExportNamespace = 1 << 2,
}
function checkExportsOnMergedDeclarations(node: Node): void {
if (!produceDiagnostics) {
return;
@@ -30247,16 +30253,6 @@ namespace ts {
}
}
function isNotAccessor(declaration: Declaration): boolean {
// Accessors check for their own matching duplicates, and in contexts where they are valid, there are already duplicate identifier checks
return !isAccessor(declaration);
}
function isNotOverload(declaration: Declaration): boolean {
return (declaration.kind !== SyntaxKind.FunctionDeclaration && declaration.kind !== SyntaxKind.MethodDeclaration) ||
!!(declaration as FunctionDeclaration).body;
}
function checkSourceElement(node: Node | undefined): void {
if (node) {
const saveCurrentNode = currentNode;
@@ -32825,13 +32821,7 @@ namespace ts {
}
function checkGrammarObjectLiteralExpression(node: ObjectLiteralExpression, inDestructuring: boolean) {
const enum Flags {
Property = 1,
GetAccessor = 2,
SetAccessor = 4,
GetOrSetAccessor = GetAccessor | SetAccessor,
}
const seen = createUnderscoreEscapedMap<Flags>();
const seen = createUnderscoreEscapedMap<DeclarationMeaning>();
for (const prop of node.properties) {
if (prop.kind === SyntaxKind.SpreadAssignment) {
@@ -32873,7 +32863,7 @@ namespace ts {
// c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true.
// d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true
// and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields
let currentKind: Flags;
let currentKind: DeclarationMeaning;
switch (prop.kind) {
case SyntaxKind.ShorthandPropertyAssignment:
checkGrammarForInvalidExclamationToken(prop.exclamationToken, Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context);
@@ -32884,15 +32874,16 @@ namespace ts {
if (name.kind === SyntaxKind.NumericLiteral) {
checkGrammarNumericLiteral(name);
}
// falls through
currentKind = DeclarationMeaning.PropertyAssignment;
break;
case SyntaxKind.MethodDeclaration:
currentKind = Flags.Property;
currentKind = DeclarationMeaning.Method;
break;
case SyntaxKind.GetAccessor:
currentKind = Flags.GetAccessor;
currentKind = DeclarationMeaning.GetAccessor;
break;
case SyntaxKind.SetAccessor:
currentKind = Flags.SetAccessor;
currentKind = DeclarationMeaning.SetAccessor;
break;
default:
throw Debug.assertNever(prop, "Unexpected syntax kind:" + (<Node>prop).kind);
@@ -32908,11 +32899,11 @@ namespace ts {
seen.set(effectiveName, currentKind);
}
else {
if (currentKind === Flags.Property && existingKind === Flags.Property) {
if ((currentKind & DeclarationMeaning.PropertyAssignmentOrMethod) && (existingKind & DeclarationMeaning.PropertyAssignmentOrMethod)) {
grammarErrorOnNode(name, Diagnostics.Duplicate_identifier_0, getTextOfNode(name));
}
else if ((currentKind & Flags.GetOrSetAccessor) && (existingKind & Flags.GetOrSetAccessor)) {
if (existingKind !== Flags.GetOrSetAccessor && currentKind !== existingKind) {
else if ((currentKind & DeclarationMeaning.GetOrSetAccessor) && (existingKind & DeclarationMeaning.GetOrSetAccessor)) {
if (existingKind !== DeclarationMeaning.GetOrSetAccessor && currentKind !== existingKind) {
seen.set(effectiveName, currentKind | existingKind);
}
else {
@@ -33659,6 +33650,16 @@ namespace ts {
}
}
function isNotAccessor(declaration: Declaration): boolean {
// Accessors check for their own matching duplicates, and in contexts where they are valid, there are already duplicate identifier checks
return !isAccessor(declaration);
}
function isNotOverload(declaration: Declaration): boolean {
return (declaration.kind !== SyntaxKind.FunctionDeclaration && declaration.kind !== SyntaxKind.MethodDeclaration) ||
!!(declaration as FunctionDeclaration).body;
}
/** Like 'isDeclarationName', but returns true for LHS of `import { x as y }` or `export { x as y }`. */
function isDeclarationNameOrImportPropertyName(name: Node): boolean {
switch (name.parent.kind) {