diff --git a/packages/compiler-cli/ngcc/src/host/commonjs_host.ts b/packages/compiler-cli/ngcc/src/host/commonjs_host.ts index 6e8cf61888..9af21021ac 100644 --- a/packages/compiler-cli/ngcc/src/host/commonjs_host.ts +++ b/packages/compiler-cli/ngcc/src/host/commonjs_host.ts @@ -19,10 +19,12 @@ import {NgccClassSymbol} from './ngcc_host'; export class CommonJsReflectionHost extends Esm5ReflectionHost { protected commonJsExports = new Map|null>(); protected topLevelHelperCalls = new Map>(); - constructor( - logger: Logger, isCore: boolean, protected program: ts.Program, - protected compilerHost: ts.CompilerHost, dts?: BundleProgram|null) { - super(logger, isCore, program.getTypeChecker(), dts); + protected program: ts.Program; + protected compilerHost: ts.CompilerHost; + constructor(logger: Logger, isCore: boolean, src: BundleProgram, dts?: BundleProgram|null) { + super(logger, isCore, src, dts); + this.program = src.program; + this.compilerHost = src.host; } getImportOfIdentifier(id: ts.Identifier): Import|null { diff --git a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts index ef6dd09114..2bda8e8e8e 100644 --- a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts +++ b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts @@ -83,9 +83,9 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N protected decoratorCache = new Map(); constructor( - protected logger: Logger, protected isCore: boolean, checker: ts.TypeChecker, + protected logger: Logger, protected isCore: boolean, src: BundleProgram, dts?: BundleProgram|null) { - super(checker); + super(src.program.getTypeChecker()); this.dtsDeclarationMap = dts && this.computeDtsDeclarationMap(dts.path, dts.program, dts.package) || null; } diff --git a/packages/compiler-cli/ngcc/src/host/umd_host.ts b/packages/compiler-cli/ngcc/src/host/umd_host.ts index 7d49bafcc5..f91dfe1d97 100644 --- a/packages/compiler-cli/ngcc/src/host/umd_host.ts +++ b/packages/compiler-cli/ngcc/src/host/umd_host.ts @@ -18,10 +18,12 @@ export class UmdReflectionHost extends Esm5ReflectionHost { protected umdModules = new Map(); protected umdExports = new Map|null>(); protected umdImportPaths = new Map(); - constructor( - logger: Logger, isCore: boolean, protected program: ts.Program, - protected compilerHost: ts.CompilerHost, dts?: BundleProgram|null) { - super(logger, isCore, program.getTypeChecker(), dts); + protected program: ts.Program; + protected compilerHost: ts.CompilerHost; + constructor(logger: Logger, isCore: boolean, src: BundleProgram, dts?: BundleProgram|null) { + super(logger, isCore, src, dts); + this.program = src.program; + this.compilerHost = src.host; } getImportOfIdentifier(id: ts.Identifier): Import|null { diff --git a/packages/compiler-cli/ngcc/src/packages/transformer.ts b/packages/compiler-cli/ngcc/src/packages/transformer.ts index c80738b642..65c3f0a223 100644 --- a/packages/compiler-cli/ngcc/src/packages/transformer.ts +++ b/packages/compiler-cli/ngcc/src/packages/transformer.ts @@ -100,18 +100,15 @@ export class Transformer { } getHost(bundle: EntryPointBundle): NgccReflectionHost { - const typeChecker = bundle.src.program.getTypeChecker(); switch (bundle.format) { case 'esm2015': - return new Esm2015ReflectionHost(this.logger, bundle.isCore, typeChecker, bundle.dts); + return new Esm2015ReflectionHost(this.logger, bundle.isCore, bundle.src, bundle.dts); case 'esm5': - return new Esm5ReflectionHost(this.logger, bundle.isCore, typeChecker, bundle.dts); + return new Esm5ReflectionHost(this.logger, bundle.isCore, bundle.src, bundle.dts); case 'umd': - return new UmdReflectionHost( - this.logger, bundle.isCore, bundle.src.program, bundle.src.host, bundle.dts); + return new UmdReflectionHost(this.logger, bundle.isCore, bundle.src, bundle.dts); case 'commonjs': - return new CommonJsReflectionHost( - this.logger, bundle.isCore, bundle.src.program, bundle.src.host, bundle.dts); + return new CommonJsReflectionHost(this.logger, bundle.isCore, bundle.src, bundle.dts); default: throw new Error(`Reflection host for "${bundle.format}" not yet implemented.`); } diff --git a/packages/compiler-cli/ngcc/test/analysis/decoration_analyzer_spec.ts b/packages/compiler-cli/ngcc/test/analysis/decoration_analyzer_spec.ts index 572f26e10c..0ecba3079d 100644 --- a/packages/compiler-cli/ngcc/test/analysis/decoration_analyzer_spec.ts +++ b/packages/compiler-cli/ngcc/test/analysis/decoration_analyzer_spec.ts @@ -110,8 +110,7 @@ runInEachFileSystem(() => { const bundle = makeTestEntryPointBundle('test-package', 'esm2015', false, rootFiles); program = bundle.src.program; - const reflectionHost = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const reflectionHost = new Esm2015ReflectionHost(new MockLogger(), false, bundle.src); const referencesRegistry = new NgccReferencesRegistry(reflectionHost); diagnosticLogs = []; const analyzer = new DecorationAnalyzer( diff --git a/packages/compiler-cli/ngcc/test/analysis/module_with_providers_analyzer_spec.ts b/packages/compiler-cli/ngcc/test/analysis/module_with_providers_analyzer_spec.ts index 1e2cbc53fb..87e07e9bc8 100644 --- a/packages/compiler-cli/ngcc/test/analysis/module_with_providers_analyzer_spec.ts +++ b/packages/compiler-cli/ngcc/test/analysis/module_with_providers_analyzer_spec.ts @@ -334,8 +334,7 @@ runInEachFileSystem(() => { getRootFiles(TEST_DTS_PROGRAM)); program = bundle.src.program; dtsProgram = bundle.dts !; - const host = new Esm2015ReflectionHost( - new MockLogger(), false, program.getTypeChecker(), dtsProgram); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle.src, dtsProgram); referencesRegistry = new NgccReferencesRegistry(host); const processDts = true; @@ -538,8 +537,7 @@ runInEachFileSystem(() => { getRootFiles(TEST_DTS_PROGRAM)); const program = bundle.src.program; const dtsProgram = bundle.dts !; - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dtsProgram); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle.src, dtsProgram); const referencesRegistry = new NgccReferencesRegistry(host); const processDts = true; @@ -569,8 +567,7 @@ runInEachFileSystem(() => { const bundle = makeTestEntryPointBundle('test-package', 'esm2015', false, getRootFiles(TEST_PROGRAM)); const program = bundle.src.program; - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), null); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle.src, null); const referencesRegistry = new NgccReferencesRegistry(host); const processDts = false; // Emulate the scenario where typings have already been processed diff --git a/packages/compiler-cli/ngcc/test/analysis/private_declarations_analyzer_spec.ts b/packages/compiler-cli/ngcc/test/analysis/private_declarations_analyzer_spec.ts index b6419c41f4..5e2bfbeba8 100644 --- a/packages/compiler-cli/ngcc/test/analysis/private_declarations_analyzer_spec.ts +++ b/packages/compiler-cli/ngcc/test/analysis/private_declarations_analyzer_spec.ts @@ -235,12 +235,12 @@ runInEachFileSystem(() => { function setup(jsProgram: TestFile[], dtsProgram: TestFile[]) { loadTestFiles(jsProgram); loadTestFiles(dtsProgram); - const {src: {program}, dts} = makeTestEntryPointBundle( + const {src, dts} = makeTestEntryPointBundle( 'test-package', 'esm2015', false, getRootFiles(jsProgram), getRootFiles(dtsProgram)); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + const host = new Esm2015ReflectionHost(new MockLogger(), false, src, dts); const referencesRegistry = new NgccReferencesRegistry(host); const analyzer = new PrivateDeclarationsAnalyzer(host, referencesRegistry); - return {program, referencesRegistry, analyzer}; + return {program: src.program, referencesRegistry, analyzer}; } /** diff --git a/packages/compiler-cli/ngcc/test/analysis/switch_marker_analyzer_spec.ts b/packages/compiler-cli/ngcc/test/analysis/switch_marker_analyzer_spec.ts index f5d24b6255..b67ab259b8 100644 --- a/packages/compiler-cli/ngcc/test/analysis/switch_marker_analyzer_spec.ts +++ b/packages/compiler-cli/ngcc/test/analysis/switch_marker_analyzer_spec.ts @@ -74,7 +74,7 @@ runInEachFileSystem(() => { const bundle = makeTestEntryPointBundle( 'test', 'esm2015', false, [_('/node_modules/test/entrypoint.js')]); const program = bundle.src.program; - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle.src); const analyzer = new SwitchMarkerAnalyzer(host, bundle.entryPoint.package); const analysis = analyzer.analyzeProgram(program); @@ -105,7 +105,7 @@ runInEachFileSystem(() => { const bundle = makeTestEntryPointBundle( 'test', 'esm2015', false, [_('/node_modules/test/entrypoint.js')]); const program = bundle.src.program; - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle.src); const analyzer = new SwitchMarkerAnalyzer(host, bundle.entryPoint.package); const analysis = analyzer.analyzeProgram(program); diff --git a/packages/compiler-cli/ngcc/test/host/commonjs_host_import_helper_spec.ts b/packages/compiler-cli/ngcc/test/host/commonjs_host_import_helper_spec.ts index 29963c56ed..0d9554a810 100644 --- a/packages/compiler-cli/ngcc/test/host/commonjs_host_import_helper_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/commonjs_host_import_helper_spec.ts @@ -85,10 +85,11 @@ exports.AliasedDirective$1 = AliasedDirective$1; it('should find the decorators on a class at the top level', () => { loadFakeCore(getFileSystem()); loadTestFiles([TOPLEVEL_DECORATORS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toEqual(1); @@ -105,10 +106,10 @@ exports.AliasedDirective$1 = AliasedDirective$1; it('should find the decorators on an aliased class at the top level', () => { loadFakeCore(getFileSystem()); loadTestFiles([TOPLEVEL_DECORATORS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, TOPLEVEL_DECORATORS_FILE.name, 'AliasedDirective$1', + bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'AliasedDirective$1', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; diff --git a/packages/compiler-cli/ngcc/test/host/commonjs_host_spec.ts b/packages/compiler-cli/ngcc/test/host/commonjs_host_spec.ts index c83b3ae5bd..ad1c536d73 100644 --- a/packages/compiler-cli/ngcc/test/host/commonjs_host_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/commonjs_host_spec.ts @@ -887,10 +887,11 @@ exports.ExternalModule = ExternalModule; describe('getDecoratorsOfDeclaration()', () => { it('should find the decorators on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -906,11 +907,11 @@ exports.ExternalModule = ExternalModule; it('should find the decorators on a class at the top level', () => { loadTestFiles([TOPLEVEL_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -926,40 +927,41 @@ exports.ExternalModule = ExternalModule; it('should return null if the symbol is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); + const functionNode = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); const decorators = host.getDecoratorsOfDeclaration(functionNode); expect(decorators).toBe(null); }); it('should return null if there are no decorators', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); expect(decorators).toBe(null); }); it('should ignore `decorators` if it is not an array literal', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); expect(decorators).toEqual([]); }); it('should ignore decorator elements that are not object literals', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', + bundle.program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -969,10 +971,11 @@ exports.ExternalModule = ExternalModule; it('should ignore decorator elements that have no `type` property', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -981,10 +984,11 @@ exports.ExternalModule = ExternalModule; it('should ignore decorator elements whose `type` value is not an identifier', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -994,11 +998,10 @@ exports.ExternalModule = ExternalModule; describe('(returned decorators `args`)', () => { it('should be an empty array if decorator has no `args` property', () => { loadTestFiles([INVALID_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', + bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -1009,11 +1012,10 @@ exports.ExternalModule = ExternalModule; it('should be an empty array if decorator\'s `args` has no property assignment', () => { loadTestFiles([INVALID_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', + bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -1024,11 +1026,10 @@ exports.ExternalModule = ExternalModule; it('should be an empty array if `args` property value is not an array literal', () => { loadTestFiles([INVALID_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -1042,10 +1043,11 @@ exports.ExternalModule = ExternalModule; describe('getMembersOfClass()', () => { it('should find decorated members on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -1061,11 +1063,11 @@ exports.ExternalModule = ExternalModule; it('should find decorated members on a class at the top level', () => { loadTestFiles([TOPLEVEL_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -1081,10 +1083,11 @@ exports.ExternalModule = ExternalModule; it('should find non decorated properties on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const instanceProperty = members.find(member => member.name === 'instanceProperty') !; @@ -1096,10 +1099,11 @@ exports.ExternalModule = ExternalModule; it('should find static methods on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticMethod = members.find(member => member.name === 'staticMethod') !; @@ -1110,10 +1114,11 @@ exports.ExternalModule = ExternalModule; it('should find static properties on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticProperty = members.find(member => member.name === 'staticProperty') !; @@ -1125,10 +1130,10 @@ exports.ExternalModule = ExternalModule; it('should throw if the symbol is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); + const functionNode = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getMembersOfClass(functionNode); }).toThrowError(`Attempted to get members of a non-class: "function foo() {}"`); @@ -1136,10 +1141,10 @@ exports.ExternalModule = ExternalModule; it('should return an empty array if there are no prop decorators', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); expect(members).toEqual([]); @@ -1148,12 +1153,10 @@ exports.ExternalModule = ExternalModule; it('should not process decorated properties in `propDecorators` if it is not an object literal', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral', + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -1162,11 +1165,10 @@ exports.ExternalModule = ExternalModule; it('should ignore prop decorator elements that are not object literals', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp', + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1178,11 +1180,10 @@ exports.ExternalModule = ExternalModule; it('should ignore prop decorator elements that have no `type` property', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1194,11 +1195,10 @@ exports.ExternalModule = ExternalModule; it('should ignore prop decorator elements whose `type` value is not an identifier', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1210,11 +1210,12 @@ exports.ExternalModule = ExternalModule; it('should have import information on decorators', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toEqual(1); @@ -1224,11 +1225,10 @@ exports.ExternalModule = ExternalModule; describe('(returned prop decorators `args`)', () => { it('should be an empty array if prop decorator has no `args` property', () => { loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', + bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1242,12 +1242,10 @@ exports.ExternalModule = ExternalModule; it('should be an empty array if prop decorator\'s `args` has no property assignment', () => { loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', + bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1260,11 +1258,10 @@ 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 {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1280,10 +1277,11 @@ exports.ExternalModule = ExternalModule; describe('getConstructorParameters', () => { it('should find the decorated constructor parameters', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBeDefined(); @@ -1299,11 +1297,11 @@ exports.ExternalModule = ExternalModule; it('should find the decorated constructor parameters at the top level', () => { loadTestFiles([TOPLEVEL_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBeDefined(); @@ -1319,11 +1317,10 @@ exports.ExternalModule = ExternalModule; it('should accept `ctorParameters` as an array', () => { loadTestFiles([CTOR_DECORATORS_ARRAY_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(CTOR_DECORATORS_ARRAY_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(CTOR_DECORATORS_ARRAY_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, CTOR_DECORATORS_ARRAY_FILE.name, 'CtorDecoratedAsArray', + bundle.program, CTOR_DECORATORS_ARRAY_FILE.name, 'CtorDecoratedAsArray', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode) !; @@ -1334,10 +1331,10 @@ exports.ExternalModule = ExternalModule; it('should throw if the symbol is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); + const functionNode = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getConstructorParameters(functionNode); }) .toThrowError( 'Attempted to get constructor parameters of a non-class: "function foo() {}"'); @@ -1348,10 +1345,10 @@ exports.ExternalModule = ExternalModule; it('should return an array even if there are no decorators', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', + bundle.program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1363,11 +1360,10 @@ exports.ExternalModule = ExternalModule; it('should return an empty array if there are no constructor parameters', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1379,11 +1375,10 @@ exports.ExternalModule = ExternalModule; it('should ignore `ctorParameters` if it does not return an array literal', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1397,11 +1392,10 @@ exports.ExternalModule = ExternalModule; describe('(returned parameters `decorators`)', () => { it('should ignore param decorator elements that are not object literals', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1418,11 +1412,10 @@ exports.ExternalModule = ExternalModule; it('should ignore param decorator elements that have no `type` property', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1434,12 +1427,10 @@ exports.ExternalModule = ExternalModule; it('should ignore param decorator elements whose `type` value is not an identifier', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1450,10 +1441,11 @@ exports.ExternalModule = ExternalModule; it('should have import information on decorators', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![2].decorators !; @@ -1467,11 +1459,10 @@ exports.ExternalModule = ExternalModule; describe('(returned parameters `decorators.args`)', () => { it('should be an empty array if param decorator has no `args` property', () => { loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', + bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters !.length).toBe(1); @@ -1485,12 +1476,10 @@ exports.ExternalModule = ExternalModule; it('should be an empty array if param decorator\'s `args` has no property assignment', () => { loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', + bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1502,11 +1491,10 @@ 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 {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1522,12 +1510,11 @@ exports.ExternalModule = ExternalModule; it('should return an object describing the function declaration passed as an argument', () => { loadTestFiles([FUNCTION_BODY_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(FUNCTION_BODY_FILE.name); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(FUNCTION_BODY_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const fooNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !; const fooDef = host.getDefinitionOfFunction(fooNode) !; expect(fooDef.node).toBe(fooNode); expect(fooDef.body !.length).toEqual(1); @@ -1537,7 +1524,7 @@ exports.ExternalModule = ExternalModule; expect(fooDef.parameters[0].initializer).toBe(null); const barNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'bar', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'bar', isNamedFunctionDeclaration) !; const barDef = host.getDefinitionOfFunction(barNode) !; expect(barDef.node).toBe(barNode); expect(barDef.body !.length).toEqual(1); @@ -1550,7 +1537,7 @@ exports.ExternalModule = ExternalModule; expect(barDef.parameters[1].initializer !.getText()).toEqual('42'); const bazNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'baz', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'baz', isNamedFunctionDeclaration) !; const bazDef = host.getDefinitionOfFunction(bazNode) !; expect(bazDef.node).toBe(bazNode); expect(bazDef.body !.length).toEqual(3); @@ -1559,7 +1546,7 @@ exports.ExternalModule = ExternalModule; expect(bazDef.parameters[0].initializer).toBe(null); const quxNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'qux', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'qux', isNamedFunctionDeclaration) !; const quxDef = host.getDefinitionOfFunction(quxNode) !; expect(quxDef.node).toBe(quxNode); expect(quxDef.body !.length).toEqual(2); @@ -1572,10 +1559,10 @@ exports.ExternalModule = ExternalModule; describe('getImportOfIdentifier', () => { it('should find the import of an identifier', () => { loadTestFiles(IMPORTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/index.js')); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const variableNode = - getDeclaration(program, _('/file_b.js'), 'b', isNamedVariableDeclaration); + getDeclaration(bundle.program, _('/file_b.js'), 'b', isNamedVariableDeclaration); const identifier = (variableNode.initializer && ts.isPropertyAccessExpression(variableNode.initializer)) ? variableNode.initializer.name : @@ -1599,10 +1586,10 @@ exports.ExternalModule = ExternalModule; contents: `export declare class MyClass {}`, } ]); - const {program, host: compilerHost} = makeTestBundleProgram(_('/index.d.ts')); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(_('/index.d.ts')); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const variableNode = - getDeclaration(program, _('/index.d.ts'), 'a', isNamedVariableDeclaration); + getDeclaration(bundle.program, _('/index.d.ts'), 'a', isNamedVariableDeclaration); const identifier = ((variableNode.type as ts.TypeReferenceNode).typeName as ts.Identifier); @@ -1612,10 +1599,10 @@ exports.ExternalModule = ExternalModule; it('should return null if the identifier was not imported', () => { loadTestFiles(IMPORTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/index.js')); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const variableNode = - getDeclaration(program, _('/file_b.js'), 'd', isNamedVariableDeclaration); + getDeclaration(bundle.program, _('/file_b.js'), 'd', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); @@ -1624,10 +1611,10 @@ exports.ExternalModule = ExternalModule; it('should handle factory functions not wrapped in parentheses', () => { loadTestFiles(IMPORTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/index.js')); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const variableNode = - getDeclaration(program, _('/file_c.js'), 'c', isNamedVariableDeclaration); + getDeclaration(bundle.program, _('/file_c.js'), 'c', isNamedVariableDeclaration); const identifier = (variableNode.initializer && ts.isPropertyAccessExpression(variableNode.initializer)) ? variableNode.initializer.name : @@ -1642,10 +1629,11 @@ exports.ExternalModule = ExternalModule; describe('getDeclarationOfIdentifier', () => { it('should return the declaration of a locally defined identifier', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const ctrDecorators = host.getConstructorParameters(classNode) !; const identifierOfViewContainerRef = (ctrDecorators[0].typeValueReference !as{ local: true, @@ -1654,7 +1642,8 @@ exports.ExternalModule = ExternalModule; }).expression; const expectedDeclarationNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'ViewContainerRef', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'ViewContainerRef', + isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfViewContainerRef); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -1664,10 +1653,11 @@ exports.ExternalModule = ExternalModule; it('should return the source-file of an import namespace', () => { loadFakeCore(getFileSystem()); loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + 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) @@ -1675,7 +1665,7 @@ exports.ExternalModule = ExternalModule; .expression as ts.Identifier; const expectedDeclarationNode = - getSourceFileOrError(program, _('/node_modules/@angular/core/index.d.ts')); + getSourceFileOrError(bundle.program, _('/node_modules/@angular/core/index.d.ts')); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -1699,10 +1689,10 @@ exports.ExternalModule = ExternalModule; } ]); - const {program, host: compilerHost} = makeTestBundleProgram(_('/index.js')); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const variableNode = - getDeclaration(program, _('/index.js'), 'b', isNamedVariableDeclaration); + getDeclaration(bundle.program, _('/index.js'), 'b', isNamedVariableDeclaration); const identifier = variableNode.name as ts.Identifier; const importOfIdent = host.getDeclarationOfIdentifier(identifier !) !; @@ -1725,10 +1715,10 @@ exports.ExternalModule = ExternalModule; }, ]); - const {program, host: compilerHost} = makeTestBundleProgram(_('/index.js')); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const variableNode = - getDeclaration(program, _('/index.js'), 'b', isNamedVariableDeclaration); + getDeclaration(bundle.program, _('/index.js'), 'b', isNamedVariableDeclaration); const identifier = (variableNode.initializer !as ts.PropertyAccessExpression).name; const importOfIdent = host.getDeclarationOfIdentifier(identifier !) !; @@ -1740,9 +1730,9 @@ exports.ExternalModule = ExternalModule; it('should return a map of all the exports from a given module', () => { loadFakeCore(getFileSystem()); loadTestFiles(EXPORTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/index.js')); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const file = getSourceFileOrError(program, _('/b_module.js')); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); + const file = getSourceFileOrError(bundle.program, _('/b_module.js')); const exportDeclarations = host.getExportsOfModule(file); expect(exportDeclarations).not.toBe(null); expect(Array.from(exportDeclarations !.entries()) @@ -1766,9 +1756,9 @@ exports.ExternalModule = ExternalModule; it('should handle wildcard re-exports of other modules', () => { loadFakeCore(getFileSystem()); loadTestFiles(EXPORTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/index.js')); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const file = getSourceFileOrError(program, _('/wildcard_reexports.js')); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); + const file = getSourceFileOrError(bundle.program, _('/wildcard_reexports.js')); const exportDeclarations = host.getExportsOfModule(file); expect(exportDeclarations).not.toBe(null); expect(Array.from(exportDeclarations !.entries()) @@ -1793,9 +1783,9 @@ exports.ExternalModule = ExternalModule; it('should handle inline exports', () => { loadTestFiles([INLINE_EXPORT_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(_('/inline_export.js')); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const file = getSourceFileOrError(program, _('/inline_export.js')); + const bundle = makeTestBundleProgram(_('/inline_export.js')); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); + const file = getSourceFileOrError(bundle.program, _('/inline_export.js')); const exportDeclarations = host.getExportsOfModule(file); expect(exportDeclarations).not.toBeNull(); const decl = exportDeclarations !.get('directives') as InlineDeclaration; @@ -1808,11 +1798,10 @@ exports.ExternalModule = ExternalModule; describe('getClassSymbol()', () => { it('should return the class symbol for an ES2015 class', () => { loadTestFiles([SIMPLE_ES2015_CLASS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const node = getDeclaration( - program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); + bundle.program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const classSymbol = host.getClassSymbol(node); expect(classSymbol).toBeDefined(); @@ -1822,10 +1811,10 @@ exports.ExternalModule = ExternalModule; it('should return the class symbol for an ES5 class (outer variable declaration)', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const classSymbol = host.getClassSymbol(outerNode); @@ -1836,10 +1825,10 @@ exports.ExternalModule = ExternalModule; it('should return the class symbol for an ES5 class (inner function declaration)', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const classSymbol = host.getClassSymbol(innerNode); @@ -1851,11 +1840,10 @@ exports.ExternalModule = ExternalModule; it('should return the same class symbol (of the outer declaration) for outer and inner declarations', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; @@ -1868,11 +1856,11 @@ exports.ExternalModule = ExternalModule; it('should return the class symbol for an ES5 class whose IIFE is not wrapped in parens', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'NoParensClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'NoParensClass', + isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const classSymbol = host.getClassSymbol(outerNode); @@ -1885,11 +1873,11 @@ exports.ExternalModule = ExternalModule; it('should return the class symbol for an ES5 class whose IIFE is not wrapped with inner parens', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'InnerParensClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'InnerParensClass', + isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const classSymbol = host.getClassSymbol(outerNode); @@ -1901,10 +1889,10 @@ exports.ExternalModule = ExternalModule; it('should return undefined if node is not an ES5 class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const node = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); const classSymbol = host.getClassSymbol(node); expect(classSymbol).toBeUndefined(); @@ -1917,11 +1905,10 @@ exports.ExternalModule = ExternalModule; contents: `var MyClass = null;`, }; loadTestFiles([testFile]); - const {program, host: compilerHost} = makeTestBundleProgram(testFile.name); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const node = - getDeclaration(program, testFile.name, 'MyClass', isNamedVariableDeclaration); + const bundle = makeTestBundleProgram(testFile.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, testFile.name, 'MyClass', isNamedVariableDeclaration); const classSymbol = host.getClassSymbol(node); expect(classSymbol).toBeUndefined(); @@ -1931,33 +1918,30 @@ exports.ExternalModule = ExternalModule; describe('isClass()', () => { it('should return true if a given node is a TS class declaration', () => { loadTestFiles([SIMPLE_ES2015_CLASS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const node = getDeclaration( - program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); + bundle.program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); expect(host.isClass(node)).toBe(true); }); it('should return true if a given node is the outer variable declaration of a class', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const node = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); expect(host.isClass(node)).toBe(true); }); it('should return true if a given node is the inner variable declaration of a class', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; expect(host.isClass(innerNode)).toBe(true); @@ -1965,10 +1949,10 @@ exports.ExternalModule = ExternalModule; it('should return false if a given node is a function declaration', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const node = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(host.isClass(node)).toBe(false); }); }); @@ -1981,10 +1965,10 @@ exports.ExternalModule = ExternalModule; }; loadTestFiles([file]); - const {program, host: compilerHost} = makeTestBundleProgram(file.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(file.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration); return host.hasBaseClass(classNode); } @@ -2028,10 +2012,10 @@ exports.ExternalModule = ExternalModule; }; loadTestFiles([file]); - const {program, host: compilerHost} = makeTestBundleProgram(file.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(file.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration); const expression = host.getBaseClassExpression(classNode); if (expression !== null && !ts.isIdentifier(expression)) { throw new Error( @@ -2100,10 +2084,10 @@ exports.ExternalModule = ExternalModule; }; loadTestFiles([file]); - const {program, host: compilerHost} = makeTestBundleProgram(file.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(file.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration); const expression = host.getBaseClassExpression(classNode) !; expect(expression.getText()).toBe('foo()'); }); @@ -2112,11 +2096,10 @@ exports.ExternalModule = ExternalModule; describe('findClassSymbols()', () => { it('should return an array of all classes in the given source file', () => { loadTestFiles(DECORATED_FILES); - const {program, host: compilerHost} = - makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const primaryFile = getSourceFileOrError(program, DECORATED_FILES[0].name); - const secondaryFile = getSourceFileOrError(program, DECORATED_FILES[1].name); + const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); + const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name); + const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name); const classSymbolsPrimary = host.findClassSymbols(primaryFile); expect(classSymbolsPrimary.length).toEqual(2); @@ -2131,11 +2114,10 @@ exports.ExternalModule = ExternalModule; describe('getDecoratorsOfSymbol()', () => { it('should return decorators of class symbol', () => { loadTestFiles(DECORATED_FILES); - const {program, host: compilerHost} = - makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const primaryFile = getSourceFileOrError(program, DECORATED_FILES[0].name); - const secondaryFile = getSourceFileOrError(program, DECORATED_FILES[1].name); + const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); + const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name); + const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name); const classSymbolsPrimary = host.findClassSymbols(primaryFile); const classDecoratorsPrimary = @@ -2157,12 +2139,11 @@ exports.ExternalModule = ExternalModule; () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestDtsBundleProgram(_('/typings/index.d.ts'), _('/')); - const class1 = - getDeclaration(program, _('/src/class1.js'), 'Class1', ts.isVariableDeclaration); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost, dts); + const class1 = getDeclaration( + bundle.program, _('/src/class1.js'), 'Class1', ts.isVariableDeclaration); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(class1); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/class1.d.ts')); @@ -2171,12 +2152,11 @@ exports.ExternalModule = ExternalModule; it('should find the dts declaration for exported functions', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestDtsBundleProgram(_('/typings/index.d.ts'), _('/')); const mooFn = - getDeclaration(program, _('/src/func1.js'), 'mooFn', ts.isFunctionDeclaration); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost, dts); + getDeclaration(bundle.program, _('/src/func1.js'), 'mooFn', ts.isFunctionDeclaration); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(mooFn); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/func1.d.ts')); }); @@ -2184,12 +2164,11 @@ exports.ExternalModule = ExternalModule; it('should return null if there is no matching class in the matching dts file', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestDtsBundleProgram(_('/typings/index.d.ts'), _('/')); const missingClass = getDeclaration( - program, _('/src/class1.js'), 'MissingClass1', ts.isVariableDeclaration); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost, dts); + bundle.program, _('/src/class1.js'), 'MissingClass1', ts.isVariableDeclaration); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); }); @@ -2197,12 +2176,12 @@ exports.ExternalModule = ExternalModule; it('should return null if there is no matching dts file', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestDtsBundleProgram(_('/typings/index.d.ts'), _('/')); const missingClass = getDeclaration( - program, _('/src/missing-class.js'), 'MissingClass2', ts.isVariableDeclaration); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost, dts); + bundle.program, _('/src/missing-class.js'), 'MissingClass2', + ts.isVariableDeclaration); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); }); @@ -2211,12 +2190,11 @@ exports.ExternalModule = ExternalModule; () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestDtsBundleProgram(_('/typings/index.d.ts'), _('/')); const class1 = getDeclaration( - program, _('/src/flat-file.js'), 'Class1', ts.isVariableDeclaration); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost, dts); + bundle.program, _('/src/flat-file.js'), 'Class1', ts.isVariableDeclaration); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(class1); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/class1.d.ts')); @@ -2225,12 +2203,11 @@ exports.ExternalModule = ExternalModule; it('should find aliased exports', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestDtsBundleProgram(_('/typings/index.d.ts'), _('/')); - const class3 = - getDeclaration(program, _('/src/flat-file.js'), 'Class3', ts.isVariableDeclaration); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost, dts); + const class3 = getDeclaration( + bundle.program, _('/src/flat-file.js'), 'Class3', ts.isVariableDeclaration); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(class3); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/class3.d.ts')); @@ -2240,12 +2217,11 @@ exports.ExternalModule = ExternalModule; () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestDtsBundleProgram(_('/typings/index.d.ts'), _('/')); const internalClass = getDeclaration( - program, _('/src/internal.js'), 'InternalClass', ts.isVariableDeclaration); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost, dts); + bundle.program, _('/src/internal.js'), 'InternalClass', ts.isVariableDeclaration); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(internalClass); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/internal.d.ts')); @@ -2255,14 +2231,13 @@ exports.ExternalModule = ExternalModule; () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestDtsBundleProgram(_('/typings/index.d.ts'), _('/')); - const class2 = - getDeclaration(program, _('/src/class2.js'), 'Class2', ts.isVariableDeclaration); - const internalClass2 = - getDeclaration(program, _('/src/internal.js'), 'Class2', ts.isVariableDeclaration); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost, dts); + const class2 = getDeclaration( + bundle.program, _('/src/class2.js'), 'Class2', ts.isVariableDeclaration); + const internalClass2 = getDeclaration( + bundle.program, _('/src/internal.js'), 'Class2', ts.isVariableDeclaration); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle, dts); const class2DtsDeclaration = host.getDtsDeclaration(class2); expect(class2DtsDeclaration !.getSourceFile().fileName) @@ -2277,23 +2252,23 @@ exports.ExternalModule = ExternalModule; describe('getInternalNameOfClass()', () => { it('should return the name of the inner class declaration', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const emptyClass = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); expect(host.getInternalNameOfClass(emptyClass).text).toEqual('EmptyClass'); const class1 = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'OuterClass1', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'OuterClass1', isNamedVariableDeclaration); expect(host.getInternalNameOfClass(class1).text).toEqual('InnerClass1'); const class2 = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'OuterClass2', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'OuterClass2', isNamedVariableDeclaration); expect(host.getInternalNameOfClass(class2).text).toEqual('InnerClass2'); const childClass = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'ChildClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'ChildClass', isNamedVariableDeclaration); expect(host.getInternalNameOfClass(childClass).text).toEqual('InnerChildClass'); }); }); @@ -2301,23 +2276,23 @@ exports.ExternalModule = ExternalModule; describe('getAdjacentNameOfClass()', () => { it('should return the name of the inner class declaration', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); const emptyClass = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); expect(host.getAdjacentNameOfClass(emptyClass).text).toEqual('EmptyClass'); const class1 = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'OuterClass1', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'OuterClass1', isNamedVariableDeclaration); expect(host.getAdjacentNameOfClass(class1).text).toEqual('InnerClass1'); const class2 = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'OuterClass2', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'OuterClass2', isNamedVariableDeclaration); expect(host.getAdjacentNameOfClass(class2).text).toEqual('InnerClass2'); const childClass = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'ChildClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'ChildClass', isNamedVariableDeclaration); expect(host.getAdjacentNameOfClass(childClass).text).toEqual('InnerChildClass'); }); }); @@ -2326,10 +2301,9 @@ exports.ExternalModule = ExternalModule; it('should find every exported function that returns an object that looks like a ModuleWithProviders object', () => { loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const file = getSourceFileOrError(program, _('/src/functions.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); + const host = 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])) .toEqual([ @@ -2343,10 +2317,9 @@ exports.ExternalModule = ExternalModule; it('should find every static method on exported classes that return an object that looks like a ModuleWithProviders object', () => { loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); - const host = - new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const file = getSourceFileOrError(program, _('/src/methods.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); + const host = 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([ [ @@ -2371,9 +2344,9 @@ exports.ExternalModule = ExternalModule; // https://github.com/angular/angular/issues/29078 it('should resolve aliased module references to their original declaration', () => { loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); - const host = new CommonJsReflectionHost(new MockLogger(), false, program, compilerHost); - const file = getSourceFileOrError(program, _('/src/aliased_class.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); + const host = new CommonJsReflectionHost(new MockLogger(), false, bundle); + const file = getSourceFileOrError(bundle.program, _('/src/aliased_class.js')); const fn = host.getModuleWithProvidersFunctions(file); expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.node.name.text])).toEqual([ ['function() { return { ngModule: AliasedModule_1 }; }', 'AliasedModule'], diff --git a/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts b/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts index da7b484a92..e9baddd052 100644 --- a/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts @@ -163,11 +163,11 @@ runInEachFileSystem(() => { describe('getDecoratorsOfDeclaration()', () => { it('should find the decorators on a class', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -184,11 +184,10 @@ runInEachFileSystem(() => { it('should find the decorators on a class when mixing `ctorParameters` and `__decorate`', () => { - const {program} = makeTestBundleProgram(_('/some_directive_ctor_parameters.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive_ctor_parameters.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive_ctor_parameters.js'), 'SomeDirective', + bundle.program, _('/some_directive_ctor_parameters.js'), 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -205,12 +204,11 @@ runInEachFileSystem(() => { }); it('should support decorators being used inside @angular/core', () => { - const {program} = + const bundle = makeTestBundleProgram(_('/node_modules/@angular/core/some_directive.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), true, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), true, bundle); const classNode = getDeclaration( - program, _('/node_modules/@angular/core/some_directive.js'), 'SomeDirective', + bundle.program, _('/node_modules/@angular/core/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -229,11 +227,11 @@ runInEachFileSystem(() => { describe('getMembersOfClass()', () => { it('should find decorated members on a class', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -249,11 +247,10 @@ runInEachFileSystem(() => { it('should find decorated members on a class when mixing `ctorParameters` and `__decorate`', () => { - const {program} = makeTestBundleProgram(_('/some_directive_ctor_parameters.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive_ctor_parameters.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive_ctor_parameters.js'), 'SomeDirective', + bundle.program, _('/some_directive_ctor_parameters.js'), 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -264,11 +261,11 @@ runInEachFileSystem(() => { }); it('should find non decorated properties on a class', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const instanceProperty = members.find(member => member.name === 'instanceProperty') !; @@ -279,11 +276,11 @@ runInEachFileSystem(() => { }); it('should find static methods on a class', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticMethod = members.find(member => member.name === 'staticMethod') !; @@ -293,11 +290,11 @@ runInEachFileSystem(() => { }); it('should find static properties on a class', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticProperty = members.find(member => member.name === 'staticProperty') !; @@ -309,11 +306,11 @@ runInEachFileSystem(() => { it('should find static properties on a class that has an intermediate variable assignment', () => { - const {program} = makeTestBundleProgram(_('/ngmodule.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/ngmodule.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/ngmodule.js'), 'HttpClientXsrfModule', isNamedVariableDeclaration); + bundle.program, _('/ngmodule.js'), 'HttpClientXsrfModule', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticProperty = members.find(member => member.name === 'staticProperty') !; @@ -324,12 +321,11 @@ runInEachFileSystem(() => { }); it('should support decorators being used inside @angular/core', () => { - const {program} = + const bundle = makeTestBundleProgram(_('/node_modules/@angular/core/some_directive.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), true, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), true, bundle); const classNode = getDeclaration( - program, _('/node_modules/@angular/core/some_directive.js'), 'SomeDirective', + bundle.program, _('/node_modules/@angular/core/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -342,11 +338,11 @@ runInEachFileSystem(() => { describe('getConstructorParameters', () => { it('should find the decorated constructor parameters', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBeDefined(); @@ -362,11 +358,10 @@ runInEachFileSystem(() => { it('should find the decorated constructor parameters when mixing `ctorParameters` and `__decorate`', () => { - const {program} = makeTestBundleProgram(_('/some_directive_ctor_parameters.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive_ctor_parameters.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive_ctor_parameters.js'), 'SomeDirective', + bundle.program, _('/some_directive_ctor_parameters.js'), 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -390,11 +385,11 @@ runInEachFileSystem(() => { describe('getDeclarationOfIdentifier', () => { it('should return the declaration of a locally defined identifier', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const ctrDecorators = host.getConstructorParameters(classNode) !; const identifierOfViewContainerRef = (ctrDecorators[0].typeValueReference !as{ local: true, @@ -403,7 +398,7 @@ runInEachFileSystem(() => { }).expression; const expectedDeclarationNode = getDeclaration( - program, _('/some_directive.js'), 'ViewContainerRef', ts.isClassDeclaration); + bundle.program, _('/some_directive.js'), 'ViewContainerRef', ts.isClassDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfViewContainerRef); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -411,11 +406,11 @@ runInEachFileSystem(() => { }); it('should return the declaration of an externally defined identifier', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const classDecorators = host.getDecoratorsOfDeclaration(classNode) !; const decoratorNode = classDecorators[0].node !; const identifierOfDirective = @@ -424,7 +419,7 @@ runInEachFileSystem(() => { null; const expectedDeclarationNode = getDeclaration( - program, _('/node_modules/@angular/core/index.d.ts'), 'Directive', + bundle.program, _('/node_modules/@angular/core/index.d.ts'), 'Directive', isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective !); expect(actualDeclaration).not.toBe(null); @@ -435,11 +430,10 @@ runInEachFileSystem(() => { describe('getVariableValue', () => { it('should find the "actual" declaration of an aliased variable identifier', () => { - const {program} = makeTestBundleProgram(_('/ngmodule.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/ngmodule.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const ngModuleRef = findVariableDeclaration( - getSourceFileOrError(program, _('/ngmodule.js')), 'HttpClientXsrfModule_1'); + getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'HttpClientXsrfModule_1'); const value = host.getVariableValue(ngModuleRef !); expect(value).not.toBe(null); @@ -451,21 +445,19 @@ runInEachFileSystem(() => { }); it('should return null if the variable has no assignment', () => { - const {program} = makeTestBundleProgram(_('/ngmodule.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/ngmodule.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const missingValue = findVariableDeclaration( - getSourceFileOrError(program, _('/ngmodule.js')), 'missingValue'); + getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'missingValue'); const value = host.getVariableValue(missingValue !); expect(value).toBe(null); }); it('should return null if the variable is not assigned from a call to __decorate', () => { - const {program} = makeTestBundleProgram(_('/ngmodule.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/ngmodule.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const nonDecoratedVar = findVariableDeclaration( - getSourceFileOrError(program, _('/ngmodule.js')), 'nonDecoratedVar'); + getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'nonDecoratedVar'); const value = host.getVariableValue(nonDecoratedVar !); expect(value).toBe(null); }); @@ -473,11 +465,10 @@ runInEachFileSystem(() => { describe('getEndOfClass()', () => { it('should return the last statement related to the class', () => { - const {program} = makeTestBundleProgram(_('/ngmodule.js')); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/ngmodule.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classSymbol = - host.findClassSymbols(program.getSourceFile(_('/ngmodule.js')) !)[0]; + host.findClassSymbols(bundle.program.getSourceFile(_('/ngmodule.js')) !)[0]; const endOfClass = host.getEndOfClass(classSymbol); expect(endOfClass.getText()) .toMatch( diff --git a/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts b/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts index 4934a4fac2..9aec67f381 100644 --- a/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts @@ -705,10 +705,10 @@ runInEachFileSystem(() => { describe('getDecoratorsOfDeclaration()', () => { it('should find the decorators on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -724,10 +724,10 @@ runInEachFileSystem(() => { it('should find the decorators on an aliased class', () => { loadTestFiles([CLASS_EXPRESSION_FILE]); - const {program} = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, CLASS_EXPRESSION_FILE.name, 'AliasedClass', isNamedVariableDeclaration); + bundle.program, CLASS_EXPRESSION_FILE.name, 'AliasedClass', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -743,40 +743,42 @@ runInEachFileSystem(() => { it('should return null if the symbol is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const functionNode = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); const decorators = host.getDecoratorsOfDeclaration(functionNode); expect(decorators).toBe(null); }); it('should return null if there are no decorators', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const classNode = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const classNode = getDeclaration( + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); expect(decorators).toBe(null); }); it('should ignore `decorators` if it is not an array literal', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', + isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); expect(decorators).toEqual([]); }); it('should ignore decorator elements that are not object literals', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedClassDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', + isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -785,10 +787,11 @@ runInEachFileSystem(() => { it('should ignore decorator elements that have no `type` property', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', + isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -797,10 +800,10 @@ runInEachFileSystem(() => { it('should ignore decorator elements whose `type` value is not an identifier', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -809,10 +812,10 @@ runInEachFileSystem(() => { it('should have import information on decorators', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toEqual(1); @@ -822,10 +825,11 @@ runInEachFileSystem(() => { describe('(returned decorators `args`)', () => { it('should be an empty array if decorator has no `args` property', () => { loadTestFiles([INVALID_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedClassDeclaration); + bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', + isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -835,10 +839,10 @@ runInEachFileSystem(() => { it('should be an empty array if decorator\'s `args` has no property assignment', () => { loadTestFiles([INVALID_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', + bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -849,10 +853,10 @@ runInEachFileSystem(() => { it('should be an empty array if `args` property value is not an array literal', () => { loadTestFiles([INVALID_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -866,10 +870,10 @@ runInEachFileSystem(() => { describe('getMembersOfClass()', () => { it('should find decorated properties on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -887,10 +891,10 @@ runInEachFileSystem(() => { it('should find non decorated properties on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const instanceProperty = members.find(member => member.name === 'instanceProperty') !; @@ -902,10 +906,10 @@ runInEachFileSystem(() => { it('should handle equally named getter/setter pairs correctly', () => { loadTestFiles([ACCESSORS_FILE]); - const {program} = makeTestBundleProgram(ACCESSORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const classNode = - getDeclaration(program, ACCESSORS_FILE.name, 'SomeDirective', isNamedClassDeclaration); + const bundle = makeTestBundleProgram(ACCESSORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const classNode = getDeclaration( + bundle.program, ACCESSORS_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const [combinedSetter, combinedGetter] = @@ -924,10 +928,10 @@ runInEachFileSystem(() => { it('should find static methods on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const staticMethod = members.find(member => member.name === 'staticMethod') !; @@ -938,10 +942,10 @@ runInEachFileSystem(() => { it('should find static properties on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const staticProperty = members.find(member => member.name === 'staticProperty') !; @@ -954,10 +958,10 @@ runInEachFileSystem(() => { it('should ignore index signature properties', () => { loadTestFiles([INDEX_SIGNATURE_PROP_FILE]); const logger = new MockLogger(); - const {program} = makeTestBundleProgram(INDEX_SIGNATURE_PROP_FILE.name); - const host = new Esm2015ReflectionHost(logger, false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INDEX_SIGNATURE_PROP_FILE.name); + const host = new Esm2015ReflectionHost(logger, false, bundle); const classNode = getDeclaration( - program, INDEX_SIGNATURE_PROP_FILE.name, 'IndexSignatureClass', + bundle.program, INDEX_SIGNATURE_PROP_FILE.name, 'IndexSignatureClass', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); @@ -967,10 +971,10 @@ runInEachFileSystem(() => { it('should throw if the symbol is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const functionNode = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getMembersOfClass(functionNode); }).toThrowError(`Attempted to get members of a non-class: "function foo() {}"`); @@ -978,10 +982,10 @@ runInEachFileSystem(() => { it('should return an empty array if there are no prop decorators', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const classNode = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const classNode = getDeclaration( + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); expect(members).toEqual([]); @@ -990,11 +994,10 @@ runInEachFileSystem(() => { it('should not process decorated properties in `propDecorators` if it is not an object literal', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral', + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); @@ -1003,10 +1006,10 @@ runInEachFileSystem(() => { it('should ignore prop decorator elements that are not object literals', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp', + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1018,10 +1021,11 @@ runInEachFileSystem(() => { it('should ignore prop decorator elements that have no `type` property', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration); + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', + isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; const decorators = prop.decorators !; @@ -1032,10 +1036,11 @@ runInEachFileSystem(() => { it('should ignore prop decorator elements whose `type` value is not an identifier', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration); + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', + isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; const decorators = prop.decorators !; @@ -1047,10 +1052,10 @@ runInEachFileSystem(() => { describe('(returned prop decorators `args`)', () => { it('should be an empty array if prop decorator has no `args` property', () => { loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', + bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1064,11 +1069,10 @@ runInEachFileSystem(() => { it('should be an empty array if prop decorator\'s `args` has no property assignment', () => { loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', + bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1081,10 +1085,10 @@ runInEachFileSystem(() => { it('should be an empty array if `args` property value is not an array literal', () => { loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1101,10 +1105,10 @@ runInEachFileSystem(() => { it('should find the decorated constructor parameters', () => { loadFakeCore(getFileSystem()); loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; expect(parameters).toBeDefined(); @@ -1117,10 +1121,10 @@ runInEachFileSystem(() => { it('should accept `ctorParameters` as an array', () => { loadTestFiles([CTOR_DECORATORS_ARRAY_FILE]); - const {program} = makeTestBundleProgram(CTOR_DECORATORS_ARRAY_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(CTOR_DECORATORS_ARRAY_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, CTOR_DECORATORS_ARRAY_FILE.name, 'CtorDecoratedAsArray', + bundle.program, CTOR_DECORATORS_ARRAY_FILE.name, 'CtorDecoratedAsArray', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; @@ -1131,10 +1135,10 @@ runInEachFileSystem(() => { it('should throw if the symbol is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const functionNode = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getConstructorParameters(functionNode); }) .toThrowError( 'Attempted to get constructor parameters of a non-class: "function foo() {}"'); @@ -1142,20 +1146,20 @@ runInEachFileSystem(() => { it('should return `null` if there is no constructor', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const classNode = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const classNode = getDeclaration( + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBe(null); }); it('should return an array even if there are no decorators', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', + bundle.program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; @@ -1167,10 +1171,11 @@ runInEachFileSystem(() => { it('should return an empty array if there are no constructor parameters', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', isNamedClassDeclaration); + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', + isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toEqual([]); @@ -1178,10 +1183,11 @@ runInEachFileSystem(() => { it('should ignore decorators that are not imported from core', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotFromCore', isNamedClassDeclaration); + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotFromCore', + isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; expect(parameters.length).toBe(1); @@ -1193,10 +1199,10 @@ runInEachFileSystem(() => { it('should ignore `ctorParameters` if it is not an arrow function', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrowFunction', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrowFunction', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; @@ -1209,10 +1215,11 @@ runInEachFileSystem(() => { it('should ignore `ctorParameters` if it does not return an array literal', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration); + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', + isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; expect(parameters.length).toBe(1); @@ -1235,10 +1242,10 @@ runInEachFileSystem(() => { }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedClassDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedClassDeclaration); return host.getConstructorParameters(classNode); } @@ -1291,10 +1298,10 @@ runInEachFileSystem(() => { describe('(returned parameters `decorators`)', () => { it('should ignore param decorator elements that are not object literals', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1311,10 +1318,10 @@ runInEachFileSystem(() => { it('should ignore param decorator elements that have no `type` property', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1325,10 +1332,11 @@ runInEachFileSystem(() => { it('should ignore param decorator elements whose `type` value is not an identifier', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration); + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', + isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1338,10 +1346,10 @@ runInEachFileSystem(() => { it('should have import information on decorators', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; const decorators = parameters[2].decorators !; @@ -1353,10 +1361,10 @@ runInEachFileSystem(() => { describe('(returned parameters `decorators.args`)', () => { it('should be an empty array if param decorator has no `args` property', () => { loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', + bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters !.length).toBe(1); @@ -1370,11 +1378,10 @@ runInEachFileSystem(() => { it('should be an empty array if param decorator\'s `args` has no property assignment', () => { loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', + bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1386,10 +1393,10 @@ runInEachFileSystem(() => { it('should be an empty array if `args` property value is not an array literal', () => { loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1405,12 +1412,11 @@ runInEachFileSystem(() => { it('should return an object describing the function declaration passed as an argument', () => { loadTestFiles([FUNCTION_BODY_FILE]); - const {program} = makeTestBundleProgram(FUNCTION_BODY_FILE.name); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(FUNCTION_BODY_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const fooNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !; const fooDef = host.getDefinitionOfFunction(fooNode) !; expect(fooDef.node).toBe(fooNode); expect(fooDef.body !.length).toEqual(1); @@ -1420,7 +1426,7 @@ runInEachFileSystem(() => { expect(fooDef.parameters[0].initializer).toBe(null); const barNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'bar', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'bar', isNamedFunctionDeclaration) !; const barDef = host.getDefinitionOfFunction(barNode) !; expect(barDef.node).toBe(barNode); expect(barDef.body !.length).toEqual(1); @@ -1433,7 +1439,7 @@ runInEachFileSystem(() => { expect(barDef.parameters[1].initializer !.getText()).toEqual('42'); const bazNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'baz', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'baz', isNamedFunctionDeclaration) !; const bazDef = host.getDefinitionOfFunction(bazNode) !; expect(bazDef.node).toBe(bazNode); expect(bazDef.body !.length).toEqual(3); @@ -1442,7 +1448,7 @@ runInEachFileSystem(() => { expect(bazDef.parameters[0].initializer).toBe(null); const quxNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'qux', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'qux', isNamedFunctionDeclaration) !; const quxDef = host.getDefinitionOfFunction(quxNode) !; expect(quxDef.node).toBe(quxNode); expect(quxDef.body !.length).toEqual(2); @@ -1451,14 +1457,14 @@ runInEachFileSystem(() => { expect(quxDef.parameters[0].initializer).toBe(null); const mooNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'moo', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'moo', isNamedFunctionDeclaration) !; const mooDef = host.getDefinitionOfFunction(mooNode) !; expect(mooDef.node).toBe(mooNode); expect(mooDef.body !.length).toEqual(3); expect(mooDef.parameters).toEqual([]); const juuNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'juu', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'juu', isNamedFunctionDeclaration) !; const juuDef = host.getDefinitionOfFunction(juuNode) !; expect(juuDef.node).toBe(juuNode); expect(juuDef.body !.length).toEqual(2); @@ -1469,9 +1475,10 @@ runInEachFileSystem(() => { describe('getImportOfIdentifier()', () => { it('should find the import of an identifier', () => { loadTestFiles(IMPORTS_FILES); - const {program} = makeTestBundleProgram(_('/index.js')); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const variableNode = getDeclaration(program, _('/b.js'), 'b', isNamedVariableDeclaration); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const variableNode = + getDeclaration(bundle.program, _('/b.js'), 'b', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); expect(importOfIdent).toEqual({name: 'a', from: './a.js'}); @@ -1479,9 +1486,10 @@ runInEachFileSystem(() => { it('should find the name by which the identifier was exported, not imported', () => { loadTestFiles(IMPORTS_FILES); - const {program} = makeTestBundleProgram(_('/index.js')); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const variableNode = getDeclaration(program, _('/b.js'), 'c', isNamedVariableDeclaration); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const variableNode = + getDeclaration(bundle.program, _('/b.js'), 'c', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); expect(importOfIdent).toEqual({name: 'a', from: './a.js'}); @@ -1489,9 +1497,10 @@ runInEachFileSystem(() => { it('should return null if the identifier was not imported', () => { loadTestFiles(IMPORTS_FILES); - const {program} = makeTestBundleProgram(_('/index.js')); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const variableNode = getDeclaration(program, _('/b.js'), 'd', isNamedVariableDeclaration); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const variableNode = + getDeclaration(bundle.program, _('/b.js'), 'd', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); expect(importOfIdent).toBeNull(); @@ -1502,10 +1511,10 @@ runInEachFileSystem(() => { it('should return the declaration of a locally defined identifier', () => { loadFakeCore(getFileSystem()); loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(classNode.name); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(classNode); @@ -1515,17 +1524,17 @@ runInEachFileSystem(() => { it('should return the declaration of an externally defined identifier', () => { loadFakeCore(getFileSystem()); loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); + 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) .initializer as ts.Identifier; const expectedDeclarationNode = getDeclaration( - program, _('/node_modules/@angular/core/index.d.ts'), 'Directive', + bundle.program, _('/node_modules/@angular/core/index.d.ts'), 'Directive', isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective); expect(actualDeclaration).not.toBe(null); @@ -1536,10 +1545,10 @@ runInEachFileSystem(() => { it('should return the source-file of an import namespace', () => { loadFakeCore(getFileSystem()); loadTestFiles([NAMESPACED_IMPORT_FILE]); - const {program} = makeTestBundleProgram(NAMESPACED_IMPORT_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(NAMESPACED_IMPORT_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, NAMESPACED_IMPORT_FILE.name, 'SomeDirective', ts.isClassDeclaration); + 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) @@ -1547,7 +1556,7 @@ runInEachFileSystem(() => { .expression as ts.Identifier; const expectedDeclarationNode = - getSourceFileOrError(program, _('/node_modules/@angular/core/index.d.ts')); + getSourceFileOrError(bundle.program, _('/node_modules/@angular/core/index.d.ts')); const actualDeclaration = host.getDeclarationOfIdentifier(identifier); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -1556,12 +1565,13 @@ runInEachFileSystem(() => { it('should return the original declaration of an aliased class', () => { loadTestFiles([CLASS_EXPRESSION_FILE]); - const {program} = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classDeclaration = getDeclaration( - program, CLASS_EXPRESSION_FILE.name, 'AliasedClass', ts.isVariableDeclaration); + bundle.program, CLASS_EXPRESSION_FILE.name, 'AliasedClass', ts.isVariableDeclaration); const usageOfAliasedClass = getDeclaration( - program, CLASS_EXPRESSION_FILE.name, 'usageOfAliasedClass', ts.isVariableDeclaration); + bundle.program, CLASS_EXPRESSION_FILE.name, 'usageOfAliasedClass', + ts.isVariableDeclaration); const aliasedClassIdentifier = usageOfAliasedClass.initializer as ts.Identifier; expect(aliasedClassIdentifier.text).toBe('AliasedClass_1'); expect(host.getDeclarationOfIdentifier(aliasedClassIdentifier) !.node) @@ -1573,9 +1583,9 @@ runInEachFileSystem(() => { it('should return a map of all the exports from a given module', () => { loadFakeCore(getFileSystem()); loadTestFiles(EXPORTS_FILES); - const {program} = makeTestBundleProgram(_('/index.js')); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const file = getSourceFileOrError(program, _('/b.js')); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const file = getSourceFileOrError(bundle.program, _('/b.js')); const exportDeclarations = host.getExportsOfModule(file); expect(exportDeclarations).not.toBe(null); expect(Array.from(exportDeclarations !.keys())).toEqual([ @@ -1608,10 +1618,10 @@ runInEachFileSystem(() => { describe('getClassSymbol()', () => { it('should return the class symbol for an ES2015 class', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const node = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const classSymbol = host.getClassSymbol(node); expect(classSymbol).toBeDefined(); @@ -1622,11 +1632,11 @@ runInEachFileSystem(() => { it('should return the class symbol for a class expression (outer variable declaration)', () => { loadTestFiles([CLASS_EXPRESSION_FILE]); - const {program} = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, CLASS_EXPRESSION_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, CLASS_EXPRESSION_FILE.name, 'EmptyClass', + isNamedVariableDeclaration); const innerNode = (outerNode.initializer as ts.ClassExpression); const classSymbol = host.getClassSymbol(outerNode); @@ -1637,10 +1647,10 @@ runInEachFileSystem(() => { it('should return the class symbol for a class expression (inner class expression)', () => { loadTestFiles([CLASS_EXPRESSION_FILE]); - const {program} = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, CLASS_EXPRESSION_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, CLASS_EXPRESSION_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = (outerNode.initializer as ts.ClassExpression); const classSymbol = host.getClassSymbol(innerNode); @@ -1652,11 +1662,11 @@ runInEachFileSystem(() => { it('should return the same class symbol (of the outer declaration) for outer and inner declarations', () => { loadTestFiles([CLASS_EXPRESSION_FILE]); - const {program} = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, CLASS_EXPRESSION_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, CLASS_EXPRESSION_FILE.name, 'EmptyClass', + isNamedVariableDeclaration); const innerNode = (outerNode.initializer as ts.ClassExpression); const innerSymbol = host.getClassSymbol(innerNode) !; @@ -1667,10 +1677,10 @@ runInEachFileSystem(() => { it('should return undefined if node is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const node = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); const classSymbol = host.getClassSymbol(node); expect(classSymbol).toBeUndefined(); @@ -1683,11 +1693,10 @@ runInEachFileSystem(() => { contents: `var MyClass = null;`, }; loadTestFiles([testFile]); - const {program} = makeTestBundleProgram(testFile.name); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(testFile.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const node = - getDeclaration(program, testFile.name, 'MyClass', isNamedVariableDeclaration); + getDeclaration(bundle.program, testFile.name, 'MyClass', isNamedVariableDeclaration); const classSymbol = host.getClassSymbol(node); expect(classSymbol).toBeUndefined(); @@ -1697,41 +1706,40 @@ runInEachFileSystem(() => { describe('isClass()', () => { it('should return true if a given node is a TS class declaration', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const node = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); expect(host.isClass(node)).toBe(true); }); it('should return true if a given node is a class expression assigned into a variable', () => { loadTestFiles([CLASS_EXPRESSION_FILE]); - const {program} = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const node = getDeclaration( - program, CLASS_EXPRESSION_FILE.name, 'EmptyClass', ts.isVariableDeclaration); + bundle.program, CLASS_EXPRESSION_FILE.name, 'EmptyClass', ts.isVariableDeclaration); expect(host.isClass(node)).toBe(true); }); it('should return true if a given node is a class expression assigned into two variables', () => { loadTestFiles([CLASS_EXPRESSION_FILE]); - const {program} = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const node = getDeclaration( - program, CLASS_EXPRESSION_FILE.name, 'AliasedClass', ts.isVariableDeclaration); + bundle.program, CLASS_EXPRESSION_FILE.name, 'AliasedClass', + ts.isVariableDeclaration); expect(host.isClass(node)).toBe(true); }); it('should return false if a given node is a TS function declaration', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const node = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(host.isClass(node)).toBe(false); }); }); @@ -1743,9 +1751,10 @@ runInEachFileSystem(() => { contents: `class TestClass {}`, }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const classNode = getDeclaration(program, file.name, 'TestClass', isNamedClassDeclaration); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const classNode = + getDeclaration(bundle.program, file.name, 'TestClass', isNamedClassDeclaration); expect(host.hasBaseClass(classNode)).toBe(false); }); @@ -1757,9 +1766,10 @@ runInEachFileSystem(() => { class TestClass extends BaseClass {}`, }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const classNode = getDeclaration(program, file.name, 'TestClass', isNamedClassDeclaration); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const classNode = + getDeclaration(bundle.program, file.name, 'TestClass', isNamedClassDeclaration); expect(host.hasBaseClass(classNode)).toBe(true); }); @@ -1772,10 +1782,10 @@ runInEachFileSystem(() => { let TestClass = TestClass_1 = class TestClass extends BaseClass {}`, }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration); expect(host.hasBaseClass(classNode)).toBe(true); }); }); @@ -1787,9 +1797,10 @@ runInEachFileSystem(() => { contents: `class TestClass {}`, }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const classNode = getDeclaration(program, file.name, 'TestClass', isNamedClassDeclaration); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const classNode = + getDeclaration(bundle.program, file.name, 'TestClass', isNamedClassDeclaration); expect(host.getBaseClassExpression(classNode)).toBe(null); }); @@ -1801,9 +1812,10 @@ runInEachFileSystem(() => { class TestClass extends BaseClass {}`, }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const classNode = getDeclaration(program, file.name, 'TestClass', isNamedClassDeclaration); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const classNode = + getDeclaration(bundle.program, file.name, 'TestClass', isNamedClassDeclaration); const baseIdentifier = host.getBaseClassExpression(classNode) !; if (!ts.isIdentifier(baseIdentifier)) { throw new Error(`Expected ${baseIdentifier.getText()} to be an identifier.`); @@ -1820,10 +1832,10 @@ runInEachFileSystem(() => { let TestClass = TestClass_1 = class TestClass extends BaseClass {}`, }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration); const baseIdentifier = host.getBaseClassExpression(classNode) !; if (!ts.isIdentifier(baseIdentifier)) { throw new Error(`Expected ${baseIdentifier.getText()} to be an identifier.`); @@ -1841,11 +1853,10 @@ runInEachFileSystem(() => { class TestClass extends foo() {}`, }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedClassDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedClassDeclaration); const baseExpression = host.getBaseClassExpression(classNode) !; expect(baseExpression.getText()).toEqual('foo()'); }); @@ -1854,18 +1865,17 @@ runInEachFileSystem(() => { describe('getGenericArityOfClass()', () => { it('should properly count type parameters', () => { loadTestFiles(ARITY_CLASSES); - const {program} = makeTestBundleProgram(ARITY_CLASSES[0].name); + const bundle = makeTestBundleProgram(ARITY_CLASSES[0].name); const dts = makeTestBundleProgram(ARITY_CLASSES[1].name); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); - const noTypeParamClass = - getDeclaration(program, _('/src/class.js'), 'NoTypeParam', isNamedClassDeclaration); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts); + const noTypeParamClass = getDeclaration( + bundle.program, _('/src/class.js'), 'NoTypeParam', isNamedClassDeclaration); expect(host.getGenericArityOfClass(noTypeParamClass)).toBe(0); - const oneTypeParamClass = - getDeclaration(program, _('/src/class.js'), 'OneTypeParam', isNamedClassDeclaration); + const oneTypeParamClass = getDeclaration( + bundle.program, _('/src/class.js'), 'OneTypeParam', isNamedClassDeclaration); expect(host.getGenericArityOfClass(oneTypeParamClass)).toBe(1); - const twoTypeParamsClass = - getDeclaration(program, _('/src/class.js'), 'TwoTypeParams', isNamedClassDeclaration); + const twoTypeParamsClass = getDeclaration( + bundle.program, _('/src/class.js'), 'TwoTypeParams', isNamedClassDeclaration); expect(host.getGenericArityOfClass(twoTypeParamsClass)).toBe(2); }); }); @@ -1874,10 +1884,9 @@ runInEachFileSystem(() => { it('should return a collection of all the switchable variable declarations in the given module', () => { loadTestFiles([MARKER_FILE]); - const {program} = makeTestBundleProgram(MARKER_FILE.name); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const file = getSourceFileOrError(program, MARKER_FILE.name); + const bundle = makeTestBundleProgram(MARKER_FILE.name); + const host = 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([ ['compileNgModuleFactory', 'compileNgModuleFactory__PRE_R3__'] @@ -1888,10 +1897,10 @@ runInEachFileSystem(() => { describe('findClassSymbols()', () => { it('should return an array of all classes in the given source file', () => { loadTestFiles(DECORATED_FILES); - const {program} = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const primaryFile = getSourceFileOrError(program, DECORATED_FILES[0].name); - const secondaryFile = getSourceFileOrError(program, DECORATED_FILES[1].name); + const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name); + const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name); const classSymbolsPrimary = host.findClassSymbols(primaryFile); expect(classSymbolsPrimary.length).toEqual(3); @@ -1906,10 +1915,10 @@ runInEachFileSystem(() => { describe('getDecoratorsOfSymbol()', () => { it('should return decorators of class symbol', () => { loadTestFiles(DECORATED_FILES); - const {program} = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const primaryFile = getSourceFileOrError(program, DECORATED_FILES[0].name); - const secondaryFile = getSourceFileOrError(program, DECORATED_FILES[1].name); + const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name); + const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name); const classSymbolsPrimary = host.findClassSymbols(primaryFile); const classDecoratorsPrimary = classSymbolsPrimary.map(s => host.getDecoratorsOfSymbol(s)); @@ -1927,10 +1936,10 @@ runInEachFileSystem(() => { it('should return a cloned array on each invocation', () => { loadTestFiles(DECORATED_FILES); - const {program} = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); const classDecl = - getDeclaration(program, DECORATED_FILES[0].name, 'A', ts.isClassDeclaration) !; + getDeclaration(bundle.program, DECORATED_FILES[0].name, 'A', ts.isClassDeclaration) !; const classSymbol = host.getClassSymbol(classDecl) !; const firstResult = host.getDecoratorsOfSymbol(classSymbol); @@ -1945,12 +1954,11 @@ runInEachFileSystem(() => { () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); - const class1 = - getDeclaration(program, _('/ep/src/class1.js'), 'Class1', isNamedClassDeclaration); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + const class1 = getDeclaration( + bundle.program, _('/ep/src/class1.js'), 'Class1', isNamedClassDeclaration); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(class1); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/ep/typings/class1.d.ts')); @@ -1959,12 +1967,11 @@ runInEachFileSystem(() => { it('should find the dts declaration for exported functions', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); - const mooFn = - getDeclaration(program, _('/ep/src/func1.js'), 'mooFn', isNamedFunctionDeclaration); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + const mooFn = getDeclaration( + bundle.program, _('/ep/src/func1.js'), 'mooFn', isNamedFunctionDeclaration); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(mooFn); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/ep/typings/func1.d.ts')); @@ -1973,12 +1980,12 @@ runInEachFileSystem(() => { it('should return null if there is no matching class in the matching dts file', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); const missingClass = getDeclaration( - program, _('/ep/src/missing-class.js'), 'MissingClass2', isNamedClassDeclaration); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + bundle.program, _('/ep/src/missing-class.js'), 'MissingClass2', + isNamedClassDeclaration); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); }); @@ -1986,12 +1993,12 @@ runInEachFileSystem(() => { it('should return null if there is no matching dts file', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); const missingClass = getDeclaration( - program, _('/ep/src/missing-class.js'), 'MissingClass2', isNamedClassDeclaration); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + bundle.program, _('/ep/src/missing-class.js'), 'MissingClass2', + isNamedClassDeclaration); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); }); @@ -1999,14 +2006,13 @@ runInEachFileSystem(() => { it('should ignore dts files outside of the entrypoint', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram( + const bundle = makeTestBundleProgram( getRootFiles(TYPINGS_SRC_FILES)[0], false, [_('/ep/src/shadow-class.js')]); const dts = makeTestBundleProgram( getRootFiles(TYPINGS_DTS_FILES)[0], false, [_('/ep/typings/shadow-class.d.ts')]); const missingClass = getDeclaration( - program, _('/ep/src/shadow-class.js'), 'ShadowClass', isNamedClassDeclaration); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + bundle.program, _('/ep/src/shadow-class.js'), 'ShadowClass', isNamedClassDeclaration); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts); const dtsDecl = host.getDtsDeclaration(missingClass) !; expect(dtsDecl).not.toBeNull(); @@ -2017,12 +2023,11 @@ runInEachFileSystem(() => { () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); const class1 = getDeclaration( - program, _('/ep/src/flat-file.js'), 'Class1', isNamedClassDeclaration); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + bundle.program, _('/ep/src/flat-file.js'), 'Class1', isNamedClassDeclaration); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(class1); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/ep/typings/class1.d.ts')); @@ -2031,12 +2036,11 @@ runInEachFileSystem(() => { it('should find aliased exports', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); - const class3 = - getDeclaration(program, _('/ep/src/flat-file.js'), 'Class3', isNamedClassDeclaration); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + const class3 = getDeclaration( + bundle.program, _('/ep/src/flat-file.js'), 'Class3', isNamedClassDeclaration); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(class3); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/ep/typings/class3.d.ts')); @@ -2046,12 +2050,11 @@ runInEachFileSystem(() => { () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); const internalClass = getDeclaration( - program, _('/ep/src/internal.js'), 'InternalClass', isNamedClassDeclaration); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + bundle.program, _('/ep/src/internal.js'), 'InternalClass', isNamedClassDeclaration); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(internalClass); expect(dtsDeclaration !.getSourceFile().fileName) @@ -2062,14 +2065,13 @@ runInEachFileSystem(() => { () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); - const class2 = - getDeclaration(program, _('/ep/src/class2.js'), 'Class2', isNamedClassDeclaration); - const internalClass2 = - getDeclaration(program, _('/ep/src/internal.js'), 'Class2', isNamedClassDeclaration); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + const class2 = getDeclaration( + bundle.program, _('/ep/src/class2.js'), 'Class2', isNamedClassDeclaration); + const internalClass2 = getDeclaration( + bundle.program, _('/ep/src/internal.js'), 'Class2', isNamedClassDeclaration); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle, dts); const class2DtsDeclaration = host.getDtsDeclaration(class2); expect(class2DtsDeclaration !.getSourceFile().fileName) @@ -2084,10 +2086,10 @@ runInEachFileSystem(() => { describe('getInternalNameOfClass()', () => { it('should return the name of the class (there is no separate inner class in ES2015)', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const node = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); expect(host.getInternalNameOfClass(node).text).toEqual('EmptyClass'); }); }); @@ -2095,10 +2097,10 @@ runInEachFileSystem(() => { describe('getAdjacentNameOfClass()', () => { it('should return the name of the class (there is no separate inner class in ES2015)', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const node = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); expect(host.getAdjacentNameOfClass(node).text).toEqual('EmptyClass'); }); }); @@ -2107,10 +2109,9 @@ runInEachFileSystem(() => { it('should find every exported function that returns an object that looks like a ModuleWithProviders object', () => { loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM); - const {program} = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const file = getSourceFileOrError(program, _('/src/functions.js')); + const bundle = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]); + const host = 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])) .toEqual([ @@ -2125,10 +2126,9 @@ runInEachFileSystem(() => { it('should find every static method on exported classes that return an object that looks like a ModuleWithProviders object', () => { loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM); - const {program} = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]); - const host = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const file = getSourceFileOrError(program, _('/src/methods.js')); + const bundle = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]); + const host = 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])) .toEqual([ @@ -2143,9 +2143,9 @@ runInEachFileSystem(() => { // https://github.com/angular/angular/issues/29078 it('should resolve aliased module references to their original declaration', () => { loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM); - const {program} = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const file = getSourceFileOrError(program, _('/src/aliased_class.js')); + const bundle = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]); + const host = 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([ @@ -2175,9 +2175,9 @@ runInEachFileSystem(() => { `var value = 100;\n` }; loadTestFiles([testFile]); - const {program} = makeTestBundleProgram(testFile.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const classSymbol = host.findClassSymbols(program.getSourceFile(testFile.name) !)[0]; + const bundle = makeTestBundleProgram(testFile.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const classSymbol = host.findClassSymbols(bundle.program.getSourceFile(testFile.name) !)[0]; const endOfClass = host.getEndOfClass(classSymbol); expect(endOfClass.getText()) .toEqual( @@ -2198,9 +2198,9 @@ runInEachFileSystem(() => { `var value = 100;\n` }; loadTestFiles([testFile]); - const {program} = makeTestBundleProgram(testFile.name); - const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const classSymbol = host.findClassSymbols(program.getSourceFile(testFile.name) !)[0]; + const bundle = makeTestBundleProgram(testFile.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle); + const classSymbol = host.findClassSymbols(bundle.program.getSourceFile(testFile.name) !)[0]; const endOfClass = host.getEndOfClass(classSymbol); expect(endOfClass.getText()) .toEqual( diff --git a/packages/compiler-cli/ngcc/test/host/esm5_host_import_helper_spec.ts b/packages/compiler-cli/ngcc/test/host/esm5_host_import_helper_spec.ts index c80f5b9d3e..16c6deb129 100644 --- a/packages/compiler-cli/ngcc/test/host/esm5_host_import_helper_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm5_host_import_helper_spec.ts @@ -222,10 +222,11 @@ export { AliasedDirective$1 }; describe('getDecoratorsOfDeclaration()', () => { it('should find the decorators on a class', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -242,10 +243,10 @@ export { AliasedDirective$1 }; }); it('should find the decorators on a minified class', () => { - const {program} = makeTestBundleProgram(_('/some_minified_directive.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_minified_directive.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_minified_directive.js'), 'SomeDirective', + bundle.program, _('/some_minified_directive.js'), 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -263,10 +264,10 @@ export { AliasedDirective$1 }; }); it('should find the decorators on an aliased class', () => { - const {program} = makeTestBundleProgram(_('/some_aliased_directive.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_aliased_directive.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_aliased_directive.js'), 'AliasedDirective$1', + bundle.program, _('/some_aliased_directive.js'), 'AliasedDirective$1', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -284,11 +285,10 @@ export { AliasedDirective$1 }; it('should find the decorators on a class when mixing `ctorParameters` and `__decorate`', () => { - const {program} = makeTestBundleProgram(_('/some_directive_ctor_parameters.js')); - const host = - new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive_ctor_parameters.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive_ctor_parameters.js'), 'SomeDirective', + bundle.program, _('/some_directive_ctor_parameters.js'), 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -305,11 +305,11 @@ export { AliasedDirective$1 }; }); it('should support decorators being used inside @angular/core', () => { - const {program} = + const bundle = makeTestBundleProgram(_('/node_modules/@angular/core/some_directive.js')); - const host = new Esm5ReflectionHost(new MockLogger(), true, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), true, bundle); const classNode = getDeclaration( - program, _('/node_modules/@angular/core/some_directive.js'), 'SomeDirective', + bundle.program, _('/node_modules/@angular/core/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -328,10 +328,10 @@ export { AliasedDirective$1 }; describe('getClassSymbol()', () => { it('should find a class that has been minified', () => { - const {program} = makeTestBundleProgram(_('/some_minified_directive.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_minified_directive.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_minified_directive.js'), 'SomeDirective', + bundle.program, _('/some_minified_directive.js'), 'SomeDirective', isNamedVariableDeclaration); const innerNode = getIifeBody(classNode) !.statements.find(isNamedFunctionDeclaration) !; @@ -345,10 +345,11 @@ export { AliasedDirective$1 }; describe('getMembersOfClass()', () => { it('should find decorated members on a class', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -364,11 +365,10 @@ export { AliasedDirective$1 }; it('should find decorated members on a class when mixing `ctorParameters` and `__decorate`', () => { - const {program} = makeTestBundleProgram(_('/some_directive_ctor_parameters.js')); - const host = - new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive_ctor_parameters.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive_ctor_parameters.js'), 'SomeDirective', + bundle.program, _('/some_directive_ctor_parameters.js'), 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -379,10 +379,11 @@ export { AliasedDirective$1 }; }); it('should find non decorated properties on a class', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const instanceProperty = members.find(member => member.name === 'instanceProperty') !; @@ -393,10 +394,11 @@ export { AliasedDirective$1 }; }); it('should find static methods on a class', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticMethod = members.find(member => member.name === 'staticMethod') !; @@ -406,10 +408,11 @@ export { AliasedDirective$1 }; }); it('should find static properties on a class', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticProperty = members.find(member => member.name === 'staticProperty') !; @@ -420,11 +423,11 @@ export { AliasedDirective$1 }; }); it('should support decorators being used inside @angular/core', () => { - const {program} = + const bundle = makeTestBundleProgram(_('/node_modules/@angular/core/some_directive.js')); - const host = new Esm5ReflectionHost(new MockLogger(), true, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), true, bundle); const classNode = getDeclaration( - program, _('/node_modules/@angular/core/some_directive.js'), 'SomeDirective', + bundle.program, _('/node_modules/@angular/core/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -436,10 +439,11 @@ export { AliasedDirective$1 }; }); describe('getConstructorParameters', () => { it('should find the decorated constructor parameters', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBeDefined(); @@ -455,11 +459,10 @@ export { AliasedDirective$1 }; it('should find the decorated constructor parameters when mixing `ctorParameters` and `__decorate`', () => { - const {program} = makeTestBundleProgram(_('/some_directive_ctor_parameters.js')); - const host = - new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive_ctor_parameters.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive_ctor_parameters.js'), 'SomeDirective', + bundle.program, _('/some_directive_ctor_parameters.js'), 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -476,11 +479,11 @@ export { AliasedDirective$1 }; describe('(returned parameters `decorators`)', () => { it('should have import information on decorators', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = - new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![2].decorators !; @@ -492,15 +495,15 @@ export { AliasedDirective$1 }; describe('findClassSymbols()', () => { it('should return an array of all classes in the given source file', () => { - const {program} = makeTestBundleProgram(_('/index.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); - const ngModuleFile = getSourceFileOrError(program, _('/ngmodule.js')); + const ngModuleFile = getSourceFileOrError(bundle.program, _('/ngmodule.js')); const ngModuleClasses = host.findClassSymbols(ngModuleFile); expect(ngModuleClasses.length).toEqual(1); expect(ngModuleClasses[0].name).toBe('HttpClientXsrfModule'); - const someDirectiveFile = getSourceFileOrError(program, _('/some_directive.js')); + const someDirectiveFile = getSourceFileOrError(bundle.program, _('/some_directive.js')); const someDirectiveClasses = host.findClassSymbols(someDirectiveFile); expect(someDirectiveClasses.length).toEqual(3); expect(someDirectiveClasses[0].name).toBe('ViewContainerRef'); @@ -511,17 +514,17 @@ export { AliasedDirective$1 }; describe('getDecoratorsOfSymbol()', () => { it('should return decorators of class symbol', () => { - const {program} = makeTestBundleProgram(_('/index.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); - const ngModuleFile = getSourceFileOrError(program, _('/ngmodule.js')); + const ngModuleFile = getSourceFileOrError(bundle.program, _('/ngmodule.js')); const ngModuleClasses = host.findClassSymbols(ngModuleFile); const ngModuleDecorators = ngModuleClasses.map(s => host.getDecoratorsOfSymbol(s)); expect(ngModuleClasses.length).toEqual(1); expect(ngModuleDecorators[0] !.map(d => d.name)).toEqual(['NgModule']); - const someDirectiveFile = getSourceFileOrError(program, _('/some_directive.js')); + const someDirectiveFile = getSourceFileOrError(bundle.program, _('/some_directive.js')); const someDirectiveClasses = host.findClassSymbols(someDirectiveFile); const someDirectiveDecorators = someDirectiveClasses.map(s => host.getDecoratorsOfSymbol(s)); @@ -535,10 +538,11 @@ export { AliasedDirective$1 }; describe('getDeclarationOfIdentifier', () => { it('should return the declaration of a locally defined identifier', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const ctrDecorators = host.getConstructorParameters(classNode) !; const identifierOfViewContainerRef = (ctrDecorators[0].typeValueReference !as{ local: true, @@ -547,7 +551,8 @@ export { AliasedDirective$1 }; }).expression; const expectedDeclarationNode = getDeclaration( - program, _('/some_directive.js'), 'ViewContainerRef', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'ViewContainerRef', + isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfViewContainerRef); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -555,10 +560,11 @@ export { AliasedDirective$1 }; }); it('should return the declaration of an externally defined identifier', () => { - const {program} = makeTestBundleProgram(_('/some_directive.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/some_directive.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, _('/some_directive.js'), 'SomeDirective', isNamedVariableDeclaration); + bundle.program, _('/some_directive.js'), 'SomeDirective', + isNamedVariableDeclaration); const classDecorators = host.getDecoratorsOfDeclaration(classNode) !; const decoratorNode = classDecorators[0].node !; @@ -568,7 +574,7 @@ export { AliasedDirective$1 }; null; const expectedDeclarationNode = getDeclaration( - program, _('/node_modules/@angular/core/index.d.ts'), 'Directive', + bundle.program, _('/node_modules/@angular/core/index.d.ts'), 'Directive', isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective !); expect(actualDeclaration).not.toBe(null); @@ -577,10 +583,10 @@ export { AliasedDirective$1 }; }); it('should find the "actual" declaration of an aliased variable identifier', () => { - const {program} = makeTestBundleProgram(_('/ngmodule.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/ngmodule.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const ngModuleRef = findIdentifier( - getSourceFileOrError(program, _('/ngmodule.js')), 'HttpClientXsrfModule_1', + getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'HttpClientXsrfModule_1', isNgModulePropertyAssignment); const declaration = host.getDeclarationOfIdentifier(ngModuleRef !); @@ -590,10 +596,10 @@ export { AliasedDirective$1 }; }); describe('getVariableValue', () => { it('should find the "actual" declaration of an aliased variable identifier', () => { - const {program} = makeTestBundleProgram(_('/ngmodule.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/ngmodule.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const ngModuleRef = findVariableDeclaration( - getSourceFileOrError(program, _('/ngmodule.js')), 'HttpClientXsrfModule_1'); + getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'HttpClientXsrfModule_1'); const value = host.getVariableValue(ngModuleRef !); expect(value).not.toBe(null); @@ -605,19 +611,19 @@ export { AliasedDirective$1 }; }); it('should return undefined if the variable has no assignment', () => { - const {program} = makeTestBundleProgram(_('/ngmodule.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/ngmodule.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const missingValue = findVariableDeclaration( - getSourceFileOrError(program, _('/ngmodule.js')), 'missingValue'); + getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'missingValue'); const value = host.getVariableValue(missingValue !); expect(value).toBe(null); }); it('should return null if the variable is not assigned from a call to __decorate', () => { - const {program} = makeTestBundleProgram(_('/ngmodule.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/ngmodule.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const nonDecoratedVar = findVariableDeclaration( - getSourceFileOrError(program, _('/ngmodule.js')), 'nonDecoratedVar'); + getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'nonDecoratedVar'); const value = host.getVariableValue(nonDecoratedVar !); expect(value).toBe(null); }); @@ -625,10 +631,10 @@ export { AliasedDirective$1 }; describe('getEndOfClass()', () => { it('should return the last statement related to the class', () => { - const {program} = makeTestBundleProgram(_('/ngmodule.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(_('/ngmodule.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classSymbol = - host.findClassSymbols(program.getSourceFile(_('/ngmodule.js')) !)[0]; + host.findClassSymbols(bundle.program.getSourceFile(_('/ngmodule.js')) !)[0]; const endOfClass = host.getEndOfClass(classSymbol); expect(endOfClass.getText()) .toMatch( diff --git a/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts b/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts index 231e602698..1c71e24897 100644 --- a/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts @@ -868,10 +868,10 @@ runInEachFileSystem(() => { describe('getDecoratorsOfDeclaration()', () => { it('should find the decorators on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -887,10 +887,11 @@ runInEachFileSystem(() => { it('should find the decorators on a class at the top level', () => { loadTestFiles([TOPLEVEL_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -906,40 +907,42 @@ runInEachFileSystem(() => { it('should return null if the symbol is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const functionNode = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); const decorators = host.getDecoratorsOfDeclaration(functionNode); expect(decorators).toBe(null); }); it('should return null if there are no decorators', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); expect(decorators).toBe(null); }); it('should ignore `decorators` if it is not an array literal', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); expect(decorators).toEqual([]); }); it('should ignore decorator elements that are not object literals', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -948,10 +951,11 @@ runInEachFileSystem(() => { it('should ignore decorator elements that have no `type` property', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -960,10 +964,11 @@ runInEachFileSystem(() => { it('should ignore decorator elements whose `type` value is not an identifier', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -972,10 +977,10 @@ runInEachFileSystem(() => { it('should have import information on decorators', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toEqual(1); @@ -985,10 +990,10 @@ runInEachFileSystem(() => { describe('(returned decorators `args`)', () => { it('should be an empty array if decorator has no `args` property', () => { loadTestFiles([INVALID_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', + bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -999,10 +1004,10 @@ runInEachFileSystem(() => { it('should be an empty array if decorator\'s `args` has no property assignment', () => { loadTestFiles([INVALID_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', + bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -1013,10 +1018,10 @@ runInEachFileSystem(() => { it('should be an empty array if `args` property value is not an array literal', () => { loadTestFiles([INVALID_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -1030,10 +1035,11 @@ runInEachFileSystem(() => { describe('getMembersOfClass()', () => { it('should find decorated members on a class at the top level', () => { loadTestFiles([TOPLEVEL_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -1051,10 +1057,10 @@ runInEachFileSystem(() => { it('should find decorated members on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -1070,10 +1076,10 @@ runInEachFileSystem(() => { it('should find Object.defineProperty members on a class', () => { loadTestFiles([ACCESSORS_FILE]); - const {program} = makeTestBundleProgram(ACCESSORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(ACCESSORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, ACCESSORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, ACCESSORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const setter = members.find(member => member.name === 'setter') !; @@ -1118,10 +1124,10 @@ runInEachFileSystem(() => { it('should find non decorated properties on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const instanceProperty = members.find(member => member.name === 'instanceProperty') !; @@ -1133,10 +1139,10 @@ runInEachFileSystem(() => { it('should find static methods on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticMethod = members.find(member => member.name === 'staticMethod') !; @@ -1148,10 +1154,10 @@ runInEachFileSystem(() => { it('should find static properties on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticProperty = members.find(member => member.name === 'staticProperty') !; @@ -1163,10 +1169,10 @@ runInEachFileSystem(() => { it('should accept `ctorParameters` as an array', () => { loadTestFiles([CTOR_DECORATORS_ARRAY_FILE]); - const {program} = makeTestBundleProgram(CTOR_DECORATORS_ARRAY_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(CTOR_DECORATORS_ARRAY_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, CTOR_DECORATORS_ARRAY_FILE.name, 'CtorDecoratedAsArray', + bundle.program, CTOR_DECORATORS_ARRAY_FILE.name, 'CtorDecoratedAsArray', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode) !; @@ -1177,10 +1183,10 @@ runInEachFileSystem(() => { it('should throw if the symbol is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const functionNode = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getMembersOfClass(functionNode); }).toThrowError(`Attempted to get members of a non-class: "function foo() {}"`); @@ -1188,10 +1194,10 @@ runInEachFileSystem(() => { it('should return an empty array if there are no prop decorators', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); expect(members).toEqual([]); @@ -1200,10 +1206,10 @@ runInEachFileSystem(() => { it('should not process decorated properties in `propDecorators` if it is not an object literal', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral', + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -1212,10 +1218,10 @@ runInEachFileSystem(() => { it('should ignore prop decorator elements that are not object literals', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp', + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1227,10 +1233,10 @@ runInEachFileSystem(() => { it('should ignore prop decorator elements that have no `type` property', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1242,10 +1248,10 @@ runInEachFileSystem(() => { it('should ignore prop decorator elements whose `type` value is not an identifier', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1258,10 +1264,10 @@ runInEachFileSystem(() => { describe('(returned prop decorators `args`)', () => { it('should be an empty array if prop decorator has no `args` property', () => { loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', + bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1275,10 +1281,10 @@ runInEachFileSystem(() => { it('should be an empty array if prop decorator\'s `args` has no property assignment', () => { loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', + bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1291,10 +1297,10 @@ runInEachFileSystem(() => { it('should be an empty array if `args` property value is not an array literal', () => { loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1309,10 +1315,11 @@ runInEachFileSystem(() => { it('should ignore the prototype pseudo-static property on class imported from typings files', () => { loadTestFiles([UNWANTED_PROTOTYPE_EXPORT_FILE]); - const {program} = makeTestBundleProgram(UNWANTED_PROTOTYPE_EXPORT_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(UNWANTED_PROTOTYPE_EXPORT_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, UNWANTED_PROTOTYPE_EXPORT_FILE.name, 'SomeParam', isNamedClassDeclaration); + bundle.program, UNWANTED_PROTOTYPE_EXPORT_FILE.name, 'SomeParam', + isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); expect(members.find(m => m.name === 'prototype')).toBeUndefined(); }); @@ -1321,10 +1328,10 @@ runInEachFileSystem(() => { describe('getConstructorParameters()', () => { it('should find the decorated constructor parameters', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBeDefined(); @@ -1340,10 +1347,11 @@ runInEachFileSystem(() => { it('should find the decorated constructor parameters at the top level', () => { loadTestFiles([TOPLEVEL_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBeDefined(); @@ -1359,10 +1367,10 @@ runInEachFileSystem(() => { it('should throw if the symbol is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const functionNode = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getConstructorParameters(functionNode); }) .toThrowError( 'Attempted to get constructor parameters of a non-class: "function foo() {}"'); @@ -1373,10 +1381,10 @@ runInEachFileSystem(() => { it('should return an array even if there are no decorators', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', + bundle.program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1388,10 +1396,11 @@ runInEachFileSystem(() => { it('should return an empty array if there are no constructor parameters', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', isNamedVariableDeclaration); + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toEqual([]); @@ -1402,10 +1411,10 @@ runInEachFileSystem(() => { it('should ignore `ctorParameters` if it does not return an array literal', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1419,10 +1428,10 @@ runInEachFileSystem(() => { describe('(returned parameters `decorators`)', () => { it('should ignore param decorator elements that are not object literals', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1439,10 +1448,10 @@ runInEachFileSystem(() => { it('should ignore param decorator elements that have no `type` property', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1453,10 +1462,10 @@ runInEachFileSystem(() => { it('should ignore param decorator elements whose `type` value is not an identifier', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1467,10 +1476,11 @@ runInEachFileSystem(() => { it('should have import information on decorators', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![2].decorators !; @@ -1493,10 +1503,10 @@ runInEachFileSystem(() => { }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration); return host.getConstructorParameters(classNode); } @@ -1562,10 +1572,10 @@ runInEachFileSystem(() => { describe('(returned parameters `decorators.args`)', () => { it('should be an empty array if param decorator has no `args` property', () => { loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', + bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters !.length).toBe(1); @@ -1579,10 +1589,10 @@ runInEachFileSystem(() => { it('should be an empty array if param decorator\'s `args` has no property assignment', () => { loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', + bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1594,10 +1604,10 @@ runInEachFileSystem(() => { it('should be an empty array if `args` property value is not an array literal', () => { loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]); - const {program} = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1613,11 +1623,11 @@ runInEachFileSystem(() => { it('should return an object describing the function declaration passed as an argument', () => { loadTestFiles([FUNCTION_BODY_FILE]); - const {program} = makeTestBundleProgram(FUNCTION_BODY_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(FUNCTION_BODY_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const fooNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !; const fooDef = host.getDefinitionOfFunction(fooNode) !; expect(fooDef.node).toBe(fooNode); expect(fooDef.body !.length).toEqual(1); @@ -1627,7 +1637,7 @@ runInEachFileSystem(() => { expect(fooDef.parameters[0].initializer).toBe(null); const barNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'bar', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'bar', isNamedFunctionDeclaration) !; const barDef = host.getDefinitionOfFunction(barNode) !; expect(barDef.node).toBe(barNode); expect(barDef.body !.length).toEqual(1); @@ -1640,7 +1650,7 @@ runInEachFileSystem(() => { expect(barDef.parameters[1].initializer !.getText()).toEqual('42'); const bazNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'baz', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'baz', isNamedFunctionDeclaration) !; const bazDef = host.getDefinitionOfFunction(bazNode) !; expect(bazDef.node).toBe(bazNode); expect(bazDef.body !.length).toEqual(3); @@ -1649,7 +1659,7 @@ runInEachFileSystem(() => { expect(bazDef.parameters[0].initializer).toBe(null); const quxNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'qux', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'qux', isNamedFunctionDeclaration) !; const quxDef = host.getDefinitionOfFunction(quxNode) !; expect(quxDef.node).toBe(quxNode); expect(quxDef.body !.length).toEqual(2); @@ -1664,10 +1674,11 @@ runInEachFileSystem(() => { contents: `export declare function __spread(...args: any[][]): any[];`, }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); - const node = getDeclaration(program, file.name, '__spread', isNamedFunctionDeclaration) !; + const node = + getDeclaration(bundle.program, file.name, '__spread', isNamedFunctionDeclaration) !; const definition = host.getDefinitionOfFunction(node) !; expect(definition.node).toBe(node); @@ -1686,10 +1697,11 @@ runInEachFileSystem(() => { };`, }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); - const node = getDeclaration(program, file.name, '__spread', ts.isVariableDeclaration) !; + const node = + getDeclaration(bundle.program, file.name, '__spread', ts.isVariableDeclaration) !; const definition = host.getDefinitionOfFunction(node) !; expect(definition.node).toBe(node); @@ -1709,11 +1721,11 @@ runInEachFileSystem(() => { };`, }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const node = - getDeclaration(program, file.name, '__spread$2', ts.isVariableDeclaration) !; + getDeclaration(bundle.program, file.name, '__spread$2', ts.isVariableDeclaration) !; const definition = host.getDefinitionOfFunction(node) !; expect(definition.node).toBe(node); @@ -1728,11 +1740,11 @@ runInEachFileSystem(() => { contents: `export declare function __spreadArrays(...args: any[][]): any[];`, }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); - const node = - getDeclaration(program, file.name, '__spreadArrays', isNamedFunctionDeclaration) !; + const node = getDeclaration( + bundle.program, file.name, '__spreadArrays', isNamedFunctionDeclaration) !; const definition = host.getDefinitionOfFunction(node) !; expect(definition.node).toBe(node); @@ -1754,11 +1766,11 @@ runInEachFileSystem(() => { };`, }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const node = - getDeclaration(program, file.name, '__spreadArrays', ts.isVariableDeclaration) !; + getDeclaration(bundle.program, file.name, '__spreadArrays', ts.isVariableDeclaration) !; const definition = host.getDefinitionOfFunction(node) !; expect(definition.node).toBe(node); @@ -1781,11 +1793,11 @@ runInEachFileSystem(() => { };`, }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); - const node = - getDeclaration(program, file.name, '__spreadArrays$2', ts.isVariableDeclaration) !; + const node = getDeclaration( + bundle.program, file.name, '__spreadArrays$2', ts.isVariableDeclaration) !; const definition = host.getDefinitionOfFunction(node) !; expect(definition.node).toBe(node); @@ -1798,9 +1810,10 @@ runInEachFileSystem(() => { describe('getImportOfIdentifier()', () => { it('should find the import of an identifier', () => { loadTestFiles(IMPORTS_FILES); - const {program} = makeTestBundleProgram(_('/index.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const variableNode = getDeclaration(program, _('/b.js'), 'b', isNamedVariableDeclaration); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const variableNode = + getDeclaration(bundle.program, _('/b.js'), 'b', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); expect(importOfIdent).toEqual({name: 'a', from: './a.js'}); @@ -1808,9 +1821,10 @@ runInEachFileSystem(() => { it('should find the name by which the identifier was exported, not imported', () => { loadTestFiles(IMPORTS_FILES); - const {program} = makeTestBundleProgram(_('/index.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const variableNode = getDeclaration(program, _('/b.js'), 'c', isNamedVariableDeclaration); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const variableNode = + getDeclaration(bundle.program, _('/b.js'), 'c', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); expect(importOfIdent).toEqual({name: 'a', from: './a.js'}); @@ -1818,9 +1832,10 @@ runInEachFileSystem(() => { it('should return null if the identifier was not imported', () => { loadTestFiles(IMPORTS_FILES); - const {program} = makeTestBundleProgram(_('/index.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const variableNode = getDeclaration(program, _('/b.js'), 'd', isNamedVariableDeclaration); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const variableNode = + getDeclaration(bundle.program, _('/b.js'), 'd', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); expect(importOfIdent).toBeNull(); @@ -1830,10 +1845,10 @@ runInEachFileSystem(() => { describe('getDeclarationOfIdentifier()', () => { it('should return the declaration of a locally defined identifier', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const ctrDecorators = host.getConstructorParameters(classNode) !; const identifierOfViewContainerRef = (ctrDecorators[0].typeValueReference !as{ local: true, @@ -1842,7 +1857,8 @@ runInEachFileSystem(() => { }).expression; const expectedDeclarationNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'ViewContainerRef', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'ViewContainerRef', + isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfViewContainerRef); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -1852,17 +1868,17 @@ runInEachFileSystem(() => { it('should return the declaration of an externally defined identifier', () => { loadFakeCore(getFileSystem()); loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + 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) .initializer as ts.Identifier; const expectedDeclarationNode = getDeclaration( - program, _('/node_modules/@angular/core/index.d.ts'), 'Directive', + bundle.program, _('/node_modules/@angular/core/index.d.ts'), 'Directive', isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective); expect(actualDeclaration).not.toBe(null); @@ -1873,10 +1889,11 @@ runInEachFileSystem(() => { it('should return the source-file of an import namespace', () => { loadFakeCore(getFileSystem()); loadTestFiles([NAMESPACED_IMPORT_FILE]); - const {program} = makeTestBundleProgram(NAMESPACED_IMPORT_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(NAMESPACED_IMPORT_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, NAMESPACED_IMPORT_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + 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) @@ -1884,7 +1901,7 @@ runInEachFileSystem(() => { .expression as ts.Identifier; const expectedDeclarationNode = - getSourceFileOrError(program, _('/node_modules/@angular/core/index.d.ts')); + getSourceFileOrError(bundle.program, _('/node_modules/@angular/core/index.d.ts')); const actualDeclaration = host.getDeclarationOfIdentifier(identifier); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -1897,11 +1914,11 @@ runInEachFileSystem(() => { spyOn(Esm2015ReflectionHost.prototype, 'getDeclarationOfIdentifier') .and.callThrough(); loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const outerDeclaration = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerDeclaration = (((outerDeclaration.initializer as ts.ParenthesizedExpression) .expression as ts.CallExpression) .expression as ts.FunctionExpression) @@ -1951,11 +1968,11 @@ runInEachFileSystem(() => { }; loadTestFiles([PROGRAM_FILE]); - const {program} = makeTestBundleProgram(PROGRAM_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(PROGRAM_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const expectedDeclaration = getDeclaration( - program, PROGRAM_FILE.name, 'FroalaEditorModule', isNamedVariableDeclaration); + 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) @@ -1976,9 +1993,9 @@ runInEachFileSystem(() => { it('should return a map of all the exports from a given module', () => { loadFakeCore(getFileSystem()); loadTestFiles(EXPORTS_FILES); - const {program} = makeTestBundleProgram(_('/index.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const file = getSourceFileOrError(program, _('/b.js')); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const file = getSourceFileOrError(bundle.program, _('/b.js')); const exportDeclarations = host.getExportsOfModule(file); expect(exportDeclarations).not.toBe(null); expect(Array.from(exportDeclarations !.keys())).toEqual([ @@ -2017,10 +2034,10 @@ runInEachFileSystem(() => { describe('getClassSymbol()', () => { it('should return the class symbol for an ES2015 class', () => { loadTestFiles([SIMPLE_ES2015_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const node = getDeclaration( - program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); + bundle.program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const classSymbol = host.getClassSymbol(node); expect(classSymbol).toBeDefined(); @@ -2030,10 +2047,10 @@ runInEachFileSystem(() => { it('should return the class symbol for an ES5 class (outer variable declaration)', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const classSymbol = host.getClassSymbol(outerNode); @@ -2044,10 +2061,10 @@ runInEachFileSystem(() => { it('should return the class symbol for an ES5 class (inner function declaration)', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const classSymbol = host.getClassSymbol(innerNode); @@ -2059,10 +2076,10 @@ runInEachFileSystem(() => { it('should return the same class symbol (of the outer declaration) for outer and inner declarations', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const innerSymbol = host.getClassSymbol(innerNode) !; @@ -2074,10 +2091,10 @@ runInEachFileSystem(() => { it('should return the class symbol for an ES5 class whose IIFE is not wrapped in parens', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'NoParensClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'NoParensClass', isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const classSymbol = host.getClassSymbol(outerNode); @@ -2089,10 +2106,11 @@ runInEachFileSystem(() => { it('should return the class symbol for an ES5 class whose IIFE is not wrapped with inner parens', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'InnerParensClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'InnerParensClass', + isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const classSymbol = host.getClassSymbol(outerNode); @@ -2103,10 +2121,10 @@ runInEachFileSystem(() => { it('should return undefined if node is not an ES5 class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const node = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); const classSymbol = host.getClassSymbol(node); expect(classSymbol).toBeUndefined(); @@ -2118,9 +2136,10 @@ runInEachFileSystem(() => { contents: `var MyClass = null;`, }; loadTestFiles([testFile]); - const {program} = makeTestBundleProgram(testFile.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const node = getDeclaration(program, testFile.name, 'MyClass', isNamedVariableDeclaration); + const bundle = makeTestBundleProgram(testFile.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const node = + getDeclaration(bundle.program, testFile.name, 'MyClass', isNamedVariableDeclaration); const classSymbol = host.getClassSymbol(node); expect(classSymbol).toBeUndefined(); @@ -2130,38 +2149,38 @@ runInEachFileSystem(() => { describe('isClass()', () => { it('should return true if a given node is a TS class declaration', () => { loadTestFiles([SIMPLE_ES2015_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const node = getDeclaration( - program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); + bundle.program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); expect(host.isClass(node)).toBe(true); }); it('should return true if a given node is the outer variable declaration of a class', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const node = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); expect(host.isClass(node)).toBe(true); }); it('should return true if a given node is the inner variable declaration of a class', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const outerNode = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = 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) !; expect(host.isClass(innerNode)).toBe(true); }); it('should return false if a given node is a function declaration', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const node = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(host.isClass(node)).toBe(false); }); }); @@ -2174,10 +2193,10 @@ runInEachFileSystem(() => { }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration); return host.hasBaseClass(classNode); } @@ -2221,10 +2240,10 @@ runInEachFileSystem(() => { }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration); const expression = host.getBaseClassExpression(classNode); if (expression !== null && !ts.isIdentifier(expression)) { throw new Error( @@ -2293,10 +2312,10 @@ runInEachFileSystem(() => { }; loadTestFiles([file]); - const {program} = makeTestBundleProgram(file.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(file.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration); const expression = host.getBaseClassExpression(classNode) !; expect(expression.getText()).toBe('foo()'); }); @@ -2305,10 +2324,10 @@ runInEachFileSystem(() => { describe('findClassSymbols()', () => { it('should return an array of all classes in the given source file', () => { loadTestFiles(DECORATED_FILES); - const {program} = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const primaryFile = getSourceFileOrError(program, DECORATED_FILES[0].name); - const secondaryFile = getSourceFileOrError(program, DECORATED_FILES[1].name); + const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name); + const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name); const classSymbolsPrimary = host.findClassSymbols(primaryFile); expect(classSymbolsPrimary.length).toEqual(2); @@ -2323,10 +2342,10 @@ runInEachFileSystem(() => { describe('getDecoratorsOfSymbol()', () => { it('should return decorators of class symbol', () => { loadTestFiles(DECORATED_FILES); - const {program} = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const primaryFile = getSourceFileOrError(program, DECORATED_FILES[0].name); - const secondaryFile = getSourceFileOrError(program, DECORATED_FILES[1].name); + const bundle = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name); + const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name); const classSymbolsPrimary = host.findClassSymbols(primaryFile); const classDecoratorsPrimary = classSymbolsPrimary.map(s => host.getDecoratorsOfSymbol(s)); @@ -2347,12 +2366,11 @@ runInEachFileSystem(() => { () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); - const class1 = - getDeclaration(program, _('/src/class1.js'), 'Class1', ts.isVariableDeclaration); - const host = - new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + const class1 = getDeclaration( + bundle.program, _('/src/class1.js'), 'Class1', ts.isVariableDeclaration); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(class1); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/class1.d.ts')); @@ -2361,11 +2379,11 @@ runInEachFileSystem(() => { it('should find the dts declaration for exported functions', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); const mooFn = - getDeclaration(program, _('/src/func1.js'), 'mooFn', ts.isFunctionDeclaration); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + getDeclaration(bundle.program, _('/src/func1.js'), 'mooFn', ts.isFunctionDeclaration); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(mooFn); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/func1.d.ts')); @@ -2374,11 +2392,11 @@ runInEachFileSystem(() => { it('should return null if there is no matching class in the matching dts file', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); - const missingClass = - getDeclaration(program, _('/src/class1.js'), 'MissingClass1', ts.isVariableDeclaration); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + const missingClass = getDeclaration( + bundle.program, _('/src/class1.js'), 'MissingClass1', ts.isVariableDeclaration); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); }); @@ -2386,11 +2404,11 @@ runInEachFileSystem(() => { it('should return null if there is no matching dts file', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); const missingClass = getDeclaration( - program, _('/src/missing-class.js'), 'MissingClass2', ts.isVariableDeclaration); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + bundle.program, _('/src/missing-class.js'), 'MissingClass2', ts.isVariableDeclaration); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); }); @@ -2399,12 +2417,11 @@ runInEachFileSystem(() => { () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); - const class1 = - getDeclaration(program, _('/src/flat-file.js'), 'Class1', ts.isVariableDeclaration); - const host = - new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + const class1 = getDeclaration( + bundle.program, _('/src/flat-file.js'), 'Class1', ts.isVariableDeclaration); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(class1); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/class1.d.ts')); @@ -2413,11 +2430,11 @@ runInEachFileSystem(() => { it('should find aliased exports', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); - const class3 = - getDeclaration(program, _('/src/flat-file.js'), 'Class3', ts.isVariableDeclaration); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + const class3 = getDeclaration( + bundle.program, _('/src/flat-file.js'), 'Class3', ts.isVariableDeclaration); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(class3); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/class3.d.ts')); @@ -2427,12 +2444,11 @@ runInEachFileSystem(() => { () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); const internalClass = getDeclaration( - program, _('/src/internal.js'), 'InternalClass', ts.isVariableDeclaration); - const host = - new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + bundle.program, _('/src/internal.js'), 'InternalClass', ts.isVariableDeclaration); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(internalClass); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/internal.d.ts')); @@ -2442,14 +2458,13 @@ runInEachFileSystem(() => { () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program} = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); + const bundle = makeTestBundleProgram(getRootFiles(TYPINGS_SRC_FILES)[0]); const dts = makeTestBundleProgram(getRootFiles(TYPINGS_DTS_FILES)[0]); - const class2 = - getDeclaration(program, _('/src/class2.js'), 'Class2', ts.isVariableDeclaration); - const internalClass2 = - getDeclaration(program, _('/src/internal.js'), 'Class2', ts.isVariableDeclaration); - const host = - new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); + const class2 = getDeclaration( + bundle.program, _('/src/class2.js'), 'Class2', ts.isVariableDeclaration); + const internalClass2 = getDeclaration( + bundle.program, _('/src/internal.js'), 'Class2', ts.isVariableDeclaration); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle, dts); const class2DtsDeclaration = host.getDtsDeclaration(class2); expect(class2DtsDeclaration !.getSourceFile().fileName) @@ -2464,23 +2479,23 @@ runInEachFileSystem(() => { describe('getInternalNameOfClass()', () => { it('should return the name of the inner class declaration', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const emptyClass = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); expect(host.getInternalNameOfClass(emptyClass).text).toEqual('EmptyClass'); const class1 = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'OuterClass1', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'OuterClass1', isNamedVariableDeclaration); expect(host.getInternalNameOfClass(class1).text).toEqual('InnerClass1'); const class2 = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'OuterClass2', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'OuterClass2', isNamedVariableDeclaration); expect(host.getInternalNameOfClass(class2).text).toEqual('InnerClass2'); const childClass = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'ChildClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'ChildClass', isNamedVariableDeclaration); expect(host.getInternalNameOfClass(childClass).text).toEqual('InnerChildClass'); }); }); @@ -2488,23 +2503,23 @@ runInEachFileSystem(() => { describe('getAdjacentNameOfClass()', () => { it('should return the name of the inner class declaration', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const emptyClass = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); expect(host.getAdjacentNameOfClass(emptyClass).text).toEqual('EmptyClass'); const class1 = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'OuterClass1', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'OuterClass1', isNamedVariableDeclaration); expect(host.getAdjacentNameOfClass(class1).text).toEqual('InnerClass1'); const class2 = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'OuterClass2', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'OuterClass2', isNamedVariableDeclaration); expect(host.getAdjacentNameOfClass(class2).text).toEqual('InnerClass2'); const childClass = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'ChildClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'ChildClass', isNamedVariableDeclaration); expect(host.getAdjacentNameOfClass(childClass).text).toEqual('InnerChildClass'); }); }); @@ -2513,9 +2528,9 @@ runInEachFileSystem(() => { it('should find every exported function that returns an object that looks like a ModuleWithProviders object', () => { loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM); - const {program} = makeTestBundleProgram(_('/src/index.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const file = getSourceFileOrError(program, _('/src/functions.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); + const host = 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])) .toEqual([ @@ -2530,9 +2545,9 @@ runInEachFileSystem(() => { it('should find every static method on exported classes that return an object that looks like a ModuleWithProviders object', () => { loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM); - const {program} = makeTestBundleProgram(_('/src/index.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const file = getSourceFileOrError(program, _('/src/methods.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); + const host = 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([ [ @@ -2561,9 +2576,9 @@ runInEachFileSystem(() => { // https://github.com/angular/angular/issues/29078 it('should resolve aliased module references to their original declaration', () => { loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM); - const {program} = makeTestBundleProgram(_('/src/index.js')); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); - const file = getSourceFileOrError(program, _('/src/aliased_class.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); + const file = getSourceFileOrError(bundle.program, _('/src/aliased_class.js')); const fn = host.getModuleWithProvidersFunctions(file); expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.node.name.text])).toEqual([ ['function() { return { ngModule: AliasedModule_1 }; }', 'AliasedModule'], @@ -2574,10 +2589,10 @@ runInEachFileSystem(() => { describe('getEndOfClass()', () => { it('should return the last static property of the class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new Esm5ReflectionHost(new MockLogger(), false, bundle); const classSymbol = - host.findClassSymbols(program.getSourceFile(SOME_DIRECTIVE_FILE.name) !)[0]; + host.findClassSymbols(bundle.program.getSourceFile(SOME_DIRECTIVE_FILE.name) !)[0]; const endOfClass = host.getEndOfClass(classSymbol); expect(endOfClass.getText()).toEqual(`SomeDirective.propDecorators = { "input1": [{ type: Input },], diff --git a/packages/compiler-cli/ngcc/test/host/umd_host_import_helper_spec.ts b/packages/compiler-cli/ngcc/test/host/umd_host_import_helper_spec.ts index 9f6753844f..35929b4f71 100644 --- a/packages/compiler-cli/ngcc/test/host/umd_host_import_helper_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/umd_host_import_helper_spec.ts @@ -77,10 +77,10 @@ runInEachFileSystem(() => { describe('getDecoratorsOfDeclaration()', () => { it('should find the decorators on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -97,10 +97,11 @@ runInEachFileSystem(() => { it('should find the decorators on an aliased class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'AliasedDirective$1', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'AliasedDirective$1', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -119,10 +120,10 @@ runInEachFileSystem(() => { describe('getMembersOfClass()', () => { it('should find decorated members on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -139,10 +140,11 @@ runInEachFileSystem(() => { describe('getConstructorParameters', () => { it('should find the decorated constructor parameters', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBeDefined(); diff --git a/packages/compiler-cli/ngcc/test/host/umd_host_spec.ts b/packages/compiler-cli/ngcc/test/host/umd_host_spec.ts index fc56466ba0..66a59ac8dc 100644 --- a/packages/compiler-cli/ngcc/test/host/umd_host_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/umd_host_spec.ts @@ -982,10 +982,10 @@ runInEachFileSystem(() => { describe('getDecoratorsOfDeclaration()', () => { it('should find the decorators on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -1001,10 +1001,11 @@ runInEachFileSystem(() => { it('should find the decorators on a class at the top level', () => { loadTestFiles([TOPLEVEL_DECORATORS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -1020,40 +1021,42 @@ runInEachFileSystem(() => { it('should return null if the symbol is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); + const functionNode = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); const decorators = host.getDecoratorsOfDeclaration(functionNode); expect(decorators).toBe(null); }); it('should return null if there are no decorators', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); expect(decorators).toBe(null); }); it('should ignore `decorators` if it is not an array literal', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); expect(decorators).toEqual([]); }); it('should ignore decorator elements that are not object literals', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -1062,10 +1065,11 @@ runInEachFileSystem(() => { it('should ignore decorator elements that have no `type` property', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -1074,10 +1078,11 @@ runInEachFileSystem(() => { it('should ignore decorator elements whose `type` value is not an identifier', () => { loadTestFiles([INVALID_DECORATORS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration); + bundle.program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -1086,11 +1091,11 @@ runInEachFileSystem(() => { it('should have import information on decorators', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toEqual(1); @@ -1099,10 +1104,11 @@ runInEachFileSystem(() => { it('should find decorated members on a class at the top level', () => { loadTestFiles([TOPLEVEL_DECORATORS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -1119,11 +1125,10 @@ runInEachFileSystem(() => { describe('(returned decorators `args`)', () => { it('should be an empty array if decorator has no `args` property', () => { loadTestFiles([INVALID_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', + bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -1134,11 +1139,10 @@ runInEachFileSystem(() => { it('should be an empty array if decorator\'s `args` has no property assignment', () => { loadTestFiles([INVALID_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', + bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -1149,11 +1153,10 @@ runInEachFileSystem(() => { it('should be an empty array if `args` property value is not an array literal', () => { loadTestFiles([INVALID_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_DECORATOR_ARGS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -1167,10 +1170,10 @@ runInEachFileSystem(() => { describe('getMembersOfClass()', () => { it('should find decorated members on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -1186,10 +1189,10 @@ runInEachFileSystem(() => { it('should find non decorated properties on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const instanceProperty = members.find(member => member.name === 'instanceProperty') !; @@ -1201,10 +1204,10 @@ runInEachFileSystem(() => { it('should find static methods on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticMethod = members.find(member => member.name === 'staticMethod') !; @@ -1215,10 +1218,10 @@ runInEachFileSystem(() => { it('should find static properties on a class', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticProperty = members.find(member => member.name === 'staticProperty') !; @@ -1230,10 +1233,10 @@ runInEachFileSystem(() => { it('should throw if the symbol is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); + const functionNode = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getMembersOfClass(functionNode); }).toThrowError(`Attempted to get members of a non-class: "function foo() {}"`); @@ -1241,10 +1244,10 @@ runInEachFileSystem(() => { it('should return an empty array if there are no prop decorators', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); expect(members).toEqual([]); @@ -1253,11 +1256,10 @@ runInEachFileSystem(() => { it('should not process decorated properties in `propDecorators` if it is not an object literal', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral', + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -1266,11 +1268,10 @@ runInEachFileSystem(() => { it('should ignore prop decorator elements that are not object literals', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp', + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1282,11 +1283,10 @@ runInEachFileSystem(() => { it('should ignore prop decorator elements that have no `type` property', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1299,11 +1299,11 @@ runInEachFileSystem(() => { it('should ignore prop decorator elements whose `type` value is not an identifier', () => { loadTestFiles([INVALID_PROP_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration); + bundle.program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; const decorators = prop.decorators !; @@ -1314,11 +1314,11 @@ runInEachFileSystem(() => { it('should have import information on decorators', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toEqual(1); @@ -1328,11 +1328,10 @@ runInEachFileSystem(() => { describe('(returned prop decorators `args`)', () => { it('should be an empty array if prop decorator has no `args` property', () => { loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', + bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1345,11 +1344,10 @@ runInEachFileSystem(() => { it('should be an empty array if prop decorator\'s `args` has no property assignment', () => { loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', + bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1362,11 +1360,10 @@ runInEachFileSystem(() => { it('should be an empty array if `args` property value is not an array literal', () => { loadTestFiles([INVALID_PROP_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_PROP_DECORATOR_ARGS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; @@ -1381,10 +1378,10 @@ runInEachFileSystem(() => { describe('getConstructorParameters', () => { it('should find the decorated constructor parameters', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBeDefined(); @@ -1400,10 +1397,11 @@ runInEachFileSystem(() => { it('should find the decorated constructor parameters at the top level', () => { loadTestFiles([TOPLEVEL_DECORATORS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(TOPLEVEL_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBeDefined(); @@ -1419,11 +1417,10 @@ runInEachFileSystem(() => { it('should accept `ctorParameters` as an array', () => { loadTestFiles([CTOR_DECORATORS_ARRAY_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(CTOR_DECORATORS_ARRAY_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(CTOR_DECORATORS_ARRAY_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, CTOR_DECORATORS_ARRAY_FILE.name, 'CtorDecoratedAsArray', + bundle.program, CTOR_DECORATORS_ARRAY_FILE.name, 'CtorDecoratedAsArray', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode) !; @@ -1434,10 +1431,10 @@ runInEachFileSystem(() => { it('should throw if the symbol is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); + const functionNode = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getConstructorParameters(functionNode); }) .toThrowError( 'Attempted to get constructor parameters of a non-class: "function foo() {}"'); @@ -1448,10 +1445,10 @@ runInEachFileSystem(() => { it('should return an array even if there are no decorators', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', + bundle.program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1463,11 +1460,11 @@ runInEachFileSystem(() => { it('should return an empty array if there are no constructor parameters', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', isNamedVariableDeclaration); + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toEqual([]); @@ -1478,11 +1475,10 @@ runInEachFileSystem(() => { it('should ignore `ctorParameters` if it does not return an array literal', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1496,11 +1492,10 @@ runInEachFileSystem(() => { describe('(returned parameters `decorators`)', () => { it('should ignore param decorator elements that are not object literals', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1517,11 +1512,10 @@ runInEachFileSystem(() => { it('should ignore param decorator elements that have no `type` property', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1532,11 +1526,10 @@ runInEachFileSystem(() => { it('should ignore param decorator elements whose `type` value is not an identifier', () => { loadTestFiles([INVALID_CTOR_DECORATORS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATORS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', + bundle.program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1547,10 +1540,11 @@ runInEachFileSystem(() => { it('should use `getImportOfIdentifier()` to retrieve import info', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', + isNamedVariableDeclaration); const mockImportInfo: Import = {from: '@angular/core', name: 'Directive'}; const spy = spyOn(UmdReflectionHost.prototype, 'getImportOfIdentifier') .and.returnValue(mockImportInfo); @@ -1566,11 +1560,10 @@ runInEachFileSystem(() => { describe('(returned parameters `decorators.args`)', () => { it('should be an empty array if param decorator has no `args` property', () => { loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', + bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters !.length).toBe(1); @@ -1584,11 +1577,10 @@ runInEachFileSystem(() => { it('should be an empty array if param decorator\'s `args` has no property assignment', () => { loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', + bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1600,11 +1592,10 @@ runInEachFileSystem(() => { it('should be an empty array if `args` property value is not an array literal', () => { loadTestFiles([INVALID_CTOR_DECORATOR_ARGS_FILE]); - const {program, host: compilerHost} = - makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(INVALID_CTOR_DECORATOR_ARGS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', + bundle.program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1620,11 +1611,11 @@ runInEachFileSystem(() => { it('should return an object describing the function declaration passed as an argument', () => { loadTestFiles([FUNCTION_BODY_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(FUNCTION_BODY_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(FUNCTION_BODY_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const fooNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !; const fooDef = host.getDefinitionOfFunction(fooNode) !; expect(fooDef.node).toBe(fooNode); expect(fooDef.body !.length).toEqual(1); @@ -1634,7 +1625,7 @@ runInEachFileSystem(() => { expect(fooDef.parameters[0].initializer).toBe(null); const barNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'bar', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'bar', isNamedFunctionDeclaration) !; const barDef = host.getDefinitionOfFunction(barNode) !; expect(barDef.node).toBe(barNode); expect(barDef.body !.length).toEqual(1); @@ -1647,7 +1638,7 @@ runInEachFileSystem(() => { expect(barDef.parameters[1].initializer !.getText()).toEqual('42'); const bazNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'baz', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'baz', isNamedFunctionDeclaration) !; const bazDef = host.getDefinitionOfFunction(bazNode) !; expect(bazDef.node).toBe(bazNode); expect(bazDef.body !.length).toEqual(3); @@ -1656,7 +1647,7 @@ runInEachFileSystem(() => { expect(bazDef.parameters[0].initializer).toBe(null); const quxNode = getDeclaration( - program, FUNCTION_BODY_FILE.name, 'qux', isNamedFunctionDeclaration) !; + bundle.program, FUNCTION_BODY_FILE.name, 'qux', isNamedFunctionDeclaration) !; const quxDef = host.getDefinitionOfFunction(quxNode) !; expect(quxDef.node).toBe(quxNode); expect(quxDef.body !.length).toEqual(2); @@ -1669,10 +1660,10 @@ runInEachFileSystem(() => { describe('getImportOfIdentifier', () => { it('should find the import of an identifier', () => { loadTestFiles(IMPORTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/index.js')); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const variableNode = - getDeclaration(program, _('/file_b.js'), 'b', isNamedVariableDeclaration); + getDeclaration(bundle.program, _('/file_b.js'), 'b', isNamedVariableDeclaration); const identifier = (variableNode.initializer && ts.isPropertyAccessExpression(variableNode.initializer)) ? variableNode.initializer.name : @@ -1696,10 +1687,10 @@ runInEachFileSystem(() => { contents: `export declare class MyClass {}`, } ]); - const {program, host: compilerHost} = makeTestBundleProgram(_('/index.d.ts')); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(_('/index.d.ts')); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const variableNode = - getDeclaration(program, _('/index.d.ts'), 'a', isNamedVariableDeclaration); + getDeclaration(bundle.program, _('/index.d.ts'), 'a', isNamedVariableDeclaration); const identifier = ((variableNode.type as ts.TypeReferenceNode).typeName as ts.Identifier); const importOfIdent = host.getImportOfIdentifier(identifier !); @@ -1708,10 +1699,10 @@ runInEachFileSystem(() => { it('should return null if the identifier was not imported', () => { loadTestFiles(IMPORTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/index.js')); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const variableNode = - getDeclaration(program, _('/file_b.js'), 'd', isNamedVariableDeclaration); + getDeclaration(bundle.program, _('/file_b.js'), 'd', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); expect(importOfIdent).toBeNull(); @@ -1719,10 +1710,10 @@ runInEachFileSystem(() => { it('should handle factory functions not wrapped in parentheses', () => { loadTestFiles(IMPORTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/index.js')); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const variableNode = - getDeclaration(program, _('/file_c.js'), 'c', isNamedVariableDeclaration); + getDeclaration(bundle.program, _('/file_c.js'), 'c', isNamedVariableDeclaration); const identifier = (variableNode.initializer && ts.isPropertyAccessExpression(variableNode.initializer)) ? variableNode.initializer.name : @@ -1737,10 +1728,10 @@ runInEachFileSystem(() => { describe('getDeclarationOfIdentifier', () => { it('should return the declaration of a locally defined identifier', () => { loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const ctrDecorators = host.getConstructorParameters(classNode) !; const identifierOfViewContainerRef = (ctrDecorators[0].typeValueReference !as{ local: true, @@ -1749,7 +1740,8 @@ runInEachFileSystem(() => { }).expression; const expectedDeclarationNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'ViewContainerRef', isNamedVariableDeclaration); + bundle.program, SOME_DIRECTIVE_FILE.name, 'ViewContainerRef', + isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfViewContainerRef); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -1759,10 +1751,10 @@ runInEachFileSystem(() => { it('should return the source-file of an import namespace', () => { loadFakeCore(getFileSystem()); loadTestFiles([SOME_DIRECTIVE_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SOME_DIRECTIVE_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); + 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) @@ -1770,7 +1762,7 @@ runInEachFileSystem(() => { .expression as ts.Identifier; const expectedDeclarationNode = - getSourceFileOrError(program, _('/node_modules/@angular/core/index.d.ts')); + getSourceFileOrError(bundle.program, _('/node_modules/@angular/core/index.d.ts')); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -1798,11 +1790,11 @@ runInEachFileSystem(() => { } ]; loadTestFiles(FILES); - const {program, host: compilerHost} = makeTestBundleProgram(FILES[0].name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(FILES[0].name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const expectedDeclaration = - getDeclaration(program, FILES[2].name, 'SubModule', isNamedClassDeclaration); - const x = getDeclaration(program, FILES[0].name, 'x', isNamedVariableDeclaration); + getDeclaration(bundle.program, FILES[2].name, 'SubModule', isNamedClassDeclaration); + const x = getDeclaration(bundle.program, FILES[0].name, 'x', isNamedVariableDeclaration); if (x.initializer === undefined || !ts.isIdentifier(x.initializer)) { return fail('Expected constant `x` to have an identifer as an initializer.'); } @@ -1819,9 +1811,9 @@ runInEachFileSystem(() => { it('should return a map of all the exports from a given module', () => { loadFakeCore(getFileSystem()); loadTestFiles(EXPORTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/index.js')); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const file = getSourceFileOrError(program, _('/b_module.js')); + const bundle = makeTestBundleProgram(_('/index.js')); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); + const file = getSourceFileOrError(bundle.program, _('/b_module.js')); const exportDeclarations = host.getExportsOfModule(file); expect(exportDeclarations).not.toBe(null); expect(Array.from(exportDeclarations !.entries()) @@ -1859,10 +1851,10 @@ runInEachFileSystem(() => { describe('getClassSymbol()', () => { it('should return the class symbol for an ES2015 class', () => { loadTestFiles([SIMPLE_ES2015_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const node = getDeclaration( - program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); + bundle.program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const classSymbol = host.getClassSymbol(node); expect(classSymbol).toBeDefined(); @@ -1872,10 +1864,10 @@ runInEachFileSystem(() => { it('should return the class symbol for an ES5 class (outer variable declaration)', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const classSymbol = host.getClassSymbol(outerNode); @@ -1886,10 +1878,10 @@ runInEachFileSystem(() => { it('should return the class symbol for an ES5 class (inner function declaration)', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const classSymbol = host.getClassSymbol(innerNode); @@ -1901,10 +1893,10 @@ runInEachFileSystem(() => { it('should return the same class symbol (of the outer declaration) for outer and inner declarations', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const innerSymbol = host.getClassSymbol(innerNode) !; @@ -1916,10 +1908,10 @@ runInEachFileSystem(() => { it('should return the class symbol for an ES5 class whose IIFE is not wrapped in parens', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'NoParensClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'NoParensClass', isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const classSymbol = host.getClassSymbol(outerNode); @@ -1931,10 +1923,11 @@ runInEachFileSystem(() => { it('should return the class symbol for an ES5 class whose IIFE is not wrapped with inner parens', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'InnerParensClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'InnerParensClass', + isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; const classSymbol = host.getClassSymbol(outerNode); @@ -1945,10 +1938,10 @@ runInEachFileSystem(() => { it('should return undefined if node is not an ES5 class', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const node = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); const classSymbol = host.getClassSymbol(node); expect(classSymbol).toBeUndefined(); @@ -1960,9 +1953,10 @@ runInEachFileSystem(() => { contents: `var MyClass = null;`, }; loadTestFiles([testFile]); - const {program, host: compilerHost} = makeTestBundleProgram(testFile.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const node = getDeclaration(program, testFile.name, 'MyClass', isNamedVariableDeclaration); + const bundle = makeTestBundleProgram(testFile.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); + const node = + getDeclaration(bundle.program, testFile.name, 'MyClass', isNamedVariableDeclaration); const classSymbol = host.getClassSymbol(node); expect(classSymbol).toBeUndefined(); @@ -1972,38 +1966,38 @@ runInEachFileSystem(() => { describe('isClass()', () => { it('should return true if a given node is a TS class declaration', () => { loadTestFiles([SIMPLE_ES2015_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const node = getDeclaration( - program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); + bundle.program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); expect(host.isClass(node)).toBe(true); }); it('should return true if a given node is the outer variable declaration of a class', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const node = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); expect(host.isClass(node)).toBe(true); }); it('should return true if a given node is the inner variable declaration of a class', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const outerNode = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = 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) !; expect(host.isClass(innerNode)).toBe(true); }); it('should return false if a given node is a function declaration', () => { loadTestFiles([FOO_FUNCTION_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(FOO_FUNCTION_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const node = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); + const bundle = makeTestBundleProgram(FOO_FUNCTION_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); + const node = getDeclaration( + bundle.program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(host.isClass(node)).toBe(false); }); }); @@ -2016,10 +2010,10 @@ runInEachFileSystem(() => { }; loadTestFiles([file]); - const {program, host: compilerHost} = makeTestBundleProgram(file.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(file.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration); return host.hasBaseClass(classNode); } @@ -2063,10 +2057,10 @@ runInEachFileSystem(() => { }; loadTestFiles([file]); - const {program, host: compilerHost} = makeTestBundleProgram(file.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(file.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration); const expression = host.getBaseClassExpression(classNode); if (expression !== null && !ts.isIdentifier(expression)) { throw new Error( @@ -2135,10 +2129,10 @@ runInEachFileSystem(() => { }; loadTestFiles([file]); - const {program, host: compilerHost} = makeTestBundleProgram(file.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(file.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const classNode = - getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); + getDeclaration(bundle.program, file.name, 'TestClass', isNamedVariableDeclaration); const expression = host.getBaseClassExpression(classNode) !; expect(expression.getText()).toBe('foo()'); }); @@ -2147,10 +2141,10 @@ runInEachFileSystem(() => { describe('findClassSymbols()', () => { it('should return an array of all classes in the given source file', () => { loadTestFiles(DECORATED_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(DECORATED_FILES[0].name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const primaryFile = getSourceFileOrError(program, DECORATED_FILES[0].name); - const secondaryFile = getSourceFileOrError(program, DECORATED_FILES[1].name); + const bundle = makeTestBundleProgram(DECORATED_FILES[0].name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); + const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name); + const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name); const classSymbolsPrimary = host.findClassSymbols(primaryFile); expect(classSymbolsPrimary.length).toEqual(2); @@ -2165,10 +2159,10 @@ runInEachFileSystem(() => { describe('getDecoratorsOfSymbol()', () => { it('should return decorators of class symbol', () => { loadTestFiles(DECORATED_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(DECORATED_FILES[0].name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const primaryFile = getSourceFileOrError(program, DECORATED_FILES[0].name); - const secondaryFile = getSourceFileOrError(program, DECORATED_FILES[1].name); + const bundle = makeTestBundleProgram(DECORATED_FILES[0].name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); + const primaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[0].name); + const secondaryFile = getSourceFileOrError(bundle.program, DECORATED_FILES[1].name); const classSymbolsPrimary = host.findClassSymbols(primaryFile); const classDecoratorsPrimary = classSymbolsPrimary.map(s => host.getDecoratorsOfSymbol(s)); @@ -2189,11 +2183,11 @@ runInEachFileSystem(() => { () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestBundleProgram(_('/typings/index.d.ts')); - const class1 = - getDeclaration(program, _('/src/class1.js'), 'Class1', ts.isVariableDeclaration); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts); + const class1 = getDeclaration( + bundle.program, _('/src/class1.js'), 'Class1', ts.isVariableDeclaration); + const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(class1); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/class1.d.ts')); @@ -2202,11 +2196,11 @@ runInEachFileSystem(() => { it('should find the dts declaration for exported functions', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestBundleProgram(_('/typings/index.d.ts')); const mooFn = - getDeclaration(program, _('/src/func1.js'), 'mooFn', ts.isFunctionDeclaration); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts); + getDeclaration(bundle.program, _('/src/func1.js'), 'mooFn', ts.isFunctionDeclaration); + const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(mooFn); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/func1.d.ts')); @@ -2215,11 +2209,11 @@ runInEachFileSystem(() => { it('should return null if there is no matching class in the matching dts file', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestBundleProgram(_('/typings/index.d.ts')); - const missingClass = - getDeclaration(program, _('/src/class1.js'), 'MissingClass1', ts.isVariableDeclaration); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts); + const missingClass = getDeclaration( + bundle.program, _('/src/class1.js'), 'MissingClass1', ts.isVariableDeclaration); + const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); }); @@ -2227,11 +2221,11 @@ runInEachFileSystem(() => { it('should return null if there is no matching dts file', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestBundleProgram(_('/typings/index.d.ts')); const missingClass = getDeclaration( - program, _('/src/missing-class.js'), 'MissingClass2', ts.isVariableDeclaration); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts); + bundle.program, _('/src/missing-class.js'), 'MissingClass2', ts.isVariableDeclaration); + const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); }); @@ -2240,11 +2234,11 @@ runInEachFileSystem(() => { () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestBundleProgram(_('/typings/index.d.ts')); - const class1 = - getDeclaration(program, _('/src/flat-file.js'), 'Class1', ts.isVariableDeclaration); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts); + const class1 = getDeclaration( + bundle.program, _('/src/flat-file.js'), 'Class1', ts.isVariableDeclaration); + const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(class1); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/class1.d.ts')); @@ -2253,11 +2247,11 @@ runInEachFileSystem(() => { it('should find aliased exports', () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestBundleProgram(_('/typings/index.d.ts')); - const class3 = - getDeclaration(program, _('/src/flat-file.js'), 'Class3', ts.isVariableDeclaration); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts); + const class3 = getDeclaration( + bundle.program, _('/src/flat-file.js'), 'Class3', ts.isVariableDeclaration); + const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(class3); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/class3.d.ts')); @@ -2267,11 +2261,11 @@ runInEachFileSystem(() => { () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestBundleProgram(_('/typings/index.d.ts')); const internalClass = getDeclaration( - program, _('/src/internal.js'), 'InternalClass', ts.isVariableDeclaration); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts); + bundle.program, _('/src/internal.js'), 'InternalClass', ts.isVariableDeclaration); + const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts); const dtsDeclaration = host.getDtsDeclaration(internalClass); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/internal.d.ts')); @@ -2281,13 +2275,13 @@ runInEachFileSystem(() => { () => { loadTestFiles(TYPINGS_SRC_FILES); loadTestFiles(TYPINGS_DTS_FILES); - const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); + const bundle = makeTestBundleProgram(_('/src/index.js')); const dts = makeTestBundleProgram(_('/typings/index.d.ts')); - const class2 = - getDeclaration(program, _('/src/class2.js'), 'Class2', ts.isVariableDeclaration); - const internalClass2 = - getDeclaration(program, _('/src/internal.js'), 'Class2', ts.isVariableDeclaration); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts); + const class2 = getDeclaration( + bundle.program, _('/src/class2.js'), 'Class2', ts.isVariableDeclaration); + const internalClass2 = getDeclaration( + bundle.program, _('/src/internal.js'), 'Class2', ts.isVariableDeclaration); + const host = new UmdReflectionHost(new MockLogger(), false, bundle, dts); const class2DtsDeclaration = host.getDtsDeclaration(class2); expect(class2DtsDeclaration !.getSourceFile().fileName) @@ -2302,23 +2296,23 @@ runInEachFileSystem(() => { describe('getInternalNameOfClass()', () => { it('should return the name of the inner class declaration', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const emptyClass = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); expect(host.getInternalNameOfClass(emptyClass).text).toEqual('EmptyClass'); const class1 = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'OuterClass1', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'OuterClass1', isNamedVariableDeclaration); expect(host.getInternalNameOfClass(class1).text).toEqual('InnerClass1'); const class2 = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'OuterClass2', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'OuterClass2', isNamedVariableDeclaration); expect(host.getInternalNameOfClass(class2).text).toEqual('InnerClass2'); const childClass = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'ChildClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'ChildClass', isNamedVariableDeclaration); expect(host.getInternalNameOfClass(childClass).text).toEqual('InnerChildClass'); }); }); @@ -2326,23 +2320,23 @@ runInEachFileSystem(() => { describe('getAdjacentNameOfClass()', () => { it('should return the name of the inner class declaration', () => { loadTestFiles([SIMPLE_CLASS_FILE]); - const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); + const bundle = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); const emptyClass = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); expect(host.getAdjacentNameOfClass(emptyClass).text).toEqual('EmptyClass'); const class1 = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'OuterClass1', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'OuterClass1', isNamedVariableDeclaration); expect(host.getAdjacentNameOfClass(class1).text).toEqual('InnerClass1'); const class2 = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'OuterClass2', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'OuterClass2', isNamedVariableDeclaration); expect(host.getAdjacentNameOfClass(class2).text).toEqual('InnerClass2'); const childClass = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'ChildClass', isNamedVariableDeclaration); + bundle.program, SIMPLE_CLASS_FILE.name, 'ChildClass', isNamedVariableDeclaration); expect(host.getAdjacentNameOfClass(childClass).text).toEqual('InnerChildClass'); }); }); @@ -2351,10 +2345,9 @@ runInEachFileSystem(() => { it('should find every exported function that returns an object that looks like a ModuleWithProviders object', () => { loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM); - const {program, host: compilerHost} = - makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const file = getSourceFileOrError(program, _('/src/functions.js')); + const bundle = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]); + const host = 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])) .toEqual([ @@ -2368,10 +2361,9 @@ runInEachFileSystem(() => { it('should find every static method on exported classes that return an object that looks like a ModuleWithProviders object', () => { loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM); - const {program, host: compilerHost} = - makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const file = getSourceFileOrError(program, _('/src/methods.js')); + const bundle = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]); + const host = 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([ [ @@ -2396,10 +2388,9 @@ runInEachFileSystem(() => { // https://github.com/angular/angular/issues/29078 it('should resolve aliased module references to their original declaration', () => { loadTestFiles(MODULE_WITH_PROVIDERS_PROGRAM); - const {program, host: compilerHost} = - makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]); - const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); - const file = getSourceFileOrError(program, _('/src/aliased_class.js')); + const bundle = makeTestBundleProgram(getRootFiles(MODULE_WITH_PROVIDERS_PROGRAM)[0]); + const host = new UmdReflectionHost(new MockLogger(), false, bundle); + const file = getSourceFileOrError(bundle.program, _('/src/aliased_class.js')); const fn = host.getModuleWithProvidersFunctions(file); expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.node.name.text])).toEqual([ ['function() { return { ngModule: AliasedModule_1 }; }', 'AliasedModule'], diff --git a/packages/compiler-cli/ngcc/test/migrations/missing_injectable_migration_spec.ts b/packages/compiler-cli/ngcc/test/migrations/missing_injectable_migration_spec.ts index 707dfc1a7d..8ae41906d4 100644 --- a/packages/compiler-cli/ngcc/test/migrations/missing_injectable_migration_spec.ts +++ b/packages/compiler-cli/ngcc/test/migrations/missing_injectable_migration_spec.ts @@ -559,8 +559,7 @@ runInEachFileSystem(() => { const bundle = makeTestEntryPointBundle('test-package', 'esm2015', false, rootFiles); const program = bundle.src.program; - const reflectionHost = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const reflectionHost = new Esm2015ReflectionHost(new MockLogger(), false, bundle.src); const referencesRegistry = new NgccReferencesRegistry(reflectionHost); const analyzer = new DecorationAnalyzer( getFileSystem(), bundle, reflectionHost, referencesRegistry, error => errors.push(error)); diff --git a/packages/compiler-cli/ngcc/test/migrations/undecorated_parent_migration_spec.ts b/packages/compiler-cli/ngcc/test/migrations/undecorated_parent_migration_spec.ts index 74536c1b90..bdbed94af2 100644 --- a/packages/compiler-cli/ngcc/test/migrations/undecorated_parent_migration_spec.ts +++ b/packages/compiler-cli/ngcc/test/migrations/undecorated_parent_migration_spec.ts @@ -246,8 +246,7 @@ runInEachFileSystem(() => { const bundle = makeTestEntryPointBundle('test-package', 'esm2015', false, rootFiles); const program = bundle.src.program; - const reflectionHost = - new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const reflectionHost = new Esm2015ReflectionHost(new MockLogger(), false, bundle.src); const referencesRegistry = new NgccReferencesRegistry(reflectionHost); const analyzer = new DecorationAnalyzer( getFileSystem(), bundle, reflectionHost, referencesRegistry, error => errors.push(error)); diff --git a/packages/compiler-cli/ngcc/test/rendering/commonjs_rendering_formatter_spec.ts b/packages/compiler-cli/ngcc/test/rendering/commonjs_rendering_formatter_spec.ts index 85674a9a2b..c77e32ba1c 100644 --- a/packages/compiler-cli/ngcc/test/rendering/commonjs_rendering_formatter_spec.ts +++ b/packages/compiler-cli/ngcc/test/rendering/commonjs_rendering_formatter_spec.ts @@ -151,8 +151,7 @@ exports.D = D; const fs = getFileSystem(); const logger = new MockLogger(); const bundle = makeTestEntryPointBundle('test-package', 'commonjs', false, [file.name]); - const typeChecker = bundle.src.program.getTypeChecker(); - const host = new CommonJsReflectionHost(logger, false, bundle.src.program, bundle.src.host); + const host = new CommonJsReflectionHost(logger, false, bundle.src); const referencesRegistry = new NgccReferencesRegistry(host); const decorationAnalyses = new DecorationAnalyzer(fs, bundle, host, referencesRegistry).analyzeProgram(); diff --git a/packages/compiler-cli/ngcc/test/rendering/dts_renderer_spec.ts b/packages/compiler-cli/ngcc/test/rendering/dts_renderer_spec.ts index ab1f198611..88616383a8 100644 --- a/packages/compiler-cli/ngcc/test/rendering/dts_renderer_spec.ts +++ b/packages/compiler-cli/ngcc/test/rendering/dts_renderer_spec.ts @@ -70,8 +70,7 @@ function createTestRenderer( const isCore = packageName === '@angular/core'; const bundle = makeTestEntryPointBundle( 'test-package', 'esm2015', isCore, getRootFiles(files), dtsFiles && getRootFiles(dtsFiles)); - const typeChecker = bundle.src.program.getTypeChecker(); - const host = new Esm2015ReflectionHost(logger, isCore, typeChecker, bundle.dts); + const host = new Esm2015ReflectionHost(logger, isCore, bundle.src, bundle.dts); const referencesRegistry = new NgccReferencesRegistry(host); const decorationAnalyses = new DecorationAnalyzer(fs, bundle, host, referencesRegistry).analyzeProgram(); diff --git a/packages/compiler-cli/ngcc/test/rendering/esm5_rendering_formatter_spec.ts b/packages/compiler-cli/ngcc/test/rendering/esm5_rendering_formatter_spec.ts index 53141ba3e5..57616b0a34 100644 --- a/packages/compiler-cli/ngcc/test/rendering/esm5_rendering_formatter_spec.ts +++ b/packages/compiler-cli/ngcc/test/rendering/esm5_rendering_formatter_spec.ts @@ -28,8 +28,7 @@ function setup(file: {name: AbsoluteFsPath, contents: string}) { const fs = getFileSystem(); const logger = new MockLogger(); const bundle = makeTestEntryPointBundle('test-package', 'esm5', false, [file.name]); - const typeChecker = bundle.src.program.getTypeChecker(); - const host = new Esm5ReflectionHost(logger, false, typeChecker); + const host = new Esm5ReflectionHost(logger, false, bundle.src); const referencesRegistry = new NgccReferencesRegistry(host); const decorationAnalyses = new DecorationAnalyzer(fs, bundle, host, referencesRegistry).analyzeProgram(); diff --git a/packages/compiler-cli/ngcc/test/rendering/esm_rendering_formatter_spec.ts b/packages/compiler-cli/ngcc/test/rendering/esm_rendering_formatter_spec.ts index 640dd3fa58..9396cef745 100644 --- a/packages/compiler-cli/ngcc/test/rendering/esm_rendering_formatter_spec.ts +++ b/packages/compiler-cli/ngcc/test/rendering/esm_rendering_formatter_spec.ts @@ -33,8 +33,7 @@ function setup(files: TestFile[], dtsFiles?: TestFile[]) { const logger = new MockLogger(); const bundle = makeTestEntryPointBundle( 'test-package', 'esm2015', false, getRootFiles(files), dtsFiles && getRootFiles(dtsFiles)) !; - const typeChecker = bundle.src.program.getTypeChecker(); - const host = new Esm2015ReflectionHost(logger, false, typeChecker, bundle.dts); + const host = new Esm2015ReflectionHost(logger, false, bundle.src, bundle.dts); const referencesRegistry = new NgccReferencesRegistry(host); const decorationAnalyses = new DecorationAnalyzer(fs, bundle, host, referencesRegistry).analyzeProgram(); diff --git a/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts b/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts index 149f748a57..24f3e4c7cf 100644 --- a/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts +++ b/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts @@ -83,9 +83,8 @@ function createTestRenderer( const isCore = packageName === '@angular/core'; const bundle = makeTestEntryPointBundle( 'test-package', 'esm5', isCore, getRootFiles(files), dtsFiles && getRootFiles(dtsFiles)); - const typeChecker = bundle.src.program.getTypeChecker(); - const host = isEs5 ? new Esm5ReflectionHost(logger, isCore, typeChecker, bundle.dts) : - new Esm2015ReflectionHost(logger, isCore, typeChecker, bundle.dts); + const host = isEs5 ? new Esm5ReflectionHost(logger, isCore, bundle.src, bundle.dts) : + new Esm2015ReflectionHost(logger, isCore, bundle.src, bundle.dts); const referencesRegistry = new NgccReferencesRegistry(host); const decorationAnalyses = new DecorationAnalyzer(fs, bundle, host, referencesRegistry).analyzeProgram(); diff --git a/packages/compiler-cli/ngcc/test/rendering/umd_rendering_formatter_spec.ts b/packages/compiler-cli/ngcc/test/rendering/umd_rendering_formatter_spec.ts index 0c1b5ec378..10264beaaa 100644 --- a/packages/compiler-cli/ngcc/test/rendering/umd_rendering_formatter_spec.ts +++ b/packages/compiler-cli/ngcc/test/rendering/umd_rendering_formatter_spec.ts @@ -28,7 +28,7 @@ function setup(file: TestFile) { const logger = new MockLogger(); const bundle = makeTestEntryPointBundle('test-package', 'esm5', false, [file.name]); const src = bundle.src; - const host = new UmdReflectionHost(logger, false, src.program, src.host); + const host = new UmdReflectionHost(logger, false, src); const referencesRegistry = new NgccReferencesRegistry(host); const decorationAnalyses = new DecorationAnalyzer(fs, bundle, host, referencesRegistry).analyzeProgram();