diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts b/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts index 97691411bc..f65b93db86 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Expression, ExternalExpr, InvokeFunctionExpr, LiteralArrayExpr, LiteralExpr, R3Identifiers, R3InjectorMetadata, R3NgModuleMetadata, R3Reference, Statement, WrappedNodeExpr, compileInjector, compileNgModule} from '@angular/compiler'; +import {Expression, ExternalExpr, InvokeFunctionExpr, LiteralArrayExpr, R3Identifiers, R3InjectorMetadata, R3NgModuleMetadata, R3Reference, Statement, WrappedNodeExpr, compileInjector, compileNgModule} from '@angular/compiler'; import * as ts from 'typescript'; import {ErrorCode, FatalDiagnosticError} from '../../diagnostics'; @@ -29,7 +29,7 @@ export interface NgModuleAnalysis { metadataStmt: Statement|null; declarations: Reference[]; exports: Reference[]; - id: string|null; + id: Expression|null; } /** @@ -121,16 +121,8 @@ export class NgModuleDecoratorHandler implements DecoratorHandler { env.driveMain(); const jsContents = env.getContents('test.js'); - expect(jsContents).toContain('i0.\u0275registerNgModuleType("test", TestModule);'); + expect(jsContents).toContain('i0.\u0275registerNgModuleType(\'test\', TestModule);'); }); + it('should emit a \u0275registerNgModuleType call when the module id is defined as `module.id`', + () => { + env.tsconfig(); + env.write('index.d.ts', ` + declare const module = {id: string}; + `); + env.write('test.ts', ` + import {NgModule} from '@angular/core'; + + @NgModule({id: module.id}) + export class TestModule {} + `); + + env.driveMain(); + + const jsContents = env.getContents('test.js'); + expect(jsContents).toContain('i0.\u0275registerNgModuleType(module.id, TestModule);'); + }); + it('should filter out directives and pipes from module exports in the injector def', () => { env.tsconfig(); env.write('test.ts', `