-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Back patch spec #22235
Back patch spec #22235
Conversation
export class LibAModule {} | ||
// END FILE: node_modules/libA/module.ts | ||
// BEGIN FILE: node_modules/libA/module.metadata.json | ||
// Abridged version of metadata |
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.
A bridged (space between)?
Another case below.
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.
:-) Actually abridged is a word
const node_modules_libA_module_metadata = { | ||
'LibAModule': { | ||
refs: ["LibAComponent"], | ||
constructorDes: [], |
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.
Des
? Deps
?
Several other cases below.
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.
👍
// END FILE: src/main.ts | ||
|
||
// BEGIN FILE: src/app.ngfactory.ts | ||
function ngBackPatch_node_modules_libB_module() { |
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.
Should it return true
? The returned value is used in logical and below.
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.
We should update the code not to rely on the result of this function.
It is important that it be easy to remove everything from this function so what it be empty after the build optimizer is finished with it.
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.
added : void
moduleType: AppModule, | ||
patchedDeps: false, | ||
create(parentInjector: Injector | null): NgModuleRef<AppModule> { | ||
this.patchedDeps && ngBackPatch_node_modules_libB_module() && (this.patchedDeps = true); |
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.
!this.patchedDeps && ...
rather than this.patchedDeps && ...
?
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.
We should generate this more simply as,
if (!this.patchDeps) {
this.patchedDeps = true;
ngBackPatch_node_modules_libB_module();
}
which will be rewritten by uglify into something like:
!this.patchedDeps && (this.patchedDeps = true, b())
In other words, lets leave the ugly code production to uglify.
As it shouldn't matter, it is slightly safer to set this.pachedDeps = true
before calling the back-patch function which would an indirect recursive loop if one exists, so I moved the set of patchedDeps
.
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.
👍
class CompiledWithIvy { | ||
// NORMATIVE | ||
static ngInjectableDef = pending_pull_22005.defineInjectable( | ||
{factory: function CompileWithIvy_Factory() { return new CompiledWithIvy(); }}); |
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.
CompileWithIvy_Factory
-> CompiledWithIvy_Factory
according to the class name?
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.
fixed
function ngPatch_node_modules_some_library_path_public_CompileWithIvy() { | ||
/** @__BUILD_OPTIMIZER_COLOCATE__ */ | ||
(ThirdPartyClass as any).ngInjectableDef = pending_pull_22005.defineInjectable( | ||
{factory: function CompileWithIvy_Factory() { return new ThirdPartyClass(); }}); |
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.
CompileWithIvy_Factory
-> ThirdPartyClass_Factory
?
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.
fixed
Hi @mhevery! This PR has merge conflicts due to recent upstream merges. |
moduleType: AppModule, | ||
patchedDeps: false, | ||
create(parentInjector: Injector | null): NgModuleRef<AppModule> { | ||
this.patchedDeps && ngBackPatch_node_modules_libB_module() && (this.patchedDeps = true); |
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.
We should generate this more simply as,
if (!this.patchDeps) {
this.patchedDeps = true;
ngBackPatch_node_modules_libB_module();
}
which will be rewritten by uglify into something like:
!this.patchedDeps && (this.patchedDeps = true, b())
In other words, lets leave the ugly code production to uglify.
As it shouldn't matter, it is slightly safer to set this.pachedDeps = true
before calling the back-patch function which would an indirect recursive loop if one exists, so I moved the set of patchedDeps
.
} | ||
|
||
export const AppModuleFactory: NgModuleFactory<AppModule>&{patchedDeps: boolean} = { | ||
moduleType: AppModule, |
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.
FYI: This is generated in a separate module from AppModule
so we import this using i0.AppModule
syntax so the normative section should reflect that.
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.
fixed
|
||
export const AppModuleFactory: NgModuleFactory<AppModule>&{patchedDeps: boolean} = { | ||
moduleType: AppModule, | ||
patchedDeps: false, |
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.
We don't actually need this as the default value of patchDeps
is undefined
. We should consider changing the declaration to ... & {patchedDeps?: true}
and remove this explicit set to false
.
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.
Good idea, Done.
export const AppModuleFactory: NgModuleFactory<AppModule>&{patchedDeps: boolean} = { | ||
moduleType: AppModule, | ||
patchedDeps: false, | ||
create(parentInjector: Injector | null): NgModuleRef<AppModule> { |
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.
This syntax is hard for me to create. Consider changing this to a function expression create: function AppModuleFactory_Create { ... }
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.
done
Produces back-patch as described in the angular#22235 and referenced in angular#22480. This just contains the compiler implementations and the corresponding unit tests. Connecting the dots as described in angular#22480 will be in a follow on change.
|
||
// Simulate Imports | ||
const i0 = { | ||
AppModule: MyAppModule, |
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.
MyAppModule: MyAppModule
?
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.
fixed
ngBackPatch_node_modules_libB_module_packageAComponent(); | ||
ngBackPatch_node_modules_libB_module_packageAModule(); | ||
} | ||
|
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.
// NORMATIVE
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.
fixed
function ngBackPatch_node_modules_libB_module_packageAModule(): void { | ||
(NpmModule as any).ngInjectorDef = pending_pull_22458.defineInjector(details_elided); | ||
} | ||
|
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.
// /NORMATIVE
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.
fixed
const i0 = { | ||
AppModule: MyAppModule, | ||
}; | ||
|
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.
// NORMATIVE
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.
fixed
this.patchedDeps = true; | ||
ngBackPatch_node_modules_libB_module(); | ||
} | ||
return details_elided; |
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.
// /NORMATIVE
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.
fixed
} | ||
|
||
// Simulate Imports | ||
const i0 = { |
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.
Please change i0
to $i0$
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.
fixed
|
||
export const AppModuleFactory: NgModuleFactory<MyAppModule>&{patchedDeps?: true} = { | ||
moduleType: i0.AppModule, | ||
create: function AppModuleFactory_Create(parentInjector: Injector | null): |
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.
This would be easier if you created:
type $ParentInjector$ = Injector | null;
and used that here. This allows me to cut/paste this directly instead of having to fix up the types.
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.
done
import {Component, ContentChild, Directive, Injectable, Injector, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef} from '../../../src/core'; | ||
import * as r3 from '../../../src/render3/index'; | ||
|
||
import {pending_pull_22458} from './small_app_spec'; |
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.
import {pending_pull_22458 as $pending_pull_22458$} from './small_app_spec';
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.
done
import {NgModuleFactory, NgModuleRef} from 'core'; | ||
|
||
import {Component, ContentChild, Directive, Injectable, Injector, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef} from '../../../src/core'; | ||
import * as r3 from '../../../src/render3/index'; |
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.
import * as $r3$ from '../../src/core_rener3_private_export';
and then use the ɵ
versions.
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.
done
1aa4500
to
b437bbc
Compare
Produces back-patch as described in the angular#22235 and referenced in angular#22480. This just contains the compiler implementations and the corresponding unit tests. Connecting the dots as described in angular#22480 will be in a follow on change.
Produces back-patch as described in the angular#22235 and referenced in angular#22480. This just contains the compiler implementations and the corresponding unit tests. Connecting the dots as described in angular#22480 will be in a follow on change.
Produces back-patch as described in the angular#22235 and referenced in angular#22480. This just contains the compiler implementations and the corresponding unit tests. Connecting the dots as described in angular#22480 will be in a follow on change.
Produces back-patch as described in the angular#22235 and referenced in angular#22480. This just contains the compiler implementations and the corresponding unit tests. Connecting the dots as described in angular#22480 will be in a follow on change.
Produces back-patch as described in the angular#22235 and referenced in angular#22480. This just contains the compiler implementations and the corresponding unit tests. Connecting the dots as described in angular#22480 will be in a follow on change.
Produces back-patch as described in the angular#22235 and referenced in angular#22480. This just contains the compiler implementations and the corresponding unit tests. Connecting the dots as described in angular#22480 will be in a follow on change.
) Produces back-patch as described in the angular#22235 and referenced in angular#22480. This just contains the compiler implementations and the corresponding unit tests. Connecting the dots as described in angular#22480 will be in a follow on change. PR Close angular#22506
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This PR is a WIP which provides an example how Ivy and non-Ivy code can interoperate through back patching.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information