test(ngcc): use `DelegatingReflectionHost` for testing `NgccReflectionHost`s (#36284)
In #36089, `DelegatingReflectionHost` was introduced. Under the hood, it delegates another `NgccReflectionHost` in order to reflect over the program's source files, while using a different TypeScript `ReflectionHost` to reflect over `.d.ts` files (which is how external dependencies are represented in the program). Previously, the `NgccReflectionHost`s were used directly in tests. This does not exercise them in the way they are exercised in the actual program, because (when used directly) they will also reflect on `.d.ts` files too (instead of delegating to the TypeScript `ReflectionHost`). This could hide bugs that would happen on the actual program. This commit fixes this by using the `DelegatingReflectionHost` in the various `NgccReflectionHost` tests. NOTE: This change will cause some of the existing tests to start failing. These failures demonstrate pre-existing bugs in ngcc, that were hidden due to the tests' being inconsistent with how the `ReflectionHost`s are used in the actual program. They will be fixed in the next commit. PR Close #36284
This commit is contained in:
parent
0af6e9fcbb
commit
93f07aee6c
|
@ -8,12 +8,15 @@
|
|||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, CtorParameter, InlineDeclaration, KnownDeclaration, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, CtorParameter, InlineDeclaration, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration, KnownDeclaration, TypeScriptReflectionHost} from '../../../src/ngtsc/reflection';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
import {CommonJsReflectionHost} from '../../src/host/commonjs_host';
|
||||
import {DelegatingReflectionHost} from '../../src/host/delegating_host';
|
||||
import {getIifeBody} from '../../src/host/esm5_host';
|
||||
import {NgccReflectionHost} from '../../src/host/ngcc_host';
|
||||
import {BundleProgram} from '../../src/packages/bundle_program';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {getRootFiles, makeTestBundleProgram, makeTestDtsBundleProgram} from '../helpers/utils';
|
||||
|
||||
|
@ -21,7 +24,6 @@ import {expectTypeValueReferencesForParameters} from './util';
|
|||
|
||||
runInEachFileSystem(() => {
|
||||
describe('CommonJsReflectionHost', () => {
|
||||
|
||||
let _: typeof absoluteFrom;
|
||||
|
||||
let SOME_DIRECTIVE_FILE: TestFile;
|
||||
|
@ -45,6 +47,12 @@ runInEachFileSystem(() => {
|
|||
let TYPINGS_DTS_FILES: TestFile[];
|
||||
let MODULE_WITH_PROVIDERS_PROGRAM: TestFile[];
|
||||
|
||||
// Helpers
|
||||
const createHost = (bundle: BundleProgram, ngccHost: CommonJsReflectionHost) => {
|
||||
const tsHost = new TypeScriptReflectionHost(bundle.program.getTypeChecker());
|
||||
return new DelegatingReflectionHost(tsHost, ngccHost);
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
_ = absoluteFrom;
|
||||
|
||||
|
@ -916,12 +924,12 @@ exports.ExternalModule = ExternalModule;
|
|||
});
|
||||
|
||||
describe('CommonJsReflectionHost', () => {
|
||||
|
||||
describe('getDecoratorsOfDeclaration()', () => {
|
||||
it('should find the decorators on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -941,7 +949,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should find the decorators on a class at the top level', () => {
|
||||
loadTestFiles([TOPLEVEL_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -961,7 +970,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return null if the symbol is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const functionNode = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(functionNode);
|
||||
|
@ -971,7 +981,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return null if there are no decorators', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode);
|
||||
|
@ -981,7 +992,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should ignore `decorators` if it is not an array literal', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -992,7 +1004,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should ignore decorator elements that are not object literals', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1005,7 +1018,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should ignore decorator elements that have no `type` property', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1018,7 +1032,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should ignore decorator elements whose `type` value is not an identifier', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NotIdentifier',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1032,7 +1047,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should be an empty array if decorator has no `args` property', () => {
|
||||
loadTestFiles([INVALID_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1046,7 +1062,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should be an empty array if decorator\'s `args` has no property assignment', () => {
|
||||
loadTestFiles([INVALID_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1060,7 +1077,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||
loadTestFiles([INVALID_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1077,7 +1095,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should find decorated members on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1097,7 +1116,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should find decorated members on a class at the top level', () => {
|
||||
loadTestFiles([TOPLEVEL_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1117,7 +1137,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should find non decorated properties on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1133,7 +1154,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should find static methods on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1148,7 +1170,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should find static properties on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1164,7 +1187,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should throw if the symbol is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const functionNode = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
expect(() => {
|
||||
|
@ -1175,7 +1199,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return an empty array if there are no prop decorators', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -1187,7 +1212,8 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1199,7 +1225,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should ignore prop decorator elements that are not object literals', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1214,7 +1241,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should ignore prop decorator elements that have no `type` property', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1229,7 +1257,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should ignore prop decorator elements whose `type` value is not an identifier', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1244,7 +1273,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should have import information on decorators', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective',
|
||||
|
@ -1259,7 +1289,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should be an empty array if prop decorator has no `args` property', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1276,7 +1307,8 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1292,7 +1324,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1311,7 +1344,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should find the decorated constructor parameters', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1331,7 +1365,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should find the decorated constructor parameters at the top level', () => {
|
||||
loadTestFiles([TOPLEVEL_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1351,7 +1386,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should accept `ctorParameters` as an array', () => {
|
||||
loadTestFiles([CTOR_DECORATORS_ARRAY_FILE]);
|
||||
const bundle = makeTestBundleProgram(CTOR_DECORATORS_ARRAY_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, CTOR_DECORATORS_ARRAY_FILE.name, 'CtorDecoratedAsArray',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1365,10 +1401,13 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should throw if the symbol is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const functionNode = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
expect(() => { host.getConstructorParameters(functionNode); })
|
||||
expect(() => {
|
||||
host.getConstructorParameters(functionNode);
|
||||
})
|
||||
.toThrowError(
|
||||
'Attempted to get constructor parameters of a non-class: "function foo() {}"');
|
||||
});
|
||||
|
@ -1379,7 +1418,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return an array even if there are no decorators', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1394,7 +1434,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return an empty array if there are no constructor parameters', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1409,7 +1450,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should ignore `ctorParameters` if it does not return an array literal', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1426,7 +1468,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should ignore param decorator elements that are not object literals', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1446,7 +1489,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should ignore param decorator elements that have no `type` property', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1461,7 +1505,8 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1475,7 +1520,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should have import information on decorators', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1493,7 +1539,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should be an empty array if param decorator has no `args` property', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1510,7 +1557,8 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1525,7 +1573,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1544,7 +1593,8 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles([FUNCTION_BODY_FILE]);
|
||||
const bundle = makeTestBundleProgram(FUNCTION_BODY_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const fooNode = getDeclaration(
|
||||
bundle.program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration)!;
|
||||
|
@ -1593,7 +1643,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should find the import of an identifier', () => {
|
||||
loadTestFiles(IMPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/file_b.js'), 'b', isNamedVariableDeclaration);
|
||||
const identifier = (variableNode.initializer &&
|
||||
|
@ -1610,7 +1661,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return null if the identifier was not imported', () => {
|
||||
loadTestFiles(IMPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/file_b.js'), 'd', isNamedVariableDeclaration);
|
||||
const importOfIdent =
|
||||
|
@ -1622,7 +1674,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should handle factory functions not wrapped in parentheses', () => {
|
||||
loadTestFiles(IMPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/file_c.js'), 'c', isNamedVariableDeclaration);
|
||||
const identifier = (variableNode.initializer &&
|
||||
|
@ -1640,7 +1693,7 @@ exports.ExternalModule = ExternalModule;
|
|||
describe('getDeclarationOfIdentifier', () => {
|
||||
// Helpers
|
||||
const createTestForTsHelper =
|
||||
(program: ts.Program, host: CommonJsReflectionHost, srcFile: TestFile,
|
||||
(program: ts.Program, host: NgccReflectionHost, srcFile: TestFile,
|
||||
getHelperDeclaration: (name: string) => ts.Declaration) =>
|
||||
(varName: string, helperName: string, knownAs: KnownDeclaration,
|
||||
viaModule: string|null = null) => {
|
||||
|
@ -1651,7 +1704,8 @@ exports.ExternalModule = ExternalModule;
|
|||
|
||||
expect(helperDeclaration).toEqual({
|
||||
known: knownAs,
|
||||
node: getHelperDeclaration(helperName), viaModule,
|
||||
node: getHelperDeclaration(helperName),
|
||||
viaModule,
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -1667,7 +1721,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return the declaration of a locally defined identifier', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1702,7 +1757,8 @@ exports.ExternalModule = ExternalModule;
|
|||
|
||||
loadTestFiles([PROGRAM_FILE]);
|
||||
const bundle = makeTestBundleProgram(PROGRAM_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const expectedDeclaration = getDeclaration(
|
||||
bundle.program, PROGRAM_FILE.name, 'AliasedClass', isNamedVariableDeclaration);
|
||||
|
@ -1720,13 +1776,15 @@ exports.ExternalModule = ExternalModule;
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
const identifierOfDirective = (((classDecorators[0].node as ts.ObjectLiteralExpression)
|
||||
.properties[0] as ts.PropertyAssignment)
|
||||
const identifierOfDirective =
|
||||
(((classDecorators[0].node as ts.ObjectLiteralExpression).properties[0] as
|
||||
ts.PropertyAssignment)
|
||||
.initializer as ts.PropertyAccessExpression)
|
||||
.expression as ts.Identifier;
|
||||
|
||||
|
@ -1756,7 +1814,8 @@ exports.ExternalModule = ExternalModule;
|
|||
]);
|
||||
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/index.js'), 'b', isNamedVariableDeclaration);
|
||||
const identifier = variableNode.name as ts.Identifier;
|
||||
|
@ -1782,7 +1841,8 @@ exports.ExternalModule = ExternalModule;
|
|||
]);
|
||||
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/index.js'), 'b', isNamedVariableDeclaration);
|
||||
const identifier =
|
||||
|
@ -1807,7 +1867,8 @@ exports.ExternalModule = ExternalModule;
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const testForHelper = createTestForTsHelper(
|
||||
bundle.program, host, file,
|
||||
|
@ -1834,7 +1895,8 @@ exports.ExternalModule = ExternalModule;
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const testForHelper = createTestForTsHelper(
|
||||
bundle.program, host, file,
|
||||
|
@ -1861,7 +1923,8 @@ exports.ExternalModule = ExternalModule;
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const testForHelper = createTestForTsHelper(
|
||||
bundle.program, host, file,
|
||||
|
@ -1888,7 +1951,8 @@ exports.ExternalModule = ExternalModule;
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const testForHelper = createTestForTsHelper(
|
||||
bundle.program, host, file,
|
||||
|
@ -1925,7 +1989,8 @@ exports.ExternalModule = ExternalModule;
|
|||
|
||||
const [testFile, tslibFile] = files;
|
||||
const bundle = makeTestBundleProgram(testFile.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const tslibSourceFile = getSourceFileOrError(bundle.program, tslibFile.name);
|
||||
|
||||
const testForHelper =
|
||||
|
@ -1942,7 +2007,8 @@ exports.ExternalModule = ExternalModule;
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles(EXPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/b_module.js'));
|
||||
const exportDeclarations = host.getExportsOfModule(file);
|
||||
expect(exportDeclarations).not.toBe(null);
|
||||
|
@ -1968,7 +2034,8 @@ exports.ExternalModule = ExternalModule;
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles(EXPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const file =
|
||||
getSourceFileOrError(bundle.program, _('/wildcard_reexports_emitted_helpers.js'));
|
||||
const exportDeclarations = host.getExportsOfModule(file);
|
||||
|
@ -1997,7 +2064,8 @@ exports.ExternalModule = ExternalModule;
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles(EXPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const file =
|
||||
getSourceFileOrError(bundle.program, _('/wildcard_reexports_imported_helpers.js'));
|
||||
const exportDeclarations = host.getExportsOfModule(file);
|
||||
|
@ -2025,7 +2093,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should handle inline exports', () => {
|
||||
loadTestFiles([INLINE_EXPORT_FILE]);
|
||||
const bundle = makeTestBundleProgram(_('/inline_export.js'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/inline_export.js'));
|
||||
const exportDeclarations = host.getExportsOfModule(file);
|
||||
expect(exportDeclarations).not.toBeNull();
|
||||
|
@ -2047,7 +2116,8 @@ exports.ExternalModule = ExternalModule;
|
|||
};
|
||||
loadTestFiles([tslib]);
|
||||
const bundle = makeTestBundleProgram(tslib.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const sf = getSourceFileOrError(bundle.program, tslib.name);
|
||||
const exportDeclarations = host.getExportsOfModule(sf)!;
|
||||
|
||||
|
@ -2065,7 +2135,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return the class symbol for an ES2015 class', () => {
|
||||
loadTestFiles([SIMPLE_ES2015_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||
const classSymbol = host.getClassSymbol(node);
|
||||
|
@ -2078,7 +2149,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return the class symbol for an ES5 class (outer variable declaration)', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
|
@ -2092,7 +2164,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return the class symbol for an ES5 class (inner function declaration)', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
|
@ -2107,11 +2180,11 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const innerNode =
|
||||
getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
|
||||
const innerSymbol = host.getClassSymbol(innerNode)!;
|
||||
const outerSymbol = host.getClassSymbol(outerNode)!;
|
||||
|
@ -2123,12 +2196,12 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'NoParensClass',
|
||||
isNamedVariableDeclaration);
|
||||
const innerNode =
|
||||
getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
const classSymbol = host.getClassSymbol(outerNode);
|
||||
|
||||
expect(classSymbol).toBeDefined();
|
||||
|
@ -2140,12 +2213,12 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'InnerParensClass',
|
||||
isNamedVariableDeclaration);
|
||||
const innerNode =
|
||||
getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
const classSymbol = host.getClassSymbol(outerNode);
|
||||
|
||||
expect(classSymbol).toBeDefined();
|
||||
|
@ -2156,7 +2229,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return undefined if node is not an ES5 class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
const classSymbol = host.getClassSymbol(node);
|
||||
|
@ -2172,7 +2246,8 @@ exports.ExternalModule = ExternalModule;
|
|||
};
|
||||
loadTestFiles([testFile]);
|
||||
const bundle = makeTestBundleProgram(testFile.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, testFile.name, 'MyClass', isNamedVariableDeclaration);
|
||||
const classSymbol = host.getClassSymbol(node);
|
||||
|
@ -2185,7 +2260,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return true if a given node is a TS class declaration', () => {
|
||||
loadTestFiles([SIMPLE_ES2015_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||
expect(host.isClass(node)).toBe(true);
|
||||
|
@ -2195,7 +2271,8 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration);
|
||||
expect(host.isClass(node)).toBe(true);
|
||||
|
@ -2205,18 +2282,19 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration);
|
||||
const innerNode =
|
||||
getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
expect(host.isClass(innerNode)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if a given node is a function declaration', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
expect(host.isClass(node)).toBe(false);
|
||||
|
@ -2232,7 +2310,8 @@ exports.ExternalModule = ExternalModule;
|
|||
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||
return host.hasBaseClass(classNode);
|
||||
|
@ -2279,7 +2358,8 @@ exports.ExternalModule = ExternalModule;
|
|||
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||
const expression = host.getBaseClassExpression(classNode);
|
||||
|
@ -2351,7 +2431,8 @@ exports.ExternalModule = ExternalModule;
|
|||
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||
const expression = host.getBaseClassExpression(classNode)!;
|
||||
|
@ -2363,7 +2444,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return an array of all classes in the given source file', () => {
|
||||
loadTestFiles(DECORATED_FILES);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name);
|
||||
const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name);
|
||||
|
||||
|
@ -2381,7 +2463,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return decorators of class symbol', () => {
|
||||
loadTestFiles(DECORATED_FILES);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name);
|
||||
const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name);
|
||||
|
||||
|
@ -2409,11 +2492,11 @@ exports.ExternalModule = ExternalModule;
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const class1 = getDeclaration(
|
||||
bundle.program, _('/ep/src/class1.js'), 'Class1', ts.isVariableDeclaration);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host = createHost(
|
||||
bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(class1);
|
||||
expect(dtsDeclaration !.getSourceFile().fileName)
|
||||
.toEqual(_('/ep/typings/class1.d.ts'));
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/class1.d.ts'));
|
||||
});
|
||||
|
||||
it('should find the dts declaration for exported functions', () => {
|
||||
|
@ -2423,7 +2506,8 @@ exports.ExternalModule = ExternalModule;
|
|||
const dts = makeTestDtsBundleProgram(_('/ep/typings/func1.d.ts'), _('/'));
|
||||
const mooFn = getDeclaration(
|
||||
bundle.program, _('/ep/src/func1.js'), 'mooFn', ts.isFunctionDeclaration);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
const dtsDeclaration = host.getDtsDeclaration(mooFn);
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/func1.d.ts'));
|
||||
});
|
||||
|
@ -2435,7 +2519,8 @@ exports.ExternalModule = ExternalModule;
|
|||
const dts = makeTestDtsBundleProgram(_('/ep/typings/index.d.ts'), _('/'));
|
||||
const missingClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/class1.js'), 'MissingClass1', ts.isVariableDeclaration);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
expect(host.getDtsDeclaration(missingClass)).toBe(null);
|
||||
});
|
||||
|
@ -2448,7 +2533,8 @@ exports.ExternalModule = ExternalModule;
|
|||
const missingClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/missing-class.js'), 'MissingClass2',
|
||||
ts.isVariableDeclaration);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
expect(host.getDtsDeclaration(missingClass)).toBe(null);
|
||||
});
|
||||
|
@ -2461,11 +2547,11 @@ exports.ExternalModule = ExternalModule;
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const class1 = getDeclaration(
|
||||
bundle.program, _('/ep/src/flat-file.js'), 'Class1', ts.isVariableDeclaration);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host = createHost(
|
||||
bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(class1);
|
||||
expect(dtsDeclaration !.getSourceFile().fileName)
|
||||
.toEqual(_('/ep/typings/class1.d.ts'));
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/class1.d.ts'));
|
||||
});
|
||||
|
||||
it('should find aliased exports', () => {
|
||||
|
@ -2475,7 +2561,8 @@ exports.ExternalModule = ExternalModule;
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const sourceClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/flat-file.js'), 'SourceClass', ts.isVariableDeclaration);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(sourceClass);
|
||||
if (dtsDeclaration === null) {
|
||||
|
@ -2498,7 +2585,8 @@ exports.ExternalModule = ExternalModule;
|
|||
const internalClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/internal.js'), 'InternalClass',
|
||||
ts.isVariableDeclaration);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host = createHost(
|
||||
bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(internalClass);
|
||||
expect(dtsDeclaration!.getSourceFile().fileName)
|
||||
|
@ -2511,7 +2599,8 @@ exports.ExternalModule = ExternalModule;
|
|||
loadTestFiles(TYPINGS_DTS_FILES);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]);
|
||||
const dts = makeTestDtsBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0], _('/ep'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host = createHost(
|
||||
bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const class2 = getDeclaration(
|
||||
bundle.program, _('/ep/src/class2.js'), 'Class2', isNamedVariableDeclaration);
|
||||
|
@ -2531,7 +2620,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return the name of the inner class declaration', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const emptyClass = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
|
@ -2555,7 +2645,8 @@ exports.ExternalModule = ExternalModule;
|
|||
it('should return the name of the inner class declaration', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const emptyClass = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
|
@ -2580,7 +2671,8 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(_('/src/index.js'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/functions.js'));
|
||||
const fns = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fns.map(fn => [fn.declaration.name!.getText(), fn.ngModule.node.name.text]))
|
||||
|
@ -2596,7 +2688,8 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(_('/src/index.js'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/methods.js'));
|
||||
const fn = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.node.name.text])).toEqual([
|
||||
|
@ -2623,7 +2716,8 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(_('/src/index.js'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/outer_aliased_class.js'));
|
||||
const fn = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.node.name.text])).toEqual([
|
||||
|
@ -2636,7 +2730,8 @@ exports.ExternalModule = ExternalModule;
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(_('/src/index.js'));
|
||||
const host = new CommonJsReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new CommonJsReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/inner_aliased_class.js'));
|
||||
const fn = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.node.name.text])).toEqual([
|
||||
|
|
|
@ -9,11 +9,13 @@
|
|||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, CtorParameter, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, CtorParameter, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration, TypeScriptReflectionHost} from '../../../src/ngtsc/reflection';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
import {DelegatingReflectionHost} from '../../src/host/delegating_host';
|
||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||
import {BundleProgram} from '../../src/packages/bundle_program';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {getRootFiles, makeTestBundleProgram, makeTestDtsBundleProgram} from '../helpers/utils';
|
||||
|
||||
|
@ -21,7 +23,6 @@ import {expectTypeValueReferencesForParameters} from './util';
|
|||
|
||||
runInEachFileSystem(() => {
|
||||
describe('Esm2015ReflectionHost', () => {
|
||||
|
||||
let _: typeof absoluteFrom;
|
||||
|
||||
let SOME_DIRECTIVE_FILE: TestFile;
|
||||
|
@ -48,6 +49,12 @@ runInEachFileSystem(() => {
|
|||
let NAMESPACED_IMPORT_FILE: TestFile;
|
||||
let INDEX_SIGNATURE_PROP_FILE: TestFile;
|
||||
|
||||
// Helpers
|
||||
const createHost = (bundle: BundleProgram, ngccHost: Esm2015ReflectionHost) => {
|
||||
const tsHost = new TypeScriptReflectionHost(bundle.program.getTypeChecker());
|
||||
return new DelegatingReflectionHost(tsHost, ngccHost);
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
_ = absoluteFrom;
|
||||
|
||||
|
@ -720,7 +727,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the decorators on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
@ -739,7 +746,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the decorators on an aliased class', () => {
|
||||
loadTestFiles([CLASS_EXPRESSION_FILE]);
|
||||
const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, CLASS_EXPRESSION_FILE.name, 'AliasedClass', isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
@ -758,7 +765,7 @@ runInEachFileSystem(() => {
|
|||
it('should return null if the symbol is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const functionNode = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(functionNode);
|
||||
|
@ -768,7 +775,7 @@ runInEachFileSystem(() => {
|
|||
it('should return null if there are no decorators', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode);
|
||||
|
@ -778,7 +785,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore `decorators` if it is not an array literal', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -789,7 +796,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore decorator elements that are not object literals', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -802,7 +809,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore decorator elements that have no `type` property', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -815,7 +822,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore decorator elements whose `type` value is not an identifier', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
@ -827,7 +834,7 @@ runInEachFileSystem(() => {
|
|||
it('should have import information on decorators', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
@ -840,7 +847,8 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if decorator has no `args` property', () => {
|
||||
loadTestFiles([INVALID_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -854,7 +862,8 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if decorator\'s `args` has no property assignment', () => {
|
||||
loadTestFiles([INVALID_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -868,7 +877,8 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||
loadTestFiles([INVALID_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -885,7 +895,7 @@ runInEachFileSystem(() => {
|
|||
it('should find decorated properties on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -906,7 +916,7 @@ runInEachFileSystem(() => {
|
|||
it('should find non decorated properties on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -921,7 +931,7 @@ runInEachFileSystem(() => {
|
|||
it('should handle equally named getter/setter pairs correctly', () => {
|
||||
loadTestFiles([ACCESSORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(ACCESSORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, ACCESSORS_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -943,7 +953,7 @@ runInEachFileSystem(() => {
|
|||
it('should find static methods on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -957,7 +967,7 @@ runInEachFileSystem(() => {
|
|||
it('should find static properties on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -973,7 +983,7 @@ runInEachFileSystem(() => {
|
|||
loadTestFiles([INDEX_SIGNATURE_PROP_FILE]);
|
||||
const logger = new MockLogger();
|
||||
const bundle = makeTestBundleProgram(INDEX_SIGNATURE_PROP_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(logger, false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(logger, false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INDEX_SIGNATURE_PROP_FILE.name, 'IndexSignatureClass',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -986,7 +996,7 @@ runInEachFileSystem(() => {
|
|||
it('should throw if the symbol is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const functionNode = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
expect(() => {
|
||||
|
@ -997,7 +1007,7 @@ runInEachFileSystem(() => {
|
|||
it('should return an empty array if there are no prop decorators', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -1009,7 +1019,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1021,7 +1032,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore prop decorator elements that are not object literals', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1036,7 +1047,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore prop decorator elements that have no `type` property', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1051,7 +1062,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore prop decorator elements whose `type` value is not an identifier', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1067,7 +1078,8 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if prop decorator has no `args` property', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1084,7 +1096,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1100,7 +1113,8 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1120,7 +1134,7 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||
const parameters = host.getConstructorParameters(classNode)!;
|
||||
|
@ -1136,7 +1150,7 @@ runInEachFileSystem(() => {
|
|||
it('should accept `ctorParameters` as an array', () => {
|
||||
loadTestFiles([CTOR_DECORATORS_ARRAY_FILE]);
|
||||
const bundle = makeTestBundleProgram(CTOR_DECORATORS_ARRAY_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, CTOR_DECORATORS_ARRAY_FILE.name, 'CtorDecoratedAsArray',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1150,10 +1164,12 @@ runInEachFileSystem(() => {
|
|||
it('should throw if the symbol is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const functionNode = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
expect(() => { host.getConstructorParameters(functionNode); })
|
||||
expect(() => {
|
||||
host.getConstructorParameters(functionNode);
|
||||
})
|
||||
.toThrowError(
|
||||
'Attempted to get constructor parameters of a non-class: "function foo() {}"');
|
||||
});
|
||||
|
@ -1161,7 +1177,7 @@ runInEachFileSystem(() => {
|
|||
it('should return `null` if there is no constructor', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||
const parameters = host.getConstructorParameters(classNode);
|
||||
|
@ -1171,7 +1187,7 @@ runInEachFileSystem(() => {
|
|||
it('should return an array even if there are no decorators', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1186,7 +1202,7 @@ runInEachFileSystem(() => {
|
|||
it('should return an empty array if there are no constructor parameters', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1198,7 +1214,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore decorators that are not imported from core', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotFromCore',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1214,7 +1230,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore `ctorParameters` if it is not an arrow function', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrowFunction',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1230,7 +1246,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore `ctorParameters` if it does not return an array literal', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1257,7 +1273,8 @@ runInEachFileSystem(() => {
|
|||
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedClassDeclaration);
|
||||
return host.getConstructorParameters(classNode);
|
||||
|
@ -1313,7 +1330,8 @@ runInEachFileSystem(() => {
|
|||
it('should ignore param decorator elements that are not object literals', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1333,7 +1351,8 @@ runInEachFileSystem(() => {
|
|||
it('should ignore param decorator elements that have no `type` property', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1347,7 +1366,8 @@ runInEachFileSystem(() => {
|
|||
it('should ignore param decorator elements whose `type` value is not an identifier', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1361,7 +1381,8 @@ runInEachFileSystem(() => {
|
|||
it('should have import information on decorators', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||
const parameters = host.getConstructorParameters(classNode)!;
|
||||
|
@ -1376,7 +1397,8 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if param decorator has no `args` property', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1393,7 +1415,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1408,7 +1431,8 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1427,7 +1451,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([FUNCTION_BODY_FILE]);
|
||||
const bundle = makeTestBundleProgram(FUNCTION_BODY_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const fooNode = getDeclaration(
|
||||
bundle.program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration)!;
|
||||
|
@ -1490,7 +1515,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the import of an identifier', () => {
|
||||
loadTestFiles(IMPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/b.js'), 'b', isNamedVariableDeclaration);
|
||||
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
||||
|
@ -1501,7 +1526,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the name by which the identifier was exported, not imported', () => {
|
||||
loadTestFiles(IMPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/b.js'), 'c', isNamedVariableDeclaration);
|
||||
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
||||
|
@ -1512,7 +1537,7 @@ runInEachFileSystem(() => {
|
|||
it('should return null if the identifier was not imported', () => {
|
||||
loadTestFiles(IMPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/b.js'), 'd', isNamedVariableDeclaration);
|
||||
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
||||
|
@ -1526,7 +1551,7 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||
const actualDeclaration = host.getDeclarationOfIdentifier(classNode.name);
|
||||
|
@ -1539,12 +1564,13 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
const identifierOfDirective = ((classDecorators[0].node as ts.ObjectLiteralExpression)
|
||||
.properties[0] as ts.PropertyAssignment)
|
||||
const identifierOfDirective =
|
||||
((classDecorators[0].node as ts.ObjectLiteralExpression).properties[0] as
|
||||
ts.PropertyAssignment)
|
||||
.initializer as ts.Identifier;
|
||||
|
||||
const expectedDeclarationNode = getDeclaration(
|
||||
|
@ -1560,12 +1586,13 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles([NAMESPACED_IMPORT_FILE]);
|
||||
const bundle = makeTestBundleProgram(NAMESPACED_IMPORT_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, NAMESPACED_IMPORT_FILE.name, 'SomeDirective', ts.isClassDeclaration);
|
||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
const identifier = (((classDecorators[0].node as ts.ObjectLiteralExpression)
|
||||
.properties[0] as ts.PropertyAssignment)
|
||||
const identifier =
|
||||
(((classDecorators[0].node as ts.ObjectLiteralExpression).properties[0] as
|
||||
ts.PropertyAssignment)
|
||||
.initializer as ts.PropertyAccessExpression)
|
||||
.expression as ts.Identifier;
|
||||
|
||||
|
@ -1580,7 +1607,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the original declaration of an aliased class', () => {
|
||||
loadTestFiles([CLASS_EXPRESSION_FILE]);
|
||||
const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classDeclaration = getDeclaration(
|
||||
bundle.program, CLASS_EXPRESSION_FILE.name, 'AliasedClass', ts.isVariableDeclaration);
|
||||
const usageOfAliasedClass = getDeclaration(
|
||||
|
@ -1598,7 +1625,7 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles(EXPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/b.js'));
|
||||
const exportDeclarations = host.getExportsOfModule(file);
|
||||
expect(exportDeclarations).not.toBe(null);
|
||||
|
@ -1633,7 +1660,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the class symbol for an ES2015 class', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||
const classSymbol = host.getClassSymbol(node);
|
||||
|
@ -1647,7 +1674,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([CLASS_EXPRESSION_FILE]);
|
||||
const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, CLASS_EXPRESSION_FILE.name, 'EmptyClass',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1662,7 +1690,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the class symbol for a class expression (inner class expression)', () => {
|
||||
loadTestFiles([CLASS_EXPRESSION_FILE]);
|
||||
const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, CLASS_EXPRESSION_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const innerNode = (outerNode.initializer as ts.ClassExpression);
|
||||
|
@ -1677,7 +1705,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([CLASS_EXPRESSION_FILE]);
|
||||
const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, CLASS_EXPRESSION_FILE.name, 'EmptyClass',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1692,7 +1721,7 @@ runInEachFileSystem(() => {
|
|||
it('should return undefined if node is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
const classSymbol = host.getClassSymbol(node);
|
||||
|
@ -1708,7 +1737,8 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([testFile]);
|
||||
const bundle = makeTestBundleProgram(testFile.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node =
|
||||
getDeclaration(bundle.program, testFile.name, 'MyClass', isNamedVariableDeclaration);
|
||||
const classSymbol = host.getClassSymbol(node);
|
||||
|
@ -1721,7 +1751,7 @@ runInEachFileSystem(() => {
|
|||
it('should return true if a given node is a TS class declaration', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||
expect(host.isClass(node)).toBe(true);
|
||||
|
@ -1731,7 +1761,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([CLASS_EXPRESSION_FILE]);
|
||||
const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, CLASS_EXPRESSION_FILE.name, 'EmptyClass', ts.isVariableDeclaration);
|
||||
expect(host.isClass(node)).toBe(true);
|
||||
|
@ -1741,7 +1772,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([CLASS_EXPRESSION_FILE]);
|
||||
const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, CLASS_EXPRESSION_FILE.name, 'AliasedClass',
|
||||
ts.isVariableDeclaration);
|
||||
|
@ -1751,7 +1783,7 @@ runInEachFileSystem(() => {
|
|||
it('should return false if a given node is a TS function declaration', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
expect(host.isClass(node)).toBe(false);
|
||||
|
@ -1766,7 +1798,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedClassDeclaration);
|
||||
expect(host.hasBaseClass(classNode)).toBe(false);
|
||||
|
@ -1781,7 +1813,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedClassDeclaration);
|
||||
expect(host.hasBaseClass(classNode)).toBe(true);
|
||||
|
@ -1797,7 +1829,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||
expect(host.hasBaseClass(classNode)).toBe(true);
|
||||
|
@ -1812,7 +1844,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedClassDeclaration);
|
||||
expect(host.getBaseClassExpression(classNode)).toBe(null);
|
||||
|
@ -1827,7 +1859,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedClassDeclaration);
|
||||
const baseIdentifier = host.getBaseClassExpression(classNode)!;
|
||||
|
@ -1847,7 +1879,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||
const baseIdentifier = host.getBaseClassExpression(classNode)!;
|
||||
|
@ -1868,7 +1900,8 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedClassDeclaration);
|
||||
const baseExpression = host.getBaseClassExpression(classNode)!;
|
||||
|
@ -1881,7 +1914,8 @@ runInEachFileSystem(() => {
|
|||
loadTestFiles(ARITY_CLASSES);
|
||||
const bundle = makeTestBundleProgram(ARITY_CLASSES[0].name);
|
||||
const dts = makeTestBundleProgram(ARITY_CLASSES[1].name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
const noTypeParamClass = getDeclaration(
|
||||
bundle.program, _('/src/class.js'), 'NoTypeParam', isNamedClassDeclaration);
|
||||
expect(host.getGenericArityOfClass(noTypeParamClass)).toBe(0);
|
||||
|
@ -1899,7 +1933,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([MARKER_FILE]);
|
||||
const bundle = makeTestBundleProgram(MARKER_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, MARKER_FILE.name);
|
||||
const declarations = host.getSwitchableDeclarations(file);
|
||||
expect(declarations.map(d => [d.name.getText(), d.initializer!.getText()])).toEqual([
|
||||
|
@ -1912,7 +1947,7 @@ runInEachFileSystem(() => {
|
|||
it('should return an array of all classes in the given source file', () => {
|
||||
loadTestFiles(DECORATED_FILES);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name);
|
||||
const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name);
|
||||
|
||||
|
@ -1930,7 +1965,7 @@ runInEachFileSystem(() => {
|
|||
it('should return decorators of class symbol', () => {
|
||||
loadTestFiles(DECORATED_FILES);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name);
|
||||
const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name);
|
||||
|
||||
|
@ -1951,7 +1986,7 @@ runInEachFileSystem(() => {
|
|||
it('should return a cloned array on each invocation', () => {
|
||||
loadTestFiles(DECORATED_FILES);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classDecl =
|
||||
getDeclaration(bundle.program, DECORATED_FILES[0].name, 'A', ts.isClassDeclaration)!;
|
||||
const classSymbol = host.getClassSymbol(classDecl)!;
|
||||
|
@ -1972,7 +2007,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const class1 = getDeclaration(
|
||||
bundle.program, _('/ep/src/class1.js'), 'Class1', isNamedClassDeclaration);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(class1);
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/class1.d.ts'));
|
||||
|
@ -1985,7 +2021,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestDtsBundleProgram(_('/ep/typings/func1.d.ts'), _('/'));
|
||||
const mooFn = getDeclaration(
|
||||
bundle.program, _('/ep/src/func1.js'), 'mooFn', isNamedFunctionDeclaration);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(mooFn);
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/func1.d.ts'));
|
||||
|
@ -1999,7 +2036,8 @@ runInEachFileSystem(() => {
|
|||
const missingClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/missing-class.js'), 'MissingClass2',
|
||||
isNamedClassDeclaration);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
expect(host.getDtsDeclaration(missingClass)).toBe(null);
|
||||
});
|
||||
|
@ -2012,7 +2050,8 @@ runInEachFileSystem(() => {
|
|||
const missingClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/missing-class.js'), 'MissingClass2',
|
||||
isNamedClassDeclaration);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
expect(host.getDtsDeclaration(missingClass)).toBe(null);
|
||||
});
|
||||
|
@ -2026,7 +2065,8 @@ runInEachFileSystem(() => {
|
|||
getRootFiles(TYPINGS_DTS_FILES)[0], false, [_('/ep/typings/shadow-class.d.ts')]);
|
||||
const shadowClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/shadow-class.js'), 'ShadowClass', isNamedClassDeclaration);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDecl = host.getDtsDeclaration(shadowClass)!;
|
||||
expect(dtsDecl).not.toBeNull();
|
||||
|
@ -2054,7 +2094,8 @@ runInEachFileSystem(() => {
|
|||
const missingClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/missing-class.js'), 'MissingClass2',
|
||||
isNamedClassDeclaration);
|
||||
const host = new TestEsm2015ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new TestEsm2015ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
expect(host.getDtsDeclaration(missingClass)).toBeNull();
|
||||
});
|
||||
|
@ -2067,7 +2108,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const class1 = getDeclaration(
|
||||
bundle.program, _('/ep/src/flat-file.js'), 'Class1', isNamedClassDeclaration);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(class1);
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/class1.d.ts'));
|
||||
|
@ -2080,7 +2122,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const sourceClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/flat-file.js'), 'SourceClass', isNamedClassDeclaration);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(sourceClass);
|
||||
if (dtsDeclaration === null) {
|
||||
|
@ -2102,11 +2145,11 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const internalClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/internal.js'), 'InternalClass', isNamedClassDeclaration);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(internalClass);
|
||||
expect(dtsDeclaration !.getSourceFile().fileName)
|
||||
.toEqual(_('/ep/typings/internal.d.ts'));
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/internal.d.ts'));
|
||||
});
|
||||
|
||||
it('should match publicly and internal exported classes correctly, even if they have the same name',
|
||||
|
@ -2115,7 +2158,8 @@ runInEachFileSystem(() => {
|
|||
loadTestFiles(TYPINGS_DTS_FILES);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]);
|
||||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const class2 = getDeclaration(
|
||||
bundle.program, _('/ep/src/class2.js'), 'Class2', isNamedClassDeclaration);
|
||||
|
@ -2135,7 +2179,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the name of the class (there is no separate inner class in ES2015)', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||
expect(host.getInternalNameOfClass(node).text).toEqual('EmptyClass');
|
||||
|
@ -2146,7 +2190,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the name of the class (there is no separate inner class in ES2015)', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||
expect(host.getAdjacentNameOfClass(node).text).toEqual('EmptyClass');
|
||||
|
@ -2158,7 +2202,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/functions.js'));
|
||||
const fns = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fns.map(fn => [fn.declaration.name!.getText(), fn.ngModule.node.name.text]))
|
||||
|
@ -2175,7 +2220,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/methods.js'));
|
||||
const fn = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fn.map(fn => [fn.declaration.name!.getText(), fn.ngModule.node.name.text]))
|
||||
|
@ -2192,11 +2238,10 @@ runInEachFileSystem(() => {
|
|||
it('should resolve aliased module references to their original declaration', () => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/aliased_class.js'));
|
||||
const fn = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fn.map(fn => [fn.declaration.name !.getText(), fn.ngModule.node.name.text]))
|
||||
.toEqual([
|
||||
expect(fn.map(fn => [fn.declaration.name!.getText(), fn.ngModule.node.name.text])).toEqual([
|
||||
['forRoot', 'AliasedModule'],
|
||||
]);
|
||||
});
|
||||
|
@ -2224,7 +2269,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([testFile]);
|
||||
const bundle = makeTestBundleProgram(testFile.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classSymbol = host.findClassSymbols(bundle.program.getSourceFile(testFile.name)!)[0];
|
||||
const endOfClass = host.getEndOfClass(classSymbol);
|
||||
expect(endOfClass.getText())
|
||||
|
@ -2247,7 +2292,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([testFile]);
|
||||
const bundle = makeTestBundleProgram(testFile.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classSymbol = host.findClassSymbols(bundle.program.getSourceFile(testFile.name)!)[0];
|
||||
const endOfClass = host.getEndOfClass(classSymbol);
|
||||
expect(endOfClass.getText())
|
||||
|
|
|
@ -9,12 +9,15 @@
|
|||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, CtorParameter, Decorator, KnownDeclaration, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, CtorParameter, Decorator, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration, KnownDeclaration, TypeScriptReflectionHost} from '../../../src/ngtsc/reflection';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
import {DelegatingReflectionHost} from '../../src/host/delegating_host';
|
||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||
import {Esm5ReflectionHost, getIifeBody} from '../../src/host/esm5_host';
|
||||
import {NgccReflectionHost} from '../../src/host/ngcc_host';
|
||||
import {BundleProgram} from '../../src/packages/bundle_program';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {getRootFiles, makeTestBundleProgram, makeTestDtsBundleProgram} from '../helpers/utils';
|
||||
|
||||
|
@ -22,7 +25,6 @@ import {expectTypeValueReferencesForParameters} from './util';
|
|||
|
||||
runInEachFileSystem(() => {
|
||||
describe('Esm5ReflectionHost', () => {
|
||||
|
||||
let _: typeof absoluteFrom;
|
||||
|
||||
let SOME_DIRECTIVE_FILE: TestFile;
|
||||
|
@ -48,6 +50,12 @@ runInEachFileSystem(() => {
|
|||
let MODULE_WITH_PROVIDERS_PROGRAM: TestFile[];
|
||||
let NAMESPACED_IMPORT_FILE: TestFile;
|
||||
|
||||
// Helpers
|
||||
const createHost = (bundle: BundleProgram, ngccHost: Esm5ReflectionHost) => {
|
||||
const tsHost = new TypeScriptReflectionHost(bundle.program.getTypeChecker());
|
||||
return new DelegatingReflectionHost(tsHost, ngccHost);
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
_ = absoluteFrom;
|
||||
SOME_DIRECTIVE_FILE = {
|
||||
|
@ -891,7 +899,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the decorators on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
@ -910,7 +918,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the decorators on a class at the top level', () => {
|
||||
loadTestFiles([TOPLEVEL_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -930,7 +938,7 @@ runInEachFileSystem(() => {
|
|||
it('should return null if the symbol is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const functionNode = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(functionNode);
|
||||
|
@ -940,7 +948,7 @@ runInEachFileSystem(() => {
|
|||
it('should return null if there are no decorators', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode);
|
||||
|
@ -950,7 +958,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore `decorators` if it is not an array literal', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -961,7 +969,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore decorator elements that are not object literals', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -974,7 +982,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore decorator elements that have no `type` property', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -987,7 +995,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore decorator elements whose `type` value is not an identifier', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NotIdentifier',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1000,7 +1008,7 @@ runInEachFileSystem(() => {
|
|||
it('should have import information on decorators', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
@ -1013,7 +1021,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if decorator has no `args` property', () => {
|
||||
loadTestFiles([INVALID_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1027,7 +1035,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if decorator\'s `args` has no property assignment', () => {
|
||||
loadTestFiles([INVALID_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1041,7 +1049,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||
loadTestFiles([INVALID_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1058,7 +1066,7 @@ runInEachFileSystem(() => {
|
|||
it('should find decorated members on a class at the top level', () => {
|
||||
loadTestFiles([TOPLEVEL_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1080,7 +1088,7 @@ runInEachFileSystem(() => {
|
|||
it('should find decorated members on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -1099,7 +1107,7 @@ runInEachFileSystem(() => {
|
|||
it('should find Object.defineProperty members on a class', () => {
|
||||
loadTestFiles([ACCESSORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(ACCESSORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, ACCESSORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -1147,7 +1155,7 @@ runInEachFileSystem(() => {
|
|||
it('should find non decorated properties on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -1162,7 +1170,7 @@ runInEachFileSystem(() => {
|
|||
it('should find static methods on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -1177,7 +1185,7 @@ runInEachFileSystem(() => {
|
|||
it('should find static properties on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -1192,7 +1200,7 @@ runInEachFileSystem(() => {
|
|||
it('should accept `ctorParameters` as an array', () => {
|
||||
loadTestFiles([CTOR_DECORATORS_ARRAY_FILE]);
|
||||
const bundle = makeTestBundleProgram(CTOR_DECORATORS_ARRAY_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, CTOR_DECORATORS_ARRAY_FILE.name, 'CtorDecoratedAsArray',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1206,7 +1214,7 @@ runInEachFileSystem(() => {
|
|||
it('should throw if the symbol is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const functionNode = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
expect(() => {
|
||||
|
@ -1217,7 +1225,7 @@ runInEachFileSystem(() => {
|
|||
it('should return an empty array if there are no prop decorators', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -1229,7 +1237,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1241,7 +1249,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore prop decorator elements that are not object literals', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1256,7 +1264,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore prop decorator elements that have no `type` property', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1271,7 +1279,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore prop decorator elements whose `type` value is not an identifier', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1287,7 +1295,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if prop decorator has no `args` property', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1304,7 +1312,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1320,7 +1329,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1338,7 +1347,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([UNWANTED_PROTOTYPE_EXPORT_FILE]);
|
||||
const bundle = makeTestBundleProgram(UNWANTED_PROTOTYPE_EXPORT_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, UNWANTED_PROTOTYPE_EXPORT_FILE.name, 'SomeParam',
|
||||
isNamedClassDeclaration);
|
||||
|
@ -1351,7 +1360,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the decorated constructor parameters', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const parameters = host.getConstructorParameters(classNode);
|
||||
|
@ -1370,7 +1379,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the decorated constructor parameters at the top level', () => {
|
||||
loadTestFiles([TOPLEVEL_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1390,10 +1399,12 @@ runInEachFileSystem(() => {
|
|||
it('should throw if the symbol is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const functionNode = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
expect(() => { host.getConstructorParameters(functionNode); })
|
||||
expect(() => {
|
||||
host.getConstructorParameters(functionNode);
|
||||
})
|
||||
.toThrowError(
|
||||
'Attempted to get constructor parameters of a non-class: "function foo() {}"');
|
||||
});
|
||||
|
@ -1404,7 +1415,7 @@ runInEachFileSystem(() => {
|
|||
it('should return an array even if there are no decorators', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1419,7 +1430,7 @@ runInEachFileSystem(() => {
|
|||
it('should return an empty array if there are no constructor parameters', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1434,7 +1445,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore `ctorParameters` if it does not return an array literal', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1451,7 +1462,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore param decorator elements that are not object literals', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1471,7 +1482,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore param decorator elements that have no `type` property', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1485,7 +1496,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore param decorator elements whose `type` value is not an identifier', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1499,7 +1510,7 @@ runInEachFileSystem(() => {
|
|||
it('should have import information on decorators', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1526,7 +1537,7 @@ runInEachFileSystem(() => {
|
|||
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||
return host.getConstructorParameters(classNode);
|
||||
|
@ -1595,7 +1606,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if param decorator has no `args` property', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1612,7 +1623,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1627,7 +1639,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1646,7 +1658,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([FUNCTION_BODY_FILE]);
|
||||
const bundle = makeTestBundleProgram(FUNCTION_BODY_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const fooNode = getDeclaration(
|
||||
bundle.program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration)!;
|
||||
|
@ -1695,7 +1707,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the import of an identifier', () => {
|
||||
loadTestFiles(IMPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/b.js'), 'b', isNamedVariableDeclaration);
|
||||
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
||||
|
@ -1706,7 +1718,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the name by which the identifier was exported, not imported', () => {
|
||||
loadTestFiles(IMPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/b.js'), 'c', isNamedVariableDeclaration);
|
||||
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
||||
|
@ -1717,7 +1729,7 @@ runInEachFileSystem(() => {
|
|||
it('should return null if the identifier was not imported', () => {
|
||||
loadTestFiles(IMPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/b.js'), 'd', isNamedVariableDeclaration);
|
||||
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
||||
|
@ -1729,7 +1741,7 @@ runInEachFileSystem(() => {
|
|||
describe('getDeclarationOfIdentifier()', () => {
|
||||
// Helpers
|
||||
const createTestForTsHelper =
|
||||
(program: ts.Program, host: Esm5ReflectionHost, srcFile: TestFile,
|
||||
(program: ts.Program, host: NgccReflectionHost, srcFile: TestFile,
|
||||
getHelperDeclaration: (name: string) => ts.Declaration) =>
|
||||
(varName: string, helperName: string, knownAs: KnownDeclaration,
|
||||
viaModule: string|null = null) => {
|
||||
|
@ -1740,7 +1752,8 @@ runInEachFileSystem(() => {
|
|||
|
||||
expect(helperDeclaration).toEqual({
|
||||
known: knownAs,
|
||||
node: getHelperDeclaration(helperName), viaModule,
|
||||
node: getHelperDeclaration(helperName),
|
||||
viaModule,
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -1756,7 +1769,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the declaration of a locally defined identifier', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const ctrDecorators = host.getConstructorParameters(classNode)!;
|
||||
|
@ -1779,12 +1792,13 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
const identifierOfDirective = ((classDecorators[0].node as ts.ObjectLiteralExpression)
|
||||
.properties[0] as ts.PropertyAssignment)
|
||||
const identifierOfDirective =
|
||||
((classDecorators[0].node as ts.ObjectLiteralExpression).properties[0] as
|
||||
ts.PropertyAssignment)
|
||||
.initializer as ts.Identifier;
|
||||
|
||||
const expectedDeclarationNode = getDeclaration(
|
||||
|
@ -1800,13 +1814,14 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles([NAMESPACED_IMPORT_FILE]);
|
||||
const bundle = makeTestBundleProgram(NAMESPACED_IMPORT_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, NAMESPACED_IMPORT_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
const identifier = (((classDecorators[0].node as ts.ObjectLiteralExpression)
|
||||
.properties[0] as ts.PropertyAssignment)
|
||||
const identifier =
|
||||
(((classDecorators[0].node as ts.ObjectLiteralExpression).properties[0] as
|
||||
ts.PropertyAssignment)
|
||||
.initializer as ts.PropertyAccessExpression)
|
||||
.expression as ts.Identifier;
|
||||
|
||||
|
@ -1825,12 +1840,13 @@ runInEachFileSystem(() => {
|
|||
.and.callThrough();
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const outerDeclaration = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const innerDeclaration = (((outerDeclaration.initializer as ts.ParenthesizedExpression)
|
||||
.expression as ts.CallExpression)
|
||||
const innerDeclaration =
|
||||
(((outerDeclaration.initializer as ts.ParenthesizedExpression).expression as
|
||||
ts.CallExpression)
|
||||
.expression as ts.FunctionExpression)
|
||||
.body.statements[0] as ts.FunctionDeclaration;
|
||||
|
||||
|
@ -1864,7 +1880,7 @@ runInEachFileSystem(() => {
|
|||
|
||||
loadTestFiles([PROGRAM_FILE]);
|
||||
const bundle = makeTestBundleProgram(PROGRAM_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const expectedDeclaration = getDeclaration(
|
||||
bundle.program, PROGRAM_FILE.name, 'AliasedClass', isNamedVariableDeclaration);
|
||||
|
@ -1907,13 +1923,14 @@ runInEachFileSystem(() => {
|
|||
|
||||
loadTestFiles([PROGRAM_FILE]);
|
||||
const bundle = makeTestBundleProgram(PROGRAM_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const expectedDeclaration = getDeclaration(
|
||||
bundle.program, PROGRAM_FILE.name, 'FroalaEditorModule', isNamedVariableDeclaration);
|
||||
// Grab the `FroalaEditorModule_1` identifier returned from the `forRoot()` method
|
||||
const forRootMethod = ((((expectedDeclaration.initializer as ts.ParenthesizedExpression)
|
||||
.expression as ts.CallExpression)
|
||||
const forRootMethod =
|
||||
((((expectedDeclaration.initializer as ts.ParenthesizedExpression).expression as
|
||||
ts.CallExpression)
|
||||
.expression as ts.FunctionExpression)
|
||||
.body.statements[2] as ts.ExpressionStatement);
|
||||
const identifier =
|
||||
|
@ -1941,7 +1958,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const testForHelper = createTestForTsHelper(
|
||||
bundle.program, host, file,
|
||||
|
@ -1968,7 +1985,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const testForHelper = createTestForTsHelper(
|
||||
bundle.program, host, file,
|
||||
|
@ -1995,7 +2012,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const testForHelper = createTestForTsHelper(
|
||||
bundle.program, host, file,
|
||||
|
@ -2022,7 +2039,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const testForHelper = createTestForTsHelper(
|
||||
bundle.program, host, file,
|
||||
|
@ -2059,7 +2076,7 @@ runInEachFileSystem(() => {
|
|||
|
||||
const [testFile, tslibFile] = files;
|
||||
const bundle = makeTestBundleProgram(testFile.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const testForHelper = createTestForTsHelper(
|
||||
bundle.program, host, testFile,
|
||||
|
@ -2096,7 +2113,7 @@ runInEachFileSystem(() => {
|
|||
|
||||
const [testFile, tslibFile] = files;
|
||||
const bundle = makeTestBundleProgram(testFile.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const testForHelper = createTestForTsHelper(
|
||||
bundle.program, host, testFile,
|
||||
|
@ -2114,7 +2131,7 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles(EXPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/b.js'));
|
||||
const exportDeclarations = host.getExportsOfModule(file);
|
||||
expect(exportDeclarations).not.toBe(null);
|
||||
|
@ -2162,7 +2179,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([tslib]);
|
||||
const bundle = makeTestBundleProgram(tslib.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const sf = getSourceFileOrError(bundle.program, tslib.name);
|
||||
const exportDeclarations = host.getExportsOfModule(sf)!;
|
||||
|
||||
|
@ -2180,7 +2197,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the class symbol for an ES2015 class', () => {
|
||||
loadTestFiles([SIMPLE_ES2015_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||
const classSymbol = host.getClassSymbol(node);
|
||||
|
@ -2193,7 +2210,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the class symbol for an ES5 class (outer variable declaration)', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
|
@ -2207,7 +2224,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the class symbol for an ES5 class (inner function declaration)', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
|
@ -2222,7 +2239,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
|
@ -2237,7 +2254,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'NoParensClass', isNamedVariableDeclaration);
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
|
@ -2252,7 +2269,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'InnerParensClass',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -2267,7 +2284,7 @@ runInEachFileSystem(() => {
|
|||
it('should return undefined if node is not an ES5 class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
const classSymbol = host.getClassSymbol(node);
|
||||
|
@ -2282,7 +2299,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([testFile]);
|
||||
const bundle = makeTestBundleProgram(testFile.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node =
|
||||
getDeclaration(bundle.program, testFile.name, 'MyClass', isNamedVariableDeclaration);
|
||||
const classSymbol = host.getClassSymbol(node);
|
||||
|
@ -2295,7 +2312,7 @@ runInEachFileSystem(() => {
|
|||
it('should return true if a given node is a TS class declaration', () => {
|
||||
loadTestFiles([SIMPLE_ES2015_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||
expect(host.isClass(node)).toBe(true);
|
||||
|
@ -2304,7 +2321,7 @@ runInEachFileSystem(() => {
|
|||
it('should return true if a given node is the outer variable declaration of a class', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration);
|
||||
expect(host.isClass(node)).toBe(true);
|
||||
|
@ -2313,7 +2330,7 @@ runInEachFileSystem(() => {
|
|||
it('should return true if a given node is the inner variable declaration of a class', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration);
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
|
@ -2323,7 +2340,7 @@ runInEachFileSystem(() => {
|
|||
it('should return false if a given node is a function declaration', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
expect(host.isClass(node)).toBe(false);
|
||||
|
@ -2339,7 +2356,7 @@ runInEachFileSystem(() => {
|
|||
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||
return host.hasBaseClass(classNode);
|
||||
|
@ -2386,7 +2403,7 @@ runInEachFileSystem(() => {
|
|||
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||
const expression = host.getBaseClassExpression(classNode);
|
||||
|
@ -2458,7 +2475,7 @@ runInEachFileSystem(() => {
|
|||
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||
const expression = host.getBaseClassExpression(classNode)!;
|
||||
|
@ -2470,7 +2487,7 @@ runInEachFileSystem(() => {
|
|||
it('should return an array of all classes in the given source file', () => {
|
||||
loadTestFiles(DECORATED_FILES);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name);
|
||||
const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name);
|
||||
|
||||
|
@ -2488,7 +2505,7 @@ runInEachFileSystem(() => {
|
|||
it('should return decorators of class symbol', () => {
|
||||
loadTestFiles(DECORATED_FILES);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name);
|
||||
const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name);
|
||||
|
||||
|
@ -2515,7 +2532,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const class1 = getDeclaration(
|
||||
bundle.program, _('/ep/src/class1.js'), 'Class1', ts.isVariableDeclaration);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(class1);
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/class1.d.ts'));
|
||||
|
@ -2528,7 +2546,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestDtsBundleProgram(_('/ep/typings/func1.d.ts'), _('/'));
|
||||
const mooFn = getDeclaration(
|
||||
bundle.program, _('/ep/src/func1.js'), 'mooFn', ts.isFunctionDeclaration);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(mooFn);
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/func1.d.ts'));
|
||||
|
@ -2541,7 +2560,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const missingClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/class1.js'), 'MissingClass1', ts.isVariableDeclaration);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
expect(host.getDtsDeclaration(missingClass)).toBe(null);
|
||||
});
|
||||
|
@ -2554,7 +2574,8 @@ runInEachFileSystem(() => {
|
|||
const missingClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/missing-class.js'), 'MissingClass2',
|
||||
ts.isVariableDeclaration);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
expect(host.getDtsDeclaration(missingClass)).toBe(null);
|
||||
});
|
||||
|
@ -2567,7 +2588,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const class1 = getDeclaration(
|
||||
bundle.program, _('/ep/src/flat-file.js'), 'Class1', ts.isVariableDeclaration);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(class1);
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/class1.d.ts'));
|
||||
|
@ -2580,7 +2602,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const sourceClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/flat-file.js'), 'SourceClass', ts.isVariableDeclaration);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(sourceClass);
|
||||
if (dtsDeclaration === null) {
|
||||
|
@ -2602,11 +2625,11 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const internalClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/internal.js'), 'InternalClass', ts.isVariableDeclaration);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(internalClass);
|
||||
expect(dtsDeclaration !.getSourceFile().fileName)
|
||||
.toEqual(_('/ep/typings/internal.d.ts'));
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/internal.d.ts'));
|
||||
});
|
||||
|
||||
it('should match publicly and internal exported classes correctly, even if they have the same name',
|
||||
|
@ -2615,7 +2638,8 @@ runInEachFileSystem(() => {
|
|||
loadTestFiles(TYPINGS_DTS_FILES);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]);
|
||||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const class2 = getDeclaration(
|
||||
bundle.program, _('/ep/src/class2.js'), 'Class2', isNamedVariableDeclaration);
|
||||
|
@ -2635,7 +2659,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the name of the inner class declaration', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const emptyClass = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
|
@ -2659,7 +2683,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the name of the inner class declaration', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const emptyClass = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
|
@ -2684,7 +2708,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(_('/src/index.js'));
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/functions.js'));
|
||||
const fns = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fns.map(fn => [fn.declaration.name!.getText(), fn.ngModule.node.name.text]))
|
||||
|
@ -2701,7 +2725,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(_('/src/index.js'));
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/methods.js'));
|
||||
const fn = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.node.name.text])).toEqual([
|
||||
|
@ -2732,7 +2756,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(_('/src/index.js'));
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/outer_aliased_class.js'));
|
||||
const fn = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.node.name.text])).toEqual([
|
||||
|
@ -2745,7 +2769,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(_('/src/index.js'));
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/inner_aliased_class.js'));
|
||||
const fn = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.node.name.text])).toEqual([
|
||||
|
@ -2758,7 +2782,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the last static property of the class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new Esm5ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classSymbol =
|
||||
host.findClassSymbols(bundle.program.getSourceFile(SOME_DIRECTIVE_FILE.name)!)[0];
|
||||
const endOfClass = host.getEndOfClass(classSymbol);
|
||||
|
|
|
@ -9,12 +9,15 @@
|
|||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, CtorParameter, Import, InlineDeclaration, KnownDeclaration, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, CtorParameter, Import, InlineDeclaration, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration, KnownDeclaration, TypeScriptReflectionHost} from '../../../src/ngtsc/reflection';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
import {DelegatingReflectionHost} from '../../src/host/delegating_host';
|
||||
import {getIifeBody} from '../../src/host/esm5_host';
|
||||
import {UmdReflectionHost, parseStatementForUmdModule} from '../../src/host/umd_host';
|
||||
import {NgccReflectionHost} from '../../src/host/ngcc_host';
|
||||
import {parseStatementForUmdModule, UmdReflectionHost} from '../../src/host/umd_host';
|
||||
import {BundleProgram} from '../../src/packages/bundle_program';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {getRootFiles, makeTestBundleProgram} from '../helpers/utils';
|
||||
|
||||
|
@ -45,6 +48,12 @@ runInEachFileSystem(() => {
|
|||
let TYPINGS_DTS_FILES: TestFile[];
|
||||
let MODULE_WITH_PROVIDERS_PROGRAM: TestFile[];
|
||||
|
||||
// Helpers
|
||||
const createHost = (bundle: BundleProgram, ngccHost: UmdReflectionHost) => {
|
||||
const tsHost = new TypeScriptReflectionHost(bundle.program.getTypeChecker());
|
||||
return new DelegatingReflectionHost(tsHost, ngccHost);
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
_ = absoluteFrom;
|
||||
|
||||
|
@ -1084,7 +1093,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the decorators on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
@ -1103,7 +1112,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the decorators on a class at the top level', () => {
|
||||
loadTestFiles([TOPLEVEL_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1123,7 +1132,7 @@ runInEachFileSystem(() => {
|
|||
it('should return null if the symbol is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const functionNode = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(functionNode);
|
||||
|
@ -1133,7 +1142,7 @@ runInEachFileSystem(() => {
|
|||
it('should return null if there are no decorators', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode);
|
||||
|
@ -1143,7 +1152,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore `decorators` if it is not an array literal', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1154,7 +1163,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore decorator elements that are not object literals', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1167,7 +1176,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore decorator elements that have no `type` property', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1180,7 +1189,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore decorator elements whose `type` value is not an identifier', () => {
|
||||
loadTestFiles([INVALID_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATORS_FILE.name, 'NotIdentifier',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1193,7 +1202,7 @@ runInEachFileSystem(() => {
|
|||
it('should have import information on decorators', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
|
@ -1206,7 +1215,7 @@ runInEachFileSystem(() => {
|
|||
it('should find decorated members on a class at the top level', () => {
|
||||
loadTestFiles([TOPLEVEL_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1227,7 +1236,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if decorator has no `args` property', () => {
|
||||
loadTestFiles([INVALID_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1241,7 +1250,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if decorator\'s `args` has no property assignment', () => {
|
||||
loadTestFiles([INVALID_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1255,7 +1264,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||
loadTestFiles([INVALID_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1272,7 +1281,7 @@ runInEachFileSystem(() => {
|
|||
it('should find decorated members on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -1291,7 +1300,7 @@ runInEachFileSystem(() => {
|
|||
it('should find non decorated properties on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -1306,7 +1315,7 @@ runInEachFileSystem(() => {
|
|||
it('should find static methods on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -1320,7 +1329,7 @@ runInEachFileSystem(() => {
|
|||
it('should find static properties on a class', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -1335,7 +1344,7 @@ runInEachFileSystem(() => {
|
|||
it('should throw if the symbol is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const functionNode = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
expect(() => {
|
||||
|
@ -1346,7 +1355,7 @@ runInEachFileSystem(() => {
|
|||
it('should return an empty array if there are no prop decorators', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
@ -1358,7 +1367,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1370,7 +1379,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore prop decorator elements that are not object literals', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1385,7 +1394,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore prop decorator elements that have no `type` property', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1401,7 +1410,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore prop decorator elements whose `type` value is not an identifier', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1416,7 +1425,7 @@ runInEachFileSystem(() => {
|
|||
it('should have import information on decorators', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
|
@ -1430,7 +1439,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if prop decorator has no `args` property', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1446,7 +1455,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if prop decorator\'s `args` has no property assignment', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1462,7 +1471,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||
loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1480,7 +1489,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the decorated constructor parameters', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const parameters = host.getConstructorParameters(classNode);
|
||||
|
@ -1499,7 +1508,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the decorated constructor parameters at the top level', () => {
|
||||
loadTestFiles([TOPLEVEL_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1519,7 +1528,7 @@ runInEachFileSystem(() => {
|
|||
it('should accept `ctorParameters` as an array', () => {
|
||||
loadTestFiles([CTOR_DECORATORS_ARRAY_FILE]);
|
||||
const bundle = makeTestBundleProgram(CTOR_DECORATORS_ARRAY_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, CTOR_DECORATORS_ARRAY_FILE.name, 'CtorDecoratedAsArray',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1533,10 +1542,12 @@ runInEachFileSystem(() => {
|
|||
it('should throw if the symbol is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const functionNode = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
expect(() => { host.getConstructorParameters(functionNode); })
|
||||
expect(() => {
|
||||
host.getConstructorParameters(functionNode);
|
||||
})
|
||||
.toThrowError(
|
||||
'Attempted to get constructor parameters of a non-class: "function foo() {}"');
|
||||
});
|
||||
|
@ -1547,7 +1558,7 @@ runInEachFileSystem(() => {
|
|||
it('should return an array even if there are no decorators', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1562,7 +1573,7 @@ runInEachFileSystem(() => {
|
|||
it('should return an empty array if there are no constructor parameters', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1577,7 +1588,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore `ctorParameters` if it does not return an array literal', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1594,7 +1605,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore param decorator elements that are not object literals', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1614,7 +1625,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore param decorator elements that have no `type` property', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1628,7 +1639,7 @@ runInEachFileSystem(() => {
|
|||
it('should ignore param decorator elements whose `type` value is not an identifier', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATORS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1642,7 +1653,7 @@ runInEachFileSystem(() => {
|
|||
it('should use `getImportOfIdentifier()` to retrieve import info', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1662,7 +1673,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if param decorator has no `args` property', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1679,7 +1690,8 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host =
|
||||
createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1694,7 +1706,7 @@ runInEachFileSystem(() => {
|
|||
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||
loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]);
|
||||
const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -1713,7 +1725,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([FUNCTION_BODY_FILE]);
|
||||
const bundle = makeTestBundleProgram(FUNCTION_BODY_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const fooNode = getDeclaration(
|
||||
bundle.program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration)!;
|
||||
|
@ -1762,7 +1774,7 @@ runInEachFileSystem(() => {
|
|||
it('should find the import of an identifier', () => {
|
||||
loadTestFiles(IMPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/file_b.js'), 'b', isNamedVariableDeclaration);
|
||||
const identifier =
|
||||
|
@ -1779,7 +1791,7 @@ runInEachFileSystem(() => {
|
|||
it('should return null if the identifier was not imported', () => {
|
||||
loadTestFiles(IMPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/file_b.js'), 'd', isNamedVariableDeclaration);
|
||||
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
||||
|
@ -1790,7 +1802,7 @@ runInEachFileSystem(() => {
|
|||
it('should handle factory functions not wrapped in parentheses', () => {
|
||||
loadTestFiles(IMPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const variableNode =
|
||||
getDeclaration(bundle.program, _('/file_c.js'), 'c', isNamedVariableDeclaration);
|
||||
const identifier =
|
||||
|
@ -1808,7 +1820,7 @@ runInEachFileSystem(() => {
|
|||
describe('getDeclarationOfIdentifier', () => {
|
||||
// Helpers
|
||||
const createTestForTsHelper =
|
||||
(host: UmdReflectionHost, factoryFn: ts.FunctionExpression,
|
||||
(host: NgccReflectionHost, factoryFn: ts.FunctionExpression,
|
||||
getHelperDeclaration: (factoryFn: ts.FunctionExpression, name: string) =>
|
||||
ts.Declaration) =>
|
||||
(varName: string, helperName: string, knownAs: KnownDeclaration,
|
||||
|
@ -1819,7 +1831,8 @@ runInEachFileSystem(() => {
|
|||
|
||||
expect(helperDeclaration).toEqual({
|
||||
known: knownAs,
|
||||
node: getHelperDeclaration(factoryFn, helperName), viaModule,
|
||||
node: getHelperDeclaration(factoryFn, helperName),
|
||||
viaModule,
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -1844,7 +1857,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the declaration of a locally defined identifier', () => {
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const ctrDecorators = host.getConstructorParameters(classNode)!;
|
||||
|
@ -1884,7 +1897,7 @@ runInEachFileSystem(() => {
|
|||
|
||||
loadTestFiles([PROGRAM_FILE]);
|
||||
const bundle = makeTestBundleProgram(PROGRAM_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const expectedDeclaration = getDeclaration(
|
||||
bundle.program, PROGRAM_FILE.name, 'AliasedClass', isNamedVariableDeclaration);
|
||||
|
@ -1902,12 +1915,13 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
const identifierOfDirective = (((classDecorators[0].node as ts.ObjectLiteralExpression)
|
||||
.properties[0] as ts.PropertyAssignment)
|
||||
const identifierOfDirective =
|
||||
(((classDecorators[0].node as ts.ObjectLiteralExpression).properties[0] as
|
||||
ts.PropertyAssignment)
|
||||
.initializer as ts.PropertyAccessExpression)
|
||||
.expression as ts.Identifier;
|
||||
|
||||
|
@ -1940,7 +1954,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const {factoryFn} = parseStatementForUmdModule(
|
||||
getSourceFileOrError(bundle.program, file.name).statements[0])!;
|
||||
|
||||
|
@ -1972,7 +1986,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const {factoryFn} = parseStatementForUmdModule(
|
||||
getSourceFileOrError(bundle.program, file.name).statements[0])!;
|
||||
|
||||
|
@ -2004,7 +2018,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const {factoryFn} = parseStatementForUmdModule(
|
||||
getSourceFileOrError(bundle.program, file.name).statements[0])!;
|
||||
|
||||
|
@ -2036,7 +2050,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const {factoryFn} = parseStatementForUmdModule(
|
||||
getSourceFileOrError(bundle.program, file.name).statements[0])!;
|
||||
|
||||
|
@ -2076,7 +2090,7 @@ runInEachFileSystem(() => {
|
|||
|
||||
const [testFile, tslibFile] = files;
|
||||
const bundle = makeTestBundleProgram(testFile.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const {factoryFn} = parseStatementForUmdModule(
|
||||
getSourceFileOrError(bundle.program, testFile.name).statements[0])!;
|
||||
const tslibSourceFile = getSourceFileOrError(bundle.program, tslibFile.name);
|
||||
|
@ -2094,7 +2108,7 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles(EXPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/b_module.js'));
|
||||
const exportDeclarations = host.getExportsOfModule(file);
|
||||
expect(exportDeclarations).not.toBe(null);
|
||||
|
@ -2122,7 +2136,7 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles(EXPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/wildcard_reexports.js'));
|
||||
const exportDeclarations = host.getExportsOfModule(file);
|
||||
expect(exportDeclarations).not.toBe(null);
|
||||
|
@ -2150,7 +2164,7 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles(EXPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const file =
|
||||
getSourceFileOrError(bundle.program, _('/wildcard_reexports_imported_helpers.js'));
|
||||
const exportDeclarations = host.getExportsOfModule(file);
|
||||
|
@ -2179,7 +2193,7 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles([INLINE_EXPORT_FILE]);
|
||||
const bundle = makeTestBundleProgram(INLINE_EXPORT_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, INLINE_EXPORT_FILE.name);
|
||||
const exportDeclarations = host.getExportsOfModule(file);
|
||||
expect(exportDeclarations).not.toBe(null);
|
||||
|
@ -2201,7 +2215,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([tslib]);
|
||||
const bundle = makeTestBundleProgram(tslib.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const sf = getSourceFileOrError(bundle.program, tslib.name);
|
||||
const exportDeclarations = host.getExportsOfModule(sf)!;
|
||||
|
||||
|
@ -2219,7 +2233,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the class symbol for an ES2015 class', () => {
|
||||
loadTestFiles([SIMPLE_ES2015_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||
const classSymbol = host.getClassSymbol(node);
|
||||
|
@ -2233,7 +2247,7 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles(EXPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/wildcard_reexports.js'));
|
||||
const exportDeclarations = host.getExportsOfModule(file);
|
||||
expect(exportDeclarations).not.toBe(null);
|
||||
|
@ -2261,7 +2275,7 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles(EXPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const file =
|
||||
getSourceFileOrError(bundle.program, _('/wildcard_reexports_imported_helpers.js'));
|
||||
const exportDeclarations = host.getExportsOfModule(file);
|
||||
|
@ -2290,7 +2304,7 @@ runInEachFileSystem(() => {
|
|||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles(EXPORTS_FILES);
|
||||
const bundle = makeTestBundleProgram(_('/index.js'));
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/wildcard_reexports_with_require.js'));
|
||||
const exportDeclarations = host.getExportsOfModule(file);
|
||||
expect(exportDeclarations).not.toBe(null);
|
||||
|
@ -2317,7 +2331,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the class symbol for an ES5 class (outer variable declaration)', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
|
@ -2331,7 +2345,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the class symbol for an ES5 class (inner function declaration)', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
|
@ -2346,7 +2360,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
|
@ -2361,7 +2375,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'NoParensClass', isNamedVariableDeclaration);
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
|
@ -2376,7 +2390,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'InnerParensClass',
|
||||
isNamedVariableDeclaration);
|
||||
|
@ -2391,7 +2405,7 @@ runInEachFileSystem(() => {
|
|||
it('should return undefined if node is not an ES5 class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
const classSymbol = host.getClassSymbol(node);
|
||||
|
@ -2406,7 +2420,7 @@ runInEachFileSystem(() => {
|
|||
};
|
||||
loadTestFiles([testFile]);
|
||||
const bundle = makeTestBundleProgram(testFile.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const node =
|
||||
getDeclaration(bundle.program, testFile.name, 'MyClass', isNamedVariableDeclaration);
|
||||
const classSymbol = host.getClassSymbol(node);
|
||||
|
@ -2419,7 +2433,7 @@ runInEachFileSystem(() => {
|
|||
it('should return true if a given node is a TS class declaration', () => {
|
||||
loadTestFiles([SIMPLE_ES2015_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||
expect(host.isClass(node)).toBe(true);
|
||||
|
@ -2428,7 +2442,7 @@ runInEachFileSystem(() => {
|
|||
it('should return true if a given node is the outer variable declaration of a class', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration);
|
||||
expect(host.isClass(node)).toBe(true);
|
||||
|
@ -2437,7 +2451,7 @@ runInEachFileSystem(() => {
|
|||
it('should return true if a given node is the inner variable declaration of a class', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const outerNode = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration);
|
||||
const innerNode = getIifeBody(outerNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
|
@ -2447,7 +2461,7 @@ runInEachFileSystem(() => {
|
|||
it('should return false if a given node is a function declaration', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const node = getDeclaration(
|
||||
bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||
expect(host.isClass(node)).toBe(false);
|
||||
|
@ -2463,7 +2477,7 @@ runInEachFileSystem(() => {
|
|||
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||
return host.hasBaseClass(classNode);
|
||||
|
@ -2510,7 +2524,7 @@ runInEachFileSystem(() => {
|
|||
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||
const expression = host.getBaseClassExpression(classNode);
|
||||
|
@ -2582,7 +2596,7 @@ runInEachFileSystem(() => {
|
|||
|
||||
loadTestFiles([file]);
|
||||
const bundle = makeTestBundleProgram(file.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||
const expression = host.getBaseClassExpression(classNode)!;
|
||||
|
@ -2594,7 +2608,7 @@ runInEachFileSystem(() => {
|
|||
it('should return an array of all classes in the given source file', () => {
|
||||
loadTestFiles(DECORATED_FILES);
|
||||
const bundle = makeTestBundleProgram(DECORATED_FILES[0].name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name);
|
||||
const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name);
|
||||
|
||||
|
@ -2612,7 +2626,7 @@ runInEachFileSystem(() => {
|
|||
it('should return decorators of class symbol', () => {
|
||||
loadTestFiles(DECORATED_FILES);
|
||||
const bundle = makeTestBundleProgram(DECORATED_FILES[0].name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name);
|
||||
const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name);
|
||||
|
||||
|
@ -2639,7 +2653,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const class1 = getDeclaration(
|
||||
bundle.program, _('/ep/src/class1.js'), 'Class1', ts.isVariableDeclaration);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(class1);
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/class1.d.ts'));
|
||||
|
@ -2652,7 +2667,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(_('/ep/typings/func1.d.ts'));
|
||||
const mooFn = getDeclaration(
|
||||
bundle.program, _('/ep/src/func1.js'), 'mooFn', ts.isFunctionDeclaration);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(mooFn);
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/func1.d.ts'));
|
||||
|
@ -2665,7 +2681,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const missingClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/class1.js'), 'MissingClass1', ts.isVariableDeclaration);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
expect(host.getDtsDeclaration(missingClass)).toBe(null);
|
||||
});
|
||||
|
||||
|
@ -2677,7 +2694,8 @@ runInEachFileSystem(() => {
|
|||
const missingClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/missing-class.js'), 'MissingClass2',
|
||||
ts.isVariableDeclaration);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
expect(host.getDtsDeclaration(missingClass)).toBe(null);
|
||||
});
|
||||
|
@ -2690,7 +2708,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const class1 = getDeclaration(
|
||||
bundle.program, _('/ep/src/flat-file.js'), 'Class1', ts.isVariableDeclaration);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(class1);
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/class1.d.ts'));
|
||||
|
@ -2704,7 +2723,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const class1 = getDeclaration(
|
||||
bundle.program, _('/ep/src/flat-file.js'), 'Class1', ts.isVariableDeclaration);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(class1);
|
||||
expect(dtsDeclaration!.getSourceFile().fileName).toEqual(_('/ep/typings/class1.d.ts'));
|
||||
|
@ -2717,7 +2737,8 @@ runInEachFileSystem(() => {
|
|||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const sourceClass = getDeclaration(
|
||||
bundle.program, _('/ep/src/flat-file.js'), 'SourceClass', ts.isVariableDeclaration);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const dtsDeclaration = host.getDtsDeclaration(sourceClass);
|
||||
if (dtsDeclaration === null) {
|
||||
|
@ -2737,7 +2758,8 @@ runInEachFileSystem(() => {
|
|||
loadTestFiles(TYPINGS_DTS_FILES);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]);
|
||||
const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const class2 = getDeclaration(
|
||||
bundle.program, _('/ep/src/class2.js'), 'Class2', isNamedVariableDeclaration);
|
||||
|
@ -2762,7 +2784,8 @@ runInEachFileSystem(() => {
|
|||
bundle.program, _('/ep/src/class2.js'), 'Class2', ts.isVariableDeclaration);
|
||||
const internalClass2 = getDeclaration(
|
||||
bundle.program, _('/ep/src/internal.js'), 'Class2', ts.isVariableDeclaration);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts);
|
||||
const host =
|
||||
createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle, dts));
|
||||
|
||||
const class2DtsDeclaration = host.getDtsDeclaration(class2);
|
||||
expect(class2DtsDeclaration!.getSourceFile().fileName)
|
||||
|
@ -2778,7 +2801,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the name of the inner class declaration', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const emptyClass = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
|
@ -2802,7 +2825,7 @@ runInEachFileSystem(() => {
|
|||
it('should return the name of the inner class declaration', () => {
|
||||
loadTestFiles([SIMPLE_CLASS_FILE]);
|
||||
const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
|
||||
const emptyClass = getDeclaration(
|
||||
bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||
|
@ -2827,7 +2850,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/functions.js'));
|
||||
const fns = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fns.map(fn => [fn.declaration.name!.getText(), fn.ngModule.node.name.text]))
|
||||
|
@ -2843,7 +2866,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/methods.js'));
|
||||
const fn = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.node.name.text])).toEqual([
|
||||
|
@ -2870,7 +2893,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/outer_aliased_class.js'));
|
||||
const fn = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.node.name.text])).toEqual([
|
||||
|
@ -2883,7 +2906,7 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM);
|
||||
const bundle = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]);
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const host = createHost(bundle, new UmdReflectionHost(new MockLogger(), false, bundle));
|
||||
const file = getSourceFileOrError(bundle.program, _('/src/inner_aliased_class.js'));
|
||||
const fn = host.getModuleWithProvidersFunctions(file);
|
||||
expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.node.name.text])).toEqual([
|
||||
|
|
Loading…
Reference in New Issue