@vencord-companion/webpack-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/WebpackAstParser.d.ts +225 -0
- package/dist/WebpackAstParser.js +1597 -0
- package/dist/WebpackAstParser.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/util.d.ts +27 -0
- package/dist/util.js +62 -0
- package/dist/util.js.map +1 -0
- package/package.json +30 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { VariableInfo } from "ts-api-utils";
|
|
2
|
+
import { CallExpression, ClassDeclaration, Expression, Identifier, MemberName, NewExpression, Node, ObjectLiteralExpression, SourceFile } from "typescript";
|
|
3
|
+
import { AstParser } from "@vencord-companion/ast-parser";
|
|
4
|
+
import { Logger } from "@vencord-companion/shared/Logger";
|
|
5
|
+
import { Position } from "@vencord-companion/shared/Position";
|
|
6
|
+
import { Range } from "@vencord-companion/shared/Range";
|
|
7
|
+
import { AnyExportKey, Definition, ExportMap, ExportRange, IModuleCache, IModuleDepManager, ModuleDeps, RangeExportMap, RawExportMap, RawExportRange, Reference, Store } from "./types";
|
|
8
|
+
export declare function setLogger(l: Logger): void;
|
|
9
|
+
export declare class WebpackAstParser extends AstParser {
|
|
10
|
+
private static defaultModuleCache;
|
|
11
|
+
static setDefaultModuleCache(cache: IModuleCache | ((self: WebpackAstParser) => IModuleCache)): void;
|
|
12
|
+
private static defaultModuleDepManager;
|
|
13
|
+
static setDefaultModuleDepManager(manager: IModuleDepManager | ((self: WebpackAstParser) => IModuleDepManager)): void;
|
|
14
|
+
/**
|
|
15
|
+
* This is set on {@link RangeExportMap} when the default export is commonjs and has no properties, eg, string literal, function
|
|
16
|
+
*/
|
|
17
|
+
static readonly SYM_CJS_DEFAULT: unique symbol;
|
|
18
|
+
/**
|
|
19
|
+
* set on raw export maps to give a hover hint for LSP
|
|
20
|
+
*/
|
|
21
|
+
static readonly SYM_HOVER: unique symbol;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param text the module text
|
|
25
|
+
* @returns a {@link WebpackAstParser}
|
|
26
|
+
*
|
|
27
|
+
* NOTE: you probably want {@link WebpackAstParser.withFormattedModule|withFormattedModule}
|
|
28
|
+
*/
|
|
29
|
+
static withFormattedText(text: string): WebpackAstParser;
|
|
30
|
+
static withFormattedModule(text: string, moduleId: string | number): WebpackAstParser;
|
|
31
|
+
/**
|
|
32
|
+
* The webpack instance passed to this module
|
|
33
|
+
*
|
|
34
|
+
* The `n` of
|
|
35
|
+
* ```
|
|
36
|
+
* function (e, t, n) {
|
|
37
|
+
// webpack module contents
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
* @CacheGetter
|
|
41
|
+
*/
|
|
42
|
+
get wreq(): Identifier | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* where {@link WebpackAstParser.wreq this.wreq} is used
|
|
45
|
+
* @CacheGetter
|
|
46
|
+
*/
|
|
47
|
+
get uses(): VariableInfo | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* The module id of the current module
|
|
50
|
+
* @CacheGetter
|
|
51
|
+
*/
|
|
52
|
+
get moduleId(): string | null;
|
|
53
|
+
/**
|
|
54
|
+
* @CacheGetter
|
|
55
|
+
*/
|
|
56
|
+
get moduleCache(): IModuleCache;
|
|
57
|
+
/**
|
|
58
|
+
* @CacheGetter
|
|
59
|
+
*/
|
|
60
|
+
get moduleDepManager(): IModuleDepManager;
|
|
61
|
+
constructor(text: string);
|
|
62
|
+
protected createSourceFile(): SourceFile;
|
|
63
|
+
/**
|
|
64
|
+
* @param paramIndex the index of the param 0, 1, 2 etc...
|
|
65
|
+
* @param start finds a webpack arg from the source tree
|
|
66
|
+
* @returns the identifier of the param if found or undef
|
|
67
|
+
*
|
|
68
|
+
* NOTE: you should probably not use this
|
|
69
|
+
*
|
|
70
|
+
* @see {@link findWreq_t}
|
|
71
|
+
* @see {@link findWreq_e}
|
|
72
|
+
* @see {@link wreq}
|
|
73
|
+
*/
|
|
74
|
+
private findWebpackArg;
|
|
75
|
+
getModulesThatRequireThisModule(): ModuleDeps | null;
|
|
76
|
+
/**
|
|
77
|
+
* @Cache
|
|
78
|
+
*/
|
|
79
|
+
getModulesThatThisModuleRequires(): ModuleDeps | null;
|
|
80
|
+
tryGetFreshModuleFallbackToCache(moduleId: string | number): Promise<string | undefined>;
|
|
81
|
+
/**
|
|
82
|
+
* @param idNode the numeric literal node that is the module id
|
|
83
|
+
* This is called internally by {@link generateDefinitions}
|
|
84
|
+
*
|
|
85
|
+
* given
|
|
86
|
+
* ```js
|
|
87
|
+
* var mod = n(123456);
|
|
88
|
+
* // ^^^^^^
|
|
89
|
+
* ```
|
|
90
|
+
* returns the definitions for that module
|
|
91
|
+
*/
|
|
92
|
+
private generateDirectModuleDefinition;
|
|
93
|
+
generateDefinitions(position: Position): Promise<Definition[] | undefined>;
|
|
94
|
+
generateHover(position: Position): Promise<[Range, string] | undefined>;
|
|
95
|
+
doesReExportFromExport(exportName: AnyExportKey[]): [
|
|
96
|
+
importSourceId: string,
|
|
97
|
+
exportName: MemberName[]
|
|
98
|
+
] | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* gets the module id from a require
|
|
101
|
+
* given
|
|
102
|
+
* ```js
|
|
103
|
+
* var mod = n(123456);
|
|
104
|
+
* ```
|
|
105
|
+
* @argument dec the variable info for that mod
|
|
106
|
+
* @see {@link getVariableInitializer} which can than be passed into {@link vars|vars.get}
|
|
107
|
+
* @returns `123456`
|
|
108
|
+
*/
|
|
109
|
+
getModuleIdForImport(dec: VariableInfo | undefined): number | undefined;
|
|
110
|
+
generateReferences(position: Position): Promise<Reference[] | undefined>;
|
|
111
|
+
/**
|
|
112
|
+
* checks if this module re-exports another whole module and not just parts of it
|
|
113
|
+
* ```js
|
|
114
|
+
* e.exports = n(moduleId);
|
|
115
|
+
* ```
|
|
116
|
+
* @returns the module ID if it does, undefined otherwise
|
|
117
|
+
* @Cache
|
|
118
|
+
*/
|
|
119
|
+
doesReExportWholeModule(): string | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Figure out if this module re-exports another given the module id of the other and the name of the export from the other module
|
|
122
|
+
* @param moduleId the module id that {@link exportName} is from
|
|
123
|
+
* @param exportName the name of the re-exported export
|
|
124
|
+
*/
|
|
125
|
+
doesReExportFromImport(moduleId: string, exportName: AnyExportKey): AnyExportKey | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* @returns a map of exported names to the nodes that they are exported from
|
|
128
|
+
* @Cache
|
|
129
|
+
*/
|
|
130
|
+
getExportMapRaw(): RawExportMap;
|
|
131
|
+
/**
|
|
132
|
+
* FIXME: this is not in line with {@link getExportMapWreq_d}
|
|
133
|
+
* @Cache
|
|
134
|
+
*/
|
|
135
|
+
getExportMapRawWreq_d(): RawExportMap | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* @Cache
|
|
138
|
+
*/
|
|
139
|
+
getExportMapRawWreq_e(): ExportMap<Expression> | undefined;
|
|
140
|
+
/**
|
|
141
|
+
* @Cache
|
|
142
|
+
*/
|
|
143
|
+
getExportMapRawWreq_t(): ExportMap<Expression> | undefined;
|
|
144
|
+
/**
|
|
145
|
+
* @Cache
|
|
146
|
+
*/
|
|
147
|
+
getExportMap(): RangeExportMap;
|
|
148
|
+
getImportedVar(moduleId: string): Identifier | undefined;
|
|
149
|
+
getIdOfImportedVar(variable: Identifier): string | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* @param moduleId the imported module id where {@link exportName} is used
|
|
152
|
+
* @param exportName the string of the exported name or {@link SYM_CJS_DEFAULT} for the default export
|
|
153
|
+
* TODO: support nested exports eg: `wreq(123).ZP.storeMethod()`
|
|
154
|
+
* @returns the ranges where the export is used in this file
|
|
155
|
+
*/
|
|
156
|
+
getUsesOfImport(moduleId: string, exportName: string | symbol): Range[];
|
|
157
|
+
/**
|
|
158
|
+
* @Cache
|
|
159
|
+
*/
|
|
160
|
+
getExportMapWreq_t(): RangeExportMap | undefined;
|
|
161
|
+
rawMakeExportMapRecursive(node: Node): RawExportMap | RawExportRange;
|
|
162
|
+
rawMapToExportMap(map: RawExportRange): ExportRange;
|
|
163
|
+
rawMapToExportMap(map: RawExportMap): RangeExportMap;
|
|
164
|
+
rawMapToExportMap(map: RawExportMap | RawExportRange): RangeExportMap | ExportRange;
|
|
165
|
+
/**
|
|
166
|
+
* takes an expression, and maps it to ranges which it is in
|
|
167
|
+
*/
|
|
168
|
+
makeExportMapRecursive(node: Node): RangeExportMap | ExportRange;
|
|
169
|
+
/**
|
|
170
|
+
* @Cache
|
|
171
|
+
*/
|
|
172
|
+
getExportMapWreq_e(): RangeExportMap | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* @Cache
|
|
175
|
+
*/
|
|
176
|
+
getExportMapWreq_d(): RangeExportMap | undefined;
|
|
177
|
+
tryParseStoreForExport(node: Node | undefined, extraStoreLocs?: Range[]): RangeExportMap | undefined;
|
|
178
|
+
tryParseStore(storeInit: NewExpression): Store | undefined;
|
|
179
|
+
tryFindStoreDisplayName(storeVar: VariableInfo): string | undefined;
|
|
180
|
+
/**
|
|
181
|
+
*
|
|
182
|
+
* @returns ```js
|
|
183
|
+
* {
|
|
184
|
+
* "<PASSED_IN_CLASS_NAME>": {
|
|
185
|
+
* [WebpackAstParser.SYM_CJS_DEFAULT]: ["<CONSTRUCTOR>"],
|
|
186
|
+
* ["methodName"]: ["METHOD"]
|
|
187
|
+
* }
|
|
188
|
+
* }
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
parseClassDeclaration(clazz: ClassDeclaration, extraExportRanges?: Node[]): RawExportMap;
|
|
192
|
+
tryParseClassDeclaration(node: Node, extraExportRanges: Node[]): RawExportMap | undefined;
|
|
193
|
+
getNestedExportFromMap<T>(keys: readonly AnyExportKey[], map: ExportMap<T>): T[] | undefined;
|
|
194
|
+
findExportLocation(exportNames: readonly AnyExportKey[]): Range;
|
|
195
|
+
findHoverText(exportNames: readonly AnyExportKey[]): string | undefined;
|
|
196
|
+
/**
|
|
197
|
+
* @Cache
|
|
198
|
+
*/
|
|
199
|
+
findWreq_d(): (Omit<CallExpression, "arguments"> & {
|
|
200
|
+
arguments: readonly [Identifier, ObjectLiteralExpression];
|
|
201
|
+
}) | undefined;
|
|
202
|
+
tryFindExportwreq_d(exportName: string): Range | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* @Cache
|
|
205
|
+
*/
|
|
206
|
+
findWreq_t(): Identifier | undefined;
|
|
207
|
+
tryFindExportWreq_t(exportName: string): Range | undefined;
|
|
208
|
+
/**
|
|
209
|
+
* @Cache
|
|
210
|
+
*/
|
|
211
|
+
findWreq_e(): Identifier | undefined;
|
|
212
|
+
tryFindExportsWreq_e(exportName: string): Range | undefined;
|
|
213
|
+
getAllReExportsForExport(exportName: AnyExportKey): Promise<[moduleId: string, exportChain: AnyExportKey[]][]>;
|
|
214
|
+
/**
|
|
215
|
+
* @returns the string of the export if this is the flux dispatcher module, null otherwise
|
|
216
|
+
* @Cache
|
|
217
|
+
*/
|
|
218
|
+
isFluxDispatcherModule(): string | undefined;
|
|
219
|
+
/**
|
|
220
|
+
* checks if this module exports a flux dispatcher
|
|
221
|
+
*
|
|
222
|
+
* @returns the string of the export name if this module exports a flux dispatcher
|
|
223
|
+
*/
|
|
224
|
+
exportsFluxDispatcherInstance(): string | null;
|
|
225
|
+
}
|