mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-27 13:42:16 -05:00
Updated baselines
This commit is contained in:
@@ -8702,6 +8702,41 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
/** Checks a type reference node as an expression. */
|
||||
function checkTypeNodeAsExpression(node: TypeNode | LiteralExpression) {
|
||||
if (node && node.kind === SyntaxKind.TypeReference) {
|
||||
var type = getTypeFromTypeNode(node);
|
||||
if (!type || type.flags & (TypeFlags.Intrinsic | TypeFlags.NumberLike | TypeFlags.StringLike)) {
|
||||
return;
|
||||
}
|
||||
if (type.symbol.valueDeclaration) {
|
||||
checkExpressionOrQualifiedName((<TypeReferenceNode>node).typeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the type annotation of an accessor declaration or property declaration as
|
||||
* an expression if it is a type reference to a type with a value declaration.
|
||||
*/
|
||||
function checkTypeAnnotationAsExpression(node: AccessorDeclaration | PropertyDeclaration | ParameterDeclaration | MethodDeclaration) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.PropertyDeclaration: return checkTypeNodeAsExpression((<PropertyDeclaration>node).type);
|
||||
case SyntaxKind.Parameter: return checkTypeNodeAsExpression((<ParameterDeclaration>node).type);
|
||||
case SyntaxKind.MethodDeclaration: return checkTypeNodeAsExpression((<MethodDeclaration>node).type);
|
||||
case SyntaxKind.GetAccessor: return checkTypeNodeAsExpression((<AccessorDeclaration>node).type);
|
||||
case SyntaxKind.SetAccessor: return checkTypeNodeAsExpression(getSetAccessorTypeAnnotationNode(<AccessorDeclaration>node));
|
||||
}
|
||||
}
|
||||
|
||||
/** Checks the type annotation of the parameters of a function/method or the constructor of a class as expressions */
|
||||
function checkParameterTypeAnnotationsAsExpressions(node: FunctionLikeDeclaration) {
|
||||
// ensure all type annotations with a value declaration are checked as an expression
|
||||
if (node) {
|
||||
forEach(node.parameters, checkTypeAnnotationAsExpression);
|
||||
}
|
||||
}
|
||||
|
||||
/** Check the decorators of a node */
|
||||
function checkDecorators(node: Node): void {
|
||||
if (!node.decorators) {
|
||||
@@ -8710,18 +8745,28 @@ module ts {
|
||||
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
var constructor = getFirstConstructorWithBody(<ClassDeclaration>node);
|
||||
if (constructor) {
|
||||
checkParameterTypeAnnotationsAsExpressions(constructor);
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
checkParameterTypeAnnotationsAsExpressions(<FunctionLikeDeclaration>node);
|
||||
// fall-through
|
||||
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
emitDecorate = true;
|
||||
checkTypeAnnotationAsExpression(<PropertyDeclaration | ParameterDeclaration>node);
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
emitDecorate = true;
|
||||
forEach(node.decorators, checkDecorator);
|
||||
}
|
||||
|
||||
@@ -11400,17 +11445,17 @@ module ts {
|
||||
else if (type.flags & TypeFlags.ESSymbol) {
|
||||
return "Symbol";
|
||||
}
|
||||
else if (type.symbol.valueDeclaration) {
|
||||
return serializeEntityName(node.typeName, getGeneratedNameForNode);
|
||||
}
|
||||
else if (typeHasCallOrConstructSignatures(type)) {
|
||||
return "Function";
|
||||
}
|
||||
else if (type === unknownType) {
|
||||
var fallbackPath: string[] = [];
|
||||
serializeEntityName(node.typeName, getGeneratedNameForNode, fallbackPath);
|
||||
return fallbackPath;
|
||||
}
|
||||
else if (type.symbol && type.symbol.valueDeclaration) {
|
||||
return serializeEntityName(node.typeName, getGeneratedNameForNode);
|
||||
}
|
||||
else if (typeHasCallOrConstructSignatures(type)) {
|
||||
return "Function";
|
||||
}
|
||||
|
||||
return "Object";
|
||||
}
|
||||
@@ -11473,7 +11518,7 @@ module ts {
|
||||
//
|
||||
// For rules on serializing type annotations, see `serializeTypeNode`.
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ClassDeclaration: return serializeEntityName((<ClassDeclaration>node).name, getGeneratedNameForNode);
|
||||
case SyntaxKind.ClassDeclaration: return "Function";
|
||||
case SyntaxKind.PropertyDeclaration: return serializeTypeNode((<PropertyDeclaration>node).type, getGeneratedNameForNode);
|
||||
case SyntaxKind.Parameter: return serializeTypeNode((<ParameterDeclaration>node).type, getGeneratedNameForNode);
|
||||
case SyntaxKind.GetAccessor: return serializeTypeNode((<AccessorDeclaration>node).type, getGeneratedNameForNode);
|
||||
@@ -11508,7 +11553,22 @@ module ts {
|
||||
if (parameterCount > 0) {
|
||||
result = new Array<string>(parameterCount);
|
||||
for (var i = 0; i < parameterCount; i++) {
|
||||
result[i] = serializeTypeOfNode(parameters[i], getGeneratedNameForNode);
|
||||
if (parameters[i].dotDotDotToken) {
|
||||
var parameterType = parameters[i].type;
|
||||
if (parameterType.kind === SyntaxKind.ArrayType) {
|
||||
parameterType = (<ArrayTypeNode>parameterType).elementType;
|
||||
}
|
||||
else if (parameterType.kind === SyntaxKind.TypeReference && (<TypeReferenceNode>parameterType).typeArguments && (<TypeReferenceNode>parameterType).typeArguments.length === 1) {
|
||||
parameterType = (<TypeReferenceNode>parameterType).typeArguments[0];
|
||||
}
|
||||
else {
|
||||
parameterType = undefined;
|
||||
}
|
||||
result[i] = serializeTypeNode(parameterType, getGeneratedNameForNode);
|
||||
}
|
||||
else {
|
||||
result[i] = serializeTypeOfNode(parameters[i], getGeneratedNameForNode);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -11612,6 +11672,9 @@ module ts {
|
||||
resolvesToSomeValue,
|
||||
collectLinkedAliases,
|
||||
getBlockScopedVariableId,
|
||||
serializeTypeOfNode,
|
||||
serializeParameterTypesOfNode,
|
||||
serializeReturnTypeOfNode,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3791,7 +3791,7 @@ module ts {
|
||||
emitStart(node);
|
||||
emitDeclarationName(node);
|
||||
write(" = ");
|
||||
emitDecorateStart(node.decorators);
|
||||
emitDecorateStart(node);
|
||||
emitDeclarationName(node);
|
||||
write(");");
|
||||
emitEnd(node);
|
||||
@@ -3879,7 +3879,7 @@ module ts {
|
||||
write(", ");
|
||||
}
|
||||
|
||||
emitDecorateStart(decorators);
|
||||
emitDecorateStart(member);
|
||||
emitStart(member.name);
|
||||
emitClassMemberPrefix(node, member);
|
||||
write(", ");
|
||||
@@ -3931,7 +3931,7 @@ module ts {
|
||||
|
||||
writeLine();
|
||||
emitStart(parameter);
|
||||
emitDecorateStart(parameter.decorators);
|
||||
emitDecorateStart(parameter);
|
||||
emitStart(parameter.name);
|
||||
|
||||
if (member.kind === SyntaxKind.Constructor) {
|
||||
@@ -3953,8 +3953,9 @@ module ts {
|
||||
});
|
||||
}
|
||||
|
||||
function emitDecorateStart(decorators: Decorator[]): void {
|
||||
function emitDecorateStart(node: Declaration): void {
|
||||
write("__decorate([");
|
||||
let decorators = node.decorators;
|
||||
let decoratorCount = decorators.length;
|
||||
for (let i = 0; i < decoratorCount; i++) {
|
||||
if (i > 0) {
|
||||
@@ -3965,9 +3966,95 @@ module ts {
|
||||
emit(decorator.expression);
|
||||
emitEnd(decorator);
|
||||
}
|
||||
emitSerializedTypeMetadata(node);
|
||||
write("], ");
|
||||
}
|
||||
|
||||
function formatPathSegment(location: Node, path: string[], index: number): string {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return `typeof ${path[index]} !== 'undefined' && ${path[index]}`;
|
||||
case 1:
|
||||
return `${formatPathSegment(location, path, index - 1) }.${path[index]}`;
|
||||
default:
|
||||
let temp = createTempVariable(location);
|
||||
recordTempDeclaration(temp);
|
||||
return `(${temp.text} = ${formatPathSegment(location, path, index - 1) }) && ${temp.text}.${path[index]}`;
|
||||
}
|
||||
}
|
||||
|
||||
function shouldEmitTypeMetadata(node: Declaration): boolean {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function shouldEmitReturnTypeMetadata(node: Declaration): boolean {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function shouldEmitParamTypesMetadata(node: Declaration): boolean {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.SetAccessor:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function emitSerializedTypeMetadata(node: Declaration): void {
|
||||
if (shouldEmitTypeMetadata(node)) {
|
||||
var serializedType = resolver.serializeTypeOfNode(node, getGeneratedNameForNode);
|
||||
if (serializedType) {
|
||||
write(", __metadata('design:type', ");
|
||||
emitSerializedType(node, serializedType);
|
||||
write(")");
|
||||
}
|
||||
}
|
||||
if (shouldEmitParamTypesMetadata(node)) {
|
||||
var serializedTypes = resolver.serializeParameterTypesOfNode(node, getGeneratedNameForNode);
|
||||
if (serializedTypes) {
|
||||
write(", __metadata('design:paramtypes', [");
|
||||
for (var i = 0; i < serializedTypes.length; ++i) {
|
||||
if (i > 0) {
|
||||
write(", ");
|
||||
}
|
||||
emitSerializedType(node, serializedTypes[i]);
|
||||
}
|
||||
write("])");
|
||||
}
|
||||
}
|
||||
if (shouldEmitReturnTypeMetadata(node)) {
|
||||
var serializedType = resolver.serializeReturnTypeOfNode(node, getGeneratedNameForNode);
|
||||
if (serializedType) {
|
||||
write(", __metadata('design:returntype', ");
|
||||
emitSerializedType(node, serializedType);
|
||||
write(")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitSerializedType(location: Node, name: string | string[]): void {
|
||||
if (typeof name === "string") {
|
||||
write(name);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
Debug.assert(name.length > 0, "Invalid type name path for serialization");
|
||||
write(`(${formatPathSegment(location, name, name.length - 1) }) || Object`);
|
||||
}
|
||||
}
|
||||
function emitInterfaceDeclaration(node: InterfaceDeclaration) {
|
||||
emitOnlyPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
|
||||
@@ -1236,6 +1236,9 @@ module ts {
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
resolvesToSomeValue(location: Node, name: string): boolean;
|
||||
getBlockScopedVariableId(node: Identifier): number;
|
||||
serializeTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
|
||||
serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[];
|
||||
serializeReturnTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
|
||||
}
|
||||
|
||||
export const enum SymbolFlags {
|
||||
|
||||
36
src/lib/es6.d.ts
vendored
36
src/lib/es6.d.ts
vendored
@@ -3513,27 +3513,27 @@ interface ProxyHandler<T> {
|
||||
|
||||
interface ProxyConstructor {
|
||||
revocable<T>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; };
|
||||
new <T>(target: T, handeler: ProxyHandler<T>): T
|
||||
new <T>(target: T, handler: ProxyHandler<T>): T
|
||||
}
|
||||
declare var Proxy: ProxyConstructor;
|
||||
|
||||
declare var Reflect: {
|
||||
apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
|
||||
construct(target: Function, argumentsList: ArrayLike<any>): any;
|
||||
defineProperty(target: any, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean;
|
||||
deleteProperty(target: any, propertyKey: PropertyKey): boolean;
|
||||
enumerate(target: any): IterableIterator<any>;
|
||||
get(target: any, propertyKey: PropertyKey, receiver?: any): any;
|
||||
getOwnPropertyDescriptor(target: any, propertyKey: PropertyKey): PropertyDescriptor;
|
||||
getPrototypeOf(target: any): any;
|
||||
has(target: any, propertyKey: string): boolean;
|
||||
has(target: any, propertyKey: symbol): boolean;
|
||||
isExtensible(target: any): boolean;
|
||||
ownKeys(target: any): Array<PropertyKey>;
|
||||
preventExtensions(target: any): boolean;
|
||||
set(target: any, propertyKey: PropertyKey, value: any, receiver? :any): boolean;
|
||||
setPrototypeOf(target: any, proto: any): boolean;
|
||||
};
|
||||
declare module Reflect {
|
||||
function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
|
||||
function construct(target: Function, argumentsList: ArrayLike<any>): any;
|
||||
function defineProperty(target: any, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean;
|
||||
function deleteProperty(target: any, propertyKey: PropertyKey): boolean;
|
||||
function enumerate(target: any): IterableIterator<any>;
|
||||
function get(target: any, propertyKey: PropertyKey, receiver?: any): any;
|
||||
function getOwnPropertyDescriptor(target: any, propertyKey: PropertyKey): PropertyDescriptor;
|
||||
function getPrototypeOf(target: any): any;
|
||||
function has(target: any, propertyKey: string): boolean;
|
||||
function has(target: any, propertyKey: symbol): boolean;
|
||||
function isExtensible(target: any): boolean;
|
||||
function ownKeys(target: any): Array<PropertyKey>;
|
||||
function preventExtensions(target: any): boolean;
|
||||
function set(target: any, propertyKey: PropertyKey, value: any, receiver? :any): boolean;
|
||||
function setPrototypeOf(target: any, proto: any): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the completion of an asynchronous operation
|
||||
|
||||
Reference in New Issue
Block a user