@appthreat/atom-parsetools 1.0.13 → 1.0.14
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/astgen.js +283 -66
- package/package.json +3 -2
- package/plugins/composer/installed.php +6 -6
- package/plugins/rubyastgen/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/prism-1.6.0/gem_make.out +5 -5
- package/plugins/rubyastgen/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/racc-1.8.1/gem_make.out +5 -5
package/astgen.js
CHANGED
|
@@ -4,6 +4,7 @@ import { join, dirname } from "path";
|
|
|
4
4
|
import yargs from "yargs";
|
|
5
5
|
import { hideBin } from "yargs/helpers";
|
|
6
6
|
import { parse } from "@babel/parser";
|
|
7
|
+
import { parse as parseHermes } from "hermes-parser";
|
|
7
8
|
import tsc from "typescript";
|
|
8
9
|
import {
|
|
9
10
|
readFileSync,
|
|
@@ -39,6 +40,28 @@ const babelParserOptions = {
|
|
|
39
40
|
]
|
|
40
41
|
};
|
|
41
42
|
|
|
43
|
+
const babelFlowParserOptions = {
|
|
44
|
+
sourceType: "unambiguous",
|
|
45
|
+
allowImportExportEverywhere: true,
|
|
46
|
+
allowAwaitOutsideFunction: true,
|
|
47
|
+
allowNewTargetOutsideFunction: true,
|
|
48
|
+
allowReturnOutsideFunction: true,
|
|
49
|
+
allowSuperOutsideMethod: true,
|
|
50
|
+
allowUndeclaredExports: true,
|
|
51
|
+
errorRecovery: true,
|
|
52
|
+
plugins: [
|
|
53
|
+
"optionalChaining",
|
|
54
|
+
"classProperties",
|
|
55
|
+
"decorators-legacy",
|
|
56
|
+
"exportDefaultFrom",
|
|
57
|
+
"doExpressions",
|
|
58
|
+
"numericSeparator",
|
|
59
|
+
"dynamicImport",
|
|
60
|
+
"jsx",
|
|
61
|
+
["flow", { all: true, enums: true }]
|
|
62
|
+
]
|
|
63
|
+
};
|
|
64
|
+
|
|
42
65
|
const babelSafeParserOptions = {
|
|
43
66
|
sourceType: "module",
|
|
44
67
|
allowImportExportEverywhere: true,
|
|
@@ -57,6 +80,30 @@ const babelSafeParserOptions = {
|
|
|
57
80
|
]
|
|
58
81
|
};
|
|
59
82
|
|
|
83
|
+
const babelSafeFlowParserOptions = {
|
|
84
|
+
sourceType: "module",
|
|
85
|
+
allowImportExportEverywhere: true,
|
|
86
|
+
allowAwaitOutsideFunction: true,
|
|
87
|
+
allowReturnOutsideFunction: true,
|
|
88
|
+
errorRecovery: true,
|
|
89
|
+
plugins: [
|
|
90
|
+
"optionalChaining",
|
|
91
|
+
"classProperties",
|
|
92
|
+
"decorators-legacy",
|
|
93
|
+
"exportDefaultFrom",
|
|
94
|
+
"doExpressions",
|
|
95
|
+
"numericSeparator",
|
|
96
|
+
"dynamicImport",
|
|
97
|
+
"flow"
|
|
98
|
+
]
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const shouldIncludeNodeModulesBundles =
|
|
102
|
+
process.env?.ASTGEN_INCLUDE_NODE_MODULES_BUNDLES === "true" ||
|
|
103
|
+
(process.env?.ASTGEN_IGNORE_DIRS &&
|
|
104
|
+
process.env.ASTGEN_IGNORE_DIRS.length > 0 &&
|
|
105
|
+
!process.env.ASTGEN_IGNORE_DIRS.toLowerCase().includes("node_modules"));
|
|
106
|
+
|
|
60
107
|
/**
|
|
61
108
|
* Return paths to all (j|tsx?) files.
|
|
62
109
|
* Optionally includes specific bundled files from node_modules if:
|
|
@@ -66,7 +113,7 @@ const babelSafeParserOptions = {
|
|
|
66
113
|
const getAllSrcJSAndTSFiles = (src) => {
|
|
67
114
|
const filePattern = "\\.(js|jsx|cjs|mjs|ts|tsx|vue|svelte|xsjs|xsjslib|ejs)$";
|
|
68
115
|
const bundledNodeModulesPattern =
|
|
69
|
-
"node_modules
|
|
116
|
+
"node_modules[\\\\/].*[\\\\/](?:.*\\.)?(bundle|dist|index|min|app)\\.(js|cjs|mjs)$";
|
|
70
117
|
|
|
71
118
|
// Step 1: Collect all JS/TS files EXCLUDING node_modules
|
|
72
119
|
const allFilesPromise = Promise.resolve(
|
|
@@ -79,14 +126,6 @@ const getAllSrcJSAndTSFiles = (src) => {
|
|
|
79
126
|
true // ignore node_modules
|
|
80
127
|
)
|
|
81
128
|
);
|
|
82
|
-
|
|
83
|
-
// Step 2: Check if we should include node_modules bundles
|
|
84
|
-
const shouldIncludeNodeModulesBundles =
|
|
85
|
-
process.env?.ASTGEN_INCLUDE_NODE_MODULES_BUNDLES === "true" ||
|
|
86
|
-
(process.env?.ASTGEN_IGNORE_DIRS &&
|
|
87
|
-
process.env.ASTGEN_IGNORE_DIRS.length > 0 &&
|
|
88
|
-
!process.env.ASTGEN_IGNORE_DIRS.toLowerCase().includes("node_modules"));
|
|
89
|
-
|
|
90
129
|
let bundledFilesPromise = Promise.resolve([]);
|
|
91
130
|
if (shouldIncludeNodeModulesBundles) {
|
|
92
131
|
bundledFilesPromise = Promise.resolve(
|
|
@@ -100,8 +139,7 @@ const getAllSrcJSAndTSFiles = (src) => {
|
|
|
100
139
|
)
|
|
101
140
|
);
|
|
102
141
|
}
|
|
103
|
-
|
|
104
|
-
// Step 3: Combine both lists
|
|
142
|
+
// Step 2: Combine both lists
|
|
105
143
|
return Promise.all([allFilesPromise, bundledFilesPromise]).then(
|
|
106
144
|
([allFiles, bundledFiles]) => [...allFiles, ...bundledFiles]
|
|
107
145
|
);
|
|
@@ -110,21 +148,66 @@ const getAllSrcJSAndTSFiles = (src) => {
|
|
|
110
148
|
/**
|
|
111
149
|
* Convert a single JS/TS file to AST
|
|
112
150
|
*/
|
|
113
|
-
const fileToJsAst = (file) => {
|
|
151
|
+
const fileToJsAst = (file, projectType) => {
|
|
114
152
|
if (file.endsWith(".vue") || file.endsWith(".svelte")) {
|
|
115
153
|
return toVueAst(file);
|
|
116
154
|
}
|
|
117
|
-
|
|
155
|
+
if (file.endsWith(".ejs")) {
|
|
156
|
+
return toEjsAst(file);
|
|
157
|
+
}
|
|
158
|
+
return codeToJsAst(file, readFileSync(file, "utf-8"), projectType);
|
|
118
159
|
};
|
|
119
160
|
|
|
120
161
|
/**
|
|
121
162
|
* Convert a single JS/TS code snippet to AST
|
|
122
163
|
*/
|
|
123
|
-
const codeToJsAst = (code) => {
|
|
164
|
+
const codeToJsAst = (file, code, projectType) => {
|
|
165
|
+
const isJs = /\.(js|jsx|cjs|mjs)$/.test(file);
|
|
166
|
+
if (isJs && projectType === "flow") {
|
|
167
|
+
try {
|
|
168
|
+
return parseHermes(code, {
|
|
169
|
+
sourceType: "unambiguous",
|
|
170
|
+
babel: true,
|
|
171
|
+
allowReturnOutsideFunction: true,
|
|
172
|
+
flow: "all",
|
|
173
|
+
sourceFilename: file,
|
|
174
|
+
tokens: true
|
|
175
|
+
});
|
|
176
|
+
} catch (err) {
|
|
177
|
+
// Ignore
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// If user explicitly said 'flow', we try Babel-Flow first, then Babel-Standard.
|
|
181
|
+
// Otherwise, we try Babel-Standard (TS/ESNext) first, then Babel-Flow and finally hermes.
|
|
182
|
+
let primaryBabelOptions = babelParserOptions;
|
|
183
|
+
let secondaryBabelOptions = babelFlowParserOptions;
|
|
184
|
+
if (projectType === "flow") {
|
|
185
|
+
primaryBabelOptions = babelFlowParserOptions;
|
|
186
|
+
secondaryBabelOptions = babelParserOptions;
|
|
187
|
+
}
|
|
124
188
|
try {
|
|
125
|
-
return parse(code,
|
|
126
|
-
} catch {
|
|
127
|
-
|
|
189
|
+
return parse(code, primaryBabelOptions);
|
|
190
|
+
} catch (errPrimary) {
|
|
191
|
+
try {
|
|
192
|
+
return parse(code, secondaryBabelOptions);
|
|
193
|
+
} catch (errSecondary) {
|
|
194
|
+
try {
|
|
195
|
+
return parse(code, babelSafeParserOptions);
|
|
196
|
+
} catch (errSafe) {
|
|
197
|
+
try {
|
|
198
|
+
return parse(code, babelSafeFlowParserOptions);
|
|
199
|
+
} catch (errSafeFlow) {
|
|
200
|
+
return parseHermes(code, {
|
|
201
|
+
sourceType: "unambiguous",
|
|
202
|
+
babel: true,
|
|
203
|
+
allowReturnOutsideFunction: true,
|
|
204
|
+
flow: "all",
|
|
205
|
+
sourceFilename: file,
|
|
206
|
+
tokens: true
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
128
211
|
}
|
|
129
212
|
};
|
|
130
213
|
|
|
@@ -168,19 +251,92 @@ const toVueAst = (file) => {
|
|
|
168
251
|
.replace(vueTemplateRegex, function (match, grA, grB, grC) {
|
|
169
252
|
return grA + grB.replaceAll("{{", "{ ").replaceAll("}}", " }") + grC;
|
|
170
253
|
});
|
|
171
|
-
return codeToJsAst(cleanedCode);
|
|
254
|
+
return codeToJsAst(file, cleanedCode, "ts");
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Convert a single EJS file to AST.
|
|
259
|
+
*/
|
|
260
|
+
const toEjsAst = (file) => {
|
|
261
|
+
const originalCode = readFileSync(file, "utf-8");
|
|
262
|
+
let arr = originalCode.split("");
|
|
263
|
+
const scriptRegex = /(<script>)([\s\S]*?)(<\/script>)/gi;
|
|
264
|
+
let match;
|
|
265
|
+
|
|
266
|
+
while ((match = scriptRegex.exec(originalCode)) !== null) {
|
|
267
|
+
const openStart = match.index;
|
|
268
|
+
const openLen = match[1].length;
|
|
269
|
+
arr[openStart] = "<";
|
|
270
|
+
arr[openStart + 1] = "%";
|
|
271
|
+
for (let i = 2; i < openLen; i++) arr[openStart + i] = " ";
|
|
272
|
+
const closeStart = match.index + match[0].length - match[3].length;
|
|
273
|
+
const closeLen = match[3].length;
|
|
274
|
+
arr[closeStart] = "%";
|
|
275
|
+
arr[closeStart + 1] = ">";
|
|
276
|
+
for (let i = 2; i < closeLen; i++) arr[closeStart + i] = " ";
|
|
277
|
+
const content = match[2];
|
|
278
|
+
const contentOffset = openStart + openLen;
|
|
279
|
+
const innerRegex = /(<%[=\-_#]?)([\s\S]*?)([-_#]?%>)/g;
|
|
280
|
+
let innerMatch;
|
|
281
|
+
while ((innerMatch = innerRegex.exec(content)) !== null) {
|
|
282
|
+
const innerAbsStart = contentOffset + innerMatch.index;
|
|
283
|
+
if (innerMatch[1] === "<%" && innerMatch[3] === "-%>") {
|
|
284
|
+
for (let k = 0; k < innerMatch[0].length; k++)
|
|
285
|
+
arr[innerAbsStart + k] = " ";
|
|
286
|
+
} else {
|
|
287
|
+
for (let k = 0; k < innerMatch[1].length; k++)
|
|
288
|
+
arr[innerAbsStart + k] = " ";
|
|
289
|
+
const endDelimStart =
|
|
290
|
+
innerAbsStart + innerMatch[0].length - innerMatch[3].length;
|
|
291
|
+
for (let k = 0; k < innerMatch[3].length; k++)
|
|
292
|
+
arr[endDelimStart + k] = " ";
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const codeWithoutScriptTag = arr.join("");
|
|
297
|
+
const out = new Array(codeWithoutScriptTag.length).fill(" ");
|
|
298
|
+
for (let i = 0; i < codeWithoutScriptTag.length; i++) {
|
|
299
|
+
const c = codeWithoutScriptTag[i];
|
|
300
|
+
if (c === "\n" || c === "\r") out[i] = c;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const tagRegex = /(<%[=\-_#]?)([\s\S]*?)([-_#]?%>)/g;
|
|
304
|
+
let tagMatch;
|
|
305
|
+
while ((tagMatch = tagRegex.exec(codeWithoutScriptTag)) !== null) {
|
|
306
|
+
const [fullMatch, openTag, content, closeTag] = tagMatch;
|
|
307
|
+
if (openTag === "<%#" || content.trim().startsWith("include ")) continue;
|
|
308
|
+
const startIndex = tagMatch.index + openTag.length;
|
|
309
|
+
const endIndex = tagMatch.index + fullMatch.length - closeTag.length;
|
|
310
|
+
for (let k = startIndex; k < endIndex; k++) {
|
|
311
|
+
out[k] = codeWithoutScriptTag[k];
|
|
312
|
+
}
|
|
313
|
+
const trimmed = content.trim();
|
|
314
|
+
const needsSemi =
|
|
315
|
+
trimmed.length > 0 &&
|
|
316
|
+
!trimmed.endsWith("{") &&
|
|
317
|
+
!trimmed.endsWith("}") &&
|
|
318
|
+
!trimmed.endsWith(";");
|
|
319
|
+
|
|
320
|
+
if (needsSemi) {
|
|
321
|
+
out[endIndex] = ";";
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return codeToJsAst(file, out.join(""), "ts");
|
|
172
326
|
};
|
|
173
327
|
|
|
174
328
|
function createTsc(srcFiles) {
|
|
175
329
|
try {
|
|
176
330
|
const program = tsc.createProgram(srcFiles, {
|
|
177
|
-
target: tsc.ScriptTarget.
|
|
331
|
+
target: tsc.ScriptTarget.ES2022,
|
|
178
332
|
module: tsc.ModuleKind.CommonJS,
|
|
333
|
+
moduleResolution: tsc.ModuleResolutionKind.Node10,
|
|
179
334
|
allowImportingTsExtensions: false,
|
|
180
335
|
allowArbitraryExtensions: false,
|
|
181
336
|
allowSyntheticDefaultImports: true,
|
|
182
337
|
allowUmdGlobalAccess: true,
|
|
183
338
|
allowJs: true,
|
|
339
|
+
checkJs: true,
|
|
184
340
|
allowUnreachableCode: true,
|
|
185
341
|
allowUnusedLabels: true,
|
|
186
342
|
alwaysStrict: false,
|
|
@@ -191,7 +347,7 @@ function createTsc(srcFiles) {
|
|
|
191
347
|
noStrictGenericChecks: true,
|
|
192
348
|
noUncheckedIndexedAccess: false,
|
|
193
349
|
noPropertyAccessFromIndexSignature: false,
|
|
194
|
-
|
|
350
|
+
lib: ["lib.es2022.d.ts", "lib.dom.d.ts"]
|
|
195
351
|
});
|
|
196
352
|
const typeChecker = program.getTypeChecker();
|
|
197
353
|
const seenTypes = new Map();
|
|
@@ -213,48 +369,93 @@ function createTsc(srcFiles) {
|
|
|
213
369
|
};
|
|
214
370
|
|
|
215
371
|
const addType = (node) => {
|
|
216
|
-
|
|
372
|
+
// STRUCTURAL/CONTAINER NODES
|
|
217
373
|
if (
|
|
218
|
-
tsc.
|
|
219
|
-
tsc.
|
|
220
|
-
tsc.
|
|
221
|
-
tsc.
|
|
222
|
-
tsc.
|
|
223
|
-
tsc.
|
|
224
|
-
tsc.
|
|
225
|
-
tsc.
|
|
226
|
-
tsc.
|
|
227
|
-
tsc.
|
|
228
|
-
tsc.
|
|
229
|
-
tsc.isEnumDeclaration(node) ||
|
|
230
|
-
tsc.isNamespaceExportDeclaration(node) ||
|
|
231
|
-
tsc.isImportEqualsDeclaration(node)
|
|
374
|
+
node.kind === tsc.SyntaxKind.SourceFile ||
|
|
375
|
+
node.kind === tsc.SyntaxKind.Block ||
|
|
376
|
+
node.kind === tsc.SyntaxKind.ImportDeclaration ||
|
|
377
|
+
node.kind === tsc.SyntaxKind.ImportClause ||
|
|
378
|
+
node.kind === tsc.SyntaxKind.NamedImports ||
|
|
379
|
+
node.kind === tsc.SyntaxKind.NamespaceImport ||
|
|
380
|
+
node.kind === tsc.SyntaxKind.ExportDeclaration ||
|
|
381
|
+
node.kind === tsc.SyntaxKind.NamedExports ||
|
|
382
|
+
node.kind === tsc.SyntaxKind.TypeAliasDeclaration ||
|
|
383
|
+
node.kind === tsc.SyntaxKind.InterfaceDeclaration ||
|
|
384
|
+
node.kind === tsc.SyntaxKind.ModuleDeclaration
|
|
232
385
|
) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
386
|
+
tsc.forEachChild(node, addType);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
let typeStr;
|
|
391
|
+
|
|
392
|
+
try {
|
|
393
|
+
// WRAPPER NODES
|
|
394
|
+
if (
|
|
395
|
+
(tsc.SyntaxKind.SatisfiesExpression &&
|
|
396
|
+
node.kind === tsc.SyntaxKind.SatisfiesExpression) ||
|
|
397
|
+
node.kind === tsc.SyntaxKind.AsExpression ||
|
|
398
|
+
node.kind === tsc.SyntaxKind.TypeAssertionExpression
|
|
399
|
+
) {
|
|
245
400
|
typeStr = safeTypeWithContextToString(
|
|
246
|
-
typeChecker.getTypeAtLocation(node),
|
|
247
|
-
node
|
|
401
|
+
typeChecker.getTypeAtLocation(node.expression),
|
|
402
|
+
node.expression
|
|
248
403
|
);
|
|
249
404
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
node
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
405
|
+
// FUNCTION/METHOD SIGNATURES
|
|
406
|
+
else if (
|
|
407
|
+
tsc.isFunctionLike(node) ||
|
|
408
|
+
tsc.isMethodDeclaration(node) ||
|
|
409
|
+
tsc.isGetAccessor(node) ||
|
|
410
|
+
tsc.isSetAccessor(node) ||
|
|
411
|
+
tsc.isCallSignatureDeclaration(node) ||
|
|
412
|
+
tsc.isConstructSignatureDeclaration(node)
|
|
413
|
+
) {
|
|
414
|
+
const signature = typeChecker.getSignatureFromDeclaration(node);
|
|
415
|
+
if (signature) {
|
|
416
|
+
const returnType = typeChecker.getReturnTypeOfSignature(signature);
|
|
417
|
+
typeStr = safeTypeToString(returnType);
|
|
418
|
+
} else {
|
|
419
|
+
const funcType = typeChecker.getTypeAtLocation(node);
|
|
420
|
+
const callSignatures = typeChecker.getSignaturesOfType(
|
|
421
|
+
funcType,
|
|
422
|
+
tsc.SignatureKind.Call
|
|
423
|
+
);
|
|
424
|
+
if (callSignatures.length > 0) {
|
|
425
|
+
typeStr = safeTypeToString(callSignatures[0].getReturnType());
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
// STANDARD EXPRESSIONS & IDENTIFIERS
|
|
430
|
+
else {
|
|
431
|
+
let typeObj = typeChecker.getTypeAtLocation(node);
|
|
432
|
+
if (
|
|
433
|
+
typeObj.isLiteral() ||
|
|
434
|
+
typeObj.flags & tsc.TypeFlags.BooleanLiteral
|
|
435
|
+
) {
|
|
436
|
+
try {
|
|
437
|
+
typeObj = typeChecker.getBaseTypeOfLiteralType(typeObj);
|
|
438
|
+
} catch (e) {
|
|
439
|
+
// ignore
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
typeStr = safeTypeWithContextToString(typeObj, node);
|
|
443
|
+
}
|
|
444
|
+
if (
|
|
445
|
+
typeStr &&
|
|
446
|
+
![
|
|
447
|
+
"any",
|
|
448
|
+
"unknown",
|
|
449
|
+
"any[]",
|
|
450
|
+
"unknown[]",
|
|
451
|
+
"error",
|
|
452
|
+
"/*unresolved*/ any"
|
|
453
|
+
].includes(typeStr)
|
|
454
|
+
) {
|
|
455
|
+
seenTypes.set(node.getStart(), typeStr);
|
|
456
|
+
}
|
|
457
|
+
} catch (err) {
|
|
458
|
+
// Silently fail on type resolution errors
|
|
258
459
|
}
|
|
259
460
|
tsc.forEachChild(node, addType);
|
|
260
461
|
};
|
|
@@ -266,7 +467,6 @@ function createTsc(srcFiles) {
|
|
|
266
467
|
seenTypes: seenTypes
|
|
267
468
|
};
|
|
268
469
|
} catch (err) {
|
|
269
|
-
console.warn("Retrieving types", err.message);
|
|
270
470
|
return undefined;
|
|
271
471
|
}
|
|
272
472
|
}
|
|
@@ -285,13 +485,26 @@ const createJSAst = async (options) => {
|
|
|
285
485
|
}
|
|
286
486
|
let ts;
|
|
287
487
|
if (options.tsTypes) {
|
|
288
|
-
const projectFiles =
|
|
289
|
-
(file) => !file.includes("node_modules")
|
|
290
|
-
|
|
488
|
+
const projectFiles = !shouldIncludeNodeModulesBundles
|
|
489
|
+
? srcFiles.filter((file) => !file.includes("node_modules"))
|
|
490
|
+
: srcFiles;
|
|
291
491
|
ts = createTsc(projectFiles);
|
|
292
492
|
}
|
|
293
493
|
for (const chunk of chunks) {
|
|
294
494
|
await Promise.all(chunk.map((file) => processFile(file, options, ts)));
|
|
495
|
+
if (typeof globalThis.gc === "function") {
|
|
496
|
+
try {
|
|
497
|
+
globalThis.gc();
|
|
498
|
+
} catch (e) {
|
|
499
|
+
// ignore
|
|
500
|
+
}
|
|
501
|
+
} else if (typeof Bun !== "undefined" && typeof Bun.gc === "function") {
|
|
502
|
+
try {
|
|
503
|
+
Bun.gc(true);
|
|
504
|
+
} catch (e) {
|
|
505
|
+
// ignore
|
|
506
|
+
}
|
|
507
|
+
}
|
|
295
508
|
}
|
|
296
509
|
} catch (err) {
|
|
297
510
|
console.error(err);
|
|
@@ -300,7 +513,7 @@ const createJSAst = async (options) => {
|
|
|
300
513
|
|
|
301
514
|
const processFile = (file, options, ts) => {
|
|
302
515
|
try {
|
|
303
|
-
const ast = fileToJsAst(file);
|
|
516
|
+
const ast = fileToJsAst(file, options.type);
|
|
304
517
|
writeAstFile(file, ast, options);
|
|
305
518
|
if (ts) {
|
|
306
519
|
try {
|
|
@@ -311,11 +524,11 @@ const processFile = (file, options, ts) => {
|
|
|
311
524
|
ts.seenTypes.clear();
|
|
312
525
|
}
|
|
313
526
|
} catch (err) {
|
|
314
|
-
console.warn("
|
|
527
|
+
console.warn("Process file", file, ":", err.message);
|
|
315
528
|
}
|
|
316
529
|
}
|
|
317
530
|
} catch (err) {
|
|
318
|
-
console.error(file, err
|
|
531
|
+
console.error("Failure:", file, err?.message);
|
|
319
532
|
}
|
|
320
533
|
};
|
|
321
534
|
|
|
@@ -364,7 +577,10 @@ const writeAstFile = (file, ast, options) => {
|
|
|
364
577
|
ast: ast
|
|
365
578
|
};
|
|
366
579
|
mkdirSync(dirname(outAstFile), { recursive: true });
|
|
367
|
-
writeFileSync(
|
|
580
|
+
writeFileSync(
|
|
581
|
+
outAstFile,
|
|
582
|
+
JSON.stringify(data, getCircularReplacer(), undefined)
|
|
583
|
+
);
|
|
368
584
|
console.log("Converted AST for", relativePath, "to", outAstFile);
|
|
369
585
|
};
|
|
370
586
|
|
|
@@ -374,7 +590,7 @@ const writeTypesFile = (file, seenTypes, options) => {
|
|
|
374
590
|
mkdirSync(dirname(outTypeFile), { recursive: true });
|
|
375
591
|
writeFileSync(
|
|
376
592
|
outTypeFile,
|
|
377
|
-
JSON.stringify(Object.fromEntries(seenTypes), undefined,
|
|
593
|
+
JSON.stringify(Object.fromEntries(seenTypes), undefined, undefined)
|
|
378
594
|
);
|
|
379
595
|
console.log("Converted types for", relativePath, "to", outTypeFile);
|
|
380
596
|
};
|
|
@@ -414,6 +630,7 @@ const start = async (options) => {
|
|
|
414
630
|
case "javascript":
|
|
415
631
|
case "typescript":
|
|
416
632
|
case "ts":
|
|
633
|
+
case "flow":
|
|
417
634
|
return await createJSAst(options);
|
|
418
635
|
case "vue":
|
|
419
636
|
return await createVueAst(options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appthreat/atom-parsetools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "Parsing tools that complement the @appthreat/atom project.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
"lint": "eslint *.mjs *.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@appthreat/atom-common": "^1.0.
|
|
12
|
+
"@appthreat/atom-common": "^1.0.14",
|
|
13
13
|
"@babel/parser": "^7.28.5",
|
|
14
14
|
"typescript": "^5.9.3",
|
|
15
|
+
"hermes-parser": "^0.33.0",
|
|
15
16
|
"yargs": "^17.7.2"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<?php return array(
|
|
2
2
|
'root' => array(
|
|
3
3
|
'name' => '__root__',
|
|
4
|
-
'pretty_version' => 'v2.4.
|
|
5
|
-
'version' => '2.4.
|
|
6
|
-
'reference' => '
|
|
4
|
+
'pretty_version' => 'v2.4.5',
|
|
5
|
+
'version' => '2.4.5.0',
|
|
6
|
+
'reference' => '299c497bc039924dfb56de60c871fad0d645e5bf',
|
|
7
7
|
'type' => 'library',
|
|
8
8
|
'install_path' => __DIR__ . '/../../',
|
|
9
9
|
'aliases' => array(),
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
),
|
|
12
12
|
'versions' => array(
|
|
13
13
|
'__root__' => array(
|
|
14
|
-
'pretty_version' => 'v2.4.
|
|
15
|
-
'version' => '2.4.
|
|
16
|
-
'reference' => '
|
|
14
|
+
'pretty_version' => 'v2.4.5',
|
|
15
|
+
'version' => '2.4.5.0',
|
|
16
|
+
'reference' => '299c497bc039924dfb56de60c871fad0d645e5bf',
|
|
17
17
|
'type' => 'library',
|
|
18
18
|
'install_path' => __DIR__ . '/../../',
|
|
19
19
|
'aliases' => array(),
|
package/plugins/rubyastgen/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/prism-1.6.0/gem_make.out
CHANGED
|
@@ -6,10 +6,10 @@ checking for whether -fvisibility=hidden is accepted as CFLAGS... yes
|
|
|
6
6
|
creating Makefile
|
|
7
7
|
|
|
8
8
|
current directory: /home/runner/work/atom/atom/wrapper/nodejs/packages/atom-parsetools/plugins/rubyastgen/bundle/ruby/3.4.0/gems/prism-1.6.0/ext/prism
|
|
9
|
-
make DESTDIR\= sitearchdir\=./.gem.
|
|
9
|
+
make DESTDIR\= sitearchdir\=./.gem.20251216-3015-nvqm76 sitelibdir\=./.gem.20251216-3015-nvqm76 clean
|
|
10
10
|
|
|
11
11
|
current directory: /home/runner/work/atom/atom/wrapper/nodejs/packages/atom-parsetools/plugins/rubyastgen/bundle/ruby/3.4.0/gems/prism-1.6.0/ext/prism
|
|
12
|
-
make DESTDIR\= sitearchdir\=./.gem.
|
|
12
|
+
make DESTDIR\= sitearchdir\=./.gem.20251216-3015-nvqm76 sitelibdir\=./.gem.20251216-3015-nvqm76
|
|
13
13
|
compiling api_node.c
|
|
14
14
|
compiling api_pack.c
|
|
15
15
|
compiling extension.c
|
|
@@ -37,8 +37,8 @@ compiling ./../../src/util/pm_strpbrk.c
|
|
|
37
37
|
linking shared-object prism/prism.so
|
|
38
38
|
|
|
39
39
|
current directory: /home/runner/work/atom/atom/wrapper/nodejs/packages/atom-parsetools/plugins/rubyastgen/bundle/ruby/3.4.0/gems/prism-1.6.0/ext/prism
|
|
40
|
-
make DESTDIR\= sitearchdir\=./.gem.
|
|
41
|
-
/usr/bin/install -c -m 0755 prism.so ./.gem.
|
|
40
|
+
make DESTDIR\= sitearchdir\=./.gem.20251216-3015-nvqm76 sitelibdir\=./.gem.20251216-3015-nvqm76 install
|
|
41
|
+
/usr/bin/install -c -m 0755 prism.so ./.gem.20251216-3015-nvqm76/prism
|
|
42
42
|
|
|
43
43
|
current directory: /home/runner/work/atom/atom/wrapper/nodejs/packages/atom-parsetools/plugins/rubyastgen/bundle/ruby/3.4.0/gems/prism-1.6.0/ext/prism
|
|
44
|
-
make DESTDIR\= sitearchdir\=./.gem.
|
|
44
|
+
make DESTDIR\= sitearchdir\=./.gem.20251216-3015-nvqm76 sitelibdir\=./.gem.20251216-3015-nvqm76 clean
|
package/plugins/rubyastgen/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/racc-1.8.1/gem_make.out
CHANGED
|
@@ -3,16 +3,16 @@ current directory: /home/runner/work/atom/atom/wrapper/nodejs/packages/atom-pars
|
|
|
3
3
|
creating Makefile
|
|
4
4
|
|
|
5
5
|
current directory: /home/runner/work/atom/atom/wrapper/nodejs/packages/atom-parsetools/plugins/rubyastgen/bundle/ruby/3.4.0/gems/racc-1.8.1/ext/racc/cparse
|
|
6
|
-
make DESTDIR\= sitearchdir\=./.gem.
|
|
6
|
+
make DESTDIR\= sitearchdir\=./.gem.20251216-3015-19oeas sitelibdir\=./.gem.20251216-3015-19oeas clean
|
|
7
7
|
|
|
8
8
|
current directory: /home/runner/work/atom/atom/wrapper/nodejs/packages/atom-parsetools/plugins/rubyastgen/bundle/ruby/3.4.0/gems/racc-1.8.1/ext/racc/cparse
|
|
9
|
-
make DESTDIR\= sitearchdir\=./.gem.
|
|
9
|
+
make DESTDIR\= sitearchdir\=./.gem.20251216-3015-19oeas sitelibdir\=./.gem.20251216-3015-19oeas
|
|
10
10
|
compiling cparse.c
|
|
11
11
|
linking shared-object racc/cparse.so
|
|
12
12
|
|
|
13
13
|
current directory: /home/runner/work/atom/atom/wrapper/nodejs/packages/atom-parsetools/plugins/rubyastgen/bundle/ruby/3.4.0/gems/racc-1.8.1/ext/racc/cparse
|
|
14
|
-
make DESTDIR\= sitearchdir\=./.gem.
|
|
15
|
-
/usr/bin/install -c -m 0755 cparse.so ./.gem.
|
|
14
|
+
make DESTDIR\= sitearchdir\=./.gem.20251216-3015-19oeas sitelibdir\=./.gem.20251216-3015-19oeas install
|
|
15
|
+
/usr/bin/install -c -m 0755 cparse.so ./.gem.20251216-3015-19oeas/racc
|
|
16
16
|
|
|
17
17
|
current directory: /home/runner/work/atom/atom/wrapper/nodejs/packages/atom-parsetools/plugins/rubyastgen/bundle/ruby/3.4.0/gems/racc-1.8.1/ext/racc/cparse
|
|
18
|
-
make DESTDIR\= sitearchdir\=./.gem.
|
|
18
|
+
make DESTDIR\= sitearchdir\=./.gem.20251216-3015-19oeas sitelibdir\=./.gem.20251216-3015-19oeas clean
|