From 0fa72a8bc83b6b1f02edbc92650ebb1d2baa2c78 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Sun, 28 Apr 2019 20:48:34 +0100 Subject: [PATCH] refactor(ivy): ngcc - fake core and tslib should be typings files (#25445) Previously these fake files were full TypeScript source files (`.ts`) but this is not necessary as we only need the typings not the implementation. PR Close #25445 --- .../compiler-cli/ngcc/test/helpers/utils.ts | 51 ++++++++----------- .../host/esm2015_host_import_helper_spec.ts | 2 +- .../ngcc/test/host/esm2015_host_spec.ts | 7 ++- .../test/host/esm5_host_import_helper_spec.ts | 2 +- .../ngcc/test/host/esm5_host_spec.ts | 7 ++- 5 files changed, 28 insertions(+), 41 deletions(-) diff --git a/packages/compiler-cli/ngcc/test/helpers/utils.ts b/packages/compiler-cli/ngcc/test/helpers/utils.ts index f4eae77e54..5463251b46 100644 --- a/packages/compiler-cli/ngcc/test/helpers/utils.ts +++ b/packages/compiler-cli/ngcc/test/helpers/utils.ts @@ -64,49 +64,38 @@ export function makeTestProgram( // TODO: unify this with the //packages/compiler-cli/test/ngtsc/fake_core package export function getFakeCore() { return { - name: 'node_modules/@angular/core/index.ts', + name: 'node_modules/@angular/core/index.d.ts', contents: ` type FnWithArg = (arg?: any) => T; - function callableClassDecorator(): FnWithArg<(clazz: any) => any> { - return null !; + export declare const Component: FnWithArg<(clazz: any) => any>; + export declare const Directive: FnWithArg<(clazz: any) => any>; + export declare const Injectable: FnWithArg<(clazz: any) => any>; + export declare const NgModule: FnWithArg<(clazz: any) => any>; + + export declare const Input: any; + + export declare const Inject: FnWithArg<(a: any, b: any, c: any) => void>; + export declare const Self: FnWithArg<(a: any, b: any, c: any) => void>; + export declare const SkipSelf: FnWithArg<(a: any, b: any, c: any) => void>; + export declare const Optional: FnWithArg<(a: any, b: any, c: any) => void>; + + export declare class InjectionToken { + constructor(name: string); } - function callableParamDecorator(): FnWithArg<(a: any, b: any, c: any) => void> { - return null !; - } - - function makePropDecorator(): any { - } - - export const Component = callableClassDecorator(); - export const Directive = callableClassDecorator(); - export const Injectable = callableClassDecorator(); - export const NgModule = callableClassDecorator(); - - export const Input = makePropDecorator(); - - export const Inject = callableParamDecorator(); - export const Self = callableParamDecorator(); - export const SkipSelf = callableParamDecorator(); - export const Optional = callableParamDecorator(); - - export class InjectionToken { - constructor(name: string) {} - } - - export interface ModuleWithProviders {} + export declare interface ModuleWithProviders {} ` }; } export function getFakeTslib() { return { - name: 'node_modules/tslib/index.ts', + name: 'node_modules/tslib/index.d.ts', contents: ` - export function __decorate(decorators: any[], target: any, key?: string | symbol, desc?: any) {} - export function __param(paramIndex: number, decorator: any) {} - export function __metadata(metadataKey: any, metadataValue: any) {} + export declare function __decorate(decorators: any[], target: any, key?: string | symbol, desc?: any); + export declare function __param(paramIndex: number, decorator: any); + export declare function __metadata(metadataKey: any, metadataValue: any); ` }; } diff --git a/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts b/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts index da5834541a..44d6315a52 100644 --- a/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts @@ -346,7 +346,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { null; const expectedDeclarationNode = getDeclaration( - program, 'node_modules/@angular/core/index.ts', 'Directive', + program, 'node_modules/@angular/core/index.d.ts', 'Directive', isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective !); expect(actualDeclaration).not.toBe(null); diff --git a/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts b/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts index 1da2f5b0eb..75defb0600 100644 --- a/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts @@ -1359,7 +1359,8 @@ describe('Esm2015ReflectionHost', () => { .initializer as ts.Identifier; const expectedDeclarationNode = getDeclaration( - program, 'node_modules/@angular/core/index.ts', 'Directive', isNamedVariableDeclaration); + program, 'node_modules/@angular/core/index.d.ts', 'Directive', + isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -1419,9 +1420,7 @@ describe('Esm2015ReflectionHost', () => { const values = Array.from(exportDeclarations !.values()) .map(declaration => [declaration.node.getText(), declaration.viaModule]); expect(values).toEqual([ - // TODO clarify what is expected here... - // [`Directive = callableClassDecorator()`, '@angular/core'], - [`Directive = callableClassDecorator()`, null], + [`Directive: FnWithArg<(clazz: any) => any>`, null], [`a = 'a'`, null], [`b = a`, null], [`c = foo`, null], diff --git a/packages/compiler-cli/ngcc/test/host/esm5_host_import_helper_spec.ts b/packages/compiler-cli/ngcc/test/host/esm5_host_import_helper_spec.ts index bcaadcc8a9..65b02de6ff 100644 --- a/packages/compiler-cli/ngcc/test/host/esm5_host_import_helper_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm5_host_import_helper_spec.ts @@ -365,7 +365,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { null; const expectedDeclarationNode = getDeclaration( - program, 'node_modules/@angular/core/index.ts', 'Directive', + program, 'node_modules/@angular/core/index.d.ts', 'Directive', isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective !); expect(actualDeclaration).not.toBe(null); diff --git a/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts b/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts index c4966b9023..76cc48b156 100644 --- a/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts @@ -1514,7 +1514,8 @@ describe('Esm5ReflectionHost', () => { .initializer as ts.Identifier; const expectedDeclarationNode = getDeclaration( - program, 'node_modules/@angular/core/index.ts', 'Directive', isNamedVariableDeclaration); + program, 'node_modules/@angular/core/index.d.ts', 'Directive', + isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -1590,9 +1591,7 @@ describe('Esm5ReflectionHost', () => { const values = Array.from(exportDeclarations !.values()) .map(declaration => [declaration.node.getText(), declaration.viaModule]); expect(values).toEqual([ - // TODO: clarify what is expected here... - //[`Directive = callableClassDecorator()`, '@angular/core'], - [`Directive = callableClassDecorator()`, null], + [`Directive: FnWithArg<(clazz: any) => any>`, null], [`a = 'a'`, null], [`b = a`, null], [`c = foo`, null],