Skip to content

Commit e63ffe5

Browse files
committed
Move FreshLiteral flag from TypeFlags to ObjectFlags
1 parent 7df5a2c commit e63ffe5

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

src/compiler/checker.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ namespace ts {
8282
const noImplicitAny = getStrictOptionValue(compilerOptions, "noImplicitAny");
8383
const noImplicitThis = getStrictOptionValue(compilerOptions, "noImplicitThis");
8484
const keyofStringsOnly = !!compilerOptions.keyofStringsOnly;
85+
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : ObjectFlags.FreshLiteral;
8586

8687
const emitResolver = createResolver();
8788
const nodeBuilder = createNodeBuilder();
@@ -10000,8 +10001,8 @@ namespace ts {
1000010001
emptyArray,
1000110002
getNonReadonlyIndexSignature(stringIndexInfo),
1000210003
getNonReadonlyIndexSignature(numberIndexInfo));
10003-
spread.flags |= typeFlags | TypeFlags.ContainsObjectLiteral;
10004-
(spread as ObjectType).objectFlags |= objectFlags | (ObjectFlags.ObjectLiteral | ObjectFlags.ContainsSpread);
10004+
spread.flags |= TypeFlags.ContainsObjectLiteral | typeFlags;
10005+
spread.objectFlags |= ObjectFlags.ObjectLiteral | ObjectFlags.ContainsSpread | objectFlags;
1000510006
return spread;
1000610007
}
1000710008

