From 2790352d048db5e4d1a8ff7f62536002dd791b39 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Wed, 20 Mar 2019 12:10:58 +0200 Subject: [PATCH] refactor(ivy): use `ClassDeclaration` in more `ReflectionHost` methods (#29209) PR Close #29209 --- .../ngcc/src/host/esm2015_host.ts | 40 ++--- .../compiler-cli/ngcc/src/host/esm5_host.ts | 19 +- .../host/esm2015_host_import_helper_spec.ts | 30 ++-- .../ngcc/test/host/esm2015_host_spec.ts | 167 +++++++++--------- .../test/host/esm5_host_import_helper_spec.ts | 35 ++-- .../ngcc/test/host/esm5_host_spec.ts | 124 +++++++------ .../src/ngtsc/annotations/test/BUILD.bazel | 1 - .../ngtsc/annotations/test/component_spec.ts | 3 +- .../ngtsc/annotations/test/directive_spec.ts | 5 +- .../ngtsc/annotations/test/ng_module_spec.ts | 3 +- .../src/ngtsc/reflection/index.ts | 3 +- .../src/ngtsc/reflection/src/host.ts | 24 ++- .../src/ngtsc/reflection/src/typescript.ts | 23 +-- .../src/ngtsc/reflection/src/util.ts | 27 +++ .../src/ngtsc/reflection/test/ts_host_spec.ts | 17 +- .../src/ngtsc/scope/src/dependency.ts | 3 +- .../compiler-cli/src/ngtsc/scope/src/util.ts | 8 +- .../src/ngtsc/transform/src/compilation.ts | 4 +- packages/compiler-cli/src/ngtsc/tsc_plugin.ts | 7 +- .../src/ngtsc/typecheck/test/BUILD.bazel | 1 + .../typecheck/test/type_constructor_spec.ts | 3 +- .../src/ngtsc/util/src/typescript.ts | 5 - 22 files changed, 291 insertions(+), 261 deletions(-) create mode 100644 packages/compiler-cli/src/ngtsc/reflection/src/util.ts diff --git a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts index 0d9a24a352..d412e22a59 100644 --- a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts +++ b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts @@ -8,7 +8,7 @@ import * as ts from 'typescript'; -import {ClassMember, ClassMemberKind, ClassSymbol, CtorParameter, Decorator, Import, TypeScriptReflectionHost, reflectObjectLiteral} from '../../../src/ngtsc/reflection'; +import {ClassDeclaration, ClassMember, ClassMemberKind, ClassSymbol, CtorParameter, Decorator, Import, TypeScriptReflectionHost, reflectObjectLiteral} from '../../../src/ngtsc/reflection'; import {BundleProgram} from '../packages/bundle_program'; import {findAll, getNameText, isDefined} from '../utils'; @@ -79,16 +79,13 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N * Examine a declaration which should be of a class, and return metadata about the members of the * class. * - * @param declaration a TypeScript `ts.Declaration` node representing the class over which to - * reflect. If the source is in ES6 format, this will be a `ts.ClassDeclaration` node. If the - * source is in ES5 format, this might be a `ts.VariableDeclaration` as classes in ES5 are - * represented as the result of an IIFE execution. + * @param clazz a `ClassDeclaration` representing the class over which to reflect. * * @returns an array of `ClassMember` metadata representing the members of the class. * * @throws if `declaration` does not resolve to a class declaration. */ - getMembersOfClass(clazz: ts.Declaration): ClassMember[] { + getMembersOfClass(clazz: ClassDeclaration): ClassMember[] { const members: ClassMember[] = []; const symbol = this.getClassSymbol(clazz); if (!symbol) { @@ -170,10 +167,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N * This method only looks at the constructor of a class directly and not at any inherited * constructors. * - * @param declaration a TypeScript `ts.Declaration` node representing the class over which to - * reflect. If the source is in ES6 format, this will be a `ts.ClassDeclaration` node. If the - * source is in ES5 format, this might be a `ts.VariableDeclaration` as classes in ES5 are - * represented as the result of an IIFE execution. + * @param clazz a `ClassDeclaration` representing the class over which to reflect. * * @returns an array of `Parameter` metadata representing the parameters of the constructor, if * a constructor exists. If the constructor exists and has 0 parameters, this array will be empty. @@ -181,7 +175,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N * * @throws if `declaration` does not resolve to a class declaration. */ - getConstructorParameters(clazz: ts.Declaration): CtorParameter[]|null { + getConstructorParameters(clazz: ClassDeclaration): CtorParameter[]|null { const classSymbol = this.getClassSymbol(clazz); if (!classSymbol) { throw new Error( @@ -325,10 +319,12 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N /** * Get the number of generic type parameters of a given class. * + * @param clazz a `ClassDeclaration` representing the class over which to reflect. + * * @returns the number of type parameters of the class, if known, or `null` if the declaration * is not a class or has an unknown number of type parameters. */ - getGenericArityOfClass(clazz: ts.Declaration): number|null { + getGenericArityOfClass(clazz: ClassDeclaration): number|null { const dtsDeclaration = this.getDtsDeclaration(clazz); if (dtsDeclaration && ts.isClassDeclaration(dtsDeclaration)) { return dtsDeclaration.typeParameters ? dtsDeclaration.typeParameters.length : 0; @@ -396,7 +392,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N ///////////// Protected Helpers ///////////// - protected getDecoratorsOfSymbol(symbol: ts.Symbol): Decorator[]|null { + protected getDecoratorsOfSymbol(symbol: ClassSymbol): Decorator[]|null { const decoratorsProperty = this.getStaticProperty(symbol, DECORATORS); if (decoratorsProperty) { return this.getClassDecoratorsFromStaticProperty(decoratorsProperty); @@ -443,7 +439,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N * @param propertyName the name of static property. * @returns the symbol if it is found or `undefined` if not. */ - protected getStaticProperty(symbol: ts.Symbol, propertyName: ts.__String): ts.Symbol|undefined { + protected getStaticProperty(symbol: ClassSymbol, propertyName: ts.__String): ts.Symbol|undefined { return symbol.exports && symbol.exports.get(propertyName); } @@ -489,7 +485,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N * @param symbol the class whose decorators we want to get. * @returns an array of decorators or null if none where found. */ - protected getClassDecoratorsFromHelperCall(symbol: ts.Symbol): Decorator[]|null { + protected getClassDecoratorsFromHelperCall(symbol: ClassSymbol): Decorator[]|null { const decorators: Decorator[] = []; const helperCalls = this.getHelperCallsForClass(symbol, '__decorate'); helperCalls.forEach(helperCall => { @@ -507,7 +503,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N * @returns a map whose keys are the name of the members and whose values are collections of * decorators for the given member. */ - protected getMemberDecorators(classSymbol: ts.Symbol): Map { + protected getMemberDecorators(classSymbol: ClassSymbol): Map { const decoratorsProperty = this.getStaticProperty(classSymbol, PROP_DECORATORS); if (decoratorsProperty) { return this.getMemberDecoratorsFromStaticProperty(decoratorsProperty); @@ -563,7 +559,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N * @returns a map whose keys are the name of the members and whose values are collections of * decorators for the given member. */ - protected getMemberDecoratorsFromHelperCalls(classSymbol: ts.Symbol): Map { + protected getMemberDecoratorsFromHelperCalls(classSymbol: ClassSymbol): Map { const memberDecoratorMap = new Map(); const helperCalls = this.getHelperCallsForClass(classSymbol, '__decorate'); helperCalls.forEach(helperCall => { @@ -862,7 +858,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N * @returns an array of `ts.ParameterDeclaration` objects representing each of the parameters in * the class's constructor or null if there is no constructor. */ - protected getConstructorParameterDeclarations(classSymbol: ts.Symbol): + protected getConstructorParameterDeclarations(classSymbol: ClassSymbol): ts.ParameterDeclaration[]|null { const constructorSymbol = classSymbol.members && classSymbol.members.get(CONSTRUCTOR); if (constructorSymbol) { @@ -891,7 +887,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N * @returns an array of constructor parameter info objects. */ protected getConstructorParamInfo( - classSymbol: ts.Symbol, parameterNodes: ts.ParameterDeclaration[]): CtorParameter[] { + classSymbol: ClassSymbol, parameterNodes: ts.ParameterDeclaration[]): CtorParameter[] { const paramsProperty = this.getStaticProperty(classSymbol, CONSTRUCTOR_PARAMS); const paramInfo: ParamInfo[]|null = paramsProperty ? this.getParamInfoFromStaticProperty(paramsProperty) : @@ -965,7 +961,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N * @returns an array of objects containing the type and decorators for each parameter. */ protected getParamInfoFromHelperCall( - classSymbol: ts.Symbol, parameterNodes: ts.ParameterDeclaration[]): ParamInfo[] { + classSymbol: ClassSymbol, parameterNodes: ts.ParameterDeclaration[]): ParamInfo[] { const parameters: ParamInfo[] = parameterNodes.map(() => ({typeExpression: null, decorators: null})); const helperCalls = this.getHelperCallsForClass(classSymbol, '__decorate'); @@ -1012,7 +1008,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N * in. * @returns an array of CallExpression nodes for each matching helper call. */ - protected getHelperCallsForClass(classSymbol: ts.Symbol, helperName: string): + protected getHelperCallsForClass(classSymbol: ClassSymbol, helperName: string): ts.CallExpression[] { return this.getStatementsForClass(classSymbol) .map(statement => this.getHelperCall(statement, helperName)) @@ -1028,7 +1024,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N * @param classSymbol the class whose helper calls we are interested in. * @returns an array of statements that may contain helper calls. */ - protected getStatementsForClass(classSymbol: ts.Symbol): ts.Statement[] { + protected getStatementsForClass(classSymbol: ClassSymbol): ts.Statement[] { return Array.from(classSymbol.valueDeclaration.getSourceFile().statements); } diff --git a/packages/compiler-cli/ngcc/src/host/esm5_host.ts b/packages/compiler-cli/ngcc/src/host/esm5_host.ts index 1e11de66f2..ec1a44a104 100644 --- a/packages/compiler-cli/ngcc/src/host/esm5_host.ts +++ b/packages/compiler-cli/ngcc/src/host/esm5_host.ts @@ -41,12 +41,14 @@ export class Esm5ReflectionHost extends Esm2015ReflectionHost { } /** - * Determines whether the given declaration has a base class. + * Determines whether the given declaration, which should be a "class", has a base "class". * - * In ES5, we need to determine if the IIFE wrapper takes a `_super` parameter . + * In ES5 code, we need to determine if the IIFE wrapper takes a `_super` parameter . + * + * @param clazz a `ClassDeclaration` representing the class over which to reflect. */ - hasBaseClass(node: ts.Declaration): boolean { - const classSymbol = this.getClassSymbol(node); + hasBaseClass(clazz: ClassDeclaration): boolean { + const classSymbol = this.getClassSymbol(clazz); if (!classSymbol) return false; const iifeBody = classSymbol.valueDeclaration.parent; @@ -183,7 +185,7 @@ export class Esm5ReflectionHost extends Esm2015ReflectionHost { * @returns an array of `ts.ParameterDeclaration` objects representing each of the parameters in * the class's constructor or null if there is no constructor. */ - protected getConstructorParameterDeclarations(classSymbol: ts.Symbol): + protected getConstructorParameterDeclarations(classSymbol: ClassSymbol): ts.ParameterDeclaration[]|null { const constructor = classSymbol.valueDeclaration as ts.FunctionDeclaration; if (constructor.parameters.length > 0) { @@ -310,10 +312,9 @@ export class Esm5ReflectionHost extends Esm2015ReflectionHost { * to reference the inner identifier inside the IIFE. * @returns an array of statements that may contain helper calls. */ - protected getStatementsForClass(classSymbol: ts.Symbol): ts.Statement[] { - const classDeclaration = classSymbol.valueDeclaration; - return ts.isBlock(classDeclaration.parent) ? Array.from(classDeclaration.parent.statements) : - []; + protected getStatementsForClass(classSymbol: ClassSymbol): ts.Statement[] { + const classDeclarationParent = classSymbol.valueDeclaration.parent; + return ts.isBlock(classDeclarationParent) ? Array.from(classDeclarationParent.statements) : []; } } 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 58a541cb1a..8637a2d30b 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 @@ -8,7 +8,7 @@ import * as ts from 'typescript'; -import {ClassMemberKind, Import} from '../../../src/ngtsc/reflection'; +import {ClassMemberKind, Import, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection'; import {Esm2015ReflectionHost} from '../../src/host/esm2015_host'; import {convertToDirectTsLibImport, getDeclaration, makeTestProgram} from '../helpers/utils'; @@ -108,7 +108,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -132,7 +132,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -148,7 +148,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const host = new Esm2015ReflectionHost(true, program.getTypeChecker()); const classNode = getDeclaration( program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -168,7 +168,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -186,7 +186,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const instanceProperty = members.find(member => member.name === 'instanceProperty') !; @@ -200,7 +200,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticMethod = members.find(member => member.name === 'staticMethod') !; @@ -213,7 +213,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticProperty = members.find(member => member.name === 'staticProperty') !; @@ -230,7 +230,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); host.getMembersOfClass(classNode); const identifiers = spy.calls.all().map(call => (call.args[0] as ts.Identifier).text); @@ -242,7 +242,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const host = new Esm2015ReflectionHost(true, program.getTypeChecker()); const classNode = getDeclaration( program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -257,7 +257,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBeDefined(); @@ -280,7 +280,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![2].decorators !; @@ -298,7 +298,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const ctrDecorators = host.getConstructorParameters(classNode) !; const identifierOfViewContainerRef = (ctrDecorators[0].typeValueReference !as{ local: true, @@ -318,7 +318,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const classDecorators = host.getDecoratorsOfDeclaration(classNode) !; const decoratorNode = classDecorators[0].node; const identifierOfDirective = @@ -328,7 +328,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { const expectedDeclarationNode = getDeclaration( program, 'node_modules/@angular/core/index.ts', 'Directive', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective !); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); 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 e9391d1a7a..8497412751 100644 --- a/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts @@ -8,7 +8,7 @@ import * as ts from 'typescript'; -import {ClassMemberKind, Import} from '../../../src/ngtsc/reflection'; +import {ClassMemberKind, Import, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection'; import {Esm2015ReflectionHost} from '../../src/host/esm2015_host'; import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils'; @@ -559,8 +559,8 @@ describe('Esm2015ReflectionHost', () => { it('should find the decorators on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); - const classNode = - getDeclaration(program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isClassDeclaration); + const classNode = getDeclaration( + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -578,7 +578,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', ts.isFunctionDeclaration); + getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); const decorators = host.getDecoratorsOfDeclaration(functionNode); expect(decorators).toBe(null); }); @@ -587,7 +587,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isClassDeclaration); + getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); expect(decorators).toBe(null); }); @@ -596,7 +596,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', ts.isClassDeclaration); + program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); expect(decorators).toEqual([]); }); @@ -605,7 +605,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', ts.isClassDeclaration); + program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -616,7 +616,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', ts.isClassDeclaration); + program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -627,7 +627,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', ts.isClassDeclaration); + program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -641,8 +641,8 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); - const classNode = - getDeclaration(program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isClassDeclaration); + const classNode = getDeclaration( + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toEqual(1); @@ -657,7 +657,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', ts.isClassDeclaration); + program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -670,7 +670,7 @@ describe('Esm2015ReflectionHost', () => { const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', - ts.isClassDeclaration); + isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -682,7 +682,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', ts.isClassDeclaration); + program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -696,8 +696,8 @@ describe('Esm2015ReflectionHost', () => { it('should find decorated properties on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); - const classNode = - getDeclaration(program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isClassDeclaration); + const classNode = getDeclaration( + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -714,8 +714,8 @@ describe('Esm2015ReflectionHost', () => { it('should find non decorated properties on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); - const classNode = - getDeclaration(program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isClassDeclaration); + const classNode = getDeclaration( + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const instanceProperty = members.find(member => member.name === 'instanceProperty') !; @@ -729,7 +729,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(ACCESSORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = - getDeclaration(program, ACCESSORS_FILE.name, 'SomeDirective', ts.isClassDeclaration); + getDeclaration(program, ACCESSORS_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const [combinedSetter, combinedGetter] = @@ -749,8 +749,8 @@ describe('Esm2015ReflectionHost', () => { it('should find static methods on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); - const classNode = - getDeclaration(program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isClassDeclaration); + const classNode = getDeclaration( + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const staticMethod = members.find(member => member.name === 'staticMethod') !; @@ -762,8 +762,8 @@ describe('Esm2015ReflectionHost', () => { it('should find static properties on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); - const classNode = - getDeclaration(program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isClassDeclaration); + const classNode = getDeclaration( + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const staticProperty = members.find(member => member.name === 'staticProperty') !; @@ -777,7 +777,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', ts.isFunctionDeclaration); + getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getMembersOfClass(functionNode); }).toThrowError(`Attempted to get members of a non-class: "function foo() {}"`); @@ -787,7 +787,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isClassDeclaration); + getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); expect(members).toEqual([]); @@ -798,7 +798,8 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral', ts.isClassDeclaration); + program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral', + isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); expect(members.map(member => member.name)).not.toContain('prop'); @@ -809,7 +810,7 @@ describe('Esm2015ReflectionHost', () => { const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp', - ts.isClassDeclaration); + isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; const decorators = prop.decorators !; @@ -822,7 +823,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', ts.isClassDeclaration); + 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 !; @@ -835,7 +836,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', ts.isClassDeclaration); + 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 !; @@ -854,8 +855,8 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); - const classNode = - getDeclaration(program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isClassDeclaration); + const classNode = getDeclaration( + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); expect(spy).toHaveBeenCalled(); @@ -878,7 +879,7 @@ describe('Esm2015ReflectionHost', () => { const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', - ts.isClassDeclaration); + isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; const decorators = prop.decorators !; @@ -893,7 +894,7 @@ describe('Esm2015ReflectionHost', () => { const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', - ts.isClassDeclaration); + isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; const decorators = prop.decorators !; @@ -908,7 +909,7 @@ describe('Esm2015ReflectionHost', () => { const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', - ts.isClassDeclaration); + isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; const decorators = prop.decorators !; @@ -924,8 +925,8 @@ describe('Esm2015ReflectionHost', () => { it('should find the decorated constructor parameters', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); - const classNode = - getDeclaration(program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isClassDeclaration); + const classNode = getDeclaration( + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; expect(parameters).toBeDefined(); @@ -939,7 +940,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', ts.isFunctionDeclaration); + getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getConstructorParameters(functionNode); }) .toThrowError( 'Attempted to get constructor parameters of a non-class: "function foo() {}"'); @@ -949,7 +950,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isClassDeclaration); + getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBe(null); }); @@ -958,7 +959,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', ts.isClassDeclaration); + program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; expect(parameters).toEqual(jasmine.any(Array)); @@ -971,7 +972,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', ts.isClassDeclaration); + program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toEqual([]); @@ -981,7 +982,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotFromCore', ts.isClassDeclaration); + program, INVALID_CTOR_DECORATORS_FILE.name, 'NotFromCore', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; expect(parameters.length).toBe(1); @@ -995,7 +996,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrowFunction', ts.isClassDeclaration); + program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrowFunction', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; expect(parameters.length).toBe(1); @@ -1009,7 +1010,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', ts.isClassDeclaration); + program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; expect(parameters.length).toBe(1); @@ -1033,7 +1034,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(file); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); - const classNode = getDeclaration(program, file.name, 'TestClass', ts.isClassDeclaration); + const classNode = getDeclaration(program, file.name, 'TestClass', isNamedClassDeclaration); return host.getConstructorParameters(classNode); } @@ -1088,7 +1089,8 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral', ts.isClassDeclaration); + program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral', + isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters !.length).toBe(2); @@ -1106,7 +1108,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', ts.isClassDeclaration); + program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1118,7 +1120,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', ts.isClassDeclaration); + program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1134,7 +1136,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isClassDeclaration); + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; const decorators = parameters[2].decorators !; @@ -1152,7 +1154,7 @@ describe('Esm2015ReflectionHost', () => { const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', - ts.isClassDeclaration); + isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters !.length).toBe(1); const decorators = parameters ![0].decorators !; @@ -1167,7 +1169,7 @@ describe('Esm2015ReflectionHost', () => { const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', - ts.isClassDeclaration); + isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1181,7 +1183,7 @@ describe('Esm2015ReflectionHost', () => { const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', - ts.isClassDeclaration); + isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1198,7 +1200,7 @@ describe('Esm2015ReflectionHost', () => { const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const fooNode = - getDeclaration(program, FUNCTION_BODY_FILE.name, 'foo', ts.isFunctionDeclaration) !; + getDeclaration(program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !; const fooDef = host.getDefinitionOfFunction(fooNode); expect(fooDef.node).toBe(fooNode); expect(fooDef.body !.length).toEqual(1); @@ -1208,7 +1210,7 @@ describe('Esm2015ReflectionHost', () => { expect(fooDef.parameters[0].initializer).toBe(null); const barNode = - getDeclaration(program, FUNCTION_BODY_FILE.name, 'bar', ts.isFunctionDeclaration) !; + getDeclaration(program, FUNCTION_BODY_FILE.name, 'bar', isNamedFunctionDeclaration) !; const barDef = host.getDefinitionOfFunction(barNode); expect(barDef.node).toBe(barNode); expect(barDef.body !.length).toEqual(1); @@ -1221,7 +1223,7 @@ describe('Esm2015ReflectionHost', () => { expect(barDef.parameters[1].initializer !.getText()).toEqual('42'); const bazNode = - getDeclaration(program, FUNCTION_BODY_FILE.name, 'baz', ts.isFunctionDeclaration) !; + getDeclaration(program, FUNCTION_BODY_FILE.name, 'baz', isNamedFunctionDeclaration) !; const bazDef = host.getDefinitionOfFunction(bazNode); expect(bazDef.node).toBe(bazNode); expect(bazDef.body !.length).toEqual(3); @@ -1230,7 +1232,7 @@ describe('Esm2015ReflectionHost', () => { expect(bazDef.parameters[0].initializer).toBe(null); const quxNode = - getDeclaration(program, FUNCTION_BODY_FILE.name, 'qux', ts.isFunctionDeclaration) !; + getDeclaration(program, FUNCTION_BODY_FILE.name, 'qux', isNamedFunctionDeclaration) !; const quxDef = host.getDefinitionOfFunction(quxNode); expect(quxDef.node).toBe(quxNode); expect(quxDef.body !.length).toEqual(2); @@ -1239,14 +1241,14 @@ describe('Esm2015ReflectionHost', () => { expect(quxDef.parameters[0].initializer).toBe(null); const mooNode = - getDeclaration(program, FUNCTION_BODY_FILE.name, 'moo', ts.isFunctionDeclaration) !; + getDeclaration(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', ts.isFunctionDeclaration) !; + getDeclaration(program, FUNCTION_BODY_FILE.name, 'juu', isNamedFunctionDeclaration) !; const juuDef = host.getDefinitionOfFunction(juuNode); expect(juuDef.node).toBe(juuNode); expect(juuDef.body !.length).toEqual(2); @@ -1259,7 +1261,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(...IMPORTS_FILES); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const variableNode = - getDeclaration(program, IMPORTS_FILES[1].name, 'b', ts.isVariableDeclaration); + getDeclaration(program, IMPORTS_FILES[1].name, 'b', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); expect(importOfIdent).toEqual({name: 'a', from: './a.js'}); @@ -1269,7 +1271,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(...IMPORTS_FILES); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const variableNode = - getDeclaration(program, IMPORTS_FILES[1].name, 'c', ts.isVariableDeclaration); + getDeclaration(program, IMPORTS_FILES[1].name, 'c', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); expect(importOfIdent).toEqual({name: 'a', from: './a.js'}); @@ -1279,7 +1281,7 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(...IMPORTS_FILES); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const variableNode = - getDeclaration(program, IMPORTS_FILES[1].name, 'd', ts.isVariableDeclaration); + getDeclaration(program, IMPORTS_FILES[1].name, 'd', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); expect(importOfIdent).toBeNull(); @@ -1290,8 +1292,8 @@ describe('Esm2015ReflectionHost', () => { it('should return the declaration of a locally defined identifier', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); - const classNode = - getDeclaration(program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isClassDeclaration); + const classNode = getDeclaration( + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const ctrDecorators = host.getConstructorParameters(classNode) !; const identifierOfViewContainerRef = (ctrDecorators[0].typeValueReference !as{ local: true, @@ -1300,7 +1302,7 @@ describe('Esm2015ReflectionHost', () => { }).expression; const expectedDeclarationNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'ViewContainerRef', ts.isVariableDeclaration); + program, SOME_DIRECTIVE_FILE.name, 'ViewContainerRef', isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfViewContainerRef); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -1310,15 +1312,15 @@ describe('Esm2015ReflectionHost', () => { it('should return the declaration of an externally defined identifier', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); - const classNode = - getDeclaration(program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isClassDeclaration); + const classNode = getDeclaration( + 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.ts', 'Directive', ts.isVariableDeclaration); + program, 'node_modules/@angular/core/index.ts', 'Directive', isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -1366,14 +1368,15 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); const node = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isClassDeclaration); + getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); expect(host.isClass(node)).toBe(true); }); it('should return false if a given node is a TS function declaration', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); - const node = getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', ts.isFunctionDeclaration); + const node = + getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(host.isClass(node)).toBe(false); }); }); @@ -1385,13 +1388,13 @@ describe('Esm2015ReflectionHost', () => { const dts = makeTestBundleProgram([ARITY_CLASSES[1]]); const host = new Esm2015ReflectionHost(false, program.getTypeChecker(), dts); const noTypeParamClass = - getDeclaration(program, '/src/class.js', 'NoTypeParam', ts.isClassDeclaration); + getDeclaration(program, '/src/class.js', 'NoTypeParam', isNamedClassDeclaration); expect(host.getGenericArityOfClass(noTypeParamClass)).toBe(0); const oneTypeParamClass = - getDeclaration(program, '/src/class.js', 'OneTypeParam', ts.isClassDeclaration); + getDeclaration(program, '/src/class.js', 'OneTypeParam', isNamedClassDeclaration); expect(host.getGenericArityOfClass(oneTypeParamClass)).toBe(1); const twoTypeParamsClass = - getDeclaration(program, '/src/class.js', 'TwoTypeParams', ts.isClassDeclaration); + getDeclaration(program, '/src/class.js', 'TwoTypeParams', isNamedClassDeclaration); expect(host.getGenericArityOfClass(twoTypeParamsClass)).toBe(2); }); }); @@ -1440,7 +1443,8 @@ describe('Esm2015ReflectionHost', () => { it('should find the dts declaration that has the same relative path to the source file', () => { const srcProgram = makeTestProgram(...TYPINGS_SRC_FILES); const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); - const class1 = getDeclaration(srcProgram, '/src/class1.js', 'Class1', ts.isClassDeclaration); + const class1 = + getDeclaration(srcProgram, '/src/class1.js', 'Class1', isNamedClassDeclaration); const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); const dtsDeclaration = host.getDtsDeclaration(class1); @@ -1450,7 +1454,8 @@ describe('Esm2015ReflectionHost', () => { it('should find the dts declaration for exported functions', () => { const srcProgram = makeTestProgram(...TYPINGS_SRC_FILES); const dtsProgram = makeTestBundleProgram(TYPINGS_DTS_FILES); - const mooFn = getDeclaration(srcProgram, '/src/func1.js', 'mooFn', ts.isFunctionDeclaration); + const mooFn = + getDeclaration(srcProgram, '/src/func1.js', 'mooFn', isNamedFunctionDeclaration); const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dtsProgram); const dtsDeclaration = host.getDtsDeclaration(mooFn); @@ -1461,7 +1466,7 @@ describe('Esm2015ReflectionHost', () => { const srcProgram = makeTestProgram(...TYPINGS_SRC_FILES); const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const missingClass = - getDeclaration(srcProgram, '/src/class1.js', 'MissingClass1', ts.isClassDeclaration); + getDeclaration(srcProgram, '/src/class1.js', 'MissingClass1', isNamedClassDeclaration); const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); @@ -1471,7 +1476,7 @@ describe('Esm2015ReflectionHost', () => { const srcProgram = makeTestProgram(...TYPINGS_SRC_FILES); const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const missingClass = getDeclaration( - srcProgram, '/src/missing-class.js', 'MissingClass2', ts.isClassDeclaration); + srcProgram, '/src/missing-class.js', 'MissingClass2', isNamedClassDeclaration); const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); @@ -1482,7 +1487,7 @@ describe('Esm2015ReflectionHost', () => { const srcProgram = makeTestProgram(...TYPINGS_SRC_FILES); const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const class1 = - getDeclaration(srcProgram, '/src/flat-file.js', 'Class1', ts.isClassDeclaration); + getDeclaration(srcProgram, '/src/flat-file.js', 'Class1', isNamedClassDeclaration); const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); const dtsDeclaration = host.getDtsDeclaration(class1); @@ -1493,7 +1498,7 @@ describe('Esm2015ReflectionHost', () => { const srcProgram = makeTestProgram(...TYPINGS_SRC_FILES); const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const class3 = - getDeclaration(srcProgram, '/src/flat-file.js', 'Class3', ts.isClassDeclaration); + getDeclaration(srcProgram, '/src/flat-file.js', 'Class3', isNamedClassDeclaration); const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); const dtsDeclaration = host.getDtsDeclaration(class3); @@ -1504,8 +1509,8 @@ describe('Esm2015ReflectionHost', () => { () => { const srcProgram = makeTestProgram(...TYPINGS_SRC_FILES); const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); - const internalClass = - getDeclaration(srcProgram, '/src/internal.js', 'InternalClass', ts.isClassDeclaration); + const internalClass = getDeclaration( + srcProgram, '/src/internal.js', 'InternalClass', isNamedClassDeclaration); const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); const dtsDeclaration = host.getDtsDeclaration(internalClass); @@ -1517,9 +1522,9 @@ describe('Esm2015ReflectionHost', () => { const srcProgram = makeTestProgram(...TYPINGS_SRC_FILES); const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const class2 = - getDeclaration(srcProgram, '/src/class2.js', 'Class2', ts.isClassDeclaration); + getDeclaration(srcProgram, '/src/class2.js', 'Class2', isNamedClassDeclaration); const internalClass2 = - getDeclaration(srcProgram, '/src/internal.js', 'Class2', ts.isClassDeclaration); + getDeclaration(srcProgram, '/src/internal.js', 'Class2', isNamedClassDeclaration); const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); const class2DtsDeclaration = host.getDtsDeclaration(class2); 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 d439f82745..8cb0501a0a 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 @@ -8,7 +8,7 @@ import * as ts from 'typescript'; -import {ClassMemberKind, Import} from '../../../src/ngtsc/reflection'; +import {ClassMemberKind, Import, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection'; import {Esm5ReflectionHost} from '../../src/host/esm5_host'; import {convertToDirectTsLibImport, getDeclaration, makeTestProgram} from '../helpers/utils'; @@ -123,7 +123,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -147,7 +147,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -163,7 +163,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const host = new Esm5ReflectionHost(true, program.getTypeChecker()); const classNode = getDeclaration( program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -183,7 +183,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -201,7 +201,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const instanceProperty = members.find(member => member.name === 'instanceProperty') !; @@ -215,7 +215,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticMethod = members.find(member => member.name === 'staticMethod') !; @@ -228,7 +228,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticProperty = members.find(member => member.name === 'staticProperty') !; @@ -245,7 +245,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); host.getMembersOfClass(classNode); const identifiers = spy.calls.all().map(call => (call.args[0] as ts.Identifier).text); @@ -257,7 +257,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const host = new Esm5ReflectionHost(true, program.getTypeChecker()); const classNode = getDeclaration( program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -272,7 +272,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBeDefined(); @@ -295,7 +295,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![2].decorators !; @@ -334,7 +334,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const ctrDecorators = host.getConstructorParameters(classNode) !; const identifierOfViewContainerRef = (ctrDecorators[0].typeValueReference !as{ local: true, @@ -343,7 +343,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { }).expression; const expectedDeclarationNode = getDeclaration( - program, '/some_directive.js', 'ViewContainerRef', ts.isVariableDeclaration); + program, '/some_directive.js', 'ViewContainerRef', isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfViewContainerRef); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -354,7 +354,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const program = makeTestProgram(fileSystem.files[0]); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration); + program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const classDecorators = host.getDecoratorsOfDeclaration(classNode) !; const decoratorNode = classDecorators[0].node; @@ -365,7 +365,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { const expectedDeclarationNode = getDeclaration( program, 'node_modules/@angular/core/index.ts', 'Directive', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective !); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -427,8 +427,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { if (!node) { return; } - if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && - node.name.text === variableName) { + if (isNamedVariableDeclaration(node) && node.name.text === variableName) { return node; } return node.forEachChild(node => findVariableDeclaration(node, variableName)); 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 a01684d411..4063809f5a 100644 --- a/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts @@ -8,7 +8,7 @@ import * as ts from 'typescript'; -import {ClassDeclaration, ClassMemberKind, ClassSymbol, Import} from '../../../src/ngtsc/reflection'; +import {ClassDeclaration, ClassMemberKind, ClassSymbol, Import, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection'; import {Esm2015ReflectionHost} from '../../src/host/esm2015_host'; import {Esm5ReflectionHost} from '../../src/host/esm5_host'; import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils'; @@ -702,7 +702,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isVariableDeclaration); + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators).toBeDefined(); @@ -720,7 +720,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', ts.isFunctionDeclaration); + getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); const decorators = host.getDecoratorsOfDeclaration(functionNode); expect(decorators).toBe(null); }); @@ -729,7 +729,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); + getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); expect(decorators).toBe(null); }); @@ -738,7 +738,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', ts.isVariableDeclaration); + program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); expect(decorators).toEqual([]); }); @@ -747,7 +747,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', ts.isVariableDeclaration); + program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -758,7 +758,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', ts.isVariableDeclaration); + program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -769,7 +769,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', ts.isVariableDeclaration); + program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -784,7 +784,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isVariableDeclaration); + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toEqual(1); @@ -799,7 +799,8 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', ts.isVariableDeclaration); + program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -812,7 +813,7 @@ describe('Esm5ReflectionHost', () => { const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -824,7 +825,8 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', ts.isVariableDeclaration); + program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', + isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); @@ -839,7 +841,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isVariableDeclaration); + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const input1 = members.find(member => member.name === 'input1') !; @@ -857,7 +859,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(ACCESSORS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = - getDeclaration(program, ACCESSORS_FILE.name, 'SomeDirective', ts.isVariableDeclaration); + getDeclaration(program, ACCESSORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const setter = members.find(member => member.name === 'setter') !; @@ -904,7 +906,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isVariableDeclaration); + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const instanceProperty = members.find(member => member.name === 'instanceProperty') !; @@ -918,7 +920,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isVariableDeclaration); + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticMethod = members.find(member => member.name === 'staticMethod') !; @@ -932,7 +934,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isVariableDeclaration); + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const staticProperty = members.find(member => member.name === 'staticProperty') !; @@ -946,7 +948,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', ts.isFunctionDeclaration); + getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getMembersOfClass(functionNode); }).toThrowError(`Attempted to get members of a non-class: "function foo() {}"`); @@ -956,7 +958,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); + getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); expect(members).toEqual([]); @@ -968,7 +970,7 @@ describe('Esm5ReflectionHost', () => { const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); expect(members.map(member => member.name)).not.toContain('prop'); @@ -979,7 +981,7 @@ describe('Esm5ReflectionHost', () => { const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; const decorators = prop.decorators !; @@ -992,7 +994,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', ts.isVariableDeclaration); + program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; const decorators = prop.decorators !; @@ -1005,7 +1007,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', ts.isVariableDeclaration); + 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 !; @@ -1024,7 +1026,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isVariableDeclaration); + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); expect(spy).toHaveBeenCalled(); @@ -1041,7 +1043,7 @@ describe('Esm5ReflectionHost', () => { const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; const decorators = prop.decorators !; @@ -1056,7 +1058,7 @@ describe('Esm5ReflectionHost', () => { const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; const decorators = prop.decorators !; @@ -1071,7 +1073,7 @@ describe('Esm5ReflectionHost', () => { const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); const prop = members.find(m => m.name === 'prop') !; const decorators = prop.decorators !; @@ -1087,7 +1089,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(UNWANTED_PROTOTYPE_EXPORT_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, UNWANTED_PROTOTYPE_EXPORT_FILE.name, 'SomeParam', ts.isClassDeclaration); + program, UNWANTED_PROTOTYPE_EXPORT_FILE.name, 'SomeParam', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); expect(members.find(m => m.name === 'prototype')).toBeUndefined(); }); @@ -1098,7 +1100,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isVariableDeclaration); + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toBeDefined(); @@ -1116,7 +1118,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const functionNode = - getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', ts.isFunctionDeclaration); + getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getConstructorParameters(functionNode); }) .toThrowError( 'Attempted to get constructor parameters of a non-class: "function foo() {}"'); @@ -1129,7 +1131,8 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', ts.isVariableDeclaration); + program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toEqual(jasmine.any(Array)); @@ -1142,7 +1145,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', ts.isVariableDeclaration); + program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters).toEqual([]); @@ -1155,7 +1158,8 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', ts.isVariableDeclaration); + program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters !.length).toBe(1); @@ -1171,7 +1175,7 @@ describe('Esm5ReflectionHost', () => { const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters !.length).toBe(2); @@ -1189,7 +1193,8 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', ts.isVariableDeclaration); + program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1201,7 +1206,8 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', ts.isVariableDeclaration); + program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1217,7 +1223,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isVariableDeclaration); + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![2].decorators !; @@ -1244,7 +1250,8 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(file); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); - const classNode = getDeclaration(program, file.name, 'TestClass', ts.isVariableDeclaration); + const classNode = + getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); return host.getConstructorParameters(classNode); } @@ -1313,7 +1320,7 @@ describe('Esm5ReflectionHost', () => { const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); expect(parameters !.length).toBe(1); const decorators = parameters ![0].decorators !; @@ -1328,7 +1335,7 @@ describe('Esm5ReflectionHost', () => { const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1342,7 +1349,7 @@ describe('Esm5ReflectionHost', () => { const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', - ts.isVariableDeclaration); + isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); const decorators = parameters ![0].decorators !; @@ -1359,7 +1366,7 @@ describe('Esm5ReflectionHost', () => { const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const fooNode = - getDeclaration(program, FUNCTION_BODY_FILE.name, 'foo', ts.isFunctionDeclaration) !; + getDeclaration(program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !; const fooDef = host.getDefinitionOfFunction(fooNode); expect(fooDef.node).toBe(fooNode); expect(fooDef.body !.length).toEqual(1); @@ -1369,7 +1376,7 @@ describe('Esm5ReflectionHost', () => { expect(fooDef.parameters[0].initializer).toBe(null); const barNode = - getDeclaration(program, FUNCTION_BODY_FILE.name, 'bar', ts.isFunctionDeclaration) !; + getDeclaration(program, FUNCTION_BODY_FILE.name, 'bar', isNamedFunctionDeclaration) !; const barDef = host.getDefinitionOfFunction(barNode); expect(barDef.node).toBe(barNode); expect(barDef.body !.length).toEqual(1); @@ -1382,7 +1389,7 @@ describe('Esm5ReflectionHost', () => { expect(barDef.parameters[1].initializer !.getText()).toEqual('42'); const bazNode = - getDeclaration(program, FUNCTION_BODY_FILE.name, 'baz', ts.isFunctionDeclaration) !; + getDeclaration(program, FUNCTION_BODY_FILE.name, 'baz', isNamedFunctionDeclaration) !; const bazDef = host.getDefinitionOfFunction(bazNode); expect(bazDef.node).toBe(bazNode); expect(bazDef.body !.length).toEqual(3); @@ -1391,7 +1398,7 @@ describe('Esm5ReflectionHost', () => { expect(bazDef.parameters[0].initializer).toBe(null); const quxNode = - getDeclaration(program, FUNCTION_BODY_FILE.name, 'qux', ts.isFunctionDeclaration) !; + getDeclaration(program, FUNCTION_BODY_FILE.name, 'qux', isNamedFunctionDeclaration) !; const quxDef = host.getDefinitionOfFunction(quxNode); expect(quxDef.node).toBe(quxNode); expect(quxDef.body !.length).toEqual(2); @@ -1406,7 +1413,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(...IMPORTS_FILES); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const variableNode = - getDeclaration(program, IMPORTS_FILES[1].name, 'b', ts.isVariableDeclaration); + getDeclaration(program, IMPORTS_FILES[1].name, 'b', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); expect(importOfIdent).toEqual({name: 'a', from: './a.js'}); @@ -1416,7 +1423,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(...IMPORTS_FILES); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const variableNode = - getDeclaration(program, IMPORTS_FILES[1].name, 'c', ts.isVariableDeclaration); + getDeclaration(program, IMPORTS_FILES[1].name, 'c', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); expect(importOfIdent).toEqual({name: 'a', from: './a.js'}); @@ -1426,7 +1433,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(...IMPORTS_FILES); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const variableNode = - getDeclaration(program, IMPORTS_FILES[1].name, 'd', ts.isVariableDeclaration); + getDeclaration(program, IMPORTS_FILES[1].name, 'd', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); expect(importOfIdent).toBeNull(); @@ -1438,7 +1445,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isVariableDeclaration); + program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const ctrDecorators = host.getConstructorParameters(classNode) !; const identifierOfViewContainerRef = (ctrDecorators[0].typeValueReference !as{ local: true, @@ -1447,7 +1454,7 @@ describe('Esm5ReflectionHost', () => { }).expression; const expectedDeclarationNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'ViewContainerRef', ts.isVariableDeclaration); + program, SOME_DIRECTIVE_FILE.name, 'ViewContainerRef', isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfViewContainerRef); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -1458,14 +1465,14 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const classNode = getDeclaration( - program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isVariableDeclaration); + 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.ts', 'Directive', ts.isVariableDeclaration); + program, 'node_modules/@angular/core/index.ts', 'Directive', isNamedVariableDeclaration); const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective); expect(actualDeclaration).not.toBe(null); expect(actualDeclaration !.node).toBe(expectedDeclarationNode); @@ -1480,7 +1487,7 @@ describe('Esm5ReflectionHost', () => { const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const outerDeclaration = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); + program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerDeclaration = (((outerDeclaration.initializer as ts.ParenthesizedExpression) .expression as ts.CallExpression) .expression as ts.FunctionExpression) @@ -1564,7 +1571,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const node = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); + getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); expect(host.getClassSymbol(node)).toBeDefined(); }); @@ -1572,7 +1579,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const outerNode = - getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); + getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = (((outerNode.initializer as ts.ParenthesizedExpression).expression as ts.CallExpression) .expression as ts.FunctionExpression) @@ -1586,7 +1593,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); const outerNode = getDeclaration( - program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); + program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = (((outerNode.initializer as ts.ParenthesizedExpression) .expression as ts.CallExpression) .expression as ts.FunctionExpression) @@ -1599,7 +1606,8 @@ describe('Esm5ReflectionHost', () => { it('should return undefined if node is not an ES5 class', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); - const node = getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', ts.isFunctionDeclaration); + const node = + getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(host.getClassSymbol(node)).toBeUndefined(); }); }); @@ -1654,7 +1662,7 @@ describe('Esm5ReflectionHost', () => { const program = makeTestProgram(file); const host = new Esm5ReflectionHost(false, program.getTypeChecker()); - const classNode = getDeclaration(program, file.name, 'TestClass', ts.isVariableDeclaration); + const classNode = getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); return host.hasBaseClass(classNode); } diff --git a/packages/compiler-cli/src/ngtsc/annotations/test/BUILD.bazel b/packages/compiler-cli/src/ngtsc/annotations/test/BUILD.bazel index 74960efdfe..5064d87775 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/test/BUILD.bazel +++ b/packages/compiler-cli/src/ngtsc/annotations/test/BUILD.bazel @@ -21,7 +21,6 @@ ts_library( "//packages/compiler-cli/src/ngtsc/scope", "//packages/compiler-cli/src/ngtsc/testing", "//packages/compiler-cli/src/ngtsc/translator", - "//packages/compiler-cli/src/ngtsc/util", "@npm//typescript", ], ) diff --git a/packages/compiler-cli/src/ngtsc/annotations/test/component_spec.ts b/packages/compiler-cli/src/ngtsc/annotations/test/component_spec.ts index 98c6212fcb..731a4e004f 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/test/component_spec.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/test/component_spec.ts @@ -12,10 +12,9 @@ import {CycleAnalyzer, ImportGraph} from '../../cycles'; import {ErrorCode, FatalDiagnosticError} from '../../diagnostics'; import {ModuleResolver, NOOP_DEFAULT_IMPORT_RECORDER, ReferenceEmitter} from '../../imports'; import {PartialEvaluator} from '../../partial_evaluator'; -import {TypeScriptReflectionHost} from '../../reflection'; +import {TypeScriptReflectionHost, isNamedClassDeclaration} from '../../reflection'; import {LocalModuleScopeRegistry, MetadataDtsModuleScopeResolver} from '../../scope'; import {getDeclaration, makeProgram} from '../../testing/in_memory_typescript'; -import {isNamedClassDeclaration} from '../../util/src/typescript'; import {ResourceLoader} from '../src/api'; import {ComponentDecoratorHandler} from '../src/component'; diff --git a/packages/compiler-cli/src/ngtsc/annotations/test/directive_spec.ts b/packages/compiler-cli/src/ngtsc/annotations/test/directive_spec.ts index 4e4de13de2..a82dd30c52 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/test/directive_spec.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/test/directive_spec.ts @@ -10,10 +10,9 @@ import * as ts from 'typescript'; import {NOOP_DEFAULT_IMPORT_RECORDER, ReferenceEmitter} from '../../imports'; import {PartialEvaluator} from '../../partial_evaluator'; -import {TypeScriptReflectionHost} from '../../reflection'; +import {ClassDeclaration, TypeScriptReflectionHost, isNamedClassDeclaration} from '../../reflection'; import {LocalModuleScopeRegistry, MetadataDtsModuleScopeResolver} from '../../scope'; import {getDeclaration, makeProgram} from '../../testing/in_memory_typescript'; -import {isNamedClassDeclaration} from '../../util/src/typescript'; import {DirectiveDecoratorHandler} from '../src/directive'; @@ -79,5 +78,5 @@ describe('DirectiveDecoratorHandler', () => { class TestReflectionHost extends TypeScriptReflectionHost { hasBaseClassReturnValue = false; - hasBaseClass(node: ts.Declaration): boolean { return this.hasBaseClassReturnValue; } + hasBaseClass(clazz: ClassDeclaration): boolean { return this.hasBaseClassReturnValue; } } diff --git a/packages/compiler-cli/src/ngtsc/annotations/test/ng_module_spec.ts b/packages/compiler-cli/src/ngtsc/annotations/test/ng_module_spec.ts index 369706d62b..213ead9276 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/test/ng_module_spec.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/test/ng_module_spec.ts @@ -12,10 +12,9 @@ import * as ts from 'typescript'; import {LocalIdentifierStrategy, NOOP_DEFAULT_IMPORT_RECORDER, ReferenceEmitter} from '../../imports'; import {PartialEvaluator} from '../../partial_evaluator'; -import {TypeScriptReflectionHost} from '../../reflection'; +import {TypeScriptReflectionHost, isNamedClassDeclaration} from '../../reflection'; import {LocalModuleScopeRegistry, MetadataDtsModuleScopeResolver} from '../../scope'; import {getDeclaration, makeProgram} from '../../testing/in_memory_typescript'; -import {isNamedClassDeclaration} from '../../util/src/typescript'; import {NgModuleDecoratorHandler} from '../src/ng_module'; import {NoopReferencesRegistry} from '../src/references_registry'; diff --git a/packages/compiler-cli/src/ngtsc/reflection/index.ts b/packages/compiler-cli/src/ngtsc/reflection/index.ts index 145dd3a55a..12de1d3320 100644 --- a/packages/compiler-cli/src/ngtsc/reflection/index.ts +++ b/packages/compiler-cli/src/ngtsc/reflection/index.ts @@ -8,4 +8,5 @@ export * from './src/host'; export {typeNodeToValueExpr} from './src/type_to_value'; -export {TypeScriptReflectionHost, filterToMembersWithDecorator, reflectIdentifierOfDeclaration, reflectNameOfDeclaration, reflectObjectLiteral, reflectTypeEntityToDeclaration} from './src/typescript'; \ No newline at end of file +export {TypeScriptReflectionHost, filterToMembersWithDecorator, reflectIdentifierOfDeclaration, reflectNameOfDeclaration, reflectObjectLiteral, reflectTypeEntityToDeclaration} from './src/typescript'; +export {isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration} from './src/util'; diff --git a/packages/compiler-cli/src/ngtsc/reflection/src/host.ts b/packages/compiler-cli/src/ngtsc/reflection/src/host.ts index 126d583833..aefa5edd99 100644 --- a/packages/compiler-cli/src/ngtsc/reflection/src/host.ts +++ b/packages/compiler-cli/src/ngtsc/reflection/src/host.ts @@ -362,16 +362,13 @@ export interface ReflectionHost { * Examine a declaration which should be of a class, and return metadata about the members of the * class. * - * @param declaration a TypeScript `ts.Declaration` node representing the class over which to - * reflect. If the source is in ES6 format, this will be a `ts.ClassDeclaration` node. If the - * source is in ES5 format, this might be a `ts.VariableDeclaration` as classes in ES5 are - * represented as the result of an IIFE execution. + * @param clazz a `ClassDeclaration` representing the class over which to reflect. * * @returns an array of `ClassMember` metadata representing the members of the class. * * @throws if `declaration` does not resolve to a class declaration. */ - getMembersOfClass(clazz: ts.Declaration): ClassMember[]; + getMembersOfClass(clazz: ClassDeclaration): ClassMember[]; /** * Reflect over the constructor of a class and return metadata about its parameters. @@ -379,16 +376,13 @@ export interface ReflectionHost { * This method only looks at the constructor of a class directly and not at any inherited * constructors. * - * @param declaration a TypeScript `ts.Declaration` node representing the class over which to - * reflect. If the source is in ES6 format, this will be a `ts.ClassDeclaration` node. If the - * source is in ES5 format, this might be a `ts.VariableDeclaration` as classes in ES5 are - * represented as the result of an IIFE execution. + * @param clazz a `ClassDeclaration` representing the class over which to reflect. * * @returns an array of `Parameter` metadata representing the parameters of the constructor, if * a constructor exists. If the constructor exists and has 0 parameters, this array will be empty. * If the class has no constructor, this method returns `null`. */ - getConstructorParameters(declaration: ts.Declaration): CtorParameter[]|null; + getConstructorParameters(clazz: ClassDeclaration): CtorParameter[]|null; /** * Reflect over a function and return metadata about its parameters and body. @@ -478,17 +472,21 @@ export interface ReflectionHost { isClass(node: ts.Node): node is ClassDeclaration; /** - * Determines whether the given declaration has a base class. + * Determines whether the given declaration, which should be a class, has a base class. + * + * @param clazz a `ClassDeclaration` representing the class over which to reflect. */ - hasBaseClass(node: ts.Declaration): boolean; + hasBaseClass(clazz: ClassDeclaration): boolean; /** * Get the number of generic type parameters of a given class. * + * @param clazz a `ClassDeclaration` representing the class over which to reflect. + * * @returns the number of type parameters of the class, if known, or `null` if the declaration * is not a class or has an unknown number of type parameters. */ - getGenericArityOfClass(clazz: ts.Declaration): number|null; + getGenericArityOfClass(clazz: ClassDeclaration): number|null; /** * Find the assigned value of a variable declaration. diff --git a/packages/compiler-cli/src/ngtsc/reflection/src/typescript.ts b/packages/compiler-cli/src/ngtsc/reflection/src/typescript.ts index 6ceafc27fb..8f252179d0 100644 --- a/packages/compiler-cli/src/ngtsc/reflection/src/typescript.ts +++ b/packages/compiler-cli/src/ngtsc/reflection/src/typescript.ts @@ -26,17 +26,17 @@ export class TypeScriptReflectionHost implements ReflectionHost { .filter((dec): dec is Decorator => dec !== null); } - getMembersOfClass(declaration: ts.Declaration): ClassMember[] { - const clazz = castDeclarationToClassOrDie(declaration); - return clazz.members.map(member => this._reflectMember(member)) + getMembersOfClass(clazz: ClassDeclaration): ClassMember[] { + const tsClazz = castDeclarationToClassOrDie(clazz); + return tsClazz.members.map(member => this._reflectMember(member)) .filter((member): member is ClassMember => member !== null); } - getConstructorParameters(declaration: ts.Declaration): CtorParameter[]|null { - const clazz = castDeclarationToClassOrDie(declaration); + getConstructorParameters(clazz: ClassDeclaration): CtorParameter[]|null { + const tsClazz = castDeclarationToClassOrDie(clazz); // First, find the constructor. - const ctor = clazz.members.find(ts.isConstructorDeclaration); + const ctor = tsClazz.members.find(ts.isConstructorDeclaration); if (ctor === undefined) { return null; } @@ -139,9 +139,9 @@ export class TypeScriptReflectionHost implements ReflectionHost { return ts.isClassDeclaration(node) && (node.name !== undefined) && ts.isIdentifier(node.name); } - hasBaseClass(node: ts.Declaration): boolean { - return ts.isClassDeclaration(node) && node.heritageClauses !== undefined && - node.heritageClauses.some(clause => clause.token === ts.SyntaxKind.ExtendsKeyword); + hasBaseClass(clazz: ClassDeclaration): boolean { + return ts.isClassDeclaration(clazz) && clazz.heritageClauses !== undefined && + clazz.heritageClauses.some(clause => clause.token === ts.SyntaxKind.ExtendsKeyword); } getDeclarationOfIdentifier(id: ts.Identifier): Declaration|null { @@ -166,7 +166,7 @@ export class TypeScriptReflectionHost implements ReflectionHost { }; } - getGenericArityOfClass(clazz: ts.Declaration): number|null { + getGenericArityOfClass(clazz: ClassDeclaration): number|null { if (!ts.isClassDeclaration(clazz)) { return null; } @@ -419,7 +419,8 @@ export function reflectObjectLiteral(node: ts.ObjectLiteralExpression): Map { if (!ts.isClassDeclaration(declaration)) { throw new Error( `Reflecting on a ${ts.SyntaxKind[declaration.kind]} instead of a ClassDeclaration.`); diff --git a/packages/compiler-cli/src/ngtsc/reflection/src/util.ts b/packages/compiler-cli/src/ngtsc/reflection/src/util.ts new file mode 100644 index 0000000000..069c709647 --- /dev/null +++ b/packages/compiler-cli/src/ngtsc/reflection/src/util.ts @@ -0,0 +1,27 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import * as ts from 'typescript'; + +import {ClassDeclaration} from './host'; + + +export function isNamedClassDeclaration(node: ts.Node): + node is ClassDeclaration&{name: ts.Identifier} { + return ts.isClassDeclaration(node) && (node.name !== undefined); +} + +export function isNamedFunctionDeclaration(node: ts.Node): + node is ClassDeclaration&{name: ts.Identifier} { + return ts.isFunctionDeclaration(node) && (node.name !== undefined); +} + +export function isNamedVariableDeclaration(node: ts.Node): + node is ClassDeclaration&{name: ts.Identifier} { + return ts.isVariableDeclaration(node) && (node.name !== undefined); +} diff --git a/packages/compiler-cli/src/ngtsc/reflection/test/ts_host_spec.ts b/packages/compiler-cli/src/ngtsc/reflection/test/ts_host_spec.ts index 4e2926ce25..16dc055fc6 100644 --- a/packages/compiler-cli/src/ngtsc/reflection/test/ts_host_spec.ts +++ b/packages/compiler-cli/src/ngtsc/reflection/test/ts_host_spec.ts @@ -11,6 +11,7 @@ import * as ts from 'typescript'; import {getDeclaration, makeProgram} from '../../testing/in_memory_typescript'; import {CtorParameter} from '../src/host'; import {TypeScriptReflectionHost} from '../src/typescript'; +import {isNamedClassDeclaration} from '../src/util'; describe('reflector', () => { describe('ctor params', () => { @@ -25,7 +26,7 @@ describe('reflector', () => { } ` }]); - const clazz = getDeclaration(program, 'entry.ts', 'Foo', ts.isClassDeclaration); + const clazz = getDeclaration(program, 'entry.ts', 'Foo', isNamedClassDeclaration); const checker = program.getTypeChecker(); const host = new TypeScriptReflectionHost(checker); const args = host.getConstructorParameters(clazz) !; @@ -54,7 +55,7 @@ describe('reflector', () => { ` } ]); - const clazz = getDeclaration(program, 'entry.ts', 'Foo', ts.isClassDeclaration); + const clazz = getDeclaration(program, 'entry.ts', 'Foo', isNamedClassDeclaration); const checker = program.getTypeChecker(); const host = new TypeScriptReflectionHost(checker); const args = host.getConstructorParameters(clazz) !; @@ -83,7 +84,7 @@ describe('reflector', () => { ` } ]); - const clazz = getDeclaration(program, 'entry.ts', 'Foo', ts.isClassDeclaration); + const clazz = getDeclaration(program, 'entry.ts', 'Foo', isNamedClassDeclaration); const checker = program.getTypeChecker(); const host = new TypeScriptReflectionHost(checker); const args = host.getConstructorParameters(clazz) !; @@ -111,7 +112,7 @@ describe('reflector', () => { ` } ]); - const clazz = getDeclaration(program, 'entry.ts', 'Foo', ts.isClassDeclaration); + const clazz = getDeclaration(program, 'entry.ts', 'Foo', isNamedClassDeclaration); const checker = program.getTypeChecker(); const host = new TypeScriptReflectionHost(checker); const args = host.getConstructorParameters(clazz) !; @@ -139,7 +140,7 @@ describe('reflector', () => { ` } ]); - const clazz = getDeclaration(program, 'entry.ts', 'Foo', ts.isClassDeclaration); + const clazz = getDeclaration(program, 'entry.ts', 'Foo', isNamedClassDeclaration); const checker = program.getTypeChecker(); const host = new TypeScriptReflectionHost(checker); const args = host.getConstructorParameters(clazz) !; @@ -166,7 +167,7 @@ describe('reflector', () => { ` } ]); - const clazz = getDeclaration(program, 'entry.ts', 'Foo', ts.isClassDeclaration); + const clazz = getDeclaration(program, 'entry.ts', 'Foo', isNamedClassDeclaration); const checker = program.getTypeChecker(); const host = new TypeScriptReflectionHost(checker); const args = host.getConstructorParameters(clazz) !; @@ -198,7 +199,7 @@ describe('reflector', () => { ` } ]); - const clazz = getDeclaration(program, 'entry.ts', 'Foo', ts.isClassDeclaration); + const clazz = getDeclaration(program, 'entry.ts', 'Foo', isNamedClassDeclaration); const checker = program.getTypeChecker(); const host = new TypeScriptReflectionHost(checker); const args = host.getConstructorParameters(clazz) !; @@ -292,4 +293,4 @@ function argExpressionToString(name: ts.Node | null): string { } else { throw new Error(`Unexpected node in arg expression: ${ts.SyntaxKind[name.kind]}.`); } -} \ No newline at end of file +} diff --git a/packages/compiler-cli/src/ngtsc/scope/src/dependency.ts b/packages/compiler-cli/src/ngtsc/scope/src/dependency.ts index 786a3f1465..8f40725dc7 100644 --- a/packages/compiler-cli/src/ngtsc/scope/src/dependency.ts +++ b/packages/compiler-cli/src/ngtsc/scope/src/dependency.ts @@ -139,7 +139,8 @@ export class MetadataDtsModuleScopeResolver implements DtsModuleScopeResolver { * * @param ref `Reference` to the class of interest, with the context of how it was obtained. */ - private readModuleMetadataFromClass(ref: Reference): RawDependencyMetadata|null { + private readModuleMetadataFromClass(ref: Reference): RawDependencyMetadata + |null { const clazz = ref.node; const resolutionContext = clazz.getSourceFile().fileName; // This operation is explicitly not memoized, as it depends on `ref.ownedByModuleGuess`. diff --git a/packages/compiler-cli/src/ngtsc/scope/src/util.ts b/packages/compiler-cli/src/ngtsc/scope/src/util.ts index 1b05dd628d..bd5dee630a 100644 --- a/packages/compiler-cli/src/ngtsc/scope/src/util.ts +++ b/packages/compiler-cli/src/ngtsc/scope/src/util.ts @@ -9,8 +9,8 @@ import * as ts from 'typescript'; import {Reference} from '../../imports'; -import {ClassDeclaration, ClassMemberKind, ReflectionHost, reflectTypeEntityToDeclaration} from '../../reflection'; -import {isNamedClassDeclaration, nodeDebugInfo} from '../../util/src/typescript'; +import {ClassDeclaration, ClassMemberKind, ReflectionHost, isNamedClassDeclaration, reflectTypeEntityToDeclaration} from '../../reflection'; +import {nodeDebugInfo} from '../../util/src/typescript'; export function extractReferencesFromType( checker: ts.TypeChecker, def: ts.TypeNode, ngModuleImportedFrom: string | null, @@ -77,7 +77,7 @@ export function readStringArrayType(type: ts.TypeNode): string[] { } -export function extractDirectiveGuards(node: ts.Declaration, reflector: ReflectionHost): { +export function extractDirectiveGuards(node: ClassDeclaration, reflector: ReflectionHost): { ngTemplateGuards: string[], hasNgTemplateContextGuard: boolean, } { @@ -88,7 +88,7 @@ export function extractDirectiveGuards(node: ts.Declaration, reflector: Reflecti return {hasNgTemplateContextGuard, ngTemplateGuards}; } -function nodeStaticMethodNames(node: ts.Declaration, reflector: ReflectionHost): string[] { +function nodeStaticMethodNames(node: ClassDeclaration, reflector: ReflectionHost): string[] { return reflector.getMembersOfClass(node) .filter(member => member.kind === ClassMemberKind.Method && member.isStatic) .map(member => member.name); diff --git a/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts b/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts index db2bf6b539..938e377f92 100644 --- a/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts +++ b/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts @@ -11,9 +11,9 @@ import * as ts from 'typescript'; import {ErrorCode, FatalDiagnosticError} from '../../diagnostics'; import {ImportRewriter} from '../../imports'; -import {ClassDeclaration, ReflectionHost, reflectNameOfDeclaration} from '../../reflection'; +import {ClassDeclaration, ReflectionHost, isNamedClassDeclaration, reflectNameOfDeclaration} from '../../reflection'; import {TypeCheckContext} from '../../typecheck'; -import {getSourceFile, isNamedClassDeclaration} from '../../util/src/typescript'; +import {getSourceFile} from '../../util/src/typescript'; import {AnalysisOutput, CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence} from './api'; import {DtsFileTransformer} from './declaration'; diff --git a/packages/compiler-cli/src/ngtsc/tsc_plugin.ts b/packages/compiler-cli/src/ngtsc/tsc_plugin.ts index a06c845957..750ac30c6f 100644 --- a/packages/compiler-cli/src/ngtsc/tsc_plugin.ts +++ b/packages/compiler-cli/src/ngtsc/tsc_plugin.ts @@ -67,12 +67,11 @@ export class NgTscPlugin implements TscPlugin { const afterDeclarations: Array> = [(context: ts.TransformationContext) => (sf: ts.SourceFile | ts.Bundle) => { const visitor = (node: ts.Node): ts.Node => { - if (node.kind === ts.SyntaxKind.ClassDeclaration) { - const clz = node as ts.ClassDeclaration; + if (ts.isClassDeclaration(node)) { // For demo purposes, transform the class name in the .d.ts output return ts.updateClassDeclaration( - clz, clz.decorators, node.modifiers, ts.createIdentifier('NEWNAME'), - clz.typeParameters, clz.heritageClauses, clz.members); + node, node.decorators, node.modifiers, ts.createIdentifier('NEWNAME'), + node.typeParameters, node.heritageClauses, node.members); } return ts.visitEachChild(node, visitor, context); }; diff --git a/packages/compiler-cli/src/ngtsc/typecheck/test/BUILD.bazel b/packages/compiler-cli/src/ngtsc/typecheck/test/BUILD.bazel index 0a693ec11e..0f84c449ae 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/test/BUILD.bazel +++ b/packages/compiler-cli/src/ngtsc/typecheck/test/BUILD.bazel @@ -12,6 +12,7 @@ ts_library( "//packages:types", "//packages/compiler-cli/src/ngtsc/imports", "//packages/compiler-cli/src/ngtsc/path", + "//packages/compiler-cli/src/ngtsc/reflection", "//packages/compiler-cli/src/ngtsc/testing", "//packages/compiler-cli/src/ngtsc/typecheck", "//packages/compiler-cli/src/ngtsc/util", diff --git a/packages/compiler-cli/src/ngtsc/typecheck/test/type_constructor_spec.ts b/packages/compiler-cli/src/ngtsc/typecheck/test/type_constructor_spec.ts index 4c3abaa7c0..ab64dded32 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/test/type_constructor_spec.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/test/type_constructor_spec.ts @@ -10,8 +10,9 @@ import * as ts from 'typescript'; import {AbsoluteModuleStrategy, LocalIdentifierStrategy, LogicalProjectStrategy, ReferenceEmitter} from '../../imports'; import {LogicalFileSystem} from '../../path'; +import {isNamedClassDeclaration} from '../../reflection'; import {getDeclaration, makeProgram} from '../../testing/in_memory_typescript'; -import {getRootDirs, isNamedClassDeclaration} from '../../util/src/typescript'; +import {getRootDirs} from '../../util/src/typescript'; import {TypeCheckContext} from '../src/context'; import {TypeCheckProgramHost} from '../src/host'; diff --git a/packages/compiler-cli/src/ngtsc/util/src/typescript.ts b/packages/compiler-cli/src/ngtsc/util/src/typescript.ts index 111c3565d4..a63ded5d28 100644 --- a/packages/compiler-cli/src/ngtsc/util/src/typescript.ts +++ b/packages/compiler-cli/src/ngtsc/util/src/typescript.ts @@ -60,11 +60,6 @@ export function isDeclaration(node: ts.Node): node is ts.Declaration { ts.isFunctionDeclaration(node) || ts.isVariableDeclaration(node); } -export function isNamedClassDeclaration(node: ts.Node): node is ts.ClassDeclaration& - {name: ts.Identifier} { - return ts.isClassDeclaration(node) && (node.name !== undefined); -} - export function isExported(node: ts.Declaration): boolean { let topLevel: ts.Node = node; if (ts.isVariableDeclaration(node) && ts.isVariableDeclarationList(node.parent)) {