From 23b06af9401322ce559ef58184ef5926ed1a50cc Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Mon, 26 Nov 2018 14:27:39 -0800 Subject: [PATCH] fix(core): export a value for InjectFlags (#27279) A recent commit (probably 2c7386c) has changed the import graph of the DI types in core, and somehow results in the ngc compiler deciding to re-export core DI types from application factories which tangentially use inject(). This is not really surprising; ngc's import graph can be very unstable. However, this results in a re-export of InjectFlags surviving JS compilation. InjectFlags was a const enum, akin to an interface in TS, with no runtime repesentation. This causes a warning to be emitted by Webpack when it sees the re-export of InjectFlags. This commit avoids the issue by removing 'const' from the declaration of InjectFlags, causing it to have a runtime value. This is a temporary fix. The real fix will be for ngc to no longer write exports of const enums. Testing strategy: manually verified. Due to the problem only manifesting when recompiling after a change and then running Webpack, there is no existing framework via which this could be easily tested with an integration test. Additionally, the potential for this issue is gone in Ivy, so this solution is only temporarily needed. Fixes #27251. PR Close #27279 --- packages/core/src/di/injector_compatibility.ts | 4 +++- .../test/bundling/animation_world/bundle.golden_symbols.json | 3 +++ .../test/bundling/hello_world_r2/bundle.golden_symbols.json | 3 +++ .../core/test/bundling/injection/bundle.golden_symbols.json | 3 +++ packages/core/test/bundling/todo/bundle.golden_symbols.json | 3 +++ .../core/test/bundling/todo_r2/bundle.golden_symbols.json | 3 +++ tools/public_api_guard/core/core.d.ts | 2 +- 7 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/core/src/di/injector_compatibility.ts b/packages/core/src/di/injector_compatibility.ts index 78a30ae32f..3eb5b47c3e 100644 --- a/packages/core/src/di/injector_compatibility.ts +++ b/packages/core/src/di/injector_compatibility.ts @@ -19,7 +19,9 @@ import {Inject, Optional, Self, SkipSelf} from './metadata'; * * @publicApi */ -export const enum InjectFlags { +export enum InjectFlags { + // TODO(alxhub): make this 'const' when ngc no longer writes exports of it into ngfactory files. + Default = 0b0000, /** diff --git a/packages/core/test/bundling/animation_world/bundle.golden_symbols.json b/packages/core/test/bundling/animation_world/bundle.golden_symbols.json index f211e5957d..0f06d41c67 100644 --- a/packages/core/test/bundling/animation_world/bundle.golden_symbols.json +++ b/packages/core/test/bundling/animation_world/bundle.golden_symbols.json @@ -86,6 +86,9 @@ { "name": "INJECTOR_SIZE" }, + { + "name": "InjectFlags" + }, { "name": "IterableChangeRecord_" }, 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 5162284265..18a8ae65f2 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 @@ -176,6 +176,9 @@ { "name": "Inject" }, + { + "name": "InjectFlags" + }, { "name": "InjectionToken" }, diff --git a/packages/core/test/bundling/injection/bundle.golden_symbols.json b/packages/core/test/bundling/injection/bundle.golden_symbols.json index c9d8c5f334..48f070ca93 100644 --- a/packages/core/test/bundling/injection/bundle.golden_symbols.json +++ b/packages/core/test/bundling/injection/bundle.golden_symbols.json @@ -17,6 +17,9 @@ { "name": "Inject" }, + { + "name": "InjectFlags" + }, { "name": "InjectionToken" }, diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index 2b08727a48..9c566d2385 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -74,6 +74,9 @@ { "name": "INJECTOR_SIZE" }, + { + "name": "InjectFlags" + }, { "name": "IterableChangeRecord_" }, 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 0fa4d1bac2..b5f77a965d 100644 --- a/packages/core/test/bundling/todo_r2/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo_r2/bundle.golden_symbols.json @@ -371,6 +371,9 @@ { "name": "Inject" }, + { + "name": "InjectFlags" + }, { "name": "InjectionToken" }, diff --git a/tools/public_api_guard/core/core.d.ts b/tools/public_api_guard/core/core.d.ts index 2b0c1cb026..2d34bab8e5 100644 --- a/tools/public_api_guard/core/core.d.ts +++ b/tools/public_api_guard/core/core.d.ts @@ -347,7 +347,7 @@ export interface InjectDecorator { new (token: any): Inject; } -export declare const enum InjectFlags { +export declare enum InjectFlags { Default = 0, Host = 1, Self = 2,