@plexcord-companion/ast-parser 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,131 @@
1
+ import { type VariableInfo } from "ts-api-utils";
2
+ import { type Expression, type Identifier, type LeftHandSideExpression, type MemberName, type Node, type PropertyAccessExpression, type ReadonlyTextRange, type SourceFile } from "typescript";
3
+ import { type Logger } from "@plexcord-companion/shared/Logger";
4
+ import { type IPosition, Position } from "@plexcord-companion/shared/Position";
5
+ import { Range } from "@plexcord-companion/shared/Range";
6
+ import type { StringifiedModule } from "./StringifiedModule.js";
7
+ import type { Functionish } from "./types.js";
8
+ export declare function setLogger(newLogger: Logger): void;
9
+ export declare class AstParser {
10
+ static withFormattedText(text: string): AstParser;
11
+ readonly text: string;
12
+ /**
13
+ * @CacheGetter
14
+ */
15
+ get sourceFile(): SourceFile;
16
+ /**
17
+ * All the variables in the source file
18
+ * @CacheGetter
19
+ */
20
+ get vars(): Map<Identifier, VariableInfo>;
21
+ /**
22
+ * @CacheGetter
23
+ */
24
+ get usesToVars(): Map<Identifier, VariableInfo>;
25
+ getVarInfoFromUse(ident: Identifier): VariableInfo | undefined;
26
+ /**
27
+ * @param use a use of a variable
28
+ * @param decl a declaration of a variable
29
+ * @returns true of the use is a use of the declaration, false otherwise
30
+ */
31
+ isUseOf(use: Identifier | undefined, decl: Identifier | undefined): boolean;
32
+ constructor(text: string);
33
+ /**
34
+ * given something like this
35
+ * ```js
36
+ * const bar = "foo";
37
+ * const baz = bar;
38
+ * const qux = baz;
39
+ * ```
40
+ * if given `qux` it will return `[bar, baz]`;
41
+ *
42
+ * fails on something where a variable is reassigned
43
+ */
44
+ unwrapVariableDeclaration(ident: Identifier): Identifier[] | undefined;
45
+ /**
46
+ * Used for interop with other systems
47
+ */
48
+ serialize(): StringifiedModule;
49
+ /**
50
+ * given the `x` of
51
+ * ```js
52
+ * const x = {
53
+ * foo: bar
54
+ * }
55
+ * ```
56
+ * NOTE: this must be the exact x, not a use of it
57
+ * @returns the expression {foo: bar}
58
+ */
59
+ getVariableInitializer(ident: Identifier): Expression | undefined;
60
+ /**
61
+ * TODO: document this
62
+ */
63
+ isConstDeclared(info: VariableInfo): [Identifier] | false;
64
+ /**
65
+ * @param expr the property access expression to flatten
66
+ *
67
+ * given a property access expression like `foo.bar.baz.qux`
68
+ *
69
+ * @returns the identifiers [`foo`, `bar`, `baz`, `qux`]
70
+ *
71
+ * given another property access expression like `foo.bar.baz[0].qux.abc`
72
+ *
73
+ * @returns the elementAccessExpression, followed by the identifiers [`foo.bar.baz[0]`, `qux`, `abc`]
74
+ */
75
+ flattenPropertyAccessExpression(expr: PropertyAccessExpression | undefined): readonly [LeftHandSideExpression, ...MemberName[]] | undefined;
76
+ /**
77
+ * given a variable, if it has a single assignment in this file, return the expression assigned to it
78
+ *
79
+ * returns undefined if there are multiple assignments, or if the variable is assigned more than once
80
+ */
81
+ findSingleAssignment(info: VariableInfo): Expression | undefined;
82
+ /**
83
+ * Create the source file for this parser
84
+ *
85
+ * MUST SET PARENT NODES
86
+ * @Cache
87
+ */
88
+ protected createSourceFile(): SourceFile;
89
+ /** Returns the token at or following the specified position or undefined if none is found inside `parent`. */
90
+ getTokenAtOffset(pos: number): Node | undefined;
91
+ getTokenAtPosition(pos: IPosition): Node | undefined;
92
+ /**
93
+ * convert two offsets to a range
94
+ *
95
+ * **DO NOT USE WITH AN AST NODE, IT WILL LEAD TO INCORRECT LOCATIONS**
96
+ * @see makeRangeFromAstNode
97
+ */
98
+ makeRange({ pos, end }: ReadonlyTextRange): Range;
99
+ makeRangeFromAstNode(node: Node): Range;
100
+ makeRangeFromAnonFunction(func: Functionish): Range;
101
+ makeRangeFromFunctionDef(ident: Identifier): Range | undefined;
102
+ /**
103
+ * Converts the position to a zero-based offset.
104
+ * Invalid positions are adjusted as described in {@link Position.line}
105
+ * and {@link Position.character}.
106
+ *
107
+ * @param position A position.
108
+ * @return A valid zero-based offset.
109
+ */
110
+ offsetAt(position: IPosition): number;
111
+ /**
112
+ * @CacheGetter
113
+ */
114
+ private get lineOffsets();
115
+ get lineCount(): number;
116
+ private ensureBeforeEOL;
117
+ private computeLineOffsets;
118
+ /**
119
+ * Converts a zero-based offset to a position.
120
+ *
121
+ * @param offset A zero-based offset.
122
+ * @return A valid {@link Position position}.
123
+ * @example The text document "ab\ncd" produces:
124
+ * position { line: 0, character: 0 } for `offset` 0.
125
+ * position { line: 0, character: 1 } for `offset` 1.
126
+ * position { line: 0, character: 2 } for `offset` 2.
127
+ * position { line: 1, character: 0 } for `offset` 3.
128
+ * position { line: 1, character: 1 } for `offset` 4.
129
+ */
130
+ positionAt(offset: number): Position;
131
+ }
@@ -0,0 +1,370 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Format } from "@sadan4/devtools-pretty-printer";
8
+ import { collectVariableUsage } from "ts-api-utils";
9
+ import { createSourceFile, isFunctionLike, isLeftHandSideExpression, isPropertyAccessExpression, isVariableDeclaration, isVariableDeclarationList, ScriptKind, ScriptTarget, SyntaxKind, } from "typescript";
10
+ import { Cache, CacheGetter } from "@plexcord-companion/shared/decorators";
11
+ import { NoopLogger } from "@plexcord-companion/shared/Logger";
12
+ import { Position } from "@plexcord-companion/shared/Position";
13
+ import { Range } from "@plexcord-companion/shared/Range";
14
+ import { CharCode, findParent, getTokenAtPosition, isAssignmentExpression, isEOL } from "./util.js";
15
+ let logger = NoopLogger;
16
+ export function setLogger(newLogger) {
17
+ logger = newLogger;
18
+ }
19
+ export class AstParser {
20
+ static withFormattedText(text) {
21
+ return new this(Format(text));
22
+ }
23
+ text;
24
+ /**
25
+ * @CacheGetter
26
+ */
27
+ get sourceFile() {
28
+ return this.createSourceFile();
29
+ }
30
+ /**
31
+ * All the variables in the source file
32
+ * @CacheGetter
33
+ */
34
+ get vars() {
35
+ return collectVariableUsage(this.sourceFile);
36
+ }
37
+ /**
38
+ * @CacheGetter
39
+ */
40
+ get usesToVars() {
41
+ const map = new Map();
42
+ for (const [, info] of this.vars) {
43
+ for (const { location } of info.uses) {
44
+ map.set(location, info);
45
+ }
46
+ // for (const decl of info.declarations) {
47
+ // map.set(decl, info);
48
+ // }
49
+ }
50
+ return map;
51
+ }
52
+ getVarInfoFromUse(ident) {
53
+ return this.usesToVars.get(ident);
54
+ }
55
+ // FIXME: add tests for this
56
+ /**
57
+ * @param use a use of a variable
58
+ * @param decl a declaration of a variable
59
+ * @returns true of the use is a use of the declaration, false otherwise
60
+ */
61
+ isUseOf(use, decl) {
62
+ if (!decl || !use)
63
+ return false;
64
+ const varInfo = this.vars.get(decl);
65
+ if (!varInfo)
66
+ return false;
67
+ const varInfoFromUse = this.usesToVars.get(use);
68
+ return varInfoFromUse === varInfo;
69
+ }
70
+ constructor(text) {
71
+ this.text = text;
72
+ }
73
+ /**
74
+ * given something like this
75
+ * ```js
76
+ * const bar = "foo";
77
+ * const baz = bar;
78
+ * const qux = baz;
79
+ * ```
80
+ * if given `qux` it will return `[bar, baz]`;
81
+ *
82
+ * fails on something where a variable is reassigned
83
+ */
84
+ unwrapVariableDeclaration(ident) {
85
+ const arr = [];
86
+ let last = ident;
87
+ while (true) {
88
+ const [varDec, ...rest] = this.getVarInfoFromUse(last)?.declarations ?? [];
89
+ if (!varDec)
90
+ break;
91
+ if (rest.length) {
92
+ arr.length = 0;
93
+ break;
94
+ }
95
+ arr.push(last = varDec);
96
+ }
97
+ if (arr.length !== 0)
98
+ return arr;
99
+ logger.debug("[AstParser] Failed finding variable declaration");
100
+ }
101
+ /**
102
+ * Used for interop with other systems
103
+ */
104
+ // FIXME: PACKAGE -
105
+ serialize() {
106
+ return {
107
+ content: this.text,
108
+ };
109
+ }
110
+ /**
111
+ * given the `x` of
112
+ * ```js
113
+ * const x = {
114
+ * foo: bar
115
+ * }
116
+ * ```
117
+ * NOTE: this must be the exact x, not a use of it
118
+ * @returns the expression {foo: bar}
119
+ */
120
+ getVariableInitializer(ident) {
121
+ const dec = ident.parent;
122
+ if (!isVariableDeclaration(dec))
123
+ return;
124
+ return dec.initializer;
125
+ }
126
+ /**
127
+ * TODO: document this
128
+ */
129
+ isConstDeclared(info) {
130
+ const len = info.declarations.length;
131
+ if (len !== 1) {
132
+ if (len > 1) {
133
+ logger.warn("[AstParser] isConstDeclared: ?????");
134
+ }
135
+ return false;
136
+ }
137
+ const [decl] = info.declarations;
138
+ const varDecl = findParent(decl, isVariableDeclarationList);
139
+ return ((varDecl?.flags ?? 0) & SyntaxKind.ConstKeyword) !== 0 ? [decl] : false;
140
+ }
141
+ // TODO: add tests for this
142
+ /**
143
+ * @param expr the property access expression to flatten
144
+ *
145
+ * given a property access expression like `foo.bar.baz.qux`
146
+ *
147
+ * @returns the identifiers [`foo`, `bar`, `baz`, `qux`]
148
+ *
149
+ * given another property access expression like `foo.bar.baz[0].qux.abc`
150
+ *
151
+ * @returns the elementAccessExpression, followed by the identifiers [`foo.bar.baz[0]`, `qux`, `abc`]
152
+ */
153
+ flattenPropertyAccessExpression(expr) {
154
+ if (!expr)
155
+ return undefined;
156
+ const toRet = [];
157
+ let cur = expr;
158
+ do {
159
+ toRet.unshift(cur.name);
160
+ if (isLeftHandSideExpression(cur.expression) && !isPropertyAccessExpression(cur.expression)) {
161
+ toRet.unshift(cur.expression);
162
+ return toRet;
163
+ }
164
+ if (!isPropertyAccessExpression(cur.expression)) {
165
+ toRet.unshift(cur.expression);
166
+ return;
167
+ }
168
+ } while ((cur = cur.expression));
169
+ }
170
+ /**
171
+ * given a variable, if it has a single assignment in this file, return the expression assigned to it
172
+ *
173
+ * returns undefined if there are multiple assignments, or if the variable is assigned more than once
174
+ */
175
+ findSingleAssignment(info) {
176
+ const { declarations, uses } = info;
177
+ if (declarations.length !== 1) {
178
+ logger.warn("[AstParser] findSingleAssignment: multiple declarations");
179
+ return;
180
+ }
181
+ const [decl] = declarations;
182
+ if (this.isConstDeclared(info)) {
183
+ const init = this.getVariableInitializer(decl);
184
+ if (!init) {
185
+ logger.warn("[AstParser] findSingleAssignment: const variable without initializer");
186
+ }
187
+ return init;
188
+ }
189
+ let init;
190
+ for (const { location } of uses) {
191
+ if (isAssignmentExpression(location.parent)) {
192
+ // filter out cases like `<some other thing> = location`
193
+ if (location.parent.left !== location) {
194
+ continue;
195
+ }
196
+ if (init || location.parent.operatorToken.kind !== SyntaxKind.EqualsToken) {
197
+ return;
198
+ }
199
+ init = location.parent.right;
200
+ }
201
+ }
202
+ return init;
203
+ }
204
+ /**
205
+ * Create the source file for this parser
206
+ *
207
+ * MUST SET PARENT NODES
208
+ * @Cache
209
+ */
210
+ createSourceFile() {
211
+ return createSourceFile("file.tsx", this.text, ScriptTarget.ESNext, true, ScriptKind.TSX);
212
+ }
213
+ /** Returns the token at or following the specified position or undefined if none is found inside `parent`. */
214
+ getTokenAtOffset(pos) {
215
+ return getTokenAtPosition(this.sourceFile, pos, this.sourceFile, false);
216
+ }
217
+ getTokenAtPosition(pos) {
218
+ return this.getTokenAtOffset(this.offsetAt(pos));
219
+ }
220
+ /**
221
+ * convert two offsets to a range
222
+ *
223
+ * **DO NOT USE WITH AN AST NODE, IT WILL LEAD TO INCORRECT LOCATIONS**
224
+ * @see makeRangeFromAstNode
225
+ */
226
+ makeRange({ pos, end }) {
227
+ return new Range(this.positionAt(pos), this.positionAt(end));
228
+ }
229
+ makeRangeFromAstNode(node) {
230
+ return new Range(this.positionAt(node.getStart(this.sourceFile)), this.positionAt(node.end));
231
+ }
232
+ makeRangeFromAnonFunction(func) {
233
+ const { pos } = func.body ?? { pos: func.getEnd() };
234
+ return this.makeRange({
235
+ pos: func.getStart(),
236
+ end: pos,
237
+ });
238
+ }
239
+ makeRangeFromFunctionDef(ident) {
240
+ const { declarations } = this.getVarInfoFromUse(ident) ?? {};
241
+ if (!declarations) {
242
+ logger.debug("makeRangeFromFunctionDef: no declarations found for identifier");
243
+ return undefined;
244
+ }
245
+ if (declarations.length !== 1) {
246
+ logger.debug("makeRangeFromFunctionDef: zero or multiple declarations found for identifier");
247
+ return undefined;
248
+ }
249
+ if (declarations[0].parent && !isFunctionLike(declarations[0].parent)) {
250
+ logger.debug("makeRangeFromFunctionDef: dec. parent is not a function");
251
+ return undefined;
252
+ }
253
+ return this.makeRangeFromAstNode(declarations[0]);
254
+ }
255
+ /**
256
+ * Converts the position to a zero-based offset.
257
+ * Invalid positions are adjusted as described in {@link Position.line}
258
+ * and {@link Position.character}.
259
+ *
260
+ * @param position A position.
261
+ * @return A valid zero-based offset.
262
+ */
263
+ // copied from vscode-languageserver-node
264
+ offsetAt(position) {
265
+ const { lineOffsets } = this;
266
+ if (position.line >= lineOffsets.length) {
267
+ return this.text.length;
268
+ }
269
+ else if (position.line < 0) {
270
+ return 0;
271
+ }
272
+ const lineOffset = lineOffsets[position.line];
273
+ if (position.character <= 0) {
274
+ return lineOffset;
275
+ }
276
+ const nextLineOffset = position.line + 1 < lineOffsets.length
277
+ ? lineOffsets[position.line + 1]
278
+ : this.text.length;
279
+ const offset = Math.min(lineOffset + position.character, nextLineOffset);
280
+ return this.ensureBeforeEOL(offset, lineOffset);
281
+ }
282
+ // methods copied from vscode-languageserver-node
283
+ /**
284
+ * @CacheGetter
285
+ */
286
+ get lineOffsets() {
287
+ return this.computeLineOffsets(true);
288
+ }
289
+ get lineCount() {
290
+ return this.lineOffsets.length;
291
+ }
292
+ ensureBeforeEOL(offset, lineOffset) {
293
+ while (offset > lineOffset && isEOL(this.text.charCodeAt(offset - 1))) {
294
+ offset--;
295
+ }
296
+ return offset;
297
+ }
298
+ computeLineOffsets(isAtLineStart, textOffset = 0) {
299
+ const { text } = this;
300
+ const result = isAtLineStart ? [textOffset] : [];
301
+ for (let i = 0; i < text.length; i++) {
302
+ const ch = text.charCodeAt(i);
303
+ if (isEOL(ch)) {
304
+ if (ch === CharCode.CarriageReturn
305
+ && i + 1 < text.length
306
+ && text.charCodeAt(i + 1) === CharCode.LineFeed) {
307
+ i++;
308
+ }
309
+ result.push(textOffset + i + 1);
310
+ }
311
+ }
312
+ return result;
313
+ }
314
+ /**
315
+ * Converts a zero-based offset to a position.
316
+ *
317
+ * @param offset A zero-based offset.
318
+ * @return A valid {@link Position position}.
319
+ * @example The text document "ab\ncd" produces:
320
+ * position { line: 0, character: 0 } for `offset` 0.
321
+ * position { line: 0, character: 1 } for `offset` 1.
322
+ * position { line: 0, character: 2 } for `offset` 2.
323
+ * position { line: 1, character: 0 } for `offset` 3.
324
+ * position { line: 1, character: 1 } for `offset` 4.
325
+ */
326
+ positionAt(offset) {
327
+ offset = Math.max(Math.min(offset, this.text.length), 0);
328
+ const { lineOffsets } = this;
329
+ let low = 0, high = lineOffsets.length;
330
+ if (high === 0) {
331
+ return new Position(0, offset);
332
+ }
333
+ while (low < high) {
334
+ const mid = Math.floor((low + high) / 2);
335
+ if (lineOffsets[mid] > offset) {
336
+ high = mid;
337
+ }
338
+ else {
339
+ low = mid + 1;
340
+ }
341
+ }
342
+ // low is the least x for which the line offset is larger than the current offset
343
+ // or array.length if no line offset is larger than the current offset
344
+ const line = low - 1;
345
+ offset = this.ensureBeforeEOL(offset, lineOffsets[line]);
346
+ return new Position(line, offset - lineOffsets[line]);
347
+ }
348
+ }
349
+ __decorate([
350
+ CacheGetter()
351
+ ], AstParser.prototype, "sourceFile", null);
352
+ __decorate([
353
+ CacheGetter()
354
+ ], AstParser.prototype, "vars", null);
355
+ __decorate([
356
+ CacheGetter()
357
+ ], AstParser.prototype, "usesToVars", null);
358
+ __decorate([
359
+ Cache()
360
+ ], AstParser.prototype, "createSourceFile", null);
361
+ __decorate([
362
+ CacheGetter()
363
+ ], AstParser.prototype, "lineOffsets", null);
364
+ __decorate([
365
+ CacheGetter()
366
+ /**
367
+ * @CacheGetter
368
+ */
369
+ ], AstParser.prototype, "lineCount", null);
370
+ //# sourceMappingURL=AstParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AstParser.js","sourceRoot":"","sources":["../src/AstParser.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAqB,MAAM,cAAc,CAAC;AACvE,OAAO,EACH,gBAAgB,EAGhB,cAAc,EACd,wBAAwB,EACxB,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EAMzB,UAAU,EACV,YAAY,EAEZ,UAAU,GACb,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAe,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAkB,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AAIzD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEjG,IAAI,MAAM,GAAW,UAAU,CAAC;AAEhC,MAAM,UAAU,SAAS,CAAC,SAAiB;IACvC,MAAM,GAAG,SAAS,CAAC;AACvB,CAAC;AAED,MAAM,OAAO,SAAS;IACX,MAAM,CAAC,iBAAiB,CAAC,IAAY;QACxC,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAClC,CAAC;IAEe,IAAI,CAAS;IAE7B;;OAEG;IAEH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACnC,CAAC;IAED;;;OAGG;IAEH,IAAW,IAAI;QACX,OAAO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AG,GAAG,IAAI,EAAE,CAAC;YAChB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAEzC,IAAI,WAAW,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,CAAC;gBAC5B,IAAI,GAAG,GAAG,CAAC;YACf,CAAC;iBAAM,CAAC;gBACJ,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;YAClB,CAAC;QACL,CAAC;QAED,iFAAiF;QACjF,sEAAsE;QACtE,MAAM,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC;QAErB,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1D,CAAC;CACJ;AAjZG;IADC,WAAW,EAAE;2CAGb;AAOD;IADC,WAAW,EAAE;qCAGb;AAMD;IADC,WAAW,EAAE;2CAcb;AA+LS;IADT,KAAK,EAAE;iDASP;AA4FD;IADC,WAAW,EAAE;4CAGb;AAMD;IAJC,WAAW,EAAE;IACd;;OAEG;0CAGF"}
@@ -0,0 +1,3 @@
1
+ export interface StringifiedModule {
2
+ content: string;
3
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=StringifiedModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StringifiedModule.js","sourceRoot":"","sources":["../src/StringifiedModule.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from "./AstParser.js";
2
+ export type * from "./types.js";
3
+ export * from "./util.js";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./AstParser.js";
2
+ export * from "./util.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAE5B,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { ArrowFunction, FunctionExpression, FunctionLikeDeclaration, Identifier, ModuleExportName, Node } from "typescript";
2
+ export type Functionish = FunctionLikeDeclaration | ArrowFunction | FunctionExpression;
3
+ export type AnyFunction = FunctionExpression | ArrowFunction;
4
+ export type AssertedType<T extends Function, E = any> = T extends (a: any) => a is infer R ? R extends E ? R : never : never;
5
+ export type CBAssertion<U = undefined, N = never> = <F extends (n: Node) => n is Node, R extends Node = AssertedType<F, Node>>(node: Node | N, func: F extends (n: Node) => n is R ? F : never) => R | U;
6
+ export type Import = {
7
+ default: boolean;
8
+ source: string;
9
+ namespace: boolean;
10
+ orig?: ModuleExportName;
11
+ as: Identifier;
12
+ };
13
+ export type WithParent<N, P> = Omit<N, "parent"> & {
14
+ parent: P;
15
+ };
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}