@@ -11553,7 +11554,7 @@ namespace ts {
1155311554
isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
1155411555

1155511556
const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes);
11556-
if (isObjectLiteralType(source) && source.flags & TypeFlags.FreshLiteral) {
11557+
if (isObjectLiteralType(source) && getObjectFlags(source) & ObjectFlags.FreshLiteral) {
1155711558
const discriminantType = target.flags & TypeFlags.Union ? findMatchingDiscriminantType(source, target as UnionType) : undefined;
1155811559
if (hasExcessProperties(<FreshObjectLiteralType>source, target, discriminantType, reportErrors)) {
1155911560
if (reportErrors) {
@@ -13284,7 +13285,7 @@ namespace ts {
1328413285
* Leave signatures alone since they are not subject to the check.
1328513286
*/
1328613287
function getRegularTypeOfObjectLiteral(type: Type): Type {
13287-
if (!(isObjectLiteralType(type) && type.flags & TypeFlags.FreshLiteral)) {
13288+
if (!(isObjectLiteralType(type) && getObjectFlags(type) & ObjectFlags.FreshLiteral)) {
1328813289
return type;
1328913290
}
1329013291
const regularType = (<FreshObjectLiteralType>type).regularType;
@@ -13300,7 +13301,7 @@ namespace ts {
1330013301
resolved.constructSignatures,
1330113302
resolved.stringIndexInfo,
1330213303
resolved.numberIndexInfo);
13303-
regularNew.flags = resolved.flags & ~TypeFlags.FreshLiteral;
13304+
regularNew.flags = resolved.flags;
1330413305
regularNew.objectFlags |= ObjectFlags.ObjectLiteral | (getObjectFlags(resolved) & ObjectFlags.JSLiteral);
1330513306
(<FreshObjectLiteralType>type).regularType = regularNew;
1330613307
return regularNew;
@@ -17637,7 +17638,7 @@ namespace ts {
1763717638
let propertiesTable: SymbolTable;
1763817639
let propertiesArray: Symbol[] = [];
1763917640
let spread: Type = emptyObjectType;
17640-
let propagatedFlags: TypeFlags = TypeFlags.FreshLiteral;
17641+
let propagatedFlags: TypeFlags = 0;
1764117642

1764217643
const contextualType = getApparentTypeOfContextualType(node);
1764317644
const contextualTypeHasPattern = contextualType && contextualType.pattern &&
@@ -17722,7 +17723,7 @@ namespace ts {
1772217723
checkExternalEmitHelpers(memberDecl, ExternalEmitHelpers.Assign);
1772317724
}
1772417725
if (propertiesArray.length > 0) {
17725-
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags, /*objectFlags*/ 0);
17726+
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags, ObjectFlags.FreshLiteral);
1772617727
propertiesArray = [];
1772717728
propertiesTable = createSymbolTable();
1772817729
hasComputedStringProperty = false;
@@ -17734,7 +17735,7 @@ namespace ts {
1773417735
error(memberDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
1773517736
return errorType;
1773617737
}
17737-
spread = getSpreadType(spread, type, node.symbol, propagatedFlags, /*objectFlags*/ 0);
17738+
spread = getSpreadType(spread, type, node.symbol, propagatedFlags, ObjectFlags.FreshLiteral);
1773817739
offset = i + 1;
1773917740
continue;
1774017741
}
@@ -17784,7 +17785,7 @@ namespace ts {
1778417785

1778517786
if (spread !== emptyObjectType) {
1778617787
if (propertiesArray.length > 0) {
17787-
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags, /*objectFlags*/ 0);
17788+
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags, ObjectFlags.FreshLiteral);
1778817789
}
1778917790
return spread;
1779017791
}
@@ -17795,9 +17796,8 @@ namespace ts {
1779517796
const stringIndexInfo = hasComputedStringProperty ? getObjectLiteralIndexInfo(node.properties, offset, propertiesArray, IndexKind.String) : undefined;
1779617797
const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node.properties, offset, propertiesArray, IndexKind.Number) : undefined;
1779717798
const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo);
17798-
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral;
17799-
result.flags |= TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags);
17800-
result.objectFlags |= ObjectFlags.ObjectLiteral;
17799+
result.flags |= TypeFlags.ContainsObjectLiteral | typeFlags & TypeFlags.PropagatingFlags;
17800+
result.objectFlags |= ObjectFlags.ObjectLiteral | freshObjectLiteralFlag;
1780117801
if (isJSObjectLiteral) {
1780217802
result.objectFlags |= ObjectFlags.JSLiteral;
1780317803
}
@@ -17807,7 +17807,7 @@ namespace ts {
1780717807
if (inDestructuringPattern) {
1780817808
result.pattern = node;
1780917809
}
17810-
propagatedFlags |= (result.flags & TypeFlags.PropagatingFlags);
17810+
propagatedFlags |= result.flags & TypeFlags.PropagatingFlags;
1781117811
return result;
1781217812
}
1781317813
}
@@ -17898,14 +17898,15 @@ namespace ts {
1789817898
let hasSpreadAnyType = false;
1789917899
let typeToIntersect: Type | undefined;
1790017900
let explicitlySpecifyChildrenAttribute = false;
17901-
let propagatingFlags: TypeFlags = 0;
17901+
let typeFlags: TypeFlags = 0;
17902+
let objectFlags: ObjectFlags = ObjectFlags.JsxAttributes;
1790217903
const jsxChildrenPropertyName = getJsxElementChildrenPropertyName(getJsxNamespaceAt(openingLikeElement));
1790317904

1790417905
for (const attributeDecl of attributes.properties) {
1790517906
const member = attributeDecl.symbol;
1790617907
if (isJsxAttribute(attributeDecl)) {
1790717908
const exprType = checkJsxAttribute(attributeDecl, checkMode);
17908-
propagatingFlags |= (exprType.flags & TypeFlags.PropagatingFlags);
17909+
typeFlags |= exprType.flags & TypeFlags.PropagatingFlags;
1790917910

1791017911
const attributeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.escapedName);
1791117912
attributeSymbol.declarations = member.declarations;
@@ -17923,15 +17924,15 @@ namespace ts {
1792317924
else {
1792417925
Debug.assert(attributeDecl.kind === SyntaxKind.JsxSpreadAttribute);
1792517926
if (attributesTable.size > 0) {
17926-
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, propagatingFlags, ObjectFlags.JsxAttributes);
17927+
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, typeFlags, objectFlags);
1792717928
attributesTable = createSymbolTable();
1792817929
}
1792917930
const exprType = checkExpressionCached(attributeDecl.expression, checkMode);
1793017931
if (isTypeAny(exprType)) {
1793117932
hasSpreadAnyType = true;
1793217933
}
1793317934
if (isValidSpreadType(exprType)) {
17934-
spread = getSpreadType(spread, exprType, attributes.symbol, propagatingFlags, ObjectFlags.JsxAttributes);
17935+
spread = getSpreadType(spread, exprType, attributes.symbol, typeFlags, objectFlags);
1793517936
}
1793617937
else {
1793717938
typeToIntersect = typeToIntersect ? getIntersectionType([typeToIntersect, exprType]) : exprType;
@@ -17941,7 +17942,7 @@ namespace ts {
1794117942

1794217943
if (!hasSpreadAnyType) {
1794317944
if (attributesTable.size > 0) {
17944-
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, propagatingFlags, ObjectFlags.JsxAttributes);
17945+
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, typeFlags, objectFlags);
1794517946
}
1794617947
}
1794717948

@@ -17969,7 +17970,7 @@ namespace ts {
1796917970
const childPropMap = createSymbolTable();
1797017971
childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol);
1797117972
spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined),
17972-
attributes.symbol, propagatingFlags, ObjectFlags.JsxAttributes);
17973+
attributes.symbol, typeFlags, objectFlags);
1797317974

1797417975
}
1797517976
}
@@ -17988,10 +17989,10 @@ namespace ts {
1798817989
* @param attributesTable a symbol table of attributes property
1798917990
*/
1799017991
function createJsxAttributesType() {
17992+
objectFlags |= freshObjectLiteralFlag;
1799117993
const result = createAnonymousType(attributes.symbol, attributesTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined);
17992-
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral;
17993-
result.flags |= (propagatingFlags |= TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag);
17994-
result.objectFlags |= ObjectFlags.ObjectLiteral | ObjectFlags.JsxAttributes;
17994+
result.flags |= TypeFlags.ContainsObjectLiteral | typeFlags;
17995+
result.objectFlags |= ObjectFlags.ObjectLiteral | objectFlags;
1799517996
return result;
1799617997
}
1799717998
}

