@vencord-companion/ast-parser 0.0.1
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.
- package/dist/AstParser.d.ts +143 -0
- package/dist/AstParser.js +426 -0
- package/dist/AstParser.js.map +1 -0
- package/dist/StringifiedModule.d.ts +3 -0
- package/dist/StringifiedModule.js +2 -0
- package/dist/StringifiedModule.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/util.d.ts +87 -0
- package/dist/util.js +287 -0
- package/dist/util.js.map +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { type VariableInfo } from "ts-api-utils";
|
|
2
|
+
import { type AssignmentExpression, type AssignmentOperatorToken, type CallExpression, type Expression, type Identifier, type LeftHandSideExpression, type LiteralToken, type MemberName, type Node, type PropertyAccessExpression, type ReadonlyTextRange, type SourceFile, type VariableDeclaration } from "typescript";
|
|
3
|
+
import { type Logger } from "@vencord-companion/shared/Logger";
|
|
4
|
+
import { IPosition, Position } from "@vencord-companion/shared/Position";
|
|
5
|
+
import { Range } from "@vencord-companion/shared/Range";
|
|
6
|
+
import { StringifiedModule } from "./StringifiedModule";
|
|
7
|
+
import { Functionish } from "./types";
|
|
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
|
+
isCallExpression(node: Node | undefined): node is CallExpression;
|
|
46
|
+
/**
|
|
47
|
+
* Used for interop with other systems
|
|
48
|
+
*/
|
|
49
|
+
serialize(): StringifiedModule;
|
|
50
|
+
/**
|
|
51
|
+
* given the `x` of
|
|
52
|
+
* ```js
|
|
53
|
+
* const x = {
|
|
54
|
+
* foo: bar
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
* NOTE: this must be the exact x, not a use of it
|
|
58
|
+
* @returns the expression {foo: bar}
|
|
59
|
+
*/
|
|
60
|
+
getVariableInitializer(ident: Identifier): Expression | undefined;
|
|
61
|
+
isVariableAssignmentLike(node: Node | undefined): node is (Omit<VariableDeclaration, "name" | "initializer"> & {
|
|
62
|
+
name: Identifier;
|
|
63
|
+
initializer: Exclude<VariableDeclaration["initializer"], undefined>;
|
|
64
|
+
}) | (Omit<AssignmentExpression<AssignmentOperatorToken>, "left"> & {
|
|
65
|
+
left: Identifier;
|
|
66
|
+
});
|
|
67
|
+
private static AssignmentTokens;
|
|
68
|
+
isAssignmentExpression(node: Node | undefined): node is AssignmentExpression<AssignmentOperatorToken>;
|
|
69
|
+
/**
|
|
70
|
+
* TODO: document this
|
|
71
|
+
*/
|
|
72
|
+
isConstDeclared(info: VariableInfo): [Identifier] | false;
|
|
73
|
+
/**
|
|
74
|
+
* @param expr the property access expression to flatten
|
|
75
|
+
*
|
|
76
|
+
* given a property access expression like `foo.bar.baz.qux`
|
|
77
|
+
*
|
|
78
|
+
* @returns the identifiers [`foo`, `bar`, `baz`, `qux`]
|
|
79
|
+
*
|
|
80
|
+
* given another property access expression like `foo.bar.baz[0].qux.abc`
|
|
81
|
+
*
|
|
82
|
+
* @returns the elementAccessExpression, followed by the identifiers [`foo.bar.baz[0]`, `qux`, `abc`]
|
|
83
|
+
*/
|
|
84
|
+
flattenPropertyAccessExpression(expr: PropertyAccessExpression | undefined): readonly [LeftHandSideExpression, ...MemberName[]] | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* given a variable, if it has a single assignment in this file, return the expression assigned to it
|
|
87
|
+
*
|
|
88
|
+
* returns undefined if there are multiple assignments, or if the variable is assigned more than once
|
|
89
|
+
*/
|
|
90
|
+
findSingleAssignment(info: VariableInfo): Expression | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Create the source file for this parser
|
|
93
|
+
*
|
|
94
|
+
* MUST SET PARENT NODES
|
|
95
|
+
* @Cache
|
|
96
|
+
*/
|
|
97
|
+
protected createSourceFile(): SourceFile;
|
|
98
|
+
/** Returns the token at or following the specified position or undefined if none is found inside `parent`. */
|
|
99
|
+
getTokenAtOffset(pos: number): Node | undefined;
|
|
100
|
+
getTokenAtPosition(pos: IPosition): Node | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* convert two offsets to a range
|
|
103
|
+
*
|
|
104
|
+
* **DO NOT USE WITH AN AST NODE, IT WILL LEAD TO INCORRECT LOCATIONS**
|
|
105
|
+
* @see makeRangeFromAstNode
|
|
106
|
+
*/
|
|
107
|
+
makeRange({ pos, end }: ReadonlyTextRange): Range;
|
|
108
|
+
makeRangeFromAstNode(node: Node): Range;
|
|
109
|
+
makeRangeFromAnonFunction(func: Functionish): Range;
|
|
110
|
+
makeRangeFromFunctionDef(ident: Identifier): Range | undefined;
|
|
111
|
+
isLiteralish(node: Node): node is LiteralToken;
|
|
112
|
+
isFunctionish(node: Node): node is Functionish;
|
|
113
|
+
isIdentifier(node: Node | undefined): node is Identifier;
|
|
114
|
+
/**
|
|
115
|
+
* Converts the position to a zero-based offset.
|
|
116
|
+
* Invalid positions are adjusted as described in {@link Position.line}
|
|
117
|
+
* and {@link Position.character}.
|
|
118
|
+
*
|
|
119
|
+
* @param position A position.
|
|
120
|
+
* @return A valid zero-based offset.
|
|
121
|
+
*/
|
|
122
|
+
offsetAt(position: IPosition): number;
|
|
123
|
+
/**
|
|
124
|
+
* @CacheGetter
|
|
125
|
+
*/
|
|
126
|
+
private get lineOffsets();
|
|
127
|
+
get lineCount(): number;
|
|
128
|
+
private ensureBeforeEOL;
|
|
129
|
+
private computeLineOffsets;
|
|
130
|
+
/**
|
|
131
|
+
* Converts a zero-based offset to a position.
|
|
132
|
+
*
|
|
133
|
+
* @param offset A zero-based offset.
|
|
134
|
+
* @return A valid {@link Position position}.
|
|
135
|
+
* @example The text document "ab\ncd" produces:
|
|
136
|
+
* position { line: 0, character: 0 } for `offset` 0.
|
|
137
|
+
* position { line: 0, character: 1 } for `offset` 1.
|
|
138
|
+
* position { line: 0, character: 2 } for `offset` 2.
|
|
139
|
+
* position { line: 1, character: 0 } for `offset` 3.
|
|
140
|
+
* position { line: 1, character: 1 } for `offset` 4.
|
|
141
|
+
*/
|
|
142
|
+
positionAt(offset: number): Position;
|
|
143
|
+
}
|
|
@@ -0,0 +1,426 @@
|
|
|
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, isArrowFunction, isBigIntLiteral, isBinaryExpression, isConstructorDeclaration, isFunctionDeclaration, isFunctionExpression, isFunctionLike, isGetAccessorDeclaration, isIdentifier, isJsxText, isMethodDeclaration, isNumericLiteral, isPropertyAccessExpression, isRegularExpressionLiteral, isSetAccessorDeclaration, isStringLiteralLike, isVariableDeclaration, isVariableDeclarationList, ScriptKind, ScriptTarget, SyntaxKind, } from "typescript";
|
|
10
|
+
import { Cache, CacheGetter } from "@vencord-companion/shared/decorators";
|
|
11
|
+
import { NoopLogger } from "@vencord-companion/shared/Logger";
|
|
12
|
+
import { Position } from "@vencord-companion/shared/Position";
|
|
13
|
+
import { Range } from "@vencord-companion/shared/Range";
|
|
14
|
+
import { findParent, getTokenAtPosition, isEOL } from "./util";
|
|
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
|
+
isCallExpression(node) {
|
|
102
|
+
return node?.kind === SyntaxKind.CallExpression;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Used for interop with other systems
|
|
106
|
+
*/
|
|
107
|
+
// FIXME: PACKAGE -
|
|
108
|
+
serialize() {
|
|
109
|
+
return {
|
|
110
|
+
content: this.text,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* given the `x` of
|
|
115
|
+
* ```js
|
|
116
|
+
* const x = {
|
|
117
|
+
* foo: bar
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
* NOTE: this must be the exact x, not a use of it
|
|
121
|
+
* @returns the expression {foo: bar}
|
|
122
|
+
*/
|
|
123
|
+
getVariableInitializer(ident) {
|
|
124
|
+
const dec = ident.parent;
|
|
125
|
+
if (!isVariableDeclaration(dec))
|
|
126
|
+
return;
|
|
127
|
+
return dec.initializer;
|
|
128
|
+
}
|
|
129
|
+
isVariableAssignmentLike(node) {
|
|
130
|
+
if (!node)
|
|
131
|
+
return false;
|
|
132
|
+
if (isVariableDeclaration(node)) {
|
|
133
|
+
return isIdentifier(node.name) && !!node.initializer;
|
|
134
|
+
}
|
|
135
|
+
else if (isBinaryExpression(node)) {
|
|
136
|
+
return this.isAssignmentExpression(node);
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
static AssignmentTokens = {
|
|
141
|
+
[SyntaxKind.EqualsToken]: true,
|
|
142
|
+
[SyntaxKind.PlusEqualsToken]: true,
|
|
143
|
+
[SyntaxKind.MinusEqualsToken]: true,
|
|
144
|
+
[SyntaxKind.AsteriskAsteriskEqualsToken]: true,
|
|
145
|
+
[SyntaxKind.AsteriskEqualsToken]: true,
|
|
146
|
+
[SyntaxKind.SlashEqualsToken]: true,
|
|
147
|
+
[SyntaxKind.PercentEqualsToken]: true,
|
|
148
|
+
[SyntaxKind.AmpersandEqualsToken]: true,
|
|
149
|
+
[SyntaxKind.BarEqualsToken]: true,
|
|
150
|
+
[SyntaxKind.CaretEqualsToken]: true,
|
|
151
|
+
[SyntaxKind.LessThanLessThanEqualsToken]: true,
|
|
152
|
+
[SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: true,
|
|
153
|
+
[SyntaxKind.GreaterThanGreaterThanEqualsToken]: true,
|
|
154
|
+
[SyntaxKind.BarBarEqualsToken]: true,
|
|
155
|
+
[SyntaxKind.AmpersandAmpersandEqualsToken]: true,
|
|
156
|
+
[SyntaxKind.QuestionQuestionEqualsToken]: true,
|
|
157
|
+
};
|
|
158
|
+
isAssignmentExpression(node) {
|
|
159
|
+
if (!node || !isBinaryExpression(node))
|
|
160
|
+
return false;
|
|
161
|
+
return AstParser.AssignmentTokens[node.operatorToken.kind] === true;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* TODO: document this
|
|
165
|
+
*/
|
|
166
|
+
isConstDeclared(info) {
|
|
167
|
+
const len = info.declarations.length;
|
|
168
|
+
if (len !== 1) {
|
|
169
|
+
if (len > 1) {
|
|
170
|
+
logger.warn("[AstParser] isConstDeclared: ?????");
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
const [decl] = info.declarations;
|
|
175
|
+
const varDecl = findParent(decl, isVariableDeclarationList);
|
|
176
|
+
return ((varDecl?.flags ?? 0) & SyntaxKind.ConstKeyword) !== 0 ? [decl] : false;
|
|
177
|
+
}
|
|
178
|
+
// TODO: add tests for this
|
|
179
|
+
/**
|
|
180
|
+
* @param expr the property access expression to flatten
|
|
181
|
+
*
|
|
182
|
+
* given a property access expression like `foo.bar.baz.qux`
|
|
183
|
+
*
|
|
184
|
+
* @returns the identifiers [`foo`, `bar`, `baz`, `qux`]
|
|
185
|
+
*
|
|
186
|
+
* given another property access expression like `foo.bar.baz[0].qux.abc`
|
|
187
|
+
*
|
|
188
|
+
* @returns the elementAccessExpression, followed by the identifiers [`foo.bar.baz[0]`, `qux`, `abc`]
|
|
189
|
+
*/
|
|
190
|
+
flattenPropertyAccessExpression(expr) {
|
|
191
|
+
if (!expr)
|
|
192
|
+
return undefined;
|
|
193
|
+
const toRet = [];
|
|
194
|
+
let cur = expr;
|
|
195
|
+
do {
|
|
196
|
+
toRet.unshift(cur.name);
|
|
197
|
+
if (isIdentifier(cur.expression)) {
|
|
198
|
+
toRet.unshift(cur.expression);
|
|
199
|
+
return toRet;
|
|
200
|
+
}
|
|
201
|
+
if (!isPropertyAccessExpression(cur.expression)) {
|
|
202
|
+
toRet.unshift(cur.expression);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
} while ((cur = cur.expression));
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* given a variable, if it has a single assignment in this file, return the expression assigned to it
|
|
209
|
+
*
|
|
210
|
+
* returns undefined if there are multiple assignments, or if the variable is assigned more than once
|
|
211
|
+
*/
|
|
212
|
+
findSingleAssignment(info) {
|
|
213
|
+
const { declarations, uses } = info;
|
|
214
|
+
if (declarations.length !== 1) {
|
|
215
|
+
logger.warn("[AstParser] findSingleAssignment: multiple declarations");
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const [decl] = declarations;
|
|
219
|
+
if (this.isConstDeclared(info)) {
|
|
220
|
+
const init = this.getVariableInitializer(decl);
|
|
221
|
+
if (!init) {
|
|
222
|
+
logger.warn("[AstParser] findSingleAssignment: const variable without initializer");
|
|
223
|
+
}
|
|
224
|
+
return init;
|
|
225
|
+
}
|
|
226
|
+
let init;
|
|
227
|
+
for (const { location } of uses) {
|
|
228
|
+
if (this.isAssignmentExpression(location.parent)) {
|
|
229
|
+
// filter out cases like `<some other thing> = location`
|
|
230
|
+
if (location.parent.left !== location) {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (init || location.parent.operatorToken.kind !== SyntaxKind.EqualsToken) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
init = location.parent.right;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return init;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Create the source file for this parser
|
|
243
|
+
*
|
|
244
|
+
* MUST SET PARENT NODES
|
|
245
|
+
* @Cache
|
|
246
|
+
*/
|
|
247
|
+
createSourceFile() {
|
|
248
|
+
return createSourceFile("file.tsx", this.text, ScriptTarget.ESNext, true, ScriptKind.TSX);
|
|
249
|
+
}
|
|
250
|
+
/** Returns the token at or following the specified position or undefined if none is found inside `parent`. */
|
|
251
|
+
getTokenAtOffset(pos) {
|
|
252
|
+
return getTokenAtPosition(this.sourceFile, pos, this.sourceFile, false);
|
|
253
|
+
}
|
|
254
|
+
getTokenAtPosition(pos) {
|
|
255
|
+
return this.getTokenAtOffset(this.offsetAt(pos));
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* convert two offsets to a range
|
|
259
|
+
*
|
|
260
|
+
* **DO NOT USE WITH AN AST NODE, IT WILL LEAD TO INCORRECT LOCATIONS**
|
|
261
|
+
* @see makeRangeFromAstNode
|
|
262
|
+
*/
|
|
263
|
+
makeRange({ pos, end }) {
|
|
264
|
+
return new Range(this.positionAt(pos), this.positionAt(end));
|
|
265
|
+
}
|
|
266
|
+
makeRangeFromAstNode(node) {
|
|
267
|
+
return new Range(this.positionAt(node.getStart(this.sourceFile)), this.positionAt(node.end));
|
|
268
|
+
}
|
|
269
|
+
makeRangeFromAnonFunction(func) {
|
|
270
|
+
const { pos } = func.body ?? { pos: func.getEnd() };
|
|
271
|
+
return this.makeRange({
|
|
272
|
+
pos: func.getStart(),
|
|
273
|
+
end: pos,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
makeRangeFromFunctionDef(ident) {
|
|
277
|
+
const { declarations } = this.getVarInfoFromUse(ident) ?? {};
|
|
278
|
+
if (!declarations) {
|
|
279
|
+
logger.debug("makeRangeFromFunctionDef: no declarations found for identifier");
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
if (declarations.length !== 1) {
|
|
283
|
+
logger.debug("makeRangeFromFunctionDef: zero or multiple declarations found for identifier");
|
|
284
|
+
return undefined;
|
|
285
|
+
}
|
|
286
|
+
if (declarations[0].parent && !isFunctionLike(declarations[0].parent)) {
|
|
287
|
+
logger.debug("makeRangeFromFunctionDef: dec. parent is not a function");
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
return this.makeRangeFromAstNode(declarations[0]);
|
|
291
|
+
}
|
|
292
|
+
isLiteralish(node) {
|
|
293
|
+
return isStringLiteralLike(node)
|
|
294
|
+
|| isNumericLiteral(node)
|
|
295
|
+
|| isBigIntLiteral(node)
|
|
296
|
+
|| isJsxText(node)
|
|
297
|
+
|| isRegularExpressionLiteral(node);
|
|
298
|
+
}
|
|
299
|
+
isFunctionish(node) {
|
|
300
|
+
return (isFunctionDeclaration(node)
|
|
301
|
+
|| isMethodDeclaration(node)
|
|
302
|
+
|| isGetAccessorDeclaration(node)
|
|
303
|
+
|| isSetAccessorDeclaration(node)
|
|
304
|
+
|| isConstructorDeclaration(node)
|
|
305
|
+
|| isFunctionExpression(node)
|
|
306
|
+
|| isArrowFunction(node));
|
|
307
|
+
}
|
|
308
|
+
isIdentifier(node) {
|
|
309
|
+
return !!node && isIdentifier(node);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Converts the position to a zero-based offset.
|
|
313
|
+
* Invalid positions are adjusted as described in {@link Position.line}
|
|
314
|
+
* and {@link Position.character}.
|
|
315
|
+
*
|
|
316
|
+
* @param position A position.
|
|
317
|
+
* @return A valid zero-based offset.
|
|
318
|
+
*/
|
|
319
|
+
// copied from vscode-languageserver-node
|
|
320
|
+
offsetAt(position) {
|
|
321
|
+
const { lineOffsets } = this;
|
|
322
|
+
if (position.line >= lineOffsets.length) {
|
|
323
|
+
return this.text.length;
|
|
324
|
+
}
|
|
325
|
+
else if (position.line < 0) {
|
|
326
|
+
return 0;
|
|
327
|
+
}
|
|
328
|
+
const lineOffset = lineOffsets[position.line];
|
|
329
|
+
if (position.character <= 0) {
|
|
330
|
+
return lineOffset;
|
|
331
|
+
}
|
|
332
|
+
const nextLineOffset = position.line + 1 < lineOffsets.length
|
|
333
|
+
? lineOffsets[position.line + 1]
|
|
334
|
+
: this.text.length;
|
|
335
|
+
const offset = Math.min(lineOffset + position.character, nextLineOffset);
|
|
336
|
+
return this.ensureBeforeEOL(offset, lineOffset);
|
|
337
|
+
}
|
|
338
|
+
// methods copied from vscode-languageserver-node
|
|
339
|
+
/**
|
|
340
|
+
* @CacheGetter
|
|
341
|
+
*/
|
|
342
|
+
get lineOffsets() {
|
|
343
|
+
return this.computeLineOffsets(true);
|
|
344
|
+
}
|
|
345
|
+
get lineCount() {
|
|
346
|
+
return this.lineOffsets.length;
|
|
347
|
+
}
|
|
348
|
+
ensureBeforeEOL(offset, lineOffset) {
|
|
349
|
+
while (offset > lineOffset && isEOL(this.text.charCodeAt(offset - 1))) {
|
|
350
|
+
offset--;
|
|
351
|
+
}
|
|
352
|
+
return offset;
|
|
353
|
+
}
|
|
354
|
+
computeLineOffsets(isAtLineStart, textOffset = 0) {
|
|
355
|
+
const { text } = this;
|
|
356
|
+
const result = isAtLineStart ? [textOffset] : [];
|
|
357
|
+
for (let i = 0; i < text.length; i++) {
|
|
358
|
+
const ch = text.charCodeAt(i);
|
|
359
|
+
if (isEOL(ch)) {
|
|
360
|
+
if (ch === 13 /* CharCode.CarriageReturn */
|
|
361
|
+
&& i + 1 < text.length
|
|
362
|
+
&& text.charCodeAt(i + 1) === 10 /* CharCode.LineFeed */) {
|
|
363
|
+
i++;
|
|
364
|
+
}
|
|
365
|
+
result.push(textOffset + i + 1);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return result;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Converts a zero-based offset to a position.
|
|
372
|
+
*
|
|
373
|
+
* @param offset A zero-based offset.
|
|
374
|
+
* @return A valid {@link Position position}.
|
|
375
|
+
* @example The text document "ab\ncd" produces:
|
|
376
|
+
* position { line: 0, character: 0 } for `offset` 0.
|
|
377
|
+
* position { line: 0, character: 1 } for `offset` 1.
|
|
378
|
+
* position { line: 0, character: 2 } for `offset` 2.
|
|
379
|
+
* position { line: 1, character: 0 } for `offset` 3.
|
|
380
|
+
* position { line: 1, character: 1 } for `offset` 4.
|
|
381
|
+
*/
|
|
382
|
+
positionAt(offset) {
|
|
383
|
+
offset = Math.max(Math.min(offset, this.text.length), 0);
|
|
384
|
+
const { lineOffsets } = this;
|
|
385
|
+
let low = 0, high = lineOffsets.length;
|
|
386
|
+
if (high === 0) {
|
|
387
|
+
return new Position(0, offset);
|
|
388
|
+
}
|
|
389
|
+
while (low < high) {
|
|
390
|
+
const mid = Math.floor((low + high) / 2);
|
|
391
|
+
if (lineOffsets[mid] > offset) {
|
|
392
|
+
high = mid;
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
low = mid + 1;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
// low is the least x for which the line offset is larger than the current offset
|
|
399
|
+
// or array.length if no line offset is larger than the current offset
|
|
400
|
+
const line = low - 1;
|
|
401
|
+
offset = this.ensureBeforeEOL(offset, lineOffsets[line]);
|
|
402
|
+
return new Position(line, offset - lineOffsets[line]);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
__decorate([
|
|
406
|
+
CacheGetter()
|
|
407
|
+
], AstParser.prototype, "sourceFile", null);
|
|
408
|
+
__decorate([
|
|
409
|
+
CacheGetter()
|
|
410
|
+
], AstParser.prototype, "vars", null);
|
|
411
|
+
__decorate([
|
|
412
|
+
CacheGetter()
|
|
413
|
+
], AstParser.prototype, "usesToVars", null);
|
|
414
|
+
__decorate([
|
|
415
|
+
Cache()
|
|
416
|
+
], AstParser.prototype, "createSourceFile", null);
|
|
417
|
+
__decorate([
|
|
418
|
+
CacheGetter()
|
|
419
|
+
], AstParser.prototype, "lineOffsets", null);
|
|
420
|
+
__decorate([
|
|
421
|
+
CacheGetter()
|
|
422
|
+
/**
|
|
423
|
+
* @CacheGetter
|
|
424
|
+
*/
|
|
425
|
+
], AstParser.prototype, "lineCount", null);
|
|
426
|
+
//# 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,EAIH,gBAAgB,EAGhB,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,wBAAwB,EACxB,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,gBAAgB,EAChB,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EAOzB,UAAU,EACV,YAAY,EAEZ,UAAU,GAEb,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAe,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAa,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAIxD,OAAO,EAAY,UAAU,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEzE,IAAI,MAAM,GAA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GAAG,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;;AA3dD;IADC,WAAW,EAAE;2CAGb;AAOD;IADC,WAAW,EAAE;qCAGb;AAMD;IADC,WAAW,EAAE;2CAcb;AAmPS;IADT,KAAK,EAAE;iDASP;AAmHD;IADC,WAAW,EAAE;4CAGb;AAMD;IAJC,WAAW,EAAE;IACd;;OAEG;0CAGF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StringifiedModule.js","sourceRoot":"","sources":["../src/StringifiedModule.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAE5B,cAAc,QAAQ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { 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 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { DefaultKeyword, Identifier, ImportClause, NamespaceImport, Node, ObjectLiteralElementLike, ObjectLiteralExpression, PropertyAccessExpression, SourceFile, SyntaxList } from "typescript";
|
|
2
|
+
import { AnyFunction, AssertedType, CBAssertion, Functionish, Import, WithParent } from "./types";
|
|
3
|
+
export declare const enum CharCode {
|
|
4
|
+
/**
|
|
5
|
+
* The `\n` character.
|
|
6
|
+
*/
|
|
7
|
+
LineFeed = 10,
|
|
8
|
+
/**
|
|
9
|
+
* The `\r` character.
|
|
10
|
+
*/
|
|
11
|
+
CarriageReturn = 13
|
|
12
|
+
}
|
|
13
|
+
export declare function isEOL(char: number): char is CharCode;
|
|
14
|
+
/**
|
|
15
|
+
* given a function like this, returns the identifier for x
|
|
16
|
+
* @example function(){
|
|
17
|
+
* // any code here
|
|
18
|
+
* return x;
|
|
19
|
+
* }
|
|
20
|
+
* @param func a function to get the return value of
|
|
21
|
+
* @returns the return identifier, if any
|
|
22
|
+
*/
|
|
23
|
+
export declare function findReturnIdentifier(func: Functionish): Identifier | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* given an object literal, returns the property assignment for `prop` if it exists
|
|
26
|
+
*
|
|
27
|
+
* if prop is defined more than once, returns the first
|
|
28
|
+
* @example
|
|
29
|
+
* {
|
|
30
|
+
* exProp: "examplePropValue"
|
|
31
|
+
* }
|
|
32
|
+
* @param prop exProp
|
|
33
|
+
*/
|
|
34
|
+
export declare function findObjectLiteralByKey(object: ObjectLiteralExpression, prop: string): ObjectLiteralElementLike | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* first parent
|
|
37
|
+
*/
|
|
38
|
+
export declare const findParent: CBAssertion<undefined, undefined>;
|
|
39
|
+
export declare function findParentLimited<F extends (n: Node) => n is Node, R extends Node = AssertedType<F, Node>>(node: Node, func: F extends (n: Node) => n is R ? F : never, limit: number): R | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* @param node the node to start from
|
|
42
|
+
* @param func a function to check if the parent matches
|
|
43
|
+
*/
|
|
44
|
+
export declare const lastParent: CBAssertion<undefined, undefined>;
|
|
45
|
+
export declare const lastChild: CBAssertion<undefined>;
|
|
46
|
+
export declare function one<T, F extends (t: T) => t is T, R extends T = AssertedType<F, T>>(arr: readonly T[], func: F extends (t: T) => t is R ? F : never): R | undefined;
|
|
47
|
+
export declare function isDefaultImport(x: Identifier): x is WithParent<typeof x, ImportClause>;
|
|
48
|
+
/**
|
|
49
|
+
* @param node any identifier in an import statment
|
|
50
|
+
*/
|
|
51
|
+
export declare function getImportName(node: Identifier): Pick<Import, "orig" | "as">;
|
|
52
|
+
/**
|
|
53
|
+
* given an access chain like `one.b.three.d` \@*returns* — `[one?, b?]`
|
|
54
|
+
*
|
|
55
|
+
* if b is returned, one is gaurenteed to be defined
|
|
56
|
+
* @param node any node in the property access chain
|
|
57
|
+
*/
|
|
58
|
+
export declare function getLeadingIdentifier(node: Node | undefined): readonly [Identifier, undefined] | readonly [Identifier, Identifier] | readonly [undefined, undefined];
|
|
59
|
+
export declare function isInImportStatment(x: Node): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* @param x an identifier in the import statment, not just any imported identifier
|
|
62
|
+
* @returns the source of the import statment
|
|
63
|
+
* @example
|
|
64
|
+
* ```
|
|
65
|
+
* import { x } from "source"
|
|
66
|
+
* ```
|
|
67
|
+
* @returns "source"
|
|
68
|
+
*/
|
|
69
|
+
export declare function getImportSource(x: Identifier): string;
|
|
70
|
+
export declare function isNamespaceImport(x: Identifier): x is WithParent<typeof x, NamespaceImport>;
|
|
71
|
+
export declare function isDefaultKeyword(n: Node): n is DefaultKeyword;
|
|
72
|
+
export declare function isSyntaxList(node: Node): node is SyntaxList;
|
|
73
|
+
/**
|
|
74
|
+
* given a function like
|
|
75
|
+
* ```ts
|
|
76
|
+
* function myFunc() {
|
|
77
|
+
* // any code here
|
|
78
|
+
* return a.b; // can be anything else, eg a.b.c a.b[anything]
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
* @returns the returned property access expression, if any
|
|
82
|
+
**/
|
|
83
|
+
export declare function findReturnPropertyAccessExpression(func: AnyFunction): PropertyAccessExpression | undefined;
|
|
84
|
+
export declare function getTokenAtPosition(parent: Node, pos: number, sourceFile?: SourceFile, allowJsDoc?: boolean): Node | undefined;
|
|
85
|
+
/** Returns the deepest AST Node at `pos`. Returns undefined if `pos` is outside of the range of `node` */
|
|
86
|
+
export declare function getAstNodeAtPosition(node: Node, pos: number): Node | undefined;
|
|
87
|
+
export declare function nonNull<T>(x: T | null | undefined): x is T;
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { forEachChild, isBlock, isIdentifier, isImportClause, isImportDeclaration, isImportSpecifier, isNamespaceImport as _TS_isNamespaceImport, isPropertyAccessExpression, isReturnStatement, isTokenKind, SyntaxKind, } from "typescript";
|
|
2
|
+
export function isEOL(char) {
|
|
3
|
+
return char === 13 /* CharCode.CarriageReturn */ || char === 10 /* CharCode.LineFeed */;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* given a function like this, returns the identifier for x
|
|
7
|
+
* @example function(){
|
|
8
|
+
* // any code here
|
|
9
|
+
* return x;
|
|
10
|
+
* }
|
|
11
|
+
* @param func a function to get the return value of
|
|
12
|
+
* @returns the return identifier, if any
|
|
13
|
+
*/
|
|
14
|
+
export function findReturnIdentifier(func) {
|
|
15
|
+
if (!func.body)
|
|
16
|
+
return undefined;
|
|
17
|
+
if (isBlock(func.body))
|
|
18
|
+
return _findReturnIdentifier(func.body);
|
|
19
|
+
if (isIdentifier(func.body))
|
|
20
|
+
return func.body;
|
|
21
|
+
}
|
|
22
|
+
function _findReturnIdentifier(func) {
|
|
23
|
+
const lastStatement = func.statements.at(-1);
|
|
24
|
+
if (!lastStatement
|
|
25
|
+
|| !isReturnStatement(lastStatement)
|
|
26
|
+
|| !lastStatement.expression
|
|
27
|
+
|| !isIdentifier(lastStatement.expression))
|
|
28
|
+
return undefined;
|
|
29
|
+
return lastStatement.expression;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* given an object literal, returns the property assignment for `prop` if it exists
|
|
33
|
+
*
|
|
34
|
+
* if prop is defined more than once, returns the first
|
|
35
|
+
* @example
|
|
36
|
+
* {
|
|
37
|
+
* exProp: "examplePropValue"
|
|
38
|
+
* }
|
|
39
|
+
* @param prop exProp
|
|
40
|
+
*/
|
|
41
|
+
export function findObjectLiteralByKey(object, prop) {
|
|
42
|
+
return object.properties.find((x) => x.name?.getText() === prop);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* first parent
|
|
46
|
+
*/
|
|
47
|
+
export const findParent = (node, func) => {
|
|
48
|
+
if (!node)
|
|
49
|
+
return undefined;
|
|
50
|
+
while (!func(node)) {
|
|
51
|
+
if (!node.parent)
|
|
52
|
+
return undefined;
|
|
53
|
+
node = node.parent;
|
|
54
|
+
}
|
|
55
|
+
return node;
|
|
56
|
+
};
|
|
57
|
+
export function findParentLimited(node, func, limit) {
|
|
58
|
+
if (!node)
|
|
59
|
+
return undefined;
|
|
60
|
+
limit += 1;
|
|
61
|
+
while (limit-- && !func(node)) {
|
|
62
|
+
if (!node.parent)
|
|
63
|
+
return undefined;
|
|
64
|
+
node = node.parent;
|
|
65
|
+
}
|
|
66
|
+
if (limit < 0) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
return node;
|
|
70
|
+
}
|
|
71
|
+
// FIXME: try simplifying this
|
|
72
|
+
/**
|
|
73
|
+
* @param node the node to start from
|
|
74
|
+
* @param func a function to check if the parent matches
|
|
75
|
+
*/
|
|
76
|
+
export const lastParent = (node, func) => {
|
|
77
|
+
if (!node)
|
|
78
|
+
return undefined;
|
|
79
|
+
if (!node.parent)
|
|
80
|
+
return undefined;
|
|
81
|
+
while (func(node.parent)) {
|
|
82
|
+
if (!node.parent)
|
|
83
|
+
break;
|
|
84
|
+
node = node.parent;
|
|
85
|
+
}
|
|
86
|
+
return func(node) ? node : undefined;
|
|
87
|
+
};
|
|
88
|
+
export const lastChild = (node, func) => {
|
|
89
|
+
if (!node)
|
|
90
|
+
return undefined;
|
|
91
|
+
const c = node.getChildren();
|
|
92
|
+
if (c.length === 0) {
|
|
93
|
+
if (func(node))
|
|
94
|
+
return node;
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
if (c.length === 1) {
|
|
98
|
+
if (func(c[0]))
|
|
99
|
+
return lastChild(c[0], func);
|
|
100
|
+
if (func(node))
|
|
101
|
+
return node;
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
const x = one(c, func);
|
|
105
|
+
if (x) {
|
|
106
|
+
return lastChild(x, func);
|
|
107
|
+
}
|
|
108
|
+
if (func(node))
|
|
109
|
+
return node;
|
|
110
|
+
return undefined;
|
|
111
|
+
};
|
|
112
|
+
// FIXME: this seems really stupid
|
|
113
|
+
export function one(arr, func) {
|
|
114
|
+
const filter = arr.filter(func);
|
|
115
|
+
return (filter.length === 1 || undefined) && filter[0];
|
|
116
|
+
}
|
|
117
|
+
export function isDefaultImport(x) {
|
|
118
|
+
return isImportClause(x.parent);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @param node any identifier in an import statment
|
|
122
|
+
*/
|
|
123
|
+
export function getImportName(node) {
|
|
124
|
+
// default or namespace
|
|
125
|
+
if (isDefaultImport(node) || isNamespaceImport(node))
|
|
126
|
+
return { as: node };
|
|
127
|
+
const specifier = findParent(node, isImportSpecifier);
|
|
128
|
+
if (!specifier)
|
|
129
|
+
throw new Error("x is not in an import statment");
|
|
130
|
+
return {
|
|
131
|
+
orig: specifier.propertyName,
|
|
132
|
+
as: specifier.name,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// i fucking hate jsdoc
|
|
136
|
+
/**
|
|
137
|
+
* given an access chain like `one.b.three.d` \@*returns* — `[one?, b?]`
|
|
138
|
+
*
|
|
139
|
+
* if b is returned, one is gaurenteed to be defined
|
|
140
|
+
* @param node any node in the property access chain
|
|
141
|
+
*/
|
|
142
|
+
export function getLeadingIdentifier(node) {
|
|
143
|
+
if (!node)
|
|
144
|
+
return [node, undefined];
|
|
145
|
+
const { expression: module, name: wpExport } = (() => {
|
|
146
|
+
const lastP = lastParent(node, isPropertyAccessExpression);
|
|
147
|
+
return lastP && lastChild(lastP, isPropertyAccessExpression);
|
|
148
|
+
})() ?? {};
|
|
149
|
+
if (!module || !isIdentifier(module))
|
|
150
|
+
return [undefined, undefined];
|
|
151
|
+
return [
|
|
152
|
+
module,
|
|
153
|
+
wpExport ? isIdentifier(wpExport) ? wpExport : undefined : undefined,
|
|
154
|
+
];
|
|
155
|
+
}
|
|
156
|
+
export function isInImportStatment(x) {
|
|
157
|
+
return findParent(x, isImportDeclaration) != null;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @param x an identifier in the import statment, not just any imported identifier
|
|
161
|
+
* @returns the source of the import statment
|
|
162
|
+
* @example
|
|
163
|
+
* ```
|
|
164
|
+
* import { x } from "source"
|
|
165
|
+
* ```
|
|
166
|
+
* @returns "source"
|
|
167
|
+
*/
|
|
168
|
+
export function getImportSource(x) {
|
|
169
|
+
const clause = findParent(x, isImportDeclaration);
|
|
170
|
+
if (!clause)
|
|
171
|
+
throw new Error("x is not in an import statment");
|
|
172
|
+
// getText returns with quotes, but the prop text does not have them ????
|
|
173
|
+
return clause.moduleSpecifier.getText()
|
|
174
|
+
.slice(1, -1);
|
|
175
|
+
}
|
|
176
|
+
export function isNamespaceImport(x) {
|
|
177
|
+
return _TS_isNamespaceImport(x.parent);
|
|
178
|
+
}
|
|
179
|
+
export function isDefaultKeyword(n) {
|
|
180
|
+
return n.kind === SyntaxKind.DefaultKeyword;
|
|
181
|
+
}
|
|
182
|
+
export function isSyntaxList(node) {
|
|
183
|
+
return node.kind === SyntaxKind.SyntaxList;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* given a function like
|
|
187
|
+
* ```ts
|
|
188
|
+
* function myFunc() {
|
|
189
|
+
* // any code here
|
|
190
|
+
* return a.b; // can be anything else, eg a.b.c a.b[anything]
|
|
191
|
+
* }
|
|
192
|
+
* ```
|
|
193
|
+
* @returns the returned property access expression, if any
|
|
194
|
+
**/
|
|
195
|
+
export function findReturnPropertyAccessExpression(func) {
|
|
196
|
+
if (isBlock(func.body))
|
|
197
|
+
return _findReturnPropertyAccessExpression(func.body);
|
|
198
|
+
if (isPropertyAccessExpression(func.body))
|
|
199
|
+
return func.body;
|
|
200
|
+
}
|
|
201
|
+
function _findReturnPropertyAccessExpression(func) {
|
|
202
|
+
const lastStatment = func.statements.at(-1);
|
|
203
|
+
if (!lastStatment
|
|
204
|
+
|| !isReturnStatement(lastStatment)
|
|
205
|
+
|| !lastStatment.expression
|
|
206
|
+
|| !isPropertyAccessExpression(lastStatment.expression))
|
|
207
|
+
return undefined;
|
|
208
|
+
return lastStatment.expression;
|
|
209
|
+
}
|
|
210
|
+
/* !
|
|
211
|
+
* taken from tsutils, license below
|
|
212
|
+
* The MIT License (MIT)
|
|
213
|
+
*
|
|
214
|
+
* Copyright (c) 2017 Klaus Meinhardt
|
|
215
|
+
*
|
|
216
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
217
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
218
|
+
* in the Software without restriction, including without limitation the rights
|
|
219
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
220
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
221
|
+
* furnished to do so, subject to the following conditions:
|
|
222
|
+
*
|
|
223
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
224
|
+
* copies or substantial portions of the Software.
|
|
225
|
+
*
|
|
226
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
227
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
228
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
229
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
230
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
231
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
232
|
+
* SOFTWARE.
|
|
233
|
+
*/
|
|
234
|
+
export function getTokenAtPosition(parent, pos, sourceFile, allowJsDoc) {
|
|
235
|
+
if (pos < parent.pos || pos >= parent.end) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (isTokenKind(parent.kind)) {
|
|
239
|
+
return parent;
|
|
240
|
+
}
|
|
241
|
+
return _getTokenAtPosition(parent, pos, sourceFile ?? parent.getSourceFile(), allowJsDoc === true);
|
|
242
|
+
}
|
|
243
|
+
function _getTokenAtPosition(node, pos, sourceFile, allowJsDoc) {
|
|
244
|
+
if (!allowJsDoc) {
|
|
245
|
+
// if we are not interested in JSDoc, we can skip to the deepest AST node at the given position
|
|
246
|
+
node = getAstNodeAtPosition(node, pos);
|
|
247
|
+
if (isTokenKind(node.kind)) {
|
|
248
|
+
return node;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
outer: while (true) {
|
|
252
|
+
for (const child of node.getChildren()) {
|
|
253
|
+
if (child.end > pos && (allowJsDoc || child.kind !== SyntaxKind.JSDoc)) {
|
|
254
|
+
if (isTokenKind(child.kind)) {
|
|
255
|
+
return child;
|
|
256
|
+
}
|
|
257
|
+
node = child;
|
|
258
|
+
continue outer;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/** Returns the deepest AST Node at `pos`. Returns undefined if `pos` is outside of the range of `node` */
|
|
265
|
+
export function getAstNodeAtPosition(node, pos) {
|
|
266
|
+
if (node.pos > pos || node.end <= pos) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
while (isNodeKind(node.kind)) {
|
|
270
|
+
const nested = forEachChild(node, (child) => (child.pos <= pos && child.end > pos ? child : undefined));
|
|
271
|
+
if (nested === undefined) {
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
node = nested;
|
|
275
|
+
}
|
|
276
|
+
return node;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* stolen form tsutils, seems sketchy
|
|
280
|
+
*/
|
|
281
|
+
function isNodeKind(kind) {
|
|
282
|
+
return kind >= SyntaxKind.FirstNode;
|
|
283
|
+
}
|
|
284
|
+
export function nonNull(x) {
|
|
285
|
+
return x != null;
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings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;IACxD,IAAI,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;QACpC,OAAO;IACX,CAAC;IACD,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,IAAI,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QAExG,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACvB,MAAM;QACV,CAAC;QACD,IAAI,GAAG,MAAM,CAAC;IAClB,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAS,UAAU,CAAC,IAAgB;IAChC,OAAO,IAAI,IAAI,UAAU,CAAC,SAAS,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,OAAO,CAAI,CAAuB;IAC9C,OAAO,CAAC,IAAI,IAAI,CAAC;AACrB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vencord-companion/ast-parser",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"keywords": [],
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "sadan",
|
|
9
|
+
"url": "https://sadan.zip"
|
|
10
|
+
},
|
|
11
|
+
"license": "LGPL-3.0-or-later",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@vencord-companion/shared": "0.0.1"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
"./*": "./dist/*.js",
|
|
17
|
+
".": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@sadan4/devtools-pretty-printer": "^1.0.4",
|
|
21
|
+
"ts-api-utils": "^2.1.0",
|
|
22
|
+
"typescript": "^5.0.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"vitest": "^3.2.4"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"preversion": "mkdir .git || :",
|
|
29
|
+
"bump": "npm version",
|
|
30
|
+
"postversion": "rmdir .git",
|
|
31
|
+
"build": "tsc -b"
|
|
32
|
+
}
|
|
33
|
+
}
|