mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Lazy resolution of global decorator types
This commit is contained in:
@@ -114,11 +114,10 @@ module ts {
|
||||
let globalIterableType: ObjectType;
|
||||
|
||||
let anyArrayType: Type;
|
||||
let globalTypedPropertyDescriptorType: ObjectType;
|
||||
let globalClassDecoratorType: ObjectType;
|
||||
let globalParameterDecoratorType: ObjectType;
|
||||
let globalPropertyDecoratorType: ObjectType;
|
||||
let globalMethodDecoratorType: ObjectType;
|
||||
let getGlobalClassDecoratorType: () => ObjectType;
|
||||
let getGlobalParameterDecoratorType: () => ObjectType;
|
||||
let getGlobalPropertyDecoratorType: () => ObjectType;
|
||||
let getGlobalMethodDecoratorType: () => ObjectType;
|
||||
|
||||
let tupleTypes: Map<TupleType> = {};
|
||||
let unionTypes: Map<UnionType> = {};
|
||||
@@ -8790,24 +8789,24 @@ module ts {
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
let classSymbol = getSymbolOfNode(node.parent);
|
||||
let classConstructorType = getTypeOfSymbol(classSymbol);
|
||||
let classDecoratorType = instantiateSingleCallFunctionType(globalClassDecoratorType, [classConstructorType]);
|
||||
let classDecoratorType = instantiateSingleCallFunctionType(getGlobalClassDecoratorType(), [classConstructorType]);
|
||||
checkTypeAssignableTo(exprType, classDecoratorType, node);
|
||||
break;
|
||||
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
checkTypeAssignableTo(exprType, globalPropertyDecoratorType, node);
|
||||
checkTypeAssignableTo(exprType, getGlobalPropertyDecoratorType(), node);
|
||||
break;
|
||||
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
let methodType = getTypeOfNode(node.parent);
|
||||
let methodDecoratorType = instantiateSingleCallFunctionType(globalMethodDecoratorType, [methodType]);
|
||||
let methodDecoratorType = instantiateSingleCallFunctionType(getGlobalMethodDecoratorType(), [methodType]);
|
||||
checkTypeAssignableTo(exprType, methodDecoratorType, node);
|
||||
break;
|
||||
|
||||
case SyntaxKind.Parameter:
|
||||
checkTypeAssignableTo(exprType, globalParameterDecoratorType, node);
|
||||
checkTypeAssignableTo(exprType, getGlobalParameterDecoratorType(), node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -11969,11 +11968,10 @@ module ts {
|
||||
globalNumberType = getGlobalType("Number");
|
||||
globalBooleanType = getGlobalType("Boolean");
|
||||
globalRegExpType = getGlobalType("RegExp");
|
||||
globalTypedPropertyDescriptorType = getTypeOfGlobalSymbol(getGlobalTypeSymbol("TypedPropertyDescriptor"), 1);
|
||||
globalClassDecoratorType = getGlobalType("ClassDecorator");
|
||||
globalPropertyDecoratorType = getGlobalType("PropertyDecorator");
|
||||
globalMethodDecoratorType = getGlobalType("MethodDecorator");
|
||||
globalParameterDecoratorType = getGlobalType("ParameterDecorator");
|
||||
getGlobalClassDecoratorType = memoize(() => getGlobalType("ClassDecorator"));
|
||||
getGlobalPropertyDecoratorType = memoize(() => getGlobalType("PropertyDecorator"));
|
||||
getGlobalMethodDecoratorType = memoize(() => getGlobalType("MethodDecorator"));
|
||||
getGlobalParameterDecoratorType = memoize(() => getGlobalType("ParameterDecorator"));
|
||||
|
||||
// If we're in ES6 mode, load the TemplateStringsArray.
|
||||
// Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios.
|
||||
|
||||
@@ -281,6 +281,17 @@ module ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function memoize<T>(callback: () => T): () => T {
|
||||
let value: T;
|
||||
return () => {
|
||||
if (callback) {
|
||||
value = callback();
|
||||
callback = undefined;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
}
|
||||
|
||||
function formatStringFromArgs(text: string, args: { [index: number]: any; }, baseIndex?: number): string {
|
||||
baseIndex = baseIndex || 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user