Skip to content

Commit 23b06af

Browse files
alxhubjasonaden
authored andcommitted
fix(core): export a value for InjectFlags (angular#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 angular#27251. PR Close angular#27279
1 parent 78e3a4c commit 23b06af

File tree

7 files changed

+19
-2
lines changed

7 files changed

+19
-2
lines changed

packages/core/src/di/injector_compatibility.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import {Inject, Optional, Self, SkipSelf} from './metadata';
1919
*
2020
* @publicApi
2121
*/
22-
export const enum InjectFlags {
22+
export enum InjectFlags {
23+
// TODO(alxhub): make this 'const' when ngc no longer writes exports of it into ngfactory files.
24+
2325
Default = 0b0000,
2426

2527
/**

packages/core/test/bundling/animation_world/bundle.golden_symbols.json

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
{
8787
"name": "INJECTOR_SIZE"
8888
},
89+
{
90+
"name": "InjectFlags"
91+
},
8992
{
9093
"name": "IterableChangeRecord_"
9194
},

packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json

+3
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@
176176
{
177177
"name": "Inject"
178178
},
179+
{
180+
"name": "InjectFlags"
181+
},
179182
{
180183
"name": "InjectionToken"
181184
},

packages/core/test/bundling/injection/bundle.golden_symbols.json

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
{
1818
"name": "Inject"
1919
},
20+
{
21+
"name": "InjectFlags"
22+
},
2023
{
2124
"name": "InjectionToken"
2225
},

packages/core/test/bundling/todo/bundle.golden_symbols.json

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
{
7575
"name": "INJECTOR_SIZE"
7676
},
77+
{
78+
"name": "InjectFlags"
79+
},
7780
{
7881
"name": "IterableChangeRecord_"
7982
},

packages/core/test/bundling/todo_r2/bundle.golden_symbols.json

+3
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@
371371
{
372372
"name": "Inject"
373373
},
374+
{
375+
"name": "InjectFlags"
376+
},
374377
{
375378
"name": "InjectionToken"
376379
},

tools/public_api_guard/core/core.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ export interface InjectDecorator {
347347
new (token: any): Inject;
348348
}
349349

350-
export declare const enum InjectFlags {
350+
export declare enum InjectFlags {
351351
Default = 0,
352352
Host = 1,
353353
Self = 2,

0 commit comments

Comments
 (0)