Skip to content

Commit

Permalink
fix(core): export a value for InjectFlags (angular#27279)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alxhub authored and jasonaden committed Nov 27, 2018
1 parent 78e3a4c commit 23b06af
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/di/injector_compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
{
"name": "INJECTOR_SIZE"
},
{
"name": "InjectFlags"
},
{
"name": "IterableChangeRecord_"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@
{
"name": "Inject"
},
{
"name": "InjectFlags"
},
{
"name": "InjectionToken"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
{
"name": "Inject"
},
{
"name": "InjectFlags"
},
{
"name": "InjectionToken"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/core/test/bundling/todo/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
{
"name": "INJECTOR_SIZE"
},
{
"name": "InjectFlags"
},
{
"name": "IterableChangeRecord_"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@
{
"name": "Inject"
},
{
"name": "InjectFlags"
},
{
"name": "InjectionToken"
},
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/core/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 23b06af

Please sign in to comment.