Repository navigation
refactor(compiler): implement factory declarations #41231
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
Closed
petebacondarwin
wants to merge
11
commits into
angular:master
from
petebacondarwin:linker-factory-declarations
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ac26d69
refactor(compiler): remove `injectFn` option from factory metadata
petebacondarwin c73d243
fixup! refactor(compiler): remove `injectFn` option from factory meta…
petebacondarwin befdb9e
refactor(compiler-cli): implement `ɵɵngDeclareFactory`
petebacondarwin 3852451
refactor(core): remove the need for `ɵɵinjectPipeChangeDetectorRef()`
petebacondarwin 7a56eb5
fixup! refactor(core): remove the need for `ɵɵinjectPipeChangeDetecto…
petebacondarwin 7aa0e20
refactor(compiler-cli): having an `ɵinj` field no longer guarantees i…
petebacondarwin 2cff73a
refactor(compiler): remove unused `dependenciesFromGlobalMetadata()` …
petebacondarwin 03ddd36
refactor(compiler): remove `R3ResolvedDependencyType` altogether
petebacondarwin 45ccecf
fixup! refactor(compiler): remove `R3ResolvedDependencyType` altogether
petebacondarwin a3b7402
refactor(compiler-cli): use a shared function for gathering factory m…
petebacondarwin 1fa86fa
refactor(compiler): rename `R3FactoryTarget` to `FactoryTarget`
petebacondarwin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_factory_linker_1.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.io/license | ||
| */ | ||
| import {compileFactoryFunction, ConstantPool, FactoryTarget, R3DeclareDependencyMetadata, R3DeclareFactoryMetadata, R3DependencyMetadata, R3FactoryMetadata, R3PartialDeclaration} from '@angular/compiler'; | ||
| import * as o from '@angular/compiler/src/output/output_ast'; | ||
|
|
||
| import {AstObject} from '../../ast/ast_value'; | ||
| import {FatalLinkerError} from '../../fatal_linker_error'; | ||
|
|
||
| import {PartialLinker} from './partial_linker'; | ||
| import {parseEnum, wrapReference} from './util'; | ||
|
|
||
| /** | ||
| * A `PartialLinker` that is designed to process `ɵɵngDeclareFactory()` call expressions. | ||
| */ | ||
| export class PartialFactoryLinkerVersion1<TExpression> implements PartialLinker<TExpression> { | ||
| linkPartialDeclaration( | ||
| constantPool: ConstantPool, | ||
| metaObj: AstObject<R3PartialDeclaration, TExpression>): o.Expression { | ||
| const meta = toR3FactoryMeta(metaObj); | ||
| const def = compileFactoryFunction(meta); | ||
| return def.expression; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Derives the `R3FactoryMetadata` structure from the AST object. | ||
| */ | ||
| export function toR3FactoryMeta<TExpression>( | ||
| metaObj: AstObject<R3DeclareFactoryMetadata, TExpression>): R3FactoryMetadata { | ||
| const typeExpr = metaObj.getValue('type'); | ||
| const typeName = typeExpr.getSymbolName(); | ||
| if (typeName === null) { | ||
| throw new FatalLinkerError( | ||
| typeExpr.expression, 'Unsupported type, its name could not be determined'); | ||
| } | ||
|
|
||
| return { | ||
| name: typeName, | ||
| type: wrapReference(typeExpr.getOpaque()), | ||
| internalType: metaObj.getOpaque('type'), | ||
| typeArgumentCount: 0, | ||
| target: parseEnum(metaObj.getValue('target'), FactoryTarget), | ||
| deps: getDeps(metaObj, 'deps'), | ||
| }; | ||
| } | ||
|
|
||
| function getDeps<TExpression>( | ||
| metaObj: AstObject<R3DeclareFactoryMetadata, TExpression>, | ||
| propName: keyof R3DeclareFactoryMetadata): R3DependencyMetadata[]|null|'invalid' { | ||
| if (!metaObj.has(propName)) { | ||
| return null; | ||
| } | ||
| const deps = metaObj.getValue(propName); | ||
| if (deps.isArray()) { | ||
| return deps.getArray().map(dep => getDep(dep.getObject())); | ||
| } | ||
| if (deps.isString()) { | ||
| return 'invalid'; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| function getDep<TExpression>(depObj: AstObject<R3DeclareDependencyMetadata, TExpression>): | ||
| R3DependencyMetadata { | ||
| const isAttribute = depObj.has('attribute') && depObj.getBoolean('attribute'); | ||
| const token = depObj.getOpaque('token'); | ||
| // Normally `attribute` is a string literal and so its `attributeNameType` is the same string | ||
| // literal. If the `attribute` is some other expression, the `attributeNameType` would be the | ||
| // `unknown` type. It is not possible to generate this when linking, since it only deals with JS | ||
| // and not typings. When linking the existence of the `attributeNameType` only acts as a marker to | ||
| // change the injection instruction that is generated, so we just pass the literal string | ||
| // `"unknown"`. | ||
| const attributeNameType = isAttribute ? o.literal('unknown') : null; | ||
| const dep: R3DependencyMetadata = { | ||
| token, | ||
| attributeNameType, | ||
| host: depObj.has('host') && depObj.getBoolean('host'), | ||
| optional: depObj.has('optional') && depObj.getBoolean('optional'), | ||
| self: depObj.has('self') && depObj.getBoolean('self'), | ||
| skipSelf: depObj.has('skipSelf') && depObj.getBoolean('skipSelf'), | ||
| }; | ||
| return dep; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Note that this PR actually decreases the payload size of angular.io, but not by as much is it appears here since
masterwas already a bit lower than the previous recorded values:Uh oh!
There was an error while loading. Please reload this page.
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.
Any pipe that has non-optional injectable dependencies will have a slightly larger footprint since the
InjectFlags.ForPipevalue (16) must be added as an extra argument, thus adding 3 characters to the injection instruction per dependency.It is worth noting that many pipes do not actually inject anything. A quick survey of pipes in
angular/angulargives 7 pipes that inject dependencies: