fix(ngcc): prevent reflected decorators from being clobbered (#33362)
ngcc has an internal cache of computed decorator information for reflected classes, which could previously be mutated by consumers of the reflection host. With the ability to inject synthesized decorators, such decorators would inadvertently be added into the array of decorators that was owned by the internal cache of the reflection host, incorrectly resulting in synthesized decorators to be considered real decorators on a class. This commit fixes the issue by cloning the cached array before returning it. PR Close #33362
This commit is contained in:
@ -1931,6 +1931,20 @@ runInEachFileSystem(() => {
|
||||
expect(classDecoratorsSecondary.length).toEqual(1);
|
||||
expect(classDecoratorsSecondary[0] !.map(d => d.name)).toEqual(['Directive']);
|
||||
});
|
||||
|
||||
it('should return a cloned array on each invocation', () => {
|
||||
loadTestFiles(DECORATED_FILES);
|
||||
const {program} = makeTestBundleProgram(getRootFiles(DECORATED_FILES)[0]);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||
const classDecl =
|
||||
getDeclaration(program, DECORATED_FILES[0].name, 'A', ts.isClassDeclaration) !;
|
||||
const classSymbol = host.getClassSymbol(classDecl) !;
|
||||
|
||||
const firstResult = host.getDecoratorsOfSymbol(classSymbol);
|
||||
const secondResult = host.getDecoratorsOfSymbol(classSymbol);
|
||||
|
||||
expect(firstResult).not.toBe(secondResult);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDtsDeclarationsOfClass()', () => {
|
||||
|
Reference in New Issue
Block a user