mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-13 06:20:23 -06:00
Lazy resolution of global decorator types
This commit is contained in:
parent
70241fdca8
commit
a5eb68bcbb
@ -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> = {};
|
||||
@ -8808,24 +8807,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;
|
||||
}
|
||||
}
|
||||
@ -11987,11 +11986,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;
|
||||
|
||||
|
||||
@ -1,19 +1,9 @@
|
||||
error TS2318: Cannot find global type 'TypedPropertyDescriptor'.
|
||||
error TS2318: Cannot find global type 'PropertyDecorator'.
|
||||
error TS2318: Cannot find global type 'ParameterDecorator'.
|
||||
error TS2318: Cannot find global type 'MethodDecorator'.
|
||||
error TS2318: Cannot find global type 'IArguments'.
|
||||
error TS2318: Cannot find global type 'ClassDecorator'.
|
||||
error TS2318: Cannot find global type 'Boolean'.
|
||||
tests/cases/compiler/noDefaultLib.ts(4,11): error TS2317: Global type 'Array' must have 1 type parameter(s).
|
||||
|
||||
|
||||
!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'.
|
||||
!!! error TS2318: Cannot find global type 'PropertyDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'ParameterDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'MethodDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'IArguments'.
|
||||
!!! error TS2318: Cannot find global type 'ClassDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'Boolean'.
|
||||
==== tests/cases/compiler/noDefaultLib.ts (1 errors) ====
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
@ -1,31 +1,21 @@
|
||||
error TS2318: Cannot find global type 'Number'.
|
||||
error TS2318: Cannot find global type 'TypedPropertyDescriptor'.
|
||||
error TS2318: Cannot find global type 'Object'.
|
||||
error TS2318: Cannot find global type 'Array'.
|
||||
error TS2318: Cannot find global type 'ClassDecorator'.
|
||||
error TS2318: Cannot find global type 'String'.
|
||||
error TS2318: Cannot find global type 'RegExp'.
|
||||
error TS2318: Cannot find global type 'PropertyDecorator'.
|
||||
error TS2318: Cannot find global type 'ParameterDecorator'.
|
||||
error TS2318: Cannot find global type 'Object'.
|
||||
error TS2318: Cannot find global type 'Number'.
|
||||
error TS2318: Cannot find global type 'IArguments'.
|
||||
error TS2318: Cannot find global type 'Function'.
|
||||
error TS2318: Cannot find global type 'Boolean'.
|
||||
error TS2318: Cannot find global type 'MethodDecorator'.
|
||||
error TS2318: Cannot find global type 'IArguments'.
|
||||
error TS2318: Cannot find global type 'Array'.
|
||||
|
||||
|
||||
!!! error TS2318: Cannot find global type 'Number'.
|
||||
!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'.
|
||||
!!! error TS2318: Cannot find global type 'Object'.
|
||||
!!! error TS2318: Cannot find global type 'Array'.
|
||||
!!! error TS2318: Cannot find global type 'ClassDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'String'.
|
||||
!!! error TS2318: Cannot find global type 'RegExp'.
|
||||
!!! error TS2318: Cannot find global type 'PropertyDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'ParameterDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'Object'.
|
||||
!!! error TS2318: Cannot find global type 'Number'.
|
||||
!!! error TS2318: Cannot find global type 'IArguments'.
|
||||
!!! error TS2318: Cannot find global type 'Function'.
|
||||
!!! error TS2318: Cannot find global type 'Boolean'.
|
||||
!!! error TS2318: Cannot find global type 'MethodDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'IArguments'.
|
||||
!!! error TS2318: Cannot find global type 'Array'.
|
||||
==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509698.ts (0 errors) ====
|
||||
/// <style requireSemi="on" />
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
@ -1,32 +1,22 @@
|
||||
error TS2318: Cannot find global type 'Object'.
|
||||
error TS2318: Cannot find global type 'Array'.
|
||||
error TS2318: Cannot find global type 'ParameterDecorator'.
|
||||
error TS2318: Cannot find global type 'ClassDecorator'.
|
||||
error TS2318: Cannot find global type 'TypedPropertyDescriptor'.
|
||||
error TS2318: Cannot find global type 'String'.
|
||||
error TS2318: Cannot find global type 'RegExp'.
|
||||
error TS2318: Cannot find global type 'PropertyDecorator'.
|
||||
error TS2318: Cannot find global type 'Object'.
|
||||
error TS2318: Cannot find global type 'Number'.
|
||||
error TS2318: Cannot find global type 'IArguments'.
|
||||
error TS2318: Cannot find global type 'Function'.
|
||||
error TS2318: Cannot find global type 'Boolean'.
|
||||
error TS2318: Cannot find global type 'Number'.
|
||||
error TS2318: Cannot find global type 'MethodDecorator'.
|
||||
error TS2318: Cannot find global type 'IArguments'.
|
||||
error TS2318: Cannot find global type 'Array'.
|
||||
test.ts(3,8): error TS2304: Cannot find name 'Array'.
|
||||
|
||||
|
||||
!!! error TS2318: Cannot find global type 'Object'.
|
||||
!!! error TS2318: Cannot find global type 'Array'.
|
||||
!!! error TS2318: Cannot find global type 'ParameterDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'ClassDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'.
|
||||
!!! error TS2318: Cannot find global type 'String'.
|
||||
!!! error TS2318: Cannot find global type 'RegExp'.
|
||||
!!! error TS2318: Cannot find global type 'PropertyDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'Object'.
|
||||
!!! error TS2318: Cannot find global type 'Number'.
|
||||
!!! error TS2318: Cannot find global type 'IArguments'.
|
||||
!!! error TS2318: Cannot find global type 'Function'.
|
||||
!!! error TS2318: Cannot find global type 'Boolean'.
|
||||
!!! error TS2318: Cannot find global type 'Number'.
|
||||
!!! error TS2318: Cannot find global type 'MethodDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'IArguments'.
|
||||
!!! error TS2318: Cannot find global type 'Array'.
|
||||
==== test.ts (1 errors) ====
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
|
||||
@ -1,32 +1,22 @@
|
||||
error TS2318: Cannot find global type 'Object'.
|
||||
error TS2318: Cannot find global type 'Array'.
|
||||
error TS2318: Cannot find global type 'ParameterDecorator'.
|
||||
error TS2318: Cannot find global type 'ClassDecorator'.
|
||||
error TS2318: Cannot find global type 'TypedPropertyDescriptor'.
|
||||
error TS2318: Cannot find global type 'String'.
|
||||
error TS2318: Cannot find global type 'RegExp'.
|
||||
error TS2318: Cannot find global type 'PropertyDecorator'.
|
||||
error TS2318: Cannot find global type 'Object'.
|
||||
error TS2318: Cannot find global type 'Number'.
|
||||
error TS2318: Cannot find global type 'IArguments'.
|
||||
error TS2318: Cannot find global type 'Function'.
|
||||
error TS2318: Cannot find global type 'Boolean'.
|
||||
error TS2318: Cannot find global type 'Number'.
|
||||
error TS2318: Cannot find global type 'MethodDecorator'.
|
||||
error TS2318: Cannot find global type 'IArguments'.
|
||||
error TS2318: Cannot find global type 'Array'.
|
||||
test.ts(3,8): error TS2304: Cannot find name 'Array'.
|
||||
|
||||
|
||||
!!! error TS2318: Cannot find global type 'Object'.
|
||||
!!! error TS2318: Cannot find global type 'Array'.
|
||||
!!! error TS2318: Cannot find global type 'ParameterDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'ClassDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'.
|
||||
!!! error TS2318: Cannot find global type 'String'.
|
||||
!!! error TS2318: Cannot find global type 'RegExp'.
|
||||
!!! error TS2318: Cannot find global type 'PropertyDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'Object'.
|
||||
!!! error TS2318: Cannot find global type 'Number'.
|
||||
!!! error TS2318: Cannot find global type 'IArguments'.
|
||||
!!! error TS2318: Cannot find global type 'Function'.
|
||||
!!! error TS2318: Cannot find global type 'Boolean'.
|
||||
!!! error TS2318: Cannot find global type 'Number'.
|
||||
!!! error TS2318: Cannot find global type 'MethodDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'IArguments'.
|
||||
!!! error TS2318: Cannot find global type 'Array'.
|
||||
==== test.ts (1 errors) ====
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
|
||||
@ -1,16 +1,11 @@
|
||||
error TS2318: Cannot find global type 'PropertyDecorator'.
|
||||
error TS2318: Cannot find global type 'Array'.
|
||||
error TS2318: Cannot find global type 'RegExp'.
|
||||
error TS2318: Cannot find global type 'ClassDecorator'.
|
||||
error TS2318: Cannot find global type 'String'.
|
||||
error TS2318: Cannot find global type 'Array'.
|
||||
error TS2318: Cannot find global type 'IArguments'.
|
||||
error TS2318: Cannot find global type 'TypedPropertyDescriptor'.
|
||||
error TS2318: Cannot find global type 'Number'.
|
||||
error TS2318: Cannot find global type 'Boolean'.
|
||||
error TS2318: Cannot find global type 'RegExp'.
|
||||
error TS2318: Cannot find global type 'Object'.
|
||||
error TS2318: Cannot find global type 'MethodDecorator'.
|
||||
error TS2318: Cannot find global type 'Number'.
|
||||
error TS2318: Cannot find global type 'Function'.
|
||||
error TS2318: Cannot find global type 'ParameterDecorator'.
|
||||
tests/cases/compiler/typeCheckTypeArgument.ts(3,19): error TS2304: Cannot find name 'UNKNOWN'.
|
||||
tests/cases/compiler/typeCheckTypeArgument.ts(5,26): error TS2304: Cannot find name 'UNKNOWN'.
|
||||
tests/cases/compiler/typeCheckTypeArgument.ts(7,21): error TS2304: Cannot find name 'UNKNOWN'.
|
||||
@ -19,19 +14,14 @@ tests/cases/compiler/typeCheckTypeArgument.ts(12,22): error TS2304: Cannot find
|
||||
tests/cases/compiler/typeCheckTypeArgument.ts(15,13): error TS2304: Cannot find name 'UNKNOWN'.
|
||||
|
||||
|
||||
!!! error TS2318: Cannot find global type 'PropertyDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'Array'.
|
||||
!!! error TS2318: Cannot find global type 'RegExp'.
|
||||
!!! error TS2318: Cannot find global type 'ClassDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'String'.
|
||||
!!! error TS2318: Cannot find global type 'Array'.
|
||||
!!! error TS2318: Cannot find global type 'IArguments'.
|
||||
!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'.
|
||||
!!! error TS2318: Cannot find global type 'Number'.
|
||||
!!! error TS2318: Cannot find global type 'Boolean'.
|
||||
!!! error TS2318: Cannot find global type 'RegExp'.
|
||||
!!! error TS2318: Cannot find global type 'Object'.
|
||||
!!! error TS2318: Cannot find global type 'MethodDecorator'.
|
||||
!!! error TS2318: Cannot find global type 'Number'.
|
||||
!!! error TS2318: Cannot find global type 'Function'.
|
||||
!!! error TS2318: Cannot find global type 'ParameterDecorator'.
|
||||
==== tests/cases/compiler/typeCheckTypeArgument.ts (6 errors) ====
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user