Skip to content

Commit 454528c

Browse files
committed
refactor(compiler): move TCB generation logic into compiler
Moves the logic for generating type check blocks into the compiler since it isn't coupled to TypeScript anymore. Note: the tests haven't been moved over, because they depend on the environment that's currently in `compiler-cli` and it still has some dependencies on TypeScript.
1 parent 5f74e7e commit 454528c

70 files changed

Lines changed: 932 additions & 1164 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/compiler-cli/private/hybrid_analysis.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,18 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
// TCB generation exports for ng-hybrid-preprocessor
10-
export {generateTypeCheckBlock} from '../src/ngtsc/typecheck/src/type_check_block';
119
export {
12-
type TypeCheckingConfig,
13-
type TcbComponentMetadata,
14-
type TcbTypeCheckBlockMetadata,
15-
type TcbTypeParameter,
16-
type TypeCheckId,
17-
type TcbDirectiveMetadata,
1810
type TemplateDiagnostic,
19-
type TcbReferenceMetadata,
2011
type SourceMapping,
21-
type OutOfBandDiagnosticRecorder,
22-
type DomSchemaChecker,
2312
type SymbolReference,
24-
OutOfBandDiagnosticCategory,
2513
SymbolKind,
2614
} from '../src/ngtsc/typecheck/api';
2715
export {RegistryDomSchemaChecker} from '../src/ngtsc/typecheck/src/dom';
2816
export {Environment} from '../src/ngtsc/typecheck/src/environment';
29-
export {TcbGenericContextBehavior} from '../src/ngtsc/typecheck/src/ops/context';
3017
export {ImportManager} from '../src/ngtsc/translator';
3118
export type {ReferenceEmitter} from '../src/ngtsc/imports';
3219
export type {ReflectionHost, ClassDeclaration} from '../src/ngtsc/reflection';
3320
export type {TypeCheckSourceResolver} from '../src/ngtsc/typecheck/src/tcb_util';
34-
export {
35-
createHostElement,
36-
type SourceNode,
37-
type StaticSourceNode,
38-
type HostObjectLiteralBinding,
39-
type HostListenerDecorator,
40-
type HostBindingDecorator,
41-
} from '../src/ngtsc/typecheck/src/host_bindings';
4221
export {
4322
findFirstMatchingNode,
4423
ExpressionIdentifier,

packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
R3DirectiveDependencyMetadata,
3333
R3NgModuleDependencyMetadata,
3434
R3PipeDependencyMetadata,
35+
createHostElement,
3536
R3TargetBinder,
3637
R3TemplateDependency,
3738
R3TemplateDependencyKind,
@@ -43,6 +44,7 @@ import {
4344
DirectiveMatcher,
4445
SelectorlessMatcher,
4546
MatchSource,
47+
TypeCheckId,
4648
} from '@angular/compiler';
4749
import ts from 'typescript';
4850

@@ -96,12 +98,9 @@ import {
9698
import {
9799
ComponentScopeKind,
98100
ComponentScopeReader,
99-
DtsModuleScopeResolver,
100-
LocalModuleScope,
101101
LocalModuleScopeRegistry,
102102
makeNotStandaloneDiagnostic,
103103
makeUnknownComponentImportDiagnostic,
104-
StandaloneScope,
105104
TypeCheckScopeRegistry,
106105
} from '../../../scope';
107106
import {
@@ -118,7 +117,6 @@ import {
118117
ResolveResult,
119118
} from '../../../transform';
120119
import {
121-
TypeCheckId,
122120
TypeCheckableDirectiveMeta,
123121
TypeCheckContext,
124122
TemplateContext,
@@ -193,7 +191,7 @@ import {
193191
collectLegacyAnimationNames,
194192
validateAndFlattenComponentImports,
195193
} from './util';
196-
import {getTemplateDiagnostics, createHostElement} from '../../../typecheck';
194+
import {getTemplateDiagnostics} from '../../../typecheck';
197195
import {JitDeclarationRegistry} from '../../common/src/jit_declaration_registry';
198196
import {extractHmrMetatadata, getHmrUpdateDeclaration} from '../../../hmr';
199197
import {getProjectRelativePath} from '../../../util/src/path';

packages/compiler-cli/src/ngtsc/annotations/directive/src/handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
R3DirectiveMetadata,
2121
R3TargetBinder,
2222
WrappedNodeExpr,
23+
createHostElement,
2324
} from '@angular/compiler';
2425
import ts from 'typescript';
2526

@@ -92,7 +93,6 @@ import {
9293
TypeCheckableDirectiveMeta,
9394
TypeCheckContext,
9495
} from '../../../typecheck/api';
95-
import {createHostElement} from '../../../typecheck';
9696

9797
const FIELD_DECORATORS = [
9898
'Input',

packages/compiler-cli/src/ngtsc/annotations/directive/src/shared.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ import {
3232
literal,
3333
ClassPropertyMapping,
3434
InputOrOutput,
35+
HostObjectLiteralBinding,
36+
HostListenerDecorator,
37+
HostBindingDecorator,
38+
SourceNode,
3539
} from '@angular/compiler';
3640
import ts from 'typescript';
3741

@@ -92,13 +96,6 @@ import {tryParseSignalInputMapping} from './input_function';
9296
import {tryParseSignalModelMapping} from './model_function';
9397
import {tryParseInitializerBasedOutput} from './output_function';
9498
import {tryParseSignalQueryFromInitializer} from './query_functions';
95-
import {
96-
HostObjectLiteralBinding,
97-
HostListenerDecorator,
98-
HostBindingDecorator,
99-
SourceNode,
100-
StaticSourceNode,
101-
} from '../../../typecheck/src/host_bindings';
10299

103100
const EMPTY_OBJECT: {[key: string]: string} = {};
104101

packages/compiler-cli/src/ngtsc/annotations/directive/src/symbol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {ClassPropertyMapping, InputOrOutput} from '@angular/compiler';
9+
import {ClassPropertyMapping, InputOrOutput, TemplateGuardMeta} from '@angular/compiler';
1010
import {
1111
areTypeParametersEqual,
1212
isArrayEqual,
@@ -15,7 +15,7 @@ import {
1515
SemanticSymbol,
1616
SemanticTypeParameter,
1717
} from '../../../incremental/semantic_graph';
18-
import {DirectiveTypeCheckMeta, InputMapping, TemplateGuardMeta} from '../../../metadata';
18+
import {DirectiveTypeCheckMeta, InputMapping} from '../../../metadata';
1919
import {ClassDeclaration} from '../../../reflection';
2020

2121
/**

packages/compiler-cli/src/ngtsc/core/src/compiler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9+
import {TypeCheckingConfig} from '@angular/compiler';
910
import ts from 'typescript';
1011

1112
import {
@@ -109,7 +110,7 @@ import {
109110
TraitCompiler,
110111
} from '../../transform';
111112
import {TemplateTypeCheckerImpl} from '../../typecheck';
112-
import {OptimizeFor, TemplateTypeChecker, TypeCheckingConfig} from '../../typecheck/api';
113+
import {OptimizeFor, TemplateTypeChecker} from '../../typecheck/api';
113114
import {
114115
ALL_DIAGNOSTIC_FACTORIES,
115116
ExtendedTemplateCheckerImpl,

packages/compiler-cli/src/ngtsc/metadata/src/api.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
ClassPropertyName,
1616
InputOrOutput,
1717
ClassPropertyMapping,
18+
TemplateGuardMeta,
1819
} from '@angular/compiler';
1920
import ts from 'typescript';
2021

@@ -332,25 +333,6 @@ export interface HostDirectiveMetaForLocalMode extends HostDirectiveMeta {
332333
directive: Expression;
333334
}
334335

335-
/**
336-
* Metadata that describes a template guard for one of the directive's inputs.
337-
*/
338-
export interface TemplateGuardMeta {
339-
/**
340-
* The input name that this guard should be applied to.
341-
*/
342-
inputName: string;
343-
344-
/**
345-
* Represents the type of the template guard.
346-
*
347-
* - 'invocation' means that a call to the template guard function is emitted so that its return
348-
* type can result in narrowing of the input type.
349-
* - 'binding' means that the input binding expression itself is used as template guard.
350-
*/
351-
type: 'invocation' | 'binding';
352-
}
353-
354336
/**
355337
* Metadata for a pipe within an NgModule's scope.
356338
*/

packages/compiler-cli/src/ngtsc/metadata/src/util.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ import {
2929
MetadataReader,
3030
NgModuleMeta,
3131
PipeMeta,
32-
TemplateGuardMeta,
3332
} from './api';
3433
import {TypeEntityToDeclarationError} from '../../reflection/src/typescript';
35-
import {ClassPropertyMapping, ClassPropertyName} from '@angular/compiler';
34+
import {ClassPropertyMapping, ClassPropertyName, TemplateGuardMeta} from '@angular/compiler';
3635

3736
export function extractReferencesFromType(
3837
checker: ts.TypeChecker,

0 commit comments

Comments
 (0)