refactor(compiler-cli): Add experimental local compilation mode. (#49846)

In this mode the compiler generates code based on each individual source file without using its dependencies. This mode is suitable only for fast edit/refresh during development.

PR Close #49846
This commit is contained in:
Payam Valadkhan 2023-04-18 16:44:27 -04:00 committed by Dylan Hunn
parent 27093a7167
commit 345dd6d81a
4 changed files with 25 additions and 5 deletions

View file

@ -73,7 +73,7 @@ export interface StrictTemplateOptions {
// @public
export interface TargetOptions {
compilationMode?: 'full' | 'partial';
compilationMode?: 'full' | 'partial' | 'experimental-local';
}
// (No @packageDocumentation comment for this package)

View file

@ -383,10 +383,13 @@ export interface TargetOptions {
* Specifies the compilation mode to use. The following modes are available:
* - 'full': generates fully AOT compiled code using Ivy instructions.
* - 'partial': generates code in a stable, but intermediate form suitable for publication to NPM.
* - 'experimental-local': generates code based on each individual source file without using its
* dependencies. This mode is suitable only for fast edit/refresh during development. It will be
* eventually replaced by the value `local` once the feature is ready to be public.
*
* The default value is 'full'.
*/
compilationMode?: 'full'|'partial';
compilationMode?: 'full'|'partial'|'experimental-local';
}
/**

View file

@ -1006,9 +1006,20 @@ export class NgCompiler {
// Note: If this compilation builds `@angular/core`, we always build in full compilation
// mode. Code inside the core package is always compatible with itself, so it does not
// make sense to go through the indirection of partial compilation
const compilationMode = this.options.compilationMode === 'partial' && !isCore ?
CompilationMode.PARTIAL :
CompilationMode.FULL;
let compilationMode: CompilationMode = CompilationMode.FULL;
if (!isCore) {
switch (this.options.compilationMode) {
case 'full':
compilationMode = CompilationMode.FULL;
break;
case 'partial':
compilationMode = CompilationMode.PARTIAL;
break;
case 'experimental-local':
compilationMode = CompilationMode.LOCAL;
break;
}
}
// Cycles are handled in full compilation mode by "remote scoping".
// "Remote scoping" does not work well with tree shaking for libraries.

View file

@ -31,6 +31,12 @@ export enum CompilationMode {
* Generates code using a stable, but intermediate format suitable to be published to NPM.
*/
PARTIAL,
/**
* Generates code based on each individual source file without using its
* dependencies (suitable for local dev edit/refresh workflow).
*/
LOCAL,
}
export enum HandlerPrecedence {