diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/metadata.ts b/packages/compiler-cli/src/ngtsc/annotations/src/metadata.ts index 56676ac84d..3ac72e8d10 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/metadata.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/metadata.ts @@ -70,8 +70,8 @@ export function generateSetClassMetadataCall( `Duplicate decorated properties found on class '${clazz.name.text}': ` + duplicateDecoratedMemberNames.join(', ')); } - const decoratedMembers = - classMembers.map(member => classMemberToMetadata(member.name, member.decorators!, isCore)); + const decoratedMembers = classMembers.map( + member => classMemberToMetadata(member.nameNode ?? member.name, member.decorators!, isCore)); if (decoratedMembers.length > 0) { metaPropDecorators = ts.createObjectLiteral(decoratedMembers); } @@ -127,7 +127,7 @@ function ctorParameterToMetadata( * Convert a reflected class member to metadata. */ function classMemberToMetadata( - name: string, decorators: Decorator[], isCore: boolean): ts.PropertyAssignment { + name: ts.PropertyName|string, decorators: Decorator[], isCore: boolean): ts.PropertyAssignment { const ngDecorators = decorators.filter(dec => isAngularDecorator(dec, isCore)) .map((decorator: Decorator) => decoratorToMetadata(decorator)); const decoratorMeta = ts.createArrayLiteral(ngDecorators); diff --git a/packages/compiler-cli/src/ngtsc/annotations/test/metadata_spec.ts b/packages/compiler-cli/src/ngtsc/annotations/test/metadata_spec.ts index b830a43326..1745af51a7 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/test/metadata_spec.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/test/metadata_spec.ts @@ -90,6 +90,19 @@ runInEachFileSystem(() => { `); expect(res).toBe(''); }); + + it('should preserve quotes around class member names', () => { + const res = compileAndPrint(` + import {Component, Input} from '@angular/core'; + + @Component('metadata') class Target { + @Input() 'has-dashes-in-name' = 123; + @Input() noDashesInName = 456; + } + `); + expect(res).toContain( + `{ 'has-dashes-in-name': [{ type: Input }], noDashesInName: [{ type: Input }] })`); + }); }); function compileAndPrint(contents: string): string {