Repository navigation
fix(ivy): objects like ElementRef should not use a special injection fn #26064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d60ae3a
6719427
96291f9
bcdd7f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,30 +101,10 @@ export enum R3ResolvedDependencyType { | |
| */ | ||
| Injector = 2, | ||
|
|
||
| /** | ||
| * The dependency is for `ElementRef`. | ||
| */ | ||
| ElementRef = 3, | ||
|
|
||
| /** | ||
| * The dependency is for `TemplateRef`. | ||
| */ | ||
| TemplateRef = 4, | ||
|
|
||
| /** | ||
| * The dependency is for `ViewContainerRef`. | ||
| */ | ||
| ViewContainerRef = 5, | ||
|
|
||
| /** | ||
| * The dependency is for `ChangeDetectorRef`. | ||
| */ | ||
| ChangeDetectorRef = 6, | ||
|
|
||
| /** | ||
| * The dependency is for `Renderer2`. | ||
| */ | ||
| Renderer2 = 7, | ||
| Renderer2 = 3, | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -282,14 +262,6 @@ function compileInjectDependency( | |
| case R3ResolvedDependencyType.Attribute: | ||
| // In the case of attributes, the attribute name in question is given as the token. | ||
| return o.importExpr(R3.injectAttribute).callFn([dep.token]); | ||
| case R3ResolvedDependencyType.ElementRef: | ||
| return o.importExpr(R3.injectElementRef).callFn([]); | ||
| case R3ResolvedDependencyType.TemplateRef: | ||
| return o.importExpr(R3.injectTemplateRef).callFn([]); | ||
| case R3ResolvedDependencyType.ViewContainerRef: | ||
| return o.importExpr(R3.injectViewContainerRef).callFn([]); | ||
| case R3ResolvedDependencyType.ChangeDetectorRef: | ||
| return o.importExpr(R3.injectChangeDetectorRef).callFn([]); | ||
| case R3ResolvedDependencyType.Renderer2: | ||
| return o.importExpr(R3.injectRenderer2).callFn([]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you thought about how we could get rid of |
||
| default: | ||
|
|
@@ -320,13 +292,7 @@ export function dependenciesFromGlobalMetadata( | |
| if (dependency.token) { | ||
| const tokenRef = tokenReference(dependency.token); | ||
| let resolved: R3ResolvedDependencyType = R3ResolvedDependencyType.Token; | ||
| if (tokenRef === elementRef) { | ||
| resolved = R3ResolvedDependencyType.ElementRef; | ||
| } else if (tokenRef === templateRef) { | ||
| resolved = R3ResolvedDependencyType.TemplateRef; | ||
| } else if (tokenRef === viewContainerRef) { | ||
| resolved = R3ResolvedDependencyType.ViewContainerRef; | ||
| } else if (tokenRef === injectorRef) { | ||
| if (tokenRef === injectorRef) { | ||
| resolved = R3ResolvedDependencyType.Injector; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you thought about how we could get rid of |
||
| } else if (tokenRef === renderer2) { | ||
| resolved = R3ResolvedDependencyType.Renderer2; | ||
|
|
@@ -363,4 +329,4 @@ function isDelegatedMetadata(meta: R3FactoryMetadata): meta is R3DelegatedFactor | |
|
|
||
| function isExpressionFactoryMetadata(meta: R3FactoryMetadata): meta is R3ExpressionFactoryMetadata { | ||
| return (meta as any).expression !== undefined; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,13 @@ ng_module( | |
| "*.ts", | ||
| "src/**/*.ts", | ||
| ], | ||
| exclude = ["src/ivy_switch.ts"], | ||
| exclude = [ | ||
| "src/ivy_switch/compiler/index.ts", | ||
| "src/ivy_switch/runtime/index.ts", | ||
| ], | ||
| ) + [ | ||
| ":ivy_switch", | ||
| ":ivy_switch_compiler", | ||
| ":ivy_switch_runtime", | ||
| ], | ||
| module_name = "@angular/core", | ||
| deps = [ | ||
|
|
@@ -42,19 +46,27 @@ ng_package( | |
|
|
||
| ## Controls if Ivy is enabled. (Temporary target until we permanently switch over to Ivy) | ||
| ## | ||
| ## This file generates `src/ivy_switch.ts` file which reexports symbols for `ViewEngine` or `Ivy.` | ||
| ## - append `--define=compile=legacy` (default) to `bazel` command to reexport `./ivy_switch_legacy` | ||
| ## and use `ViewEngine` | ||
| ## - append `--define=compile=jit` to `bazel` command to rexport `./ivy_switch_jit` and use `Ivy` | ||
| ## - append `--define=compile=local` to `bazel` command to rexport `./ivy_switch_jit` and use `Ivy` | ||
| ## This file generates the `src/ivy_switch/compiler/index.ts` and `src/ivy_switch/runtime/index.ts` files which | ||
| ## reexport symbols for `ViewEngine` or `Ivy.` | ||
| ## - append `--define=compile=legacy` (default) to `bazel` command to reexport `./legacy` from each folder | ||
| ## in the 'ivy_switch' directory and use `ViewEngine` | ||
| ## - append `--define=compile=jit` to `bazel` command to rexport `./jit` from each folder in the `ivy_switch` | ||
| ## directory and use `Ivy` | ||
| ## - append `--define=compile=local` to `bazel` command to rexport `./ivy_switch/compiler/jit` and use `Ivy` | ||
| ## in the local analysis mode. (run as part of `ngtsc`) | ||
| ## | ||
| ## NOTE: `--define=compile=jit` works with any `bazel` command or target across the repo. | ||
| ## | ||
| ## See: `//tools/bazel.rc` where `--define=ivy=false` is defined as default. | ||
| ## See: `./src/ivy_switch.ts` for more details. | ||
| ## See: `./src/ivy_switch/compiler/index.ts` for more details. | ||
| genrule( | ||
| name = "ivy_switch_compiler", | ||
| outs = ["src/ivy_switch/compiler/index.ts"], | ||
| cmd = "echo export '*' from \"'./$(compile)';\" > $@", | ||
| ) | ||
|
|
||
| genrule( | ||
| name = "ivy_switch", | ||
| outs = ["src/ivy_switch.ts"], | ||
| cmd = "echo export '*' from \"'./ivy_switch_$(compile)';\" > $@", | ||
| name = "ivy_switch_runtime", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reasoning for this change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The compiler switch relies on |
||
| outs = ["src/ivy_switch/runtime/index.ts"], | ||
| cmd = "echo export '*' from \"'./$(compile)';\" > $@", | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you thought about how we could get rid of
injectAttribute? I think calling@Attribute('name')should create a token which captures thenameand than writes a factory intoNG_ELEMENT_IDwhere thenameis captured.Given:
should generate:
so that
AttributeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds good, but let's push to another PR?