diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 50d17638371..489e44a9cd3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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 = {}; let unionTypes: Map = {}; @@ -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. diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 80840068332..6383108b0d6 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -281,6 +281,17 @@ module ts { return result; } + export function memoize(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; diff --git a/tests/baselines/reference/noDefaultLib.errors.txt b/tests/baselines/reference/noDefaultLib.errors.txt index c73f3e0b948..b8f42ba7c33 100644 --- a/tests/baselines/reference/noDefaultLib.errors.txt +++ b/tests/baselines/reference/noDefaultLib.errors.txt @@ -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) ==== /// diff --git a/tests/baselines/reference/parser509698.errors.txt b/tests/baselines/reference/parser509698.errors.txt index 3dd70275e5c..85485dd6501 100644 --- a/tests/baselines/reference/parser509698.errors.txt +++ b/tests/baselines/reference/parser509698.errors.txt @@ -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) ==== ///