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
This commit is contained in:
Pete Bacon Darwin 2019-04-28 20:48:34 +01:00 committed by Jason Aden
parent 48b77459ef
commit 0fa72a8bc8
5 changed files with 28 additions and 41 deletions

View File

@ -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<T> = (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<T = any> {}
export declare interface ModuleWithProviders<T = any> {}
`
};
}
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);
`
};
}

View File

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

View File

@ -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],

View File

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

View File

@ -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],