Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ngcc): avoid warning when reflecting on index signature member #33198

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/compiler-cli/ngcc/src/host/esm2015_host.ts
Expand Up @@ -1778,7 +1778,10 @@ function isNamedDeclaration(node: ts.Declaration): node is ts.NamedDeclaration&

function isClassMemberType(node: ts.Declaration): node is ts.ClassElement|
ts.PropertyAccessExpression|ts.BinaryExpression {
return ts.isClassElement(node) || isPropertyAccess(node) || ts.isBinaryExpression(node);
return (ts.isClassElement(node) || isPropertyAccess(node) || ts.isBinaryExpression(node)) &&
// Additionally, ensure `node` is not an index signature, for example on an abstract class:
// `abstract class Foo { [key: string]: any; }`
!ts.isIndexSignatureDeclaration(node);
}

/**
Expand Down
24 changes: 24 additions & 0 deletions packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts
Expand Up @@ -46,6 +46,7 @@ runInEachFileSystem(() => {
let TYPINGS_DTS_FILES: TestFile[];
let MODULE_WITH_PROVIDERS_PROGRAM: TestFile[];
let NAMESPACED_IMPORT_FILE: TestFile;
let INDEX_SIGNATURE_PROP_FILE: TestFile;

beforeEach(() => {
_ = absoluteFrom;
Expand Down Expand Up @@ -690,6 +691,15 @@ runInEachFileSystem(() => {
];
`
};

INDEX_SIGNATURE_PROP_FILE = {
name: _('/index_signature_prop.d.ts'),
contents: `
abstract class IndexSignatureClass {
[key: string]: any;
}
`,
};
});

describe('getDecoratorsOfDeclaration()', () => {
Expand Down Expand Up @@ -941,6 +951,20 @@ runInEachFileSystem(() => {
expect(staticProperty.value !.getText()).toEqual(`'static'`);
});

it('should ignore index signature properties', () => {
loadTestFiles([INDEX_SIGNATURE_PROP_FILE]);
const logger = new MockLogger();
const {program} = makeTestBundleProgram(INDEX_SIGNATURE_PROP_FILE.name);
const host = new Esm2015ReflectionHost(logger, false, program.getTypeChecker());
const classNode = getDeclaration(
program, INDEX_SIGNATURE_PROP_FILE.name, 'IndexSignatureClass',
isNamedClassDeclaration);
const members = host.getMembersOfClass(classNode);

expect(members).toEqual([]);
expect(logger.logs.warn).toEqual([]);
});

it('should throw if the symbol is not a class', () => {
loadTestFiles([FOO_FUNCTION_FILE]);
const {program} = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
Expand Down