UNPKG

4.76 kBTypeScriptView Raw
1/// <amd-module name="@angular/language-service/ivy/utils" />
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9import { AbsoluteSourceSpan, ParseSourceSpan } from '@angular/compiler';
10import { NgCompiler } from '@angular/compiler-cli/src/ngtsc/core';
11import { AbsoluteFsPath } from '@angular/compiler-cli/src/ngtsc/file_system';
12import { DirectiveSymbol, TemplateTypeChecker } from '@angular/compiler-cli/src/ngtsc/typecheck/api';
13import * as e from '@angular/compiler/src/expression_parser/ast';
14import * as t from '@angular/compiler/src/render3/r3_ast';
15import * as ts from 'typescript';
16export declare function getTextSpanOfNode(node: t.Node | e.AST): ts.TextSpan;
17export declare function toTextSpan(span: AbsoluteSourceSpan | ParseSourceSpan | e.ParseSpan): ts.TextSpan;
18interface NodeWithKeyAndValue extends t.Node {
19 keySpan: ParseSourceSpan;
20 valueSpan?: ParseSourceSpan;
21}
22export declare function isTemplateNodeWithKeyAndValue(node: t.Node | e.AST): node is NodeWithKeyAndValue;
23export declare function isWithinKey(position: number, node: NodeWithKeyAndValue): boolean;
24export declare function isWithinKeyValue(position: number, node: NodeWithKeyAndValue): boolean;
25export declare function isTemplateNode(node: t.Node | e.AST): node is t.Node;
26export declare function isExpressionNode(node: t.Node | e.AST): node is e.AST;
27export interface TemplateInfo {
28 template: t.Node[];
29 component: ts.ClassDeclaration;
30}
31/**
32 * Retrieves the `ts.ClassDeclaration` at a location along with its template nodes.
33 */
34export declare function getTemplateInfoAtPosition(fileName: string, position: number, compiler: NgCompiler): TemplateInfo | undefined;
35/**
36 * Given an element or template, determines which directives match because the tag is present. For
37 * example, if a directive selector is `div[myAttr]`, this would match div elements but would not if
38 * the selector were just `[myAttr]`. We find which directives are applied because of this tag by
39 * elimination: compare the directive matches with the tag present against the directive matches
40 * without it. The difference would be the directives which match because the tag is present.
41 *
42 * @param element The element or template node that the attribute/tag is part of.
43 * @param directives The list of directives to match against.
44 * @returns The list of directives matching the tag name via the strategy described above.
45 */
46export declare function getDirectiveMatchesForElementTag(element: t.Template | t.Element, directives: DirectiveSymbol[]): Set<DirectiveSymbol>;
47export declare function makeElementSelector(element: t.Element | t.Template): string;
48/**
49 * Given an attribute name, determines which directives match because the attribute is present. We
50 * find which directives are applied because of this attribute by elimination: compare the directive
51 * matches with the attribute present against the directive matches without it. The difference would
52 * be the directives which match because the attribute is present.
53 *
54 * @param name The name of the attribute
55 * @param hostNode The node which the attribute appears on
56 * @param directives The list of directives to match against.
57 * @returns The list of directives matching the tag name via the strategy described above.
58 */
59export declare function getDirectiveMatchesForAttribute(name: string, hostNode: t.Template | t.Element, directives: DirectiveSymbol[]): Set<DirectiveSymbol>;
60/**
61 * Returns a new `ts.SymbolDisplayPart` array which has the alias imports from the tcb filtered
62 * out, i.e. `i0.NgForOf`.
63 */
64export declare function filterAliasImports(displayParts: ts.SymbolDisplayPart[]): ts.SymbolDisplayPart[];
65export declare function isDollarEvent(n: t.Node | e.AST): n is e.PropertyRead;
66/**
67 * Returns a new array formed by applying a given callback function to each element of the array,
68 * and then flattening the result by one level.
69 */
70export declare function flatMap<T, R>(items: T[] | readonly T[], f: (item: T) => R[] | readonly R[]): R[];
71export declare function isTypeScriptFile(fileName: string): boolean;
72export declare function isExternalTemplate(fileName: string): boolean;
73export declare function isWithin(position: number, span: AbsoluteSourceSpan | ParseSourceSpan): boolean;
74/**
75 * For a given location in a shim file, retrieves the corresponding file url for the template and
76 * the span in the template.
77 */
78export declare function getTemplateLocationFromShimLocation(templateTypeChecker: TemplateTypeChecker, shimPath: AbsoluteFsPath, positionInShimFile: number): {
79 templateUrl: AbsoluteFsPath;
80 span: ParseSourceSpan;
81} | null;
82export {};