PR feedback

This commit is contained in:
Ron Buckton 2015-07-10 13:13:42 -07:00
parent 739f5f25cf
commit 990ce29c00
3 changed files with 46 additions and 38 deletions

View File

@ -862,7 +862,7 @@ namespace ts {
if (name.kind === SyntaxKind.Identifier) {
let message = meaning === SymbolFlags.Namespace ? Diagnostics.Cannot_find_namespace_0 : Diagnostics.Cannot_find_name_0;
symbol = resolveName(name, (<Identifier>name).text, meaning, !ignoreErrors ? message : undefined, <Identifier>name);
symbol = resolveName(name, (<Identifier>name).text, meaning, ignoreErrors ? undefined : message, <Identifier>name);
if (!symbol) {
return undefined;
}
@ -13221,47 +13221,47 @@ namespace ts {
return type.flags & TypeFlags.ObjectType && getSignaturesOfType(type, SignatureKind.Call).length > 0;
}
function isTypeWithValue(node: TypeReferenceNode): TypeWithValueResolutionResult {
function getTypeReferenceSerializationKind(node: TypeReferenceNode): TypeReferenceSerializationKind {
// Resolve the symbol as a value to ensure the type can be reached at runtime during emit.
let symbol = resolveEntityName(node.typeName, SymbolFlags.Value, /*ignoreErrors*/ true);
let constructorType = symbol ? getTypeOfSymbol(symbol) : undefined;
if (constructorType && isConstructorType(constructorType)) {
return TypeWithValueResolutionResult.ConstructorTypeWithValue;
return TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
}
let type = getTypeFromTypeNode(node);
if (type === unknownType) {
return TypeWithValueResolutionResult.Unknown;
return TypeReferenceSerializationKind.Unknown;
}
else if (type.flags & TypeFlags.Any) {
return TypeWithValueResolutionResult.ObjectType;
return TypeReferenceSerializationKind.ObjectType;
}
else if (allConstituentTypesHaveKind(type, TypeFlags.Void)) {
return TypeWithValueResolutionResult.VoidType;
return TypeReferenceSerializationKind.VoidType;
}
else if (allConstituentTypesHaveKind(type, TypeFlags.Boolean)) {
return TypeWithValueResolutionResult.BooleanType;
return TypeReferenceSerializationKind.BooleanType;
}
else if (allConstituentTypesHaveKind(type, TypeFlags.NumberLike)) {
return TypeWithValueResolutionResult.NumberType;
return TypeReferenceSerializationKind.NumberLikeType;
}
else if (allConstituentTypesHaveKind(type, TypeFlags.StringLike)) {
return TypeWithValueResolutionResult.StringType;
return TypeReferenceSerializationKind.StringLikeType;
}
else if (allConstituentTypesHaveKind(type, TypeFlags.Tuple)) {
return TypeWithValueResolutionResult.ArrayType;
return TypeReferenceSerializationKind.ArrayLikeType;
}
else if (allConstituentTypesHaveKind(type, TypeFlags.ESSymbol)) {
return TypeWithValueResolutionResult.ESSymbolType;
return TypeReferenceSerializationKind.ESSymbolType;
}
else if (isFunctionType(type)) {
return TypeWithValueResolutionResult.FunctionType;
return TypeReferenceSerializationKind.TypeWithCallSignature;
}
else if (isArrayType(type)) {
return TypeWithValueResolutionResult.ArrayType;
return TypeReferenceSerializationKind.ArrayLikeType;
}
else {
return TypeWithValueResolutionResult.ObjectType;
return TypeReferenceSerializationKind.ObjectType;
}
}
@ -13362,7 +13362,7 @@ namespace ts {
collectLinkedAliases,
getBlockScopedVariableId,
getReferencedValueDeclaration,
isTypeWithValue,
getTypeReferenceSerializationKind,
};
}

View File

@ -4672,6 +4672,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
write("Array");
return;
case SyntaxKind.TypePredicate:
case SyntaxKind.BooleanKeyword:
write("Boolean");
return;
@ -4710,9 +4711,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
/** Serializes a TypeReferenceNode to an appropriate JS constructor value. Used by the __metadata decorator. */
function emitSerializedTypeReferenceNode(node: TypeReferenceNode) {
let typeName = node.typeName;
let result = resolver.isTypeWithValue(node);
let result = resolver.getTypeReferenceSerializationKind(node);
switch (result) {
case TypeWithValueResolutionResult.Unknown:
case TypeReferenceSerializationKind.Unknown:
let temp = createAndRecordTempVariable(TempFlags.Auto);
write("(typeof (");
emitNodeWithoutSourceMap(temp);
@ -4723,31 +4724,31 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
write(") || Object");
break;
case TypeWithValueResolutionResult.ConstructorTypeWithValue:
case TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue:
emitEntityNameAsExpression(typeName, /*useFallback*/ false);
break;
case TypeWithValueResolutionResult.VoidType:
case TypeReferenceSerializationKind.VoidType:
write("void 0");
break;
case TypeWithValueResolutionResult.BooleanType:
case TypeReferenceSerializationKind.BooleanType:
write("Boolean");
break;
case TypeWithValueResolutionResult.NumberType:
case TypeReferenceSerializationKind.NumberLikeType:
write("Number");
break;
case TypeWithValueResolutionResult.StringType:
case TypeReferenceSerializationKind.StringLikeType:
write("String");
break;
case TypeWithValueResolutionResult.ArrayType:
case TypeReferenceSerializationKind.ArrayLikeType:
write("Array");
break;
case TypeWithValueResolutionResult.ESSymbolType:
case TypeReferenceSerializationKind.ESSymbolType:
if (languageVersion < ScriptTarget.ES6) {
write("typeof Symbol === 'function' ? Symbol : Object");
}
@ -4756,11 +4757,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
}
break;
case TypeWithValueResolutionResult.FunctionType:
case TypeReferenceSerializationKind.TypeWithCallSignature:
write("Function");
break;
case TypeWithValueResolutionResult.ObjectType:
case TypeReferenceSerializationKind.ObjectType:
write("Object");
break;
}

View File

@ -1502,18 +1502,25 @@ namespace ts {
errorModuleName?: string // If the symbol is not visible from module, module's name
}
/** Indicates how to serialize the name for a TypeReferenceNode when emitting decorator
* metadata */
/* @internal */
export enum TypeWithValueResolutionResult {
Unknown,
ConstructorTypeWithValue,
VoidType,
NumberType,
StringType,
BooleanType,
ArrayType,
ESSymbolType,
FunctionType,
ObjectType,
export enum TypeReferenceSerializationKind {
Unknown, // The TypeReferenceNode could not be resolved. The type name
// should be emitted using a safe fallback.
TypeWithConstructSignatureAndValue, // The TypeReferenceNode resolves to a type with a constructor
// function that can be reached at runtime (e.g. a `class`
// declaration or a `var` declaration for the static side
// of a type, such as the global `Promise` type in lib.d.ts).
VoidType, // The TypeReferenceNode resolves to a Void-like type.
NumberLikeType, // The TypeReferenceNode resolves to a Number-like type.
StringLikeType, // The TypeReferenceNode resolves to a String-like type.
BooleanType, // The TypeReferenceNode resolves to a Boolean-like type.
ArrayLikeType, // The TypeReferenceNode resolves to an Array-like type.
ESSymbolType, // The TypeReferenceNode resolves to the ESSymbol type.
TypeWithCallSignature, // The TypeReferenceNode resolves to a Function type or a type
// with call signatures.
ObjectType, // The TypeReferenceNode resolves to any other type.
}
/* @internal */
@ -1539,7 +1546,7 @@ namespace ts {
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
getBlockScopedVariableId(node: Identifier): number;
getReferencedValueDeclaration(reference: Identifier): Declaration;
isTypeWithValue(node: TypeReferenceNode): TypeWithValueResolutionResult;
getTypeReferenceSerializationKind(node: TypeReferenceNode): TypeReferenceSerializationKind;
}
export const enum SymbolFlags {