src/compiler/types.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3836,13 +3836,11 @@ namespace ts {
38363836
Substitution = 1 << 25, // Type parameter substitution
38373837
NonPrimitive = 1 << 26, // intrinsic object type
38383838
/* @internal */
3839-
FreshLiteral = 1 << 27, // Fresh literal or unique type
3839+
ContainsWideningType = 1 << 27, // Type is or contains undefined or null widening type
38403840
/* @internal */
3841-
ContainsWideningType = 1 << 28, // Type is or contains undefined or null widening type
3841+
ContainsObjectLiteral = 1 << 28, // Type is or contains object literal type
38423842
/* @internal */
3843-
ContainsObjectLiteral = 1 << 29, // Type is or contains object literal type
3844-
/* @internal */
3845-
ContainsAnyFunctionType = 1 << 30, // Type is or contains the anyFunctionType
3843+
ContainsAnyFunctionType = 1 << 29, // Type is or contains the anyFunctionType
38463844

38473845
/* @internal */
38483846
AnyOrUnknown = Any | Unknown,
@@ -3980,6 +3978,7 @@ namespace ts {
39803978
JsxAttributes = 1 << 12, // Jsx attributes type
39813979
MarkerType = 1 << 13, // Marker type used for variance probing
39823980
JSLiteral = 1 << 14, // Object type declared in JS - disables errors on read/write of nonexisting members
3981+
FreshLiteral = 1 << 15, // Fresh object literal
39833982
ClassOrInterface = Class | Interface
39843983
}
39853984

0 commit comments

Comments
 (0)