From eb1fe19088e80b674deb7aec44df35e80f555db6 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Wed, 22 Aug 2018 11:37:07 -0700 Subject: [PATCH] fix(ivy): ngtsc directive compilation should use shared ConstantPool (#25620) This fixes a bug in ngtsc where each @Directive was compiled using a separate ConstantPool. This resulted in two issues: * Directive constants were not shared across the file * Extra statements from directive compilation were dropped instead of added to the file This commit fixes both issues and adds a test to verify @Directive is working properly. PR Close #25620 --- .../src/ngtsc/annotations/src/directive.ts | 6 ++--- .../compiler-cli/test/ngtsc/ngtsc_spec.ts | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/directive.ts b/packages/compiler-cli/src/ngtsc/annotations/src/directive.ts index e67d5bce2b..bb281fc4a6 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/directive.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/directive.ts @@ -45,13 +45,13 @@ export class DirectiveDecoratorHandler implements DecoratorHandler { .toContain('function GrandChild_Factory(t) { return new (t || GrandChild)(); }'); }); + it('generates base factories for directives', () => { + writeConfig(); + write(`test.ts`, ` + import {Directive} from '@angular/core'; + + class Base {} + + @Directive({ + selector: '[test]', + }) + class Dir extends Base { + } + `); + + + const exitCode = main(['-p', basePath], errorSpy); + expect(errorSpy).not.toHaveBeenCalled(); + expect(exitCode).toBe(0); + const jsContents = getContents('test.js'); + + expect(jsContents).toContain('var ɵDir_BaseFactory = i0.ɵgetInheritedFactory(Dir)'); + }); + it('should wrap "directives" in component metadata in a closure when forward references are present', () => { writeConfig();