Merge pull request #2892 from Microsoft/lazyGlobalDecoratorTypes

Lazy resolution of global decorator types
This commit is contained in:
Ron Buckton
2015-04-23 14:47:36 -07:00
14 changed files with 6613 additions and 94 deletions

View File

@@ -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.

View File

@@ -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;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,23 @@
error TS2318: Cannot find global type 'ClassDecorator'.
!!! error TS2318: Cannot find global type 'ClassDecorator'.
==== tests/cases/conformance/decorators/a.ts (0 errors) ====
interface Object { }
interface Array<T> { }
interface String { }
interface Boolean { }
interface Number { }
interface Function { }
interface RegExp { }
interface IArguments { }
==== tests/cases/conformance/decorators/b.ts (0 errors) ====
declare var dec: any;
@dec
class C {
}

View File

@@ -0,0 +1,40 @@
//// [tests/cases/conformance/decorators/missingDecoratorType.ts] ////
//// [a.ts]
interface Object { }
interface Array<T> { }
interface String { }
interface Boolean { }
interface Number { }
interface Function { }
interface RegExp { }
interface IArguments { }
//// [b.ts]
declare var dec: any;
@dec
class C {
}
//// [a.js]
//// [b.js]
var __decorate = this.__decorate || function (decorators, target, key, desc) {
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
var C = (function () {
function C() {
}
C = __decorate([
dec
], C);
return C;
})();

View File

@@ -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"/>

View File

@@ -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"/>

View File

@@ -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"/>

View File

@@ -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"/>

View File

@@ -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"/>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,21 @@
// @target: ES5
// @noLib: true
// @Filename: a.ts
interface Object { }
interface Array<T> { }
interface String { }
interface Boolean { }
interface Number { }
interface Function { }
interface RegExp { }
interface IArguments { }
// @Filename: b.ts
/// <reference path="a.ts" />
declare var dec: any;
@dec
class C {
}