refactor(compiler): Rename DirectiveInScope -> PotentialDirective (#47561)

After implementing `getPotentialTemplateDirectives`, we will use this data struture to represent both in-scope and out-of-scope directives. So this rename is an advance cleanup.

PR Close #47561
This commit is contained in:
Dylan Hunn 2022-10-03 23:52:08 -07:00 committed by Andrew Kushnir
parent e3cef4a784
commit 3783ee01ac
7 changed files with 23 additions and 22 deletions

View file

@ -14,7 +14,7 @@ import {ErrorCode} from '../../diagnostics';
import {FullTemplateMapping, NgTemplateDiagnostic, TypeCheckableDirectiveMeta} from './api';
import {GlobalCompletion} from './completion';
import {DirectiveInScope, PipeInScope} from './scope';
import {PipeInScope, PotentialDirective} from './scope';
import {ElementSymbol, Symbol, TcbLocation, TemplateSymbol} from './symbols';
/**
@ -131,7 +131,7 @@ export interface TemplateTypeChecker {
/**
* Get basic metadata on the directives which are in scope for the given component.
*/
getDirectivesInScope(component: ts.ClassDeclaration): DirectiveInScope[]|null;
getDirectivesInScope(component: ts.ClassDeclaration): PotentialDirective[]|null;
/**
* Get basic metadata on the pipes which are in scope for the given component.
@ -139,11 +139,11 @@ export interface TemplateTypeChecker {
getPipesInScope(component: ts.ClassDeclaration): PipeInScope[]|null;
/**
* Retrieve a `Map` of potential template element tags, to either the `DirectiveInScope` that
* Retrieve a `Map` of potential template element tags, to either the `PotentialDirective` that
* declares them (if the tag is from a directive/component), or `null` if the tag originates from
* the DOM schema.
*/
getPotentialElementTags(component: ts.ClassDeclaration): Map<string, DirectiveInScope|null>;
getPotentialElementTags(component: ts.ClassDeclaration): Map<string, PotentialDirective|null>;
/**
* Get the primary decorator for an Angular class (such as @Component). This does not work for

View file

@ -14,7 +14,7 @@ import {SymbolWithValueDeclaration} from '../../util/src/typescript';
/**
* Metadata on a directive which is available in the scope of a template.
*/
export interface DirectiveInScope {
export interface PotentialDirective {
/**
* The `ts.Symbol` for the directive class.
*/

View file

@ -12,7 +12,7 @@ import ts from 'typescript';
import {AbsoluteFsPath} from '../../file_system';
import {SymbolWithValueDeclaration} from '../../util/src/typescript';
import {DirectiveInScope} from './scope';
import {PotentialDirective} from './scope';
export enum SymbolKind {
Input,
@ -262,7 +262,7 @@ export interface TemplateSymbol {
* A representation of a directive/component whose selector matches a node in a component
* template.
*/
export interface DirectiveSymbol extends DirectiveInScope {
export interface DirectiveSymbol extends PotentialDirective {
kind: SymbolKind.Directive;
/** The `ts.Type` for the class declaration. */

View file

@ -20,7 +20,7 @@ import {ClassDeclaration, isNamedClassDeclaration, ReflectionHost} from '../../r
import {ComponentScopeKind, ComponentScopeReader, TypeCheckScopeRegistry} from '../../scope';
import {isShim} from '../../shims';
import {getSourceFileOrNull, isSymbolWithValueDeclaration} from '../../util/src/typescript';
import {DirectiveInScope, ElementSymbol, FullTemplateMapping, GlobalCompletion, NgTemplateDiagnostic, OptimizeFor, PipeInScope, ProgramTypeCheckAdapter, Symbol, TcbLocation, TemplateDiagnostic, TemplateId, TemplateSymbol, TemplateTypeChecker, TypeCheckableDirectiveMeta, TypeCheckingConfig} from '../api';
import {ElementSymbol, FullTemplateMapping, GlobalCompletion, NgTemplateDiagnostic, OptimizeFor, PipeInScope, PotentialDirective, ProgramTypeCheckAdapter, Symbol, TcbLocation, TemplateDiagnostic, TemplateId, TemplateSymbol, TemplateTypeChecker, TypeCheckableDirectiveMeta, TypeCheckingConfig} from '../api';
import {makeTemplateDiagnostic} from '../diagnostics';
import {CompletionEngine} from './completion';
@ -75,7 +75,7 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker {
* destroyed when the `ts.Program` changes and the `TemplateTypeCheckerImpl` as a whole is
* destroyed and replaced.
*/
private elementTagCache = new Map<ts.ClassDeclaration, Map<string, DirectiveInScope|null>>();
private elementTagCache = new Map<ts.ClassDeclaration, Map<string, PotentialDirective|null>>();
private isComplete = false;
@ -549,7 +549,7 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker {
return builder;
}
getDirectivesInScope(component: ts.ClassDeclaration): DirectiveInScope[]|null {
getDirectivesInScope(component: ts.ClassDeclaration): PotentialDirective[]|null {
const data = this.getScopeData(component);
if (data === null) {
return null;
@ -572,12 +572,12 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker {
return this.typeCheckScopeRegistry.getTypeCheckDirectiveMetadata(new Reference(dir));
}
getPotentialElementTags(component: ts.ClassDeclaration): Map<string, DirectiveInScope|null> {
getPotentialElementTags(component: ts.ClassDeclaration): Map<string, PotentialDirective|null> {
if (this.elementTagCache.has(component)) {
return this.elementTagCache.get(component)!;
}
const tagMap = new Map<string, DirectiveInScope|null>();
const tagMap = new Map<string, PotentialDirective|null>();
for (const tag of REGISTRY.allKnownElementNames()) {
tagMap.set(tag, null);
@ -886,7 +886,7 @@ class SingleShimTypeCheckingHost extends SingleFileTypeCheckingHost {
* Cached scope information for a component.
*/
interface ScopeData {
directives: DirectiveInScope[];
directives: PotentialDirective[];
pipes: PipeInScope[];
isPoisoned: boolean;
}

View file

@ -7,7 +7,7 @@
*/
import {CssSelector, SelectorMatcher, TmplAstElement, TmplAstTemplate} from '@angular/compiler';
import {DirectiveInScope, ElementSymbol, TemplateSymbol, TemplateTypeChecker, TypeCheckableDirectiveMeta} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
import {ElementSymbol, PotentialDirective, TemplateSymbol, TemplateTypeChecker, TypeCheckableDirectiveMeta} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
import ts from 'typescript';
import {DisplayInfoKind, unsafeCastDisplayInfoKindToScriptElementKind} from './display_parts';
@ -116,7 +116,7 @@ export interface DirectiveAttributeCompletion {
/**
* The directive whose selector gave rise to this completion.
*/
directive: DirectiveInScope;
directive: PotentialDirective;
}
/**
@ -135,7 +135,7 @@ export interface DirectiveInputCompletion {
/**
* The directive which has this input.
*/
directive: DirectiveInScope;
directive: PotentialDirective;
/**
* The field name on the directive class which corresponds to this input.
@ -164,7 +164,7 @@ export interface DirectiveOutputCompletion {
/**
*The directive which has this output.
*/
directive: DirectiveInScope;
directive: PotentialDirective;
/**
* The field name on the directive class which corresponds to this output.
@ -251,7 +251,8 @@ export function buildAttributeCompletionTable(
// Next, explore hypothetical directives and determine if the addition of any single attributes
// can cause the directive to match the element.
const directivesInScope = checker.getDirectivesInScope(component);
const directivesInScope =
checker.getPotentialTemplateDirectives(component).filter(d => d.isInScope);
if (directivesInScope !== null) {
const elementSelector = makeElementSelector(element);

View file

@ -8,7 +8,7 @@
import {AST, ASTWithSource, BindingPipe, BindingType, Call, EmptyExpr, ImplicitReceiver, LiteralPrimitive, ParsedEventType, ParseSourceSpan, PropertyRead, PropertyWrite, SafePropertyRead, TmplAstBoundAttribute, TmplAstBoundEvent, TmplAstElement, TmplAstNode, TmplAstReference, TmplAstTemplate, TmplAstText, TmplAstTextAttribute, TmplAstVariable} from '@angular/compiler';
import {NgCompiler} from '@angular/compiler-cli/src/ngtsc/core';
import {CompletionKind, DirectiveInScope, SymbolKind, TemplateDeclarationSymbol} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
import {CompletionKind, PotentialDirective, SymbolKind, TemplateDeclarationSymbol} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
import {BoundEvent, TextAttribute} from '@angular/compiler/src/render3/r3_ast';
import ts from 'typescript';
@ -905,7 +905,7 @@ function makeReplacementSpanFromAst(node: PropertyRead|PropertyWrite|SafePropert
};
}
function tagCompletionKind(directive: DirectiveInScope|null): ts.ScriptElementKind {
function tagCompletionKind(directive: PotentialDirective|null): ts.ScriptElementKind {
let kind: DisplayInfoKind;
if (directive === null) {
kind = DisplayInfoKind.ELEMENT;

View file

@ -7,7 +7,7 @@
*/
import {isNamedClassDeclaration} from '@angular/compiler-cli/src/ngtsc/reflection';
import {DirectiveInScope, ReferenceSymbol, Symbol, SymbolKind, TcbLocation, VariableSymbol} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
import {PotentialDirective, ReferenceSymbol, Symbol, SymbolKind, TcbLocation, VariableSymbol} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
import ts from 'typescript';
@ -130,7 +130,7 @@ function getDocumentationFromTypeDefAtLocation(
}
export function getDirectiveDisplayInfo(
tsLS: ts.LanguageService, dir: DirectiveInScope): DisplayInfo {
tsLS: ts.LanguageService, dir: PotentialDirective): DisplayInfo {
const kind = dir.isComponent ? DisplayInfoKind.COMPONENT : DisplayInfoKind.DIRECTIVE;
const decl = dir.tsSymbol.declarations.find(ts.isClassDeclaration);
if (decl === undefined || decl.name === undefined) {