forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler-cli): add partial compilation support for deferred bloc…
…ks (angular#54908) Builds on top of the previous changes to add support for deferred blocks during partial compilation. To do this, the following changes had to be made: * The metadata passed into `ɵɵngDeclareComponent` has an additional field called `deferBlockDependencies` which has an array of the dependency loading functions for each defer block in the template. During linking, the dependency functions are loaded by matching their template index to the index in the `deferBlockDependencies` array. * There's a new `ɵɵngDeclareClassMetadataAsync` function that is created for components that have deferred dependencies. It gets transpiled to `setClassMetadataAsync` and works in the same way by capturing a dependency loading function and setting the metadata after the dependencies are resolved. It also has some extra fields for capturing the version which are standard in linker-generated code. * Deferred import statements are now stripped in partial compilation mode, similar to full compilation. PR Close angular#54908
- Loading branch information
Showing
25 changed files
with
448 additions
and
144 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...piler-cli/linker/src/file_linker/partial_linkers/partial_class_metadata_async_linker_1.ts
This file contains 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,49 @@ | ||
/** | ||
* @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 {compileOpaqueAsyncClassMetadata, ConstantPool, R3ClassMetadata, R3DeclareClassMetadataAsync} from '@angular/compiler'; | ||
|
||
import {AstObject, AstValue} from '../../ast/ast_value'; | ||
import {FatalLinkerError} from '../../fatal_linker_error'; | ||
|
||
import {LinkedDefinition, PartialLinker} from './partial_linker'; | ||
|
||
/** | ||
* A `PartialLinker` that is designed to process `ɵɵngDeclareClassMetadataAsync()` call expressions. | ||
*/ | ||
export class PartialClassMetadataAsyncLinkerVersion1<TExpression> implements | ||
PartialLinker<TExpression> { | ||
linkPartialDeclaration( | ||
constantPool: ConstantPool, | ||
metaObj: AstObject<R3DeclareClassMetadataAsync, TExpression>): LinkedDefinition { | ||
const resolveMetadataKey = 'resolveMetadata'; | ||
const resolveMetadata = | ||
metaObj.getValue(resolveMetadataKey) as unknown as AstValue<Function, TExpression>; | ||
|
||
if (!resolveMetadata.isFunction()) { | ||
throw new FatalLinkerError( | ||
resolveMetadata, `Unsupported \`${resolveMetadataKey}\` value. Expected a function.`); | ||
} | ||
|
||
const dependencyResolverFunction = metaObj.getOpaque('resolveDeferredDeps'); | ||
const deferredSymbolNames = | ||
resolveMetadata.getFunctionParameters().map(p => p.getSymbolName()!); | ||
const returnValue = resolveMetadata.getFunctionReturnValue<R3ClassMetadata>().getObject(); | ||
const metadata: R3ClassMetadata = { | ||
type: metaObj.getOpaque('type'), | ||
decorators: returnValue.getOpaque('decorators'), | ||
ctorParameters: returnValue.getOpaque('ctorParameters'), | ||
propDecorators: returnValue.getOpaque('propDecorators'), | ||
}; | ||
|
||
return { | ||
expression: compileOpaqueAsyncClassMetadata( | ||
metadata, dependencyResolverFunction, deferredSymbolNames), | ||
statements: [], | ||
}; | ||
} | ||
} |
This file contains 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 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 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.