10000 PR feedback · jango2015/TypeScript@990ce29 · GitHub
[go: up one dir, main page]

Skip to content

Commit 990ce29

Browse files
committed
PR feedback
1 parent 739f5f2 commit 990ce29

File tree

3 files changed

+46
-38
lines changed

3 files changed

+46
-38
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ namespace ts {
862862
if (name.kind === SyntaxKind.Identifier) {
863863
let message = meaning === SymbolFlags.Namespace ? Diagnostics.Cannot_find_namespace_0 : Diagnostics.Cannot_find_name_0;
864864

865-
symbol = resolveName(name, (<Identifier>name).text, meaning, !ignoreErrors ? message : undefined, <Identifier>name);
865+
symbol = resolveName(name, (<Identifier>name).text, meaning, ignoreErrors ? undefined : message, <Identifier>name);
866866
if (!symbol) {
867867
return undefined;
868868
}
@@ -13221,47 +13221,47 @@ namespace ts {
1322113221
return type.flags & TypeFlags.ObjectType && getSignaturesOfType(type, SignatureKind.Call).length > 0;
1322213222
}
1322313223

13224-
function isTypeWithValue(node: TypeReferenceNode): TypeWithValueResolutionResult {
13224+
function getTypeReferenceSerializationKind(node: TypeReferenceNode): TypeReferenceSerializationKind {
1322513225
// Resolve the symbol as a value to ensure the type can be reached at runtime during emit.
1322613226
let symbol = resolveEntityName(node.typeName, SymbolFlags.Value, /*ignoreErrors*/ true);
1322713227
let constructorType = symbol ? getTypeOfSymbol(symbol) : undefined;
1322813228
if (constructorType && isConstructorType(constructorType)) {
13229-
return TypeWithValueResolutionResult.ConstructorTypeWithValue;
13229+
return TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
1323013230
}
1323113231

1323213232
let type = getTypeFromTypeNode(node);
1323313233
if (type === unknownType) {
13234-
return TypeWithValueResolutionResult.Unknown;
13234+
return TypeReferenceSerializationKind.Unknown;
1323513235
}
1323613236
else if (type.flags & TypeFlags.Any) {
13237-
return TypeWithValueResolutionResult.ObjectType;
13237+
return TypeReferenceSerializationKind.ObjectType;
1323813238
}
1323913239
else if (allConstituentTypesHaveKind(type, TypeFlags.Void)) {
13240-
return TypeWithValueResolutionResult.VoidType;
13240+
return TypeReferenceSerializationKind.VoidType;
1324113241
}
1324213242
else if (allConstituentTypesHaveKind(type, TypeFlags.Boolean)) {
13243-
return TypeWithValueResolutionResult.BooleanType;
13243+
return TypeReferenceSerializationKind.BooleanType;
1324413244
}
1324513245
else if (allConstituentTypesHaveKind(type, TypeFlags.NumberLike)) {
13246-
return TypeWithValueResolutionResult.NumberType;
13246+
return TypeReferenceSerializationKind.NumberLikeType;
1324713247
}
1324813248
else if (allConstituentTypesHaveKind(type, TypeFlags.StringLike)) {
13249-
return TypeWithValueResolutionResult.StringType;
13249+
return TypeReferenceSerializationKind.StringLikeType;
1325013250
}
1325113251
else if (allConstituentTypesHaveKind(type, TypeFlags.Tuple)) {
13252-
return TypeWithValueResolutionResult.ArrayType;
13252+
return TypeReferenceSerializationKind.ArrayLikeType;
1325313253
}
1325413254
else if (allConstituentTypesHaveKind(type, TypeFlags.ESSymbol)) {
13255-
return TypeWithValueResolutionResult.ESSymbolType;
13255+
return TypeReferenceSerializationKind.ESSymbolType;
1325613256
}
1325713257
else if (isFunctionType(type)) {
13258-
return TypeWithValueResolutionResult.FunctionType;
13258+
return TypeReferenceSerializationKind.TypeWithCallSignature;
1325913259
}
1326013260
else if (isArrayType(type)) {
13261-
return TypeWithValueResolutionResult.ArrayType;
13261+
return TypeReferenceSerializationKind.ArrayLikeType;
1326213262
}
1326313263
else {
13264-
return TypeWithValueResolutionResult.ObjectType;
13264+
return TypeReferenceSerializationKind.ObjectType;
1326513265
}
1326613266
}
1326713267

@@ -13362,7 +13362,7 @@ namespace ts {
1336213362
collectLinkedAliases,
1336313363
getBlockScopedVariableId,
1336413364
getReferencedValueDeclaration,
13365-
isTypeWithValue,
13365+
getTypeReferenceSerializationKind,
1336613366
};
1336713367
}
1336813368

src/compiler/emitter.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4672,6 +4672,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
46724672
write("Array");
46734673
return;
46744674

4675+
case SyntaxKind.TypePredicate:
46754676
case SyntaxKind.BooleanKeyword:
46764677
write("Boolean");
46774678
return;
@@ -4710,9 +4711,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
47104711
/** Serializes a TypeReferenceNode to an appropriate JS constructor value. Used by the __metadata decorator. */
47114712
function emitSerializedTypeReferenceNode(node: TypeReferenceNode) {
47124713
let typeName = node.typeName;
4713-
let result = resolver.isTypeWithValue(node);
4714+
let result = resolver.getTypeReferenceSerializationKind(node);
47144715
switch (result) {
4715-
case TypeWithValueResolutionResult.Unknown:
4716+
case TypeReferenceSerializationKind.Unknown:
47164717
let temp = createAndRecordTempVariable(TempFlags.Auto);
47174718
write("(typeof (");
47184719
emitNodeWithoutSourceMap(temp);
@@ -4723,31 +4724,31 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
47234724
write(") || Object");
47244725
break;
47254726

4726-
case TypeWithValueResolutionResult.ConstructorTypeWithValue:
4727+
case TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue:
47274728
emitEntityNameAsExpression(typeName, /*useFallback*/ false);
47284729
break;
47294730

4730-
case TypeWithValueResolutionResult.VoidType:
4731+
case TypeReferenceSerializationKind.VoidType:
47314732
write("void 0");
47324733
break;
47334734

4734-
case TypeWithValueResolutionResult.BooleanType:
4735+
case TypeReferenceSerializationKind.BooleanType:
47354736
write("Boolean");
47364737
break;
47374738

4738-
case TypeWithValueResolutionResult.NumberType:
4739+
case TypeReferenceSerializationKind.NumberLikeType:
47394740
write("Number");
47404741
break;
47414742

4742-
case TypeWithValueResolutionResult.StringType:
4743+
case TypeReferenceSerializationKind.StringLikeType:
47434744
write("String");
47444745
break;
47454746

4746-
case TypeWithValueResolutionResult.ArrayType:
4747+
case TypeReferenceSerializationKind.ArrayLikeType:
47474748
write("Array");
47484749
break;
47494750

4750-
case TypeWithValueResolutionResult.ESSymbolType:
4751+
case TypeReferenceSerializationKind.ESSymbolType:
47514752
if (languageVersion < ScriptTarget.ES6) {
47524753
write("typeof Symbol === 'function' ? Symbol : Object");
47534754
}
@@ -4756,11 +4757,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
47564757
}
47574758
break;
47584759

4759-
case TypeWithValueResolutionResult.FunctionType:
4760+
case TypeReferenceSerializationKind.TypeWithCallSignature:
47604761
write("Function");
47614762
break;
47624763

4763-
case TypeWithValueResolutionResult.ObjectType:
4764+
case TypeReferenceSerializationKind.ObjectType:
47644765
write("Object");
47654766
break;
47664767
}

src/compiler/types.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,18 +1502,25 @@ namespace ts {
15021502
errorModuleName?: string // If the symbol is not visible from module, module's name
15031503
}
15041504

1505+
/** Indicates how to serialize the name for a TypeReferenceNode when emitting decorator
1506+
* metadata */
15051507
/* @internal */
1506-
export enum TypeWithValueResolutionResult {
1507-
Unknown,
1508-
ConstructorTypeWithValue,
1509-
VoidType,
1510-
NumberType,
1511-
StringType,
1512-
BooleanType,
1513-
ArrayType,
1514-
ESSymbolType,
1515-
FunctionType,
1516-
ObjectType,
1508+
export enum TypeReferenceSerializationKind {
1509+
Unknown, // The TypeReferenceNode could not be resolved. The type name
1510+
// should be emitted using a safe fallback.
1511+
TypeWithConstructSignatureAndValue, // The TypeReferenceNode resolves to a type with a constructor
1512+
// function that can be reached at runtime (e.g. a `class`
1513+
// declaration or a `var` declaration for the static side
1514+
// of a type, such as the global `Promise` type in lib.d.ts).
1515+
VoidType, // The TypeReferenceNode resolves to a Void-like type.
1516+
NumberLikeType, // The TypeReferenceNode resolves to a Number-like type.
1517+
StringLikeType, // The TypeReferenceNode resolves to a String-like type.
1518+
BooleanType, // The TypeReferenceNode resolves to a Boolean-like type.
1519+
ArrayLikeType, // The TypeReferenceNode resolves to an Array-like type.
1520+
ESSymbolType, // The TypeReferenceNode resolves to the ESSymbol type.
1521+
TypeWithCallSignature, // The TypeReferenceNode resolves to a Function type or a type
1522+
// with call signatures.
1523+
ObjectType, // The TypeReferenceNode resolves to any other type.
15171524
}
15181525

15191526
/* @internal */
@@ -1539,7 +1546,7 @@ namespace ts {
15391546
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
15401547
getBlockScopedVariableId(node: Identifier): number;
15411548
getReferencedValueDeclaration(reference: Identifier): Declaration;
1542-
isTypeWithValue(node: TypeReferenceNode): TypeWithValueResolutionResult;
1549+
getTypeReferenceSerializationKind(node: TypeReferenceNode): TypeReferenceSerializationKind;
15431550
}
15441551

15451552
export const enum SymbolFlags {

0 commit comments

Comments
 (0)
0