1 | import * as ts from 'typescript';
|
2 | import { IndentedWriter } from '../generators/IndentedWriter';
|
3 |
|
4 |
|
5 |
|
6 | export declare enum IndentDocCommentScope {
|
7 | |
8 |
|
9 |
|
10 | None = 0,
|
11 | |
12 |
|
13 |
|
14 | PrefixOnly = 1,
|
15 | |
16 |
|
17 |
|
18 | SpanAndChildren = 2
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 | export declare class SpanModification {
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 | omitChildren: boolean;
|
30 | |
31 |
|
32 |
|
33 | omitSeparatorAfter: boolean;
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 | sortChildren: boolean;
|
40 | |
41 |
|
42 |
|
43 | sortKey: string | undefined;
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | indentDocComment: IndentDocCommentScope;
|
58 | private readonly _span;
|
59 | private _prefix;
|
60 | private _suffix;
|
61 | constructor(span: Span);
|
62 | /**
|
63 | * Allows the Span.prefix text to be changed.
|
64 | */
|
65 | get prefix(): string;
|
66 | set prefix(value: string);
|
67 | /**
|
68 | * Allows the Span.suffix text to be changed.
|
69 | */
|
70 | get suffix(): string;
|
71 | set suffix(value: string);
|
72 | /**
|
73 | * Reverts any modifications made to this object.
|
74 | */
|
75 | reset(): void;
|
76 | /**
|
77 | * Effectively deletes the Span from the tree, by skipping its children, skipping its separator,
|
78 | * and setting its prefix/suffix to the empty string.
|
79 | */
|
80 | skipAll(): void;
|
81 | }
|
82 | /**
|
83 | * The Span class provides a simple way to rewrite TypeScript source files
|
84 | * based on simple syntax transformations, i.e. without having to process deeper aspects
|
85 | * of the underlying grammar. An example transformation might be deleting JSDoc comments
|
86 | * from a source file.
|
87 | *
|
88 | * @remarks
|
89 | * TypeScript's abstract syntax tree (AST) is represented using Node objects.
|
90 | * The Node text ignores its surrounding whitespace, and does not have an ordering guarantee.
|
91 | * For example, a JSDocComment node can be a child of a FunctionDeclaration node, even though
|
92 | * the actual comment precedes the function in the input stream.
|
93 | *
|
94 | * The Span class is a wrapper for a single Node, that provides access to every character
|
95 | * in the input stream, such that Span.getText() will exactly reproduce the corresponding
|
96 | * full Node.getText() output.
|
97 | *
|
98 | * A Span is comprised of these parts, which appear in sequential order:
|
99 | * - A prefix
|
100 | * - A collection of child spans
|
101 | * - A suffix
|
102 | * - A separator (e.g. whitespace between this span and the next item in the tree)
|
103 | *
|
104 | * These parts can be modified via Span.modification. The modification is applied by
|
105 | * calling Span.getModifiedText().
|
106 | */
|
107 | export declare class Span {
|
108 | readonly node: ts.Node;
|
109 | readonly startIndex: number;
|
110 | readonly endIndex: number;
|
111 | readonly children: Span[];
|
112 | readonly modification: SpanModification;
|
113 | private _parent;
|
114 | private _previousSibling;
|
115 | private _nextSibling;
|
116 | private _separatorStartIndex;
|
117 | private _separatorEndIndex;
|
118 | constructor(node: ts.Node);
|
119 | get kind(): ts.SyntaxKind;
|
120 | /**
|
121 | * The parent Span, if any.
|
122 | * NOTE: This will be undefined for a root Span, even though the corresponding Node
|
123 | * may have a parent in the AST.
|
124 | */
|
125 | get parent(): Span | undefined;
|
126 | /**
|
127 | * If the current object is this.parent.children[i], then previousSibling corresponds
|
128 | * to this.parent.children[i-1] if it exists.
|
129 | * NOTE: This will be undefined for a root Span, even though the corresponding Node
|
130 | * may have a previous sibling in the AST.
|
131 | */
|
132 | get previousSibling(): Span | undefined;
|
133 | /**
|
134 | * If the current object is this.parent.children[i], then previousSibling corresponds
|
135 | * to this.parent.children[i+1] if it exists.
|
136 | * NOTE: This will be undefined for a root Span, even though the corresponding Node
|
137 | * may have a previous sibling in the AST.
|
138 | */
|
139 | get nextSibling(): Span | undefined;
|
140 | /**
|
141 | * The text associated with the underlying Node, up to its first child.
|
142 | */
|
143 | get prefix(): string;
|
144 | /**
|
145 | * The text associated with the underlying Node, after its last child.
|
146 | * If there are no children, this is always an empty string.
|
147 | */
|
148 | get suffix(): string;
|
149 | /**
|
150 | * Whitespace that appeared after this node, and before the "next" node in the tree.
|
151 | * Here we mean "next" according to an inorder traversal, not necessarily a sibling.
|
152 | */
|
153 | get separator(): string;
|
154 | /**
|
155 | * Returns the separator of this Span, or else recursively calls getLastInnerSeparator()
|
156 | * on the last child.
|
157 | */
|
158 | getLastInnerSeparator(): string;
|
159 | /**
|
160 | * Returns the first parent node with the specified SyntaxKind, or undefined if there is no match.
|
161 | */
|
162 | findFirstParent(kindToMatch: ts.SyntaxKind): Span | undefined;
|
163 | /**
|
164 | * Recursively invokes the callback on this Span and all its children. The callback
|
165 | * can make changes to Span.modification for each node.
|
166 | */
|
167 | forEach(callback: (span: Span) => void): void;
|
168 | /**
|
169 | * Returns the original unmodified text represented by this Span.
|
170 | */
|
171 | getText(): string;
|
172 | /**
|
173 | * Returns the text represented by this Span, after applying all requested modifications.
|
174 | */
|
175 | getModifiedText(): string;
|
176 | writeModifiedText(output: IndentedWriter): void;
|
177 | /**
|
178 | * Returns a diagnostic dump of the tree, showing the prefix/suffix/separator for
|
179 | * each node.
|
180 | */
|
181 | getDump(indent?: string): string;
|
182 | /**
|
183 | * Returns a diagnostic dump of the tree, showing the SpanModification settings for each nodde.
|
184 | */
|
185 | getModifiedDump(indent?: string): string;
|
186 | /**
|
187 | * Recursive implementation of `getModifiedText()` and `writeModifiedText()`.
|
188 | */
|
189 | private _writeModifiedText;
|
190 | private _beginIndentDocComment;
|
191 | private _endIndentDocComment;
|
192 | /**
|
193 | * Writes one chunk of `text` to the `options.writer`, applying the `indentDocComment` rewriting.
|
194 | */
|
195 | private _write;
|
196 | private _getTrimmed;
|
197 | private _getSubstring;
|
198 | }
|
199 | //# sourceMappingURL=Span.d.ts.map |
\ | No newline at end of file |