From 4ad2f1191916cd8220fe94dc724e42c7e72e95ea Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Mon, 16 Jul 2018 08:54:16 +0100 Subject: [PATCH] test(ivy): implement ngcc specific version of `makeProgram` (#24897) PR Close #24897 --- .../src/ngcc/test/helpers/utils.ts | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 packages/compiler-cli/src/ngcc/test/helpers/utils.ts diff --git a/packages/compiler-cli/src/ngcc/test/helpers/utils.ts b/packages/compiler-cli/src/ngcc/test/helpers/utils.ts new file mode 100644 index 0000000000..4caa1e1d2e --- /dev/null +++ b/packages/compiler-cli/src/ngcc/test/helpers/utils.ts @@ -0,0 +1,52 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ +import * as ts from 'typescript'; +import {makeProgram as _makeProgram} from '../../../ngtsc/testing/in_memory_typescript'; + +export {getDeclaration} from '../../../ngtsc/testing/in_memory_typescript'; + +export function makeProgram(...files: {name: string, contents: string}[]): ts.Program { + return _makeProgram([getFakeCore(), ...files], {allowJs: true, checkJs: false}).program; +} + +// TODO: unify this with the //packages/compiler-cli/test/ngtsc/fake_core package +export function getFakeCore() { + return { + name: 'node_modules/@angular/core/index.ts', + contents: ` + type FnWithArg = (arg?: any) => T; + + function callableClassDecorator(): FnWithArg<(clazz: any) => any> { + return null !; + } + + 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) {} + } + ` + }; +}