|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.dev/license |
| 7 | + */ |
| 8 | + |
| 9 | +import { |
| 10 | + AST, |
| 11 | + BindingPipe, |
| 12 | + PropertyRead, |
| 13 | + TmplAstBoundAttribute, |
| 14 | + TmplAstBoundEvent, |
| 15 | + TmplAstComponent, |
| 16 | + TmplAstDirective, |
| 17 | + TmplAstElement, |
| 18 | + TmplAstForLoopBlock, |
| 19 | + TmplAstForLoopBlockEmpty, |
| 20 | + TmplAstHoverDeferredTrigger, |
| 21 | + TmplAstIfBlockBranch, |
| 22 | + TmplAstInteractionDeferredTrigger, |
| 23 | + TmplAstLetDeclaration, |
| 24 | + TmplAstReference, |
| 25 | + TmplAstSwitchBlockCase, |
| 26 | + TmplAstTemplate, |
| 27 | + TmplAstTextAttribute, |
| 28 | + TmplAstVariable, |
| 29 | + TmplAstViewportDeferredTrigger, |
| 30 | +} from '@angular/compiler'; |
| 31 | + |
| 32 | +import {TcbDirectiveMetadata, TypeCheckId} from './api'; |
| 33 | + |
| 34 | +/** Categories of diagnostics that can be reported by a `OutOfBandDiagnosticRecorder`. */ |
| 35 | +export enum OutOfBadDiagnosticCategory { |
| 36 | + Error, |
| 37 | + Warning, |
| 38 | +} |
| 39 | + |
| 40 | +/** |
| 41 | + * Collects diagnostics on problems which occur in the template which aren't directly sourced |
| 42 | + * from type check blocks. |
| 43 | + * |
| 44 | + * During the creation of a type check block, the template is traversed and the |
| 45 | + * `OutOfBandDiagnosticRecorder` is called to record cases when a correct interpretation for the |
| 46 | + * template cannot be found. These operations create diagnostics which are stored by the |
| 47 | + * recorder for later display. |
| 48 | + */ |
| 49 | +export interface OutOfBandDiagnosticRecorder<T> { |
| 50 | + readonly diagnostics: ReadonlyArray<T>; |
| 51 | + |
| 52 | + /** |
| 53 | + * Reports a `#ref="target"` expression in the template for which a target directive could not be |
| 54 | + * found. |
| 55 | + * |
| 56 | + * @param id the type-checking ID of the template which contains the broken reference. |
| 57 | + * @param ref the `TmplAstReference` which could not be matched to a directive. |
| 58 | + */ |
| 59 | + missingReferenceTarget(id: TypeCheckId, ref: TmplAstReference): void; |
| 60 | + |
| 61 | + /** |
| 62 | + * Reports usage of a `| pipe` expression in the template for which the named pipe could not be |
| 63 | + * found. |
| 64 | + * |
| 65 | + * @param id the type-checking ID of the template which contains the unknown pipe. |
| 66 | + * @param ast the `BindingPipe` invocation of the pipe which could not be found. |
| 67 | + * @param isStandalone whether the host component is standalone. |
| 68 | + */ |
| 69 | + missingPipe(id: TypeCheckId, ast: BindingPipe, isStandalone: boolean): void; |
| 70 | + |
| 71 | + /** |
| 72 | + * Reports usage of a pipe imported via `@Component.deferredImports` outside |
| 73 | + * of a `@defer` block in a template. |
| 74 | + * |
| 75 | + * @param id the type-checking ID of the template which contains the unknown pipe. |
| 76 | + * @param ast the `BindingPipe` invocation of the pipe which could not be found. |
| 77 | + */ |
| 78 | + deferredPipeUsedEagerly(id: TypeCheckId, ast: BindingPipe): void; |
| 79 | + |
| 80 | + /** |
| 81 | + * Reports usage of a component/directive imported via `@Component.deferredImports` outside |
| 82 | + * of a `@defer` block in a template. |
| 83 | + * |
| 84 | + * @param id the type-checking ID of the template which contains the unknown pipe. |
| 85 | + * @param element the element which hosts a component that was defer-loaded. |
| 86 | + */ |
| 87 | + deferredComponentUsedEagerly(id: TypeCheckId, element: TmplAstElement): void; |
| 88 | + |
| 89 | + /** |
| 90 | + * Reports a duplicate declaration of a template variable. |
| 91 | + * |
| 92 | + * @param id the type-checking ID of the template which contains the duplicate |
| 93 | + * declaration. |
| 94 | + * @param variable the `TmplAstVariable` which duplicates a previously declared variable. |
| 95 | + * @param firstDecl the first variable declaration which uses the same name as `variable`. |
| 96 | + */ |
| 97 | + duplicateTemplateVar( |
| 98 | + id: TypeCheckId, |
| 99 | + variable: TmplAstVariable, |
| 100 | + firstDecl: TmplAstVariable, |
| 101 | + ): void; |
| 102 | + |
| 103 | + /** |
| 104 | + * Report a warning when structural directives support context guards, but the current |
| 105 | + * type-checking configuration prohibits their usage. |
| 106 | + */ |
| 107 | + suboptimalTypeInference(id: TypeCheckId, variables: TmplAstVariable[]): void; |
| 108 | + |
| 109 | + /** |
| 110 | + * Reports a split two way binding error message. |
| 111 | + */ |
| 112 | + splitTwoWayBinding( |
| 113 | + id: TypeCheckId, |
| 114 | + input: TmplAstBoundAttribute, |
| 115 | + output: TmplAstBoundEvent, |
| 116 | + inputConsumer: Pick<TcbDirectiveMetadata, 'name' | 'isComponent' | 'ref'>, |
| 117 | + outputConsumer: Pick<TcbDirectiveMetadata, 'name' | 'isComponent' | 'ref'> | TmplAstElement, |
| 118 | + ): void; |
| 119 | + |
| 120 | + /** Reports required inputs that haven't been bound. */ |
| 121 | + missingRequiredInputs( |
| 122 | + id: TypeCheckId, |
| 123 | + element: TmplAstElement | TmplAstTemplate | TmplAstComponent | TmplAstDirective, |
| 124 | + directiveName: string, |
| 125 | + isComponent: boolean, |
| 126 | + inputAliases: string[], |
| 127 | + ): void; |
| 128 | + |
| 129 | + /** |
| 130 | + * Reports accesses of properties that aren't available in a `for` block's tracking expression. |
| 131 | + */ |
| 132 | + illegalForLoopTrackAccess( |
| 133 | + id: TypeCheckId, |
| 134 | + block: TmplAstForLoopBlock, |
| 135 | + access: PropertyRead, |
| 136 | + ): void; |
| 137 | + |
| 138 | + /** |
| 139 | + * Reports deferred triggers that cannot access the element they're referring to. |
| 140 | + */ |
| 141 | + inaccessibleDeferredTriggerElement( |
| 142 | + id: TypeCheckId, |
| 143 | + trigger: |
| 144 | + | TmplAstHoverDeferredTrigger |
| 145 | + | TmplAstInteractionDeferredTrigger |
| 146 | + | TmplAstViewportDeferredTrigger, |
| 147 | + ): void; |
| 148 | + |
| 149 | + /** |
| 150 | + * Reports cases where control flow nodes prevent content projection. |
| 151 | + */ |
| 152 | + controlFlowPreventingContentProjection( |
| 153 | + id: TypeCheckId, |
| 154 | + category: OutOfBadDiagnosticCategory, |
| 155 | + projectionNode: TmplAstElement | TmplAstTemplate, |
| 156 | + componentName: string, |
| 157 | + slotSelector: string, |
| 158 | + controlFlowNode: |
| 159 | + | TmplAstIfBlockBranch |
| 160 | + | TmplAstSwitchBlockCase |
| 161 | + | TmplAstForLoopBlock |
| 162 | + | TmplAstForLoopBlockEmpty, |
| 163 | + preservesWhitespaces: boolean, |
| 164 | + ): void; |
| 165 | + |
| 166 | + /** Reports cases where users are writing to `@let` declarations. */ |
| 167 | + illegalWriteToLetDeclaration(id: TypeCheckId, node: AST, target: TmplAstLetDeclaration): void; |
| 168 | + |
| 169 | + /** Reports cases where users are accessing an `@let` before it is defined.. */ |
| 170 | + letUsedBeforeDefinition(id: TypeCheckId, node: PropertyRead, target: TmplAstLetDeclaration): void; |
| 171 | + |
| 172 | + /** |
| 173 | + * Reports a `@let` declaration that conflicts with another symbol in the same scope. |
| 174 | + * |
| 175 | + * @param id the type-checking ID of the template which contains the declaration. |
| 176 | + * @param current the `TmplAstLetDeclaration` which is invalid. |
| 177 | + */ |
| 178 | + conflictingDeclaration(id: TypeCheckId, current: TmplAstLetDeclaration): void; |
| 179 | + |
| 180 | + /** |
| 181 | + * Reports that a named template dependency (e.g. `<Missing/>`) is not available. |
| 182 | + * @param id Type checking ID of the template in which the dependency is declared. |
| 183 | + * @param node Node that declares the dependency. |
| 184 | + */ |
| 185 | + missingNamedTemplateDependency(id: TypeCheckId, node: TmplAstComponent | TmplAstDirective): void; |
| 186 | + |
| 187 | + /** |
| 188 | + * Reports that a templace dependency of the wrong kind has been referenced at a specific position |
| 189 | + * (e.g. `<SomeDirective/>`). |
| 190 | + * @param id Type checking ID of the template in which the dependency is declared. |
| 191 | + * @param node Node that declares the dependency. |
| 192 | + */ |
| 193 | + incorrectTemplateDependencyType(id: TypeCheckId, node: TmplAstComponent | TmplAstDirective): void; |
| 194 | + |
| 195 | + /** |
| 196 | + * Reports a binding inside directive syntax that does not match any of the inputs/outputs of |
| 197 | + * the directive. |
| 198 | + * @param id Type checking ID of the template in which the directive was defined. |
| 199 | + * @param directive Directive that contains the binding. |
| 200 | + * @param node Node declaring the binding. |
| 201 | + */ |
| 202 | + unclaimedDirectiveBinding( |
| 203 | + id: TypeCheckId, |
| 204 | + directive: TmplAstDirective, |
| 205 | + node: TmplAstBoundAttribute | TmplAstTextAttribute | TmplAstBoundEvent, |
| 206 | + ): void; |
| 207 | + |
| 208 | + /** |
| 209 | + * Reports that an implicit deferred trigger is set on a block that does not have a placeholder. |
| 210 | + */ |
| 211 | + deferImplicitTriggerMissingPlaceholder( |
| 212 | + id: TypeCheckId, |
| 213 | + trigger: |
| 214 | + | TmplAstHoverDeferredTrigger |
| 215 | + | TmplAstInteractionDeferredTrigger |
| 216 | + | TmplAstViewportDeferredTrigger, |
| 217 | + ): void; |
| 218 | + |
| 219 | + /** |
| 220 | + * Reports that an implicit deferred trigger is set on a block whose placeholder is not set up |
| 221 | + * correctly (e.g. more than one root node). |
| 222 | + */ |
| 223 | + deferImplicitTriggerInvalidPlaceholder( |
| 224 | + id: TypeCheckId, |
| 225 | + trigger: |
| 226 | + | TmplAstHoverDeferredTrigger |
| 227 | + | TmplAstInteractionDeferredTrigger |
| 228 | + | TmplAstViewportDeferredTrigger, |
| 229 | + ): void; |
| 230 | + |
| 231 | + /** |
| 232 | + * Reports an unsupported binding on a form `FormField` node. |
| 233 | + */ |
| 234 | + formFieldUnsupportedBinding( |
| 235 | + id: TypeCheckId, |
| 236 | + node: TmplAstBoundAttribute | TmplAstTextAttribute, |
| 237 | + ): void; |
| 238 | + |
| 239 | + /** |
| 240 | + * Reports that multiple components in the compilation scope match a given element. |
| 241 | + */ |
| 242 | + multipleMatchingComponents( |
| 243 | + id: TypeCheckId, |
| 244 | + element: TmplAstElement, |
| 245 | + componentNames: string[], |
| 246 | + ): void; |
| 247 | +} |
0 commit comments