From a64859b4bc65385dec4c038af352e6bde429c903 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Thu, 4 Oct 2018 21:15:31 +0100 Subject: [PATCH] =?UTF-8?q?fix(core):=20ensure=20that=20`=C9=B5defineNgMod?= =?UTF-8?q?ule`=20is=20available=20in=20flat-file=20formats=20(#26403)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When compiling the flat-file version of the `@angular/core` we need to be aware that we cannot rely upon imported names to access the ivy definition functions. The compiler is already clever enough to use local function calls rather than trying to add a namespaced import, but there is a problem if the local name of the function is different to the exported name. This is the case for functions that are not part of the public API, and so are exported under a barred-O private alias. In `@angular/core` the only decorations in use are `@NgModule` and `@Injectable`. There are no directives, components, pipes, etc. Since `defineInjectable` is part of the public API of `@angular/core`, the compiler is able to generate code that references the original non-barred-O version of the function. But the `defineNgModule` is not part of the public API and so the compiler must generate code that refers to it by the private barred-O version of the function. This commit imports and then re-exports this barred-O version of `defineModule` to ensure that the symbol is available in the local scope of the flat-file versions of the `@angular/core` library. PR Close #26403 --- packages/core/src/core_render3_private_export.ts | 5 ++++- .../test/bundling/hello_world_r2/bundle.golden_symbols.json | 3 +++ .../core/test/bundling/todo_r2/bundle.golden_symbols.json | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/core/src/core_render3_private_export.ts b/packages/core/src/core_render3_private_export.ts index 385ada54fe..562651273c 100644 --- a/packages/core/src/core_render3_private_export.ts +++ b/packages/core/src/core_render3_private_export.ts @@ -7,12 +7,15 @@ */ // clang-format off +// We need to have `ɵdefineNgModule` defined locally for flat-file ngcc compilation. +// More details in the commit where this is added. +import {defineNgModule} from './render3/index'; +export const ɵdefineNgModule = defineNgModule; export { defineBase as ɵdefineBase, defineComponent as ɵdefineComponent, defineDirective as ɵdefineDirective, definePipe as ɵdefinePipe, - defineNgModule as ɵdefineNgModule, detectChanges as ɵdetectChanges, renderComponent as ɵrenderComponent, ComponentType as ɵComponentType, diff --git a/packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json b/packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json index 2ee3b4f8ad..309cd1a702 100644 --- a/packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json +++ b/packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json @@ -4633,5 +4633,8 @@ }, { "name": "ɵResourceLoaderImpl_BaseFactory" + }, + { + "name": "ɵdefineNgModule" } ] \ No newline at end of file diff --git a/packages/core/test/bundling/todo_r2/bundle.golden_symbols.json b/packages/core/test/bundling/todo_r2/bundle.golden_symbols.json index 797f265634..fe8044f8aa 100644 --- a/packages/core/test/bundling/todo_r2/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo_r2/bundle.golden_symbols.json @@ -2671,5 +2671,8 @@ }, { "name": "wtfLeave" + }, + { + "name": "ɵdefineNgModule" } ] \ No newline at end of file