Skip to content

Commit

Permalink
refactor(compiler-cli): Add experimental local compilation mode. (ang…
Browse files Browse the repository at this point in the history
…ular#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 angular#49846
  • Loading branch information
pmvald authored and dylhunn committed Apr 24, 2023
1 parent 27093a7 commit 345dd6d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion goldens/public-api/compiler-cli/compiler_options.md
Expand Up @@ -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)
Expand Down
Expand Up @@ -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';
}

/**
Expand Down
17 changes: 14 additions & 3 deletions packages/compiler-cli/src/ngtsc/core/src/compiler.ts
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions packages/compiler-cli/src/ngtsc/transform/src/api.ts
Expand Up @@ -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 {
Expand Down

0 comments on commit 345dd6d

Please sign in to comment.