@c4a/extract-ts 0.6.19 → 0.7.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/README.md +43 -5
- package/README.zh-CN.md +30 -6
- package/index.js +1815 -121
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -11375,6 +11375,416 @@ var factSchema = exports_external.union([
|
|
|
11375
11375
|
activeFactSchema,
|
|
11376
11376
|
deprecatedFactSchema
|
|
11377
11377
|
]);
|
|
11378
|
+
// ../core/src/schemas/indexerEvidenceAdapterSchema.ts
|
|
11379
|
+
import { createHash } from "node:crypto";
|
|
11380
|
+
|
|
11381
|
+
// ../core/src/indexerOutputRedaction.ts
|
|
11382
|
+
var INDEXER_OUTPUT_REDACTION_MARKER = "[REDACTED:indexer-output]";
|
|
11383
|
+
var SECRET_TOKEN = /^(?:password|passwd|pwd|secret|token|credential|credentials|cookie)$/u;
|
|
11384
|
+
var SECRET_COMPOUND = /^(?:api-key|access-key|private-key|client-secret|access-token|refresh-token)$/u;
|
|
11385
|
+
var NON_SECRET_SUFFIX = new Set([
|
|
11386
|
+
"budget",
|
|
11387
|
+
"count",
|
|
11388
|
+
"digest",
|
|
11389
|
+
"fingerprint",
|
|
11390
|
+
"hash",
|
|
11391
|
+
"index",
|
|
11392
|
+
"kind",
|
|
11393
|
+
"length",
|
|
11394
|
+
"limit",
|
|
11395
|
+
"name",
|
|
11396
|
+
"ref",
|
|
11397
|
+
"reference",
|
|
11398
|
+
"references",
|
|
11399
|
+
"refs",
|
|
11400
|
+
"status",
|
|
11401
|
+
"type"
|
|
11402
|
+
]);
|
|
11403
|
+
function keyTokens(key) {
|
|
11404
|
+
return key.replace(/([a-z0-9])([A-Z])/gu, "$1-$2").replace(/[^A-Za-z0-9]+/gu, "-").toLowerCase().split("-").filter(Boolean);
|
|
11405
|
+
}
|
|
11406
|
+
function sensitiveKey(key, value) {
|
|
11407
|
+
const tokens = keyTokens(key);
|
|
11408
|
+
if (tokens.length === 0)
|
|
11409
|
+
return false;
|
|
11410
|
+
const normalized = tokens.join("-");
|
|
11411
|
+
if (normalized === "authorization" && value !== null && typeof value === "object") {
|
|
11412
|
+
return false;
|
|
11413
|
+
}
|
|
11414
|
+
if (NON_SECRET_SUFFIX.has(tokens.at(-1)))
|
|
11415
|
+
return false;
|
|
11416
|
+
return SECRET_COMPOUND.test(normalized) || tokens.some((token) => SECRET_TOKEN.test(token)) || normalized === "authorization";
|
|
11417
|
+
}
|
|
11418
|
+
function escapeRegExp(value) {
|
|
11419
|
+
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
11420
|
+
}
|
|
11421
|
+
function normalizedBlockedScalars(policy) {
|
|
11422
|
+
const identities = new Set;
|
|
11423
|
+
const values = [];
|
|
11424
|
+
for (const value of policy.blocked_scalars ?? []) {
|
|
11425
|
+
if (typeof value === "number" && !Number.isFinite(value))
|
|
11426
|
+
continue;
|
|
11427
|
+
if (typeof value === "string" && value.length === 0)
|
|
11428
|
+
continue;
|
|
11429
|
+
const identity = `${typeof value}:${String(value)}`;
|
|
11430
|
+
if (identities.has(identity))
|
|
11431
|
+
continue;
|
|
11432
|
+
identities.add(identity);
|
|
11433
|
+
values.push(value);
|
|
11434
|
+
}
|
|
11435
|
+
return values.sort((left, right) => String(right).length - String(left).length);
|
|
11436
|
+
}
|
|
11437
|
+
function replaceWithCount(value, pattern, replacement, count) {
|
|
11438
|
+
return value.replace(pattern, (...args) => {
|
|
11439
|
+
count.replacements += 1;
|
|
11440
|
+
if (typeof replacement === "string")
|
|
11441
|
+
return replacement;
|
|
11442
|
+
return replacement(...args.slice(0, -2));
|
|
11443
|
+
});
|
|
11444
|
+
}
|
|
11445
|
+
function redactKnownText(value, count) {
|
|
11446
|
+
let output = value;
|
|
11447
|
+
output = replaceWithCount(output, /-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/gu, INDEXER_OUTPUT_REDACTION_MARKER, count);
|
|
11448
|
+
output = replaceWithCount(output, /(\bauthorization\s*:\s*(?:bearer|basic)\s+)[^\s,;]+/giu, (_match, prefix) => `${prefix}${INDEXER_OUTPUT_REDACTION_MARKER}`, count);
|
|
11449
|
+
output = replaceWithCount(output, /([a-z][a-z0-9+.-]*:\/\/)[^\s/@:]+:[^\s/@]+@/giu, (_match, prefix) => `${prefix}${INDEXER_OUTPUT_REDACTION_MARKER}@`, count);
|
|
11450
|
+
output = replaceWithCount(output, /([?&](?:access_token|refresh_token|api_key|password|secret)=)[^&#\s]+/giu, (_match, prefix) => `${prefix}${INDEXER_OUTPUT_REDACTION_MARKER}`, count);
|
|
11451
|
+
const key = "(?:[A-Za-z0-9_.-]*(?:password|passwd|pwd|secret|token|credential|cookie)[A-Za-z0-9_.-]*|api[-_]?key|access[-_]?(?:key|token)|private[-_]?key|client[-_]?secret|authorization)";
|
|
11452
|
+
const assignment = `(?:=\\s*|:\\s+(?=\\S)|:\\s*(?=["']))`;
|
|
11453
|
+
output = replaceWithCount(output, new RegExp(`((?:["']?${key}["']?)\\s*${assignment})(?:"(?:\\\\.|[^"])*"|'(?:\\\\.|[^'])*'|[^\\s,;}\\]]+)`, "giu"), (_match, prefix) => `${prefix}"${INDEXER_OUTPUT_REDACTION_MARKER}"`, count);
|
|
11454
|
+
return output;
|
|
11455
|
+
}
|
|
11456
|
+
function redactBlockedText(value, blocked, count) {
|
|
11457
|
+
let output = value;
|
|
11458
|
+
for (const scalar of blocked) {
|
|
11459
|
+
const pattern = typeof scalar === "number" ? new RegExp(`(?<![0-9.])${escapeRegExp(String(scalar))}(?![0-9.])`, "gu") : new RegExp(escapeRegExp(scalar), "gu");
|
|
11460
|
+
output = replaceWithCount(output, pattern, INDEXER_OUTPUT_REDACTION_MARKER, count);
|
|
11461
|
+
}
|
|
11462
|
+
return output;
|
|
11463
|
+
}
|
|
11464
|
+
function redactText(value, blocked, count) {
|
|
11465
|
+
return redactBlockedText(redactKnownText(value, count), blocked, count);
|
|
11466
|
+
}
|
|
11467
|
+
function blockedScalar(value, blocked) {
|
|
11468
|
+
return blocked.some((candidate) => typeof candidate === typeof value && Object.is(candidate, value));
|
|
11469
|
+
}
|
|
11470
|
+
function redactStructured(value, blocked, count, seen) {
|
|
11471
|
+
if (blockedScalar(value, blocked)) {
|
|
11472
|
+
count.replacements += 1;
|
|
11473
|
+
return INDEXER_OUTPUT_REDACTION_MARKER;
|
|
11474
|
+
}
|
|
11475
|
+
if (typeof value === "string")
|
|
11476
|
+
return redactText(value, blocked, count);
|
|
11477
|
+
if (value === null || typeof value !== "object")
|
|
11478
|
+
return value;
|
|
11479
|
+
if (seen.has(value))
|
|
11480
|
+
throw new TypeError("Indexer output redaction requires an acyclic value");
|
|
11481
|
+
seen.add(value);
|
|
11482
|
+
if (value instanceof Date) {
|
|
11483
|
+
const redacted2 = redactText(value.toISOString(), blocked, count);
|
|
11484
|
+
seen.delete(value);
|
|
11485
|
+
return redacted2;
|
|
11486
|
+
}
|
|
11487
|
+
if (value instanceof Error) {
|
|
11488
|
+
const redacted2 = {
|
|
11489
|
+
name: redactText(value.name, blocked, count),
|
|
11490
|
+
message: redactText(value.message, blocked, count)
|
|
11491
|
+
};
|
|
11492
|
+
seen.delete(value);
|
|
11493
|
+
return redacted2;
|
|
11494
|
+
}
|
|
11495
|
+
if (Array.isArray(value)) {
|
|
11496
|
+
const redacted2 = value.map((item) => redactStructured(item, blocked, count, seen));
|
|
11497
|
+
seen.delete(value);
|
|
11498
|
+
return redacted2;
|
|
11499
|
+
}
|
|
11500
|
+
const redacted = {};
|
|
11501
|
+
for (const [key, item] of Object.entries(value)) {
|
|
11502
|
+
const safeKey = redactText(key, blocked, count);
|
|
11503
|
+
if (sensitiveKey(key, item)) {
|
|
11504
|
+
count.replacements += 1;
|
|
11505
|
+
redacted[safeKey] = INDEXER_OUTPUT_REDACTION_MARKER;
|
|
11506
|
+
} else {
|
|
11507
|
+
redacted[safeKey] = redactStructured(item, blocked, count, seen);
|
|
11508
|
+
}
|
|
11509
|
+
}
|
|
11510
|
+
seen.delete(value);
|
|
11511
|
+
return redacted;
|
|
11512
|
+
}
|
|
11513
|
+
function redactIndexerOutput(input) {
|
|
11514
|
+
const count = { replacements: 0 };
|
|
11515
|
+
const blocked = normalizedBlockedScalars(input.policy ?? {});
|
|
11516
|
+
const value = typeof input.value === "string" ? redactText(input.value, blocked, count) : redactStructured(input.value, blocked, count, new WeakSet);
|
|
11517
|
+
return {
|
|
11518
|
+
value,
|
|
11519
|
+
redacted: count.replacements > 0,
|
|
11520
|
+
replacement_count: count.replacements
|
|
11521
|
+
};
|
|
11522
|
+
}
|
|
11523
|
+
function assertIndexerOutputSafe(input) {
|
|
11524
|
+
const result = redactIndexerOutput(input);
|
|
11525
|
+
if (result.redacted) {
|
|
11526
|
+
throw new TypeError(`Indexer ${input.channel} was blocked by the common output redaction boundary`);
|
|
11527
|
+
}
|
|
11528
|
+
return input.value;
|
|
11529
|
+
}
|
|
11530
|
+
|
|
11531
|
+
// ../core/src/schemas/indexerEvidenceAdapterSchema.ts
|
|
11532
|
+
var digestSchema = exports_external.string().regex(/^sha256:[a-f0-9]{64}$/u);
|
|
11533
|
+
var idSchema = exports_external.string().regex(/^[a-z0-9][a-z0-9._/-]*$/u).superRefine((value, context) => {
|
|
11534
|
+
if (value.split("/").some((segment) => segment.length === 0 || segment === "." || segment === "..")) {
|
|
11535
|
+
context.addIssue({
|
|
11536
|
+
code: exports_external.ZodIssueCode.custom,
|
|
11537
|
+
message: "must not contain empty, current-directory, or parent-directory segments"
|
|
11538
|
+
});
|
|
11539
|
+
}
|
|
11540
|
+
});
|
|
11541
|
+
var semverSchema = exports_external.string().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u);
|
|
11542
|
+
var canonicalRefSchema = exports_external.string().regex(/^[a-z][a-z0-9.-]*:[A-Za-z0-9][A-Za-z0-9._~:/#@+-]*$/u);
|
|
11543
|
+
var packageCoordinateSchema = exports_external.string().regex(/^(?:@[a-z0-9._-]+\/)?[a-z0-9][a-z0-9._-]*$/u);
|
|
11544
|
+
var portablePathSchema = exports_external.string().superRefine((value, context) => {
|
|
11545
|
+
const segments = value.split("/");
|
|
11546
|
+
if (value.length === 0 || value.includes("\x00") || value.includes("\\") || value.startsWith("/") || /^[A-Za-z]:\//u.test(value) || segments.some((segment) => segment.length === 0 || segment === "." || segment === "..")) {
|
|
11547
|
+
context.addIssue({
|
|
11548
|
+
code: exports_external.ZodIssueCode.custom,
|
|
11549
|
+
message: "must be a portable relative path"
|
|
11550
|
+
});
|
|
11551
|
+
}
|
|
11552
|
+
});
|
|
11553
|
+
function addDuplicateIssues(values, context, field) {
|
|
11554
|
+
const seen = new Set;
|
|
11555
|
+
values.forEach((value, index) => {
|
|
11556
|
+
if (seen.has(value)) {
|
|
11557
|
+
context.addIssue({
|
|
11558
|
+
code: exports_external.ZodIssueCode.custom,
|
|
11559
|
+
message: `${field} must not contain duplicate value ${value}`,
|
|
11560
|
+
path: [index]
|
|
11561
|
+
});
|
|
11562
|
+
}
|
|
11563
|
+
seen.add(value);
|
|
11564
|
+
});
|
|
11565
|
+
}
|
|
11566
|
+
var adapterIdentitySchema = exports_external.object({
|
|
11567
|
+
id: idSchema,
|
|
11568
|
+
package: packageCoordinateSchema,
|
|
11569
|
+
export: exports_external.string().regex(/^[A-Za-z_$][A-Za-z0-9_$.-]*$/u),
|
|
11570
|
+
version: semverSchema,
|
|
11571
|
+
digest: digestSchema
|
|
11572
|
+
}).strict();
|
|
11573
|
+
var adapterLocatorSchema = exports_external.object({
|
|
11574
|
+
source_ref: canonicalRefSchema,
|
|
11575
|
+
module_ref: canonicalRefSchema.nullable(),
|
|
11576
|
+
normalized_path: portablePathSchema,
|
|
11577
|
+
qualified_item_path: exports_external.string().min(1).max(1024),
|
|
11578
|
+
signature_digest: digestSchema
|
|
11579
|
+
}).strict();
|
|
11580
|
+
var indexerEvidenceAdapterFactSchema = exports_external.object({
|
|
11581
|
+
fact_ref: canonicalRefSchema,
|
|
11582
|
+
kind: idSchema,
|
|
11583
|
+
locator: adapterLocatorSchema,
|
|
11584
|
+
payload_digest: digestSchema,
|
|
11585
|
+
denominator: exports_external.enum(["none", "eligible-file", "loc", "symbol", "protocol-item"])
|
|
11586
|
+
}).strict();
|
|
11587
|
+
var indexerEvidenceAdapterFileSchema = exports_external.object({
|
|
11588
|
+
file_ref: canonicalRefSchema,
|
|
11589
|
+
source_ref: canonicalRefSchema,
|
|
11590
|
+
module_ref: canonicalRefSchema.nullable(),
|
|
11591
|
+
normalized_path: portablePathSchema,
|
|
11592
|
+
role: exports_external.enum(["primary-owner", "enricher"]),
|
|
11593
|
+
coverage_tier: exports_external.enum(["ast-catalog", "lightweight-evidence"]),
|
|
11594
|
+
disposition: exports_external.enum(["analyzed", "unsupported", "excluded"]),
|
|
11595
|
+
facts: exports_external.array(indexerEvidenceAdapterFactSchema)
|
|
11596
|
+
}).strict().superRefine((value, context) => {
|
|
11597
|
+
addDuplicateIssues(value.facts.map((fact2) => fact2.fact_ref), context, "facts");
|
|
11598
|
+
if (value.disposition !== "analyzed" && value.facts.length > 0) {
|
|
11599
|
+
context.addIssue({
|
|
11600
|
+
code: exports_external.ZodIssueCode.custom,
|
|
11601
|
+
message: "unsupported or excluded files cannot publish facts",
|
|
11602
|
+
path: ["facts"]
|
|
11603
|
+
});
|
|
11604
|
+
}
|
|
11605
|
+
if ((value.role === "enricher" || value.coverage_tier === "lightweight-evidence") && value.facts.some((fact2) => fact2.denominator !== "none")) {
|
|
11606
|
+
context.addIssue({
|
|
11607
|
+
code: exports_external.ZodIssueCode.custom,
|
|
11608
|
+
message: "enricher and lightweight evidence facts cannot contribute denominators",
|
|
11609
|
+
path: ["facts"]
|
|
11610
|
+
});
|
|
11611
|
+
}
|
|
11612
|
+
});
|
|
11613
|
+
var toolchainStepSchema = exports_external.object({
|
|
11614
|
+
step: idSchema,
|
|
11615
|
+
package: packageCoordinateSchema,
|
|
11616
|
+
export: exports_external.string().regex(/^[A-Za-z_$][A-Za-z0-9_$.-]*$/u),
|
|
11617
|
+
version: semverSchema,
|
|
11618
|
+
digest: digestSchema,
|
|
11619
|
+
capabilities: exports_external.array(idSchema).min(1),
|
|
11620
|
+
input_digest: digestSchema,
|
|
11621
|
+
output_digest: digestSchema
|
|
11622
|
+
}).strict().superRefine((value, context) => {
|
|
11623
|
+
addDuplicateIssues(value.capabilities, context, "capabilities");
|
|
11624
|
+
});
|
|
11625
|
+
var adapterDiagnosticSchema = exports_external.object({
|
|
11626
|
+
code: idSchema,
|
|
11627
|
+
fact_ref: canonicalRefSchema.optional(),
|
|
11628
|
+
severity: exports_external.enum(["info", "warning", "error"]),
|
|
11629
|
+
detail_digest: digestSchema
|
|
11630
|
+
}).strict();
|
|
11631
|
+
var indexerEvidenceAdapterResultSchema = exports_external.object({
|
|
11632
|
+
protocol: exports_external.literal("context.indexer.evidence-adapter-result/v1"),
|
|
11633
|
+
adapter: adapterIdentitySchema,
|
|
11634
|
+
authorized_scope: exports_external.object({
|
|
11635
|
+
source_ref: canonicalRefSchema,
|
|
11636
|
+
module_refs: exports_external.array(canonicalRefSchema),
|
|
11637
|
+
scope_digest: digestSchema
|
|
11638
|
+
}).strict(),
|
|
11639
|
+
input_digest: digestSchema,
|
|
11640
|
+
precedence: exports_external.number().int().nonnegative(),
|
|
11641
|
+
files: exports_external.array(indexerEvidenceAdapterFileSchema).min(1),
|
|
11642
|
+
diagnostics: exports_external.array(adapterDiagnosticSchema),
|
|
11643
|
+
toolchain: exports_external.array(toolchainStepSchema).min(1),
|
|
11644
|
+
output_digest: digestSchema
|
|
11645
|
+
}).strict().superRefine((value, context) => {
|
|
11646
|
+
addDuplicateIssues(value.authorized_scope.module_refs, context, "authorized_scope.module_refs");
|
|
11647
|
+
addDuplicateIssues(value.files.map((file) => file.file_ref), context, "files");
|
|
11648
|
+
addDuplicateIssues(value.toolchain.map((step) => step.step), context, "toolchain");
|
|
11649
|
+
});
|
|
11650
|
+
var FACT_PAYLOADS = new WeakMap;
|
|
11651
|
+
function canonicalFactPayload(value, seen = new WeakSet, path = "$") {
|
|
11652
|
+
if (value === null || typeof value === "boolean" || typeof value === "string") {
|
|
11653
|
+
return value;
|
|
11654
|
+
}
|
|
11655
|
+
if (typeof value === "number") {
|
|
11656
|
+
if (!Number.isFinite(value)) {
|
|
11657
|
+
throw new TypeError("Indexer Evidence Adapter fact payload numbers must be finite");
|
|
11658
|
+
}
|
|
11659
|
+
return value;
|
|
11660
|
+
}
|
|
11661
|
+
if (typeof value !== "object") {
|
|
11662
|
+
throw new TypeError(`Indexer Evidence Adapter fact payload ${path} must contain only JSON values`);
|
|
11663
|
+
}
|
|
11664
|
+
if (seen.has(value)) {
|
|
11665
|
+
throw new TypeError(`Indexer Evidence Adapter fact payload ${path} must be acyclic`);
|
|
11666
|
+
}
|
|
11667
|
+
seen.add(value);
|
|
11668
|
+
if (Array.isArray(value)) {
|
|
11669
|
+
const output2 = value.map((item, index) => canonicalFactPayload(item, seen, `${path}[${index}]`));
|
|
11670
|
+
seen.delete(value);
|
|
11671
|
+
return output2;
|
|
11672
|
+
}
|
|
11673
|
+
if (Object.prototype.toString.call(value) !== "[object Object]") {
|
|
11674
|
+
throw new TypeError(`Indexer Evidence Adapter fact payload ${path} must use plain JSON objects; received ${Object.prototype.toString.call(value)}`);
|
|
11675
|
+
}
|
|
11676
|
+
const output = {};
|
|
11677
|
+
for (const [key, item] of Object.entries(value).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)) {
|
|
11678
|
+
output[key] = canonicalFactPayload(item, seen, `${path}.${key}`);
|
|
11679
|
+
}
|
|
11680
|
+
seen.delete(value);
|
|
11681
|
+
return output;
|
|
11682
|
+
}
|
|
11683
|
+
function canonicalize(value) {
|
|
11684
|
+
if (Array.isArray(value))
|
|
11685
|
+
return value.map(canonicalize);
|
|
11686
|
+
if (value !== null && typeof value === "object") {
|
|
11687
|
+
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, item]) => [key, canonicalize(item)]));
|
|
11688
|
+
}
|
|
11689
|
+
return value;
|
|
11690
|
+
}
|
|
11691
|
+
function indexerEvidenceAdapterProtocolDigest(value) {
|
|
11692
|
+
const canonical = JSON.stringify(canonicalize(value));
|
|
11693
|
+
return `sha256:${createHash("sha256").update(canonical).digest("hex")}`;
|
|
11694
|
+
}
|
|
11695
|
+
function indexerEvidenceAdapterFileRef(input) {
|
|
11696
|
+
return `adapter-file:${indexerEvidenceAdapterProtocolDigest(input)}`;
|
|
11697
|
+
}
|
|
11698
|
+
function indexerEvidenceAdapterFactRef(input) {
|
|
11699
|
+
return `adapter-fact:${indexerEvidenceAdapterProtocolDigest(input)}`;
|
|
11700
|
+
}
|
|
11701
|
+
function createIndexerEvidenceAdapterFact(input) {
|
|
11702
|
+
const payload = canonicalFactPayload(input.payload);
|
|
11703
|
+
const qualifiedItemPath = input.qualified_item_path.length <= 1024 ? input.qualified_item_path : `${input.qualified_item_path.slice(0, 950)}#${indexerEvidenceAdapterProtocolDigest(input.qualified_item_path)}`;
|
|
11704
|
+
const locator = {
|
|
11705
|
+
source_ref: input.source_ref,
|
|
11706
|
+
module_ref: input.module_ref,
|
|
11707
|
+
normalized_path: input.normalized_path,
|
|
11708
|
+
qualified_item_path: qualifiedItemPath,
|
|
11709
|
+
signature_digest: indexerEvidenceAdapterProtocolDigest(input.signature)
|
|
11710
|
+
};
|
|
11711
|
+
const fact2 = {
|
|
11712
|
+
fact_ref: indexerEvidenceAdapterFactRef({ ...locator, kind: input.kind }),
|
|
11713
|
+
kind: input.kind,
|
|
11714
|
+
locator,
|
|
11715
|
+
payload_digest: indexerEvidenceAdapterProtocolDigest(payload),
|
|
11716
|
+
denominator: input.denominator
|
|
11717
|
+
};
|
|
11718
|
+
FACT_PAYLOADS.set(fact2, payload);
|
|
11719
|
+
return fact2;
|
|
11720
|
+
}
|
|
11721
|
+
function indexerEvidenceAdapterFactPayloads(result) {
|
|
11722
|
+
const payloads = result.files.flatMap((file) => file.facts.map((fact2) => {
|
|
11723
|
+
const payload = FACT_PAYLOADS.get(fact2);
|
|
11724
|
+
if (payload === undefined) {
|
|
11725
|
+
throw new TypeError(`Evidence Adapter fact payload ${fact2.fact_ref} is no longer materialized in this process`);
|
|
11726
|
+
}
|
|
11727
|
+
if (indexerEvidenceAdapterProtocolDigest(payload) !== fact2.payload_digest) {
|
|
11728
|
+
throw new TypeError(`Evidence Adapter fact payload ${fact2.fact_ref} is stale`);
|
|
11729
|
+
}
|
|
11730
|
+
return { fact_ref: fact2.fact_ref, payload };
|
|
11731
|
+
})).sort((left, right) => compareCanonicalText(left.fact_ref, right.fact_ref));
|
|
11732
|
+
return assertIndexerOutputSafe({ channel: "ipc-envelope", value: payloads });
|
|
11733
|
+
}
|
|
11734
|
+
function materializeIndexerEvidenceAdapterResult(result) {
|
|
11735
|
+
return {
|
|
11736
|
+
result,
|
|
11737
|
+
fact_payloads: indexerEvidenceAdapterFactPayloads(result)
|
|
11738
|
+
};
|
|
11739
|
+
}
|
|
11740
|
+
function indexerEvidenceAdapterOutputDigest(value) {
|
|
11741
|
+
return indexerEvidenceAdapterProtocolDigest(value);
|
|
11742
|
+
}
|
|
11743
|
+
function compareCanonicalText(left, right) {
|
|
11744
|
+
if (left < right)
|
|
11745
|
+
return -1;
|
|
11746
|
+
if (left > right)
|
|
11747
|
+
return 1;
|
|
11748
|
+
return 0;
|
|
11749
|
+
}
|
|
11750
|
+
function buildIndexerEvidenceAdapterResult(input) {
|
|
11751
|
+
const canonical = {
|
|
11752
|
+
...input,
|
|
11753
|
+
authorized_scope: {
|
|
11754
|
+
...input.authorized_scope,
|
|
11755
|
+
module_refs: [...input.authorized_scope.module_refs].sort(compareCanonicalText)
|
|
11756
|
+
},
|
|
11757
|
+
files: input.files.map((file) => ({
|
|
11758
|
+
...file,
|
|
11759
|
+
facts: [...file.facts].sort((left, right) => compareCanonicalText(left.fact_ref, right.fact_ref))
|
|
11760
|
+
})).sort((left, right) => compareCanonicalText(left.file_ref, right.file_ref)),
|
|
11761
|
+
diagnostics: [...input.diagnostics].sort((left, right) => compareCanonicalText(left.fact_ref ?? "", right.fact_ref ?? "") || compareCanonicalText(left.code, right.code) || compareCanonicalText(left.severity, right.severity) || compareCanonicalText(left.detail_digest, right.detail_digest)),
|
|
11762
|
+
toolchain: input.toolchain.map((step) => ({
|
|
11763
|
+
...step,
|
|
11764
|
+
capabilities: [...step.capabilities].sort(compareCanonicalText)
|
|
11765
|
+
}))
|
|
11766
|
+
};
|
|
11767
|
+
const payloads = new Map;
|
|
11768
|
+
for (const file of canonical.files) {
|
|
11769
|
+
for (const fact2 of file.facts) {
|
|
11770
|
+
const payload = FACT_PAYLOADS.get(fact2);
|
|
11771
|
+
if (payload !== undefined)
|
|
11772
|
+
payloads.set(fact2.fact_ref, payload);
|
|
11773
|
+
}
|
|
11774
|
+
}
|
|
11775
|
+
const parsed = indexerEvidenceAdapterResultSchema.parse({
|
|
11776
|
+
...canonical,
|
|
11777
|
+
output_digest: indexerEvidenceAdapterOutputDigest(canonical)
|
|
11778
|
+
});
|
|
11779
|
+
for (const file of parsed.files) {
|
|
11780
|
+
for (const fact2 of file.facts) {
|
|
11781
|
+
const payload = payloads.get(fact2.fact_ref);
|
|
11782
|
+
if (payload !== undefined)
|
|
11783
|
+
FACT_PAYLOADS.set(fact2, payload);
|
|
11784
|
+
}
|
|
11785
|
+
}
|
|
11786
|
+
return assertIndexerOutputSafe({ channel: "success-payload", value: parsed });
|
|
11787
|
+
}
|
|
11378
11788
|
// ../core/src/errors/httpStatus.ts
|
|
11379
11789
|
var ERROR_CODE_HTTP_STATUS = {
|
|
11380
11790
|
["VALIDATION_FAILED" /* VALIDATION_FAILED */]: 400,
|
|
@@ -11490,7 +11900,15 @@ var DEFAULT_CONTENT_TYPES = [
|
|
|
11490
11900
|
{
|
|
11491
11901
|
id: "typescript",
|
|
11492
11902
|
category: "code",
|
|
11493
|
-
match: { extensions: [".ts", ".tsx"] },
|
|
11903
|
+
match: { extensions: [".ts", ".tsx", ".mts", ".cts"] },
|
|
11904
|
+
cas: { encoding: "utf8", hashInput: "content" },
|
|
11905
|
+
pipeline: { digest: ["ast", "summary"], extraction: ["entities", "relations"] },
|
|
11906
|
+
display: { icon: "\uD83D\uDCDC", renderer: "code" }
|
|
11907
|
+
},
|
|
11908
|
+
{
|
|
11909
|
+
id: "javascript",
|
|
11910
|
+
category: "code",
|
|
11911
|
+
match: { extensions: [".js", ".jsx", ".mjs", ".cjs"] },
|
|
11494
11912
|
cas: { encoding: "utf8", hashInput: "content" },
|
|
11495
11913
|
pipeline: { digest: ["ast", "summary"], extraction: ["entities", "relations"] },
|
|
11496
11914
|
display: { icon: "\uD83D\uDCDC", renderer: "code" }
|
|
@@ -11598,6 +12016,50 @@ var INDEXABLE_EXTENSIONS = new Set([
|
|
|
11598
12016
|
var UPLOAD_ALLOWED_EXTENSIONS = collectExtensions(() => true);
|
|
11599
12017
|
var TEXT_EXTENSIONS = collectExtensions((definition) => definition.cas.encoding === "utf8");
|
|
11600
12018
|
var UPLOAD_MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
12019
|
+
// src/ecmaScriptLanguage.ts
|
|
12020
|
+
var LANGUAGE_BY_EXTENSION = {
|
|
12021
|
+
".ts": "typescript",
|
|
12022
|
+
".tsx": "tsx",
|
|
12023
|
+
".mts": "typescript",
|
|
12024
|
+
".cts": "typescript",
|
|
12025
|
+
".js": "javascript",
|
|
12026
|
+
".jsx": "jsx",
|
|
12027
|
+
".mjs": "javascript",
|
|
12028
|
+
".cjs": "javascript"
|
|
12029
|
+
};
|
|
12030
|
+
var EXTRACT_TS_CAPABILITIES = [
|
|
12031
|
+
"commonjs-module",
|
|
12032
|
+
"esm-module",
|
|
12033
|
+
"javascript-ast",
|
|
12034
|
+
"jsx-ast",
|
|
12035
|
+
"parser.javascript",
|
|
12036
|
+
"parser.typescript",
|
|
12037
|
+
"static-call-relations",
|
|
12038
|
+
"tsx-ast",
|
|
12039
|
+
"typescript-ast"
|
|
12040
|
+
];
|
|
12041
|
+
var EXTRACT_TS_COVERAGE_TIER = "ast-catalog";
|
|
12042
|
+
var ecmaScriptLanguage = (filePath) => {
|
|
12043
|
+
const lower = filePath.toLowerCase();
|
|
12044
|
+
const extension = Object.keys(LANGUAGE_BY_EXTENSION).find((candidate) => lower.endsWith(candidate));
|
|
12045
|
+
return extension ? LANGUAGE_BY_EXTENSION[extension] : "typescript";
|
|
12046
|
+
};
|
|
12047
|
+
var isJsxLikePath = (filePath) => {
|
|
12048
|
+
const language = ecmaScriptLanguage(filePath);
|
|
12049
|
+
return language === "tsx" || language === "jsx";
|
|
12050
|
+
};
|
|
12051
|
+
var isJavaScriptPath = (filePath) => {
|
|
12052
|
+
const language = ecmaScriptLanguage(filePath);
|
|
12053
|
+
return language === "javascript" || language === "jsx";
|
|
12054
|
+
};
|
|
12055
|
+
var packageLanguage = (filePaths) => {
|
|
12056
|
+
const hasJavaScript = filePaths.some(isJavaScriptPath);
|
|
12057
|
+
const hasTypeScript = filePaths.some((filePath) => !isJavaScriptPath(filePath));
|
|
12058
|
+
if (hasJavaScript && hasTypeScript)
|
|
12059
|
+
return "ecmascript";
|
|
12060
|
+
return hasJavaScript ? "javascript" : "typescript";
|
|
12061
|
+
};
|
|
12062
|
+
|
|
11601
12063
|
// src/pathUtils.ts
|
|
11602
12064
|
import { posix as posix2 } from "node:path";
|
|
11603
12065
|
|
|
@@ -11781,8 +12243,9 @@ function resolveTsConfigCandidates(specifier, resolver) {
|
|
|
11781
12243
|
}
|
|
11782
12244
|
|
|
11783
12245
|
// src/pathUtils.ts
|
|
11784
|
-
var
|
|
11785
|
-
var
|
|
12246
|
+
var TYPESCRIPT_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts"];
|
|
12247
|
+
var JAVASCRIPT_EXTENSIONS = [".js", ".jsx", ".mjs", ".cjs"];
|
|
12248
|
+
var SOURCE_EXTENSIONS = [...TYPESCRIPT_EXTENSIONS, ...JAVASCRIPT_EXTENSIONS];
|
|
11786
12249
|
var DECLARATION_EXTENSIONS = [".d.ts", ".d.mts", ".d.cts"];
|
|
11787
12250
|
var KNOWN_CODE_SUFFIXES = [
|
|
11788
12251
|
...DECLARATION_EXTENSIONS,
|
|
@@ -11794,7 +12257,7 @@ var KNOWN_CODE_SUFFIXES = [
|
|
|
11794
12257
|
".system.js",
|
|
11795
12258
|
".min.js",
|
|
11796
12259
|
...SOURCE_EXTENSIONS,
|
|
11797
|
-
...
|
|
12260
|
+
...JAVASCRIPT_EXTENSIONS
|
|
11798
12261
|
];
|
|
11799
12262
|
var BUILD_OUTPUT_ROOTS = new Set(["dist", "lib", "build", "output", "out"]);
|
|
11800
12263
|
var BUILD_FORMAT_DIRS = new Set([
|
|
@@ -11857,25 +12320,27 @@ var createCandidatePaths = (value, options = {}) => {
|
|
|
11857
12320
|
return [];
|
|
11858
12321
|
const withoutExtension = removeKnownExtension(normalized);
|
|
11859
12322
|
const mappedSourcePaths = buildToSourcePaths(withoutExtension);
|
|
11860
|
-
const
|
|
12323
|
+
const isBuildOutput = buildToSourcePaths(withoutExtension).length > 0;
|
|
12324
|
+
const directFirst = SOURCE_EXTENSIONS.some((extension) => normalized.endsWith(extension)) && !isBuildOutput;
|
|
12325
|
+
const preferredExtensions = options.preferJavaScript ? [...JAVASCRIPT_EXTENSIONS, ...TYPESCRIPT_EXTENSIONS] : [...TYPESCRIPT_EXTENSIONS, ...JAVASCRIPT_EXTENSIONS];
|
|
11861
12326
|
const bases = directFirst ? unique([normalized, withoutExtension, ...mappedSourcePaths]) : unique([...mappedSourcePaths, normalized, withoutExtension]);
|
|
11862
12327
|
const candidates = new Set;
|
|
11863
12328
|
for (const base of bases) {
|
|
11864
12329
|
if (SOURCE_EXTENSIONS.some((ext) => base.endsWith(ext))) {
|
|
11865
12330
|
candidates.add(base);
|
|
11866
12331
|
}
|
|
11867
|
-
for (const extension of
|
|
12332
|
+
for (const extension of preferredExtensions) {
|
|
11868
12333
|
candidates.add(`${base}${extension}`);
|
|
11869
12334
|
candidates.add(posix2.join(base, `index${extension}`));
|
|
11870
12335
|
}
|
|
11871
|
-
if (
|
|
11872
|
-
for (const extension of
|
|
12336
|
+
if (JAVASCRIPT_EXTENSIONS.some((extension) => normalized.endsWith(extension))) {
|
|
12337
|
+
for (const extension of preferredExtensions) {
|
|
11873
12338
|
candidates.add(removeKnownExtension(normalized) + extension);
|
|
11874
12339
|
}
|
|
11875
12340
|
}
|
|
11876
12341
|
}
|
|
11877
12342
|
if (options.allowIndexFallback ?? true) {
|
|
11878
|
-
for (const extension of
|
|
12343
|
+
for (const extension of preferredExtensions) {
|
|
11879
12344
|
candidates.add(`src/index${extension}`);
|
|
11880
12345
|
}
|
|
11881
12346
|
}
|
|
@@ -11896,7 +12361,10 @@ var resolveImportSourcePath = async (fromFile, specifier, fs, resolver) => {
|
|
|
11896
12361
|
if (resolver === undefined)
|
|
11897
12362
|
return null;
|
|
11898
12363
|
for (const target of resolveTsConfigCandidates(specifier, resolver)) {
|
|
11899
|
-
for (const candidate of createCandidatePaths(target, {
|
|
12364
|
+
for (const candidate of createCandidatePaths(target, {
|
|
12365
|
+
allowIndexFallback: false,
|
|
12366
|
+
preferJavaScript: isJavaScriptPath(fromFile)
|
|
12367
|
+
})) {
|
|
11900
12368
|
if (await fs.exists(candidate))
|
|
11901
12369
|
return normalizeRelativePath(candidate);
|
|
11902
12370
|
}
|
|
@@ -11904,7 +12372,7 @@ var resolveImportSourcePath = async (fromFile, specifier, fs, resolver) => {
|
|
|
11904
12372
|
return null;
|
|
11905
12373
|
}
|
|
11906
12374
|
const baseDir = posix2.dirname(fromFile);
|
|
11907
|
-
for (const candidate of createCandidatePaths(specifier)) {
|
|
12375
|
+
for (const candidate of createCandidatePaths(specifier, { preferJavaScript: isJavaScriptPath(fromFile) })) {
|
|
11908
12376
|
const fullPath = baseDir === "." ? candidate : posix2.join(baseDir, candidate);
|
|
11909
12377
|
if (await fs.exists(fullPath)) {
|
|
11910
12378
|
return normalizeRelativePath(fullPath);
|
|
@@ -12053,7 +12521,7 @@ var detectEntries = async (manifest, fs) => {
|
|
|
12053
12521
|
package: {
|
|
12054
12522
|
name: readString(pkg.name) ?? "unknown-package",
|
|
12055
12523
|
kind: detectPackageKind(pkg),
|
|
12056
|
-
language:
|
|
12524
|
+
language: packageLanguage(entries.map((entry) => entry.path)),
|
|
12057
12525
|
version: readString(pkg.version) ?? undefined
|
|
12058
12526
|
},
|
|
12059
12527
|
entries,
|
|
@@ -12120,6 +12588,23 @@ var fileInfoSchema = exports_external.object({
|
|
|
12120
12588
|
language: exports_external.string().min(1),
|
|
12121
12589
|
lines: exports_external.number().int().nonnegative()
|
|
12122
12590
|
});
|
|
12591
|
+
var extractionDiagnosticSchema = exports_external.object({
|
|
12592
|
+
code: exports_external.string().min(1),
|
|
12593
|
+
severity: exports_external.enum(["info", "warning", "error"]),
|
|
12594
|
+
file: exports_external.string().min(1),
|
|
12595
|
+
line: exports_external.number().int().positive(),
|
|
12596
|
+
column: exports_external.number().int().positive()
|
|
12597
|
+
});
|
|
12598
|
+
var extractionCoverageSchema = exports_external.object({
|
|
12599
|
+
tier: exports_external.enum(["ast-catalog", "lightweight-evidence"]),
|
|
12600
|
+
capabilities: exports_external.array(exports_external.string().min(1)),
|
|
12601
|
+
files: exports_external.array(exports_external.object({
|
|
12602
|
+
path: exports_external.string().min(1),
|
|
12603
|
+
disposition: exports_external.enum(["analyzed", "unsupported", "excluded"]),
|
|
12604
|
+
diagnosticCodes: exports_external.array(exports_external.string().min(1))
|
|
12605
|
+
})),
|
|
12606
|
+
diagnostics: exports_external.array(extractionDiagnosticSchema)
|
|
12607
|
+
});
|
|
12123
12608
|
var extractionMetaSchema = exports_external.object({
|
|
12124
12609
|
extractedAt: exports_external.string().datetime(),
|
|
12125
12610
|
pluginId: exports_external.string().min(1),
|
|
@@ -12146,6 +12631,7 @@ var extractionResultSchema = exports_external.object({
|
|
|
12146
12631
|
files: exports_external.array(fileInfoSchema),
|
|
12147
12632
|
symbols: exports_external.array(symbolInfoSchema),
|
|
12148
12633
|
relations: exports_external.array(relationInfoSchema),
|
|
12634
|
+
coverage: extractionCoverageSchema.optional(),
|
|
12149
12635
|
stats: extractionStatsSchema
|
|
12150
12636
|
});
|
|
12151
12637
|
var digestStatsSchema = exports_external.object({
|
|
@@ -12162,6 +12648,7 @@ var digestDataSchema = exports_external.object({
|
|
|
12162
12648
|
files: exports_external.array(fileInfoSchema),
|
|
12163
12649
|
symbols: exports_external.array(symbolInfoSchema),
|
|
12164
12650
|
relations: exports_external.array(relationInfoSchema),
|
|
12651
|
+
coverage: extractionCoverageSchema.optional(),
|
|
12165
12652
|
stats: digestStatsSchema
|
|
12166
12653
|
});
|
|
12167
12654
|
var symbolDiffSchema = exports_external.object({
|
|
@@ -12264,7 +12751,16 @@ class ExtractionPluginRegistry {
|
|
|
12264
12751
|
import { execFile } from "node:child_process";
|
|
12265
12752
|
import { promisify } from "node:util";
|
|
12266
12753
|
var execFileAsync = promisify(execFile);
|
|
12267
|
-
var SUPPORTED_EXTENSIONS = new Set([
|
|
12754
|
+
var SUPPORTED_EXTENSIONS = new Set([
|
|
12755
|
+
".ts",
|
|
12756
|
+
".tsx",
|
|
12757
|
+
".mts",
|
|
12758
|
+
".cts",
|
|
12759
|
+
".js",
|
|
12760
|
+
".jsx",
|
|
12761
|
+
".mjs",
|
|
12762
|
+
".cjs"
|
|
12763
|
+
]);
|
|
12268
12764
|
var MANIFEST_FILES = [
|
|
12269
12765
|
"package.json",
|
|
12270
12766
|
"pyproject.toml",
|
|
@@ -12316,10 +12812,616 @@ var codeExtractRunnerInputSchema = exports_external.object({
|
|
|
12316
12812
|
worktreeContentHash: exports_external.string().min(1).optional()
|
|
12317
12813
|
}).optional()
|
|
12318
12814
|
});
|
|
12815
|
+
// ../extract/src/evidenceAdapter.ts
|
|
12816
|
+
function fact2(input) {
|
|
12817
|
+
return createIndexerEvidenceAdapterFact({
|
|
12818
|
+
source_ref: input.sourceRef,
|
|
12819
|
+
module_ref: input.moduleRef,
|
|
12820
|
+
normalized_path: input.normalizedPath,
|
|
12821
|
+
qualified_item_path: input.qualifiedItemPath,
|
|
12822
|
+
kind: input.kind,
|
|
12823
|
+
signature: input.signature,
|
|
12824
|
+
payload: input.payload,
|
|
12825
|
+
denominator: input.denominator
|
|
12826
|
+
});
|
|
12827
|
+
}
|
|
12828
|
+
function semanticExtractionPayload(extraction) {
|
|
12829
|
+
return {
|
|
12830
|
+
version: extraction.version,
|
|
12831
|
+
meta: {
|
|
12832
|
+
pluginId: extraction.meta.pluginId,
|
|
12833
|
+
commitHash: extraction.meta.commitHash,
|
|
12834
|
+
language: extraction.meta.language
|
|
12835
|
+
},
|
|
12836
|
+
package: extraction.package,
|
|
12837
|
+
files: extraction.files,
|
|
12838
|
+
symbols: extraction.symbols,
|
|
12839
|
+
relations: extraction.relations,
|
|
12840
|
+
coverage: extraction.coverage,
|
|
12841
|
+
stats: extraction.stats
|
|
12842
|
+
};
|
|
12843
|
+
}
|
|
12844
|
+
function relationSourceFile(relation, symbols, filePaths) {
|
|
12845
|
+
if (filePaths.has(relation.from))
|
|
12846
|
+
return relation.from;
|
|
12847
|
+
const candidates = symbols.filter((symbol) => symbol.name === relation.from);
|
|
12848
|
+
if (candidates.length === 1)
|
|
12849
|
+
return candidates[0].file;
|
|
12850
|
+
if (relation.line !== undefined) {
|
|
12851
|
+
const containing = candidates.filter((symbol) => symbol.line <= relation.line && symbol.endLine >= relation.line);
|
|
12852
|
+
if (containing.length === 1)
|
|
12853
|
+
return containing[0].file;
|
|
12854
|
+
}
|
|
12855
|
+
return null;
|
|
12856
|
+
}
|
|
12857
|
+
function diagnosticPayload(diagnostic) {
|
|
12858
|
+
return {
|
|
12859
|
+
code: diagnostic.code,
|
|
12860
|
+
severity: diagnostic.severity,
|
|
12861
|
+
file: diagnostic.file,
|
|
12862
|
+
line: diagnostic.line,
|
|
12863
|
+
column: diagnostic.column
|
|
12864
|
+
};
|
|
12865
|
+
}
|
|
12866
|
+
function extractionResultToEvidenceAdapterResult(extraction, invocation) {
|
|
12867
|
+
const coverage = extraction.coverage;
|
|
12868
|
+
if (!coverage) {
|
|
12869
|
+
throw new TypeError("ExtractionResult coverage is required for Evidence Adapter Result conversion");
|
|
12870
|
+
}
|
|
12871
|
+
if (coverage.capabilities.length === 0) {
|
|
12872
|
+
throw new TypeError("ExtractionResult coverage must declare at least one parser capability");
|
|
12873
|
+
}
|
|
12874
|
+
const coverageByPath = new Map(coverage.files.map((file) => [file.path, file]));
|
|
12875
|
+
const fileInfoByPath = new Map(extraction.files.map((file) => [file.path, file]));
|
|
12876
|
+
const filePaths = new Set([...coverageByPath.keys(), ...fileInfoByPath.keys()]);
|
|
12877
|
+
for (const file of extraction.files) {
|
|
12878
|
+
if (!coverageByPath.has(file.path)) {
|
|
12879
|
+
throw new TypeError(`ExtractionResult file ${file.path} has no coverage disposition`);
|
|
12880
|
+
}
|
|
12881
|
+
}
|
|
12882
|
+
for (const symbol of extraction.symbols) {
|
|
12883
|
+
const disposition = coverageByPath.get(symbol.file)?.disposition;
|
|
12884
|
+
if (disposition !== "analyzed") {
|
|
12885
|
+
throw new TypeError(`ExtractionResult symbol ${symbol.name} belongs to a file without analyzed disposition`);
|
|
12886
|
+
}
|
|
12887
|
+
}
|
|
12888
|
+
const role = invocation.role ?? "primary-owner";
|
|
12889
|
+
const ownsDenominators = role === "primary-owner" && coverage.tier === "ast-catalog";
|
|
12890
|
+
const generatedDiagnostics = [];
|
|
12891
|
+
const relationsByFile = new Map;
|
|
12892
|
+
for (const relation of extraction.relations) {
|
|
12893
|
+
const file = relationSourceFile(relation, extraction.symbols, filePaths);
|
|
12894
|
+
if (file === null || coverageByPath.get(file)?.disposition !== "analyzed") {
|
|
12895
|
+
generatedDiagnostics.push({
|
|
12896
|
+
code: "relation-locator-unresolved",
|
|
12897
|
+
severity: "warning",
|
|
12898
|
+
detail_digest: indexerEvidenceAdapterProtocolDigest(relation)
|
|
12899
|
+
});
|
|
12900
|
+
continue;
|
|
12901
|
+
}
|
|
12902
|
+
const current = relationsByFile.get(file) ?? [];
|
|
12903
|
+
current.push(relation);
|
|
12904
|
+
relationsByFile.set(file, current);
|
|
12905
|
+
}
|
|
12906
|
+
const files = coverage.files.map((coverageFile) => {
|
|
12907
|
+
const normalizedPath2 = coverageFile.path;
|
|
12908
|
+
const fileRef = indexerEvidenceAdapterFileRef({
|
|
12909
|
+
source_ref: invocation.authorized_scope.source_ref,
|
|
12910
|
+
module_ref: invocation.module_ref,
|
|
12911
|
+
normalized_path: normalizedPath2
|
|
12912
|
+
});
|
|
12913
|
+
const fileInfo = fileInfoByPath.get(normalizedPath2);
|
|
12914
|
+
if (coverageFile.disposition === "analyzed" && !fileInfo) {
|
|
12915
|
+
throw new TypeError(`Analyzed file ${normalizedPath2} has no ExtractionResult file metadata`);
|
|
12916
|
+
}
|
|
12917
|
+
const facts = [];
|
|
12918
|
+
if (coverageFile.disposition === "analyzed" && fileInfo) {
|
|
12919
|
+
facts.push(fact2({
|
|
12920
|
+
sourceRef: invocation.authorized_scope.source_ref,
|
|
12921
|
+
moduleRef: invocation.module_ref,
|
|
12922
|
+
normalizedPath: normalizedPath2,
|
|
12923
|
+
qualifiedItemPath: "file",
|
|
12924
|
+
kind: "source-file",
|
|
12925
|
+
signature: { path: normalizedPath2, language: fileInfo.language },
|
|
12926
|
+
payload: fileInfo,
|
|
12927
|
+
denominator: ownsDenominators ? "eligible-file" : "none"
|
|
12928
|
+
}));
|
|
12929
|
+
facts.push(fact2({
|
|
12930
|
+
sourceRef: invocation.authorized_scope.source_ref,
|
|
12931
|
+
moduleRef: invocation.module_ref,
|
|
12932
|
+
normalizedPath: normalizedPath2,
|
|
12933
|
+
qualifiedItemPath: "loc",
|
|
12934
|
+
kind: "source-loc",
|
|
12935
|
+
signature: { path: normalizedPath2 },
|
|
12936
|
+
payload: { lines: fileInfo.lines },
|
|
12937
|
+
denominator: ownsDenominators ? "loc" : "none"
|
|
12938
|
+
}));
|
|
12939
|
+
for (const symbol of extraction.symbols.filter((item) => item.file === normalizedPath2)) {
|
|
12940
|
+
facts.push(fact2({
|
|
12941
|
+
sourceRef: invocation.authorized_scope.source_ref,
|
|
12942
|
+
moduleRef: invocation.module_ref,
|
|
12943
|
+
normalizedPath: normalizedPath2,
|
|
12944
|
+
qualifiedItemPath: `symbol:${symbol.kind}:${symbol.name}@${symbol.line}`,
|
|
12945
|
+
kind: "code-symbol",
|
|
12946
|
+
signature: {
|
|
12947
|
+
name: symbol.name,
|
|
12948
|
+
kind: symbol.kind,
|
|
12949
|
+
signature: symbol.signature ?? null,
|
|
12950
|
+
params: symbol.params ?? null,
|
|
12951
|
+
returnType: symbol.returnType ?? null,
|
|
12952
|
+
typeAnnotation: symbol.typeAnnotation ?? null
|
|
12953
|
+
},
|
|
12954
|
+
payload: symbol,
|
|
12955
|
+
denominator: ownsDenominators ? "symbol" : "none"
|
|
12956
|
+
}));
|
|
12957
|
+
}
|
|
12958
|
+
for (const relation of relationsByFile.get(normalizedPath2) ?? []) {
|
|
12959
|
+
facts.push(fact2({
|
|
12960
|
+
sourceRef: invocation.authorized_scope.source_ref,
|
|
12961
|
+
moduleRef: invocation.module_ref,
|
|
12962
|
+
normalizedPath: normalizedPath2,
|
|
12963
|
+
qualifiedItemPath: `relation:${relation.type}:${relation.from}->${relation.to}@${relation.line ?? 0}`,
|
|
12964
|
+
kind: "code-relation",
|
|
12965
|
+
signature: relation,
|
|
12966
|
+
payload: relation,
|
|
12967
|
+
denominator: "none"
|
|
12968
|
+
}));
|
|
12969
|
+
}
|
|
12970
|
+
}
|
|
12971
|
+
return {
|
|
12972
|
+
file_ref: fileRef,
|
|
12973
|
+
source_ref: invocation.authorized_scope.source_ref,
|
|
12974
|
+
module_ref: invocation.module_ref,
|
|
12975
|
+
normalized_path: normalizedPath2,
|
|
12976
|
+
role,
|
|
12977
|
+
coverage_tier: coverage.tier,
|
|
12978
|
+
disposition: coverageFile.disposition,
|
|
12979
|
+
facts
|
|
12980
|
+
};
|
|
12981
|
+
});
|
|
12982
|
+
const diagnostics = [
|
|
12983
|
+
...coverage.diagnostics.map((diagnostic) => {
|
|
12984
|
+
const coverageFile = coverageByPath.get(diagnostic.file);
|
|
12985
|
+
const fileRef = coverageFile ? indexerEvidenceAdapterFileRef({
|
|
12986
|
+
source_ref: invocation.authorized_scope.source_ref,
|
|
12987
|
+
module_ref: invocation.module_ref,
|
|
12988
|
+
normalized_path: diagnostic.file
|
|
12989
|
+
}) : undefined;
|
|
12990
|
+
return {
|
|
12991
|
+
code: diagnostic.code,
|
|
12992
|
+
severity: diagnostic.severity,
|
|
12993
|
+
detail_digest: indexerEvidenceAdapterProtocolDigest(diagnosticPayload(diagnostic)),
|
|
12994
|
+
...fileRef ? { fact_ref: fileRef } : {}
|
|
12995
|
+
};
|
|
12996
|
+
}),
|
|
12997
|
+
...generatedDiagnostics
|
|
12998
|
+
];
|
|
12999
|
+
const parserOutputDigest = indexerEvidenceAdapterProtocolDigest(semanticExtractionPayload(extraction));
|
|
13000
|
+
return buildIndexerEvidenceAdapterResult({
|
|
13001
|
+
protocol: "context.indexer.evidence-adapter-result/v1",
|
|
13002
|
+
adapter: invocation.adapter,
|
|
13003
|
+
authorized_scope: invocation.authorized_scope,
|
|
13004
|
+
input_digest: invocation.input_digest,
|
|
13005
|
+
precedence: invocation.precedence,
|
|
13006
|
+
files,
|
|
13007
|
+
diagnostics,
|
|
13008
|
+
toolchain: [{
|
|
13009
|
+
step: "parse-source",
|
|
13010
|
+
package: invocation.adapter.package,
|
|
13011
|
+
export: invocation.adapter.export,
|
|
13012
|
+
version: invocation.adapter.version,
|
|
13013
|
+
digest: invocation.adapter.digest,
|
|
13014
|
+
capabilities: coverage.capabilities,
|
|
13015
|
+
input_digest: invocation.input_digest,
|
|
13016
|
+
output_digest: parserOutputDigest
|
|
13017
|
+
}]
|
|
13018
|
+
});
|
|
13019
|
+
}
|
|
13020
|
+
// ../../node_modules/.bun/eslint-visitor-keys@5.0.1/node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
13021
|
+
var KEYS = {
|
|
13022
|
+
ArrayExpression: ["elements"],
|
|
13023
|
+
ArrayPattern: ["elements"],
|
|
13024
|
+
ArrowFunctionExpression: ["params", "body"],
|
|
13025
|
+
AssignmentExpression: ["left", "right"],
|
|
13026
|
+
AssignmentPattern: ["left", "right"],
|
|
13027
|
+
AwaitExpression: ["argument"],
|
|
13028
|
+
BinaryExpression: ["left", "right"],
|
|
13029
|
+
BlockStatement: ["body"],
|
|
13030
|
+
BreakStatement: ["label"],
|
|
13031
|
+
CallExpression: ["callee", "arguments"],
|
|
13032
|
+
CatchClause: ["param", "body"],
|
|
13033
|
+
ChainExpression: ["expression"],
|
|
13034
|
+
ClassBody: ["body"],
|
|
13035
|
+
ClassDeclaration: ["id", "superClass", "body"],
|
|
13036
|
+
ClassExpression: ["id", "superClass", "body"],
|
|
13037
|
+
ConditionalExpression: ["test", "consequent", "alternate"],
|
|
13038
|
+
ContinueStatement: ["label"],
|
|
13039
|
+
DebuggerStatement: [],
|
|
13040
|
+
DoWhileStatement: ["body", "test"],
|
|
13041
|
+
EmptyStatement: [],
|
|
13042
|
+
ExperimentalRestProperty: ["argument"],
|
|
13043
|
+
ExperimentalSpreadProperty: ["argument"],
|
|
13044
|
+
ExportAllDeclaration: ["exported", "source", "attributes"],
|
|
13045
|
+
ExportDefaultDeclaration: ["declaration"],
|
|
13046
|
+
ExportNamedDeclaration: [
|
|
13047
|
+
"declaration",
|
|
13048
|
+
"specifiers",
|
|
13049
|
+
"source",
|
|
13050
|
+
"attributes"
|
|
13051
|
+
],
|
|
13052
|
+
ExportSpecifier: ["local", "exported"],
|
|
13053
|
+
ExpressionStatement: ["expression"],
|
|
13054
|
+
ForInStatement: ["left", "right", "body"],
|
|
13055
|
+
ForOfStatement: ["left", "right", "body"],
|
|
13056
|
+
ForStatement: ["init", "test", "update", "body"],
|
|
13057
|
+
FunctionDeclaration: ["id", "params", "body"],
|
|
13058
|
+
FunctionExpression: ["id", "params", "body"],
|
|
13059
|
+
Identifier: [],
|
|
13060
|
+
IfStatement: ["test", "consequent", "alternate"],
|
|
13061
|
+
ImportAttribute: ["key", "value"],
|
|
13062
|
+
ImportDeclaration: ["specifiers", "source", "attributes"],
|
|
13063
|
+
ImportDefaultSpecifier: ["local"],
|
|
13064
|
+
ImportExpression: ["source", "options"],
|
|
13065
|
+
ImportNamespaceSpecifier: ["local"],
|
|
13066
|
+
ImportSpecifier: ["imported", "local"],
|
|
13067
|
+
JSXAttribute: ["name", "value"],
|
|
13068
|
+
JSXClosingElement: ["name"],
|
|
13069
|
+
JSXClosingFragment: [],
|
|
13070
|
+
JSXElement: ["openingElement", "children", "closingElement"],
|
|
13071
|
+
JSXEmptyExpression: [],
|
|
13072
|
+
JSXExpressionContainer: ["expression"],
|
|
13073
|
+
JSXFragment: ["openingFragment", "children", "closingFragment"],
|
|
13074
|
+
JSXIdentifier: [],
|
|
13075
|
+
JSXMemberExpression: ["object", "property"],
|
|
13076
|
+
JSXNamespacedName: ["namespace", "name"],
|
|
13077
|
+
JSXOpeningElement: ["name", "attributes"],
|
|
13078
|
+
JSXOpeningFragment: [],
|
|
13079
|
+
JSXSpreadAttribute: ["argument"],
|
|
13080
|
+
JSXSpreadChild: ["expression"],
|
|
13081
|
+
JSXText: [],
|
|
13082
|
+
LabeledStatement: ["label", "body"],
|
|
13083
|
+
Literal: [],
|
|
13084
|
+
LogicalExpression: ["left", "right"],
|
|
13085
|
+
MemberExpression: ["object", "property"],
|
|
13086
|
+
MetaProperty: ["meta", "property"],
|
|
13087
|
+
MethodDefinition: ["key", "value"],
|
|
13088
|
+
NewExpression: ["callee", "arguments"],
|
|
13089
|
+
ObjectExpression: ["properties"],
|
|
13090
|
+
ObjectPattern: ["properties"],
|
|
13091
|
+
PrivateIdentifier: [],
|
|
13092
|
+
Program: ["body"],
|
|
13093
|
+
Property: ["key", "value"],
|
|
13094
|
+
PropertyDefinition: ["key", "value"],
|
|
13095
|
+
RestElement: ["argument"],
|
|
13096
|
+
ReturnStatement: ["argument"],
|
|
13097
|
+
SequenceExpression: ["expressions"],
|
|
13098
|
+
SpreadElement: ["argument"],
|
|
13099
|
+
StaticBlock: ["body"],
|
|
13100
|
+
Super: [],
|
|
13101
|
+
SwitchCase: ["test", "consequent"],
|
|
13102
|
+
SwitchStatement: ["discriminant", "cases"],
|
|
13103
|
+
TaggedTemplateExpression: ["tag", "quasi"],
|
|
13104
|
+
TemplateElement: [],
|
|
13105
|
+
TemplateLiteral: ["quasis", "expressions"],
|
|
13106
|
+
ThisExpression: [],
|
|
13107
|
+
ThrowStatement: ["argument"],
|
|
13108
|
+
TryStatement: ["block", "handler", "finalizer"],
|
|
13109
|
+
UnaryExpression: ["argument"],
|
|
13110
|
+
UpdateExpression: ["argument"],
|
|
13111
|
+
VariableDeclaration: ["declarations"],
|
|
13112
|
+
VariableDeclarator: ["id", "init"],
|
|
13113
|
+
WhileStatement: ["test", "body"],
|
|
13114
|
+
WithStatement: ["object", "body"],
|
|
13115
|
+
YieldExpression: ["argument"]
|
|
13116
|
+
};
|
|
13117
|
+
var NODE_TYPES = Object.keys(KEYS);
|
|
13118
|
+
for (const type of NODE_TYPES) {
|
|
13119
|
+
Object.freeze(KEYS[type]);
|
|
13120
|
+
}
|
|
13121
|
+
Object.freeze(KEYS);
|
|
13122
|
+
var visitor_keys_default = KEYS;
|
|
13123
|
+
|
|
13124
|
+
// ../../node_modules/.bun/eslint-visitor-keys@5.0.1/node_modules/eslint-visitor-keys/lib/index.js
|
|
13125
|
+
var KEY_BLACKLIST = new Set([
|
|
13126
|
+
"parent",
|
|
13127
|
+
"leadingComments",
|
|
13128
|
+
"trailingComments"
|
|
13129
|
+
]);
|
|
13130
|
+
function unionWith(additionalKeys) {
|
|
13131
|
+
const retv = Object.assign({}, visitor_keys_default);
|
|
13132
|
+
for (const type of Object.keys(additionalKeys)) {
|
|
13133
|
+
if (Object.hasOwn(retv, type)) {
|
|
13134
|
+
const keys = new Set(additionalKeys[type]);
|
|
13135
|
+
for (const key of retv[type]) {
|
|
13136
|
+
keys.add(key);
|
|
13137
|
+
}
|
|
13138
|
+
retv[type] = Object.freeze(Array.from(keys));
|
|
13139
|
+
} else {
|
|
13140
|
+
retv[type] = Object.freeze(Array.from(additionalKeys[type]));
|
|
13141
|
+
}
|
|
13142
|
+
}
|
|
13143
|
+
return Object.freeze(retv);
|
|
13144
|
+
}
|
|
13145
|
+
|
|
13146
|
+
// ../../node_modules/.bun/toml-eslint-parser@1.0.3/node_modules/toml-eslint-parser/lib/index.mjs
|
|
13147
|
+
function last(arr) {
|
|
13148
|
+
return arr[arr.length - 1] ?? null;
|
|
13149
|
+
}
|
|
13150
|
+
var TOMLVerImpl = class {
|
|
13151
|
+
constructor(major, minor) {
|
|
13152
|
+
this.major = major;
|
|
13153
|
+
this.minor = minor;
|
|
13154
|
+
}
|
|
13155
|
+
lt(major, minor) {
|
|
13156
|
+
return this.major < major || this.major === major && this.minor < minor;
|
|
13157
|
+
}
|
|
13158
|
+
gte(major, minor) {
|
|
13159
|
+
return this.major > major || this.major === major && this.minor >= minor;
|
|
13160
|
+
}
|
|
13161
|
+
};
|
|
13162
|
+
var TOML_VERSION_1_0 = new TOMLVerImpl(1, 0);
|
|
13163
|
+
var TOML_VERSION_1_1 = new TOMLVerImpl(1, 1);
|
|
13164
|
+
var CodePoint = {
|
|
13165
|
+
EOF: -1,
|
|
13166
|
+
NULL: 0,
|
|
13167
|
+
SOH: 1,
|
|
13168
|
+
BACKSPACE: 8,
|
|
13169
|
+
TABULATION: 9,
|
|
13170
|
+
LINE_FEED: 10,
|
|
13171
|
+
FORM_FEED: 12,
|
|
13172
|
+
CARRIAGE_RETURN: 13,
|
|
13173
|
+
ESCAPE: 27,
|
|
13174
|
+
SO: 14,
|
|
13175
|
+
US: 31,
|
|
13176
|
+
SPACE: 32,
|
|
13177
|
+
QUOTATION_MARK: 34,
|
|
13178
|
+
HASH: 35,
|
|
13179
|
+
SINGLE_QUOTE: 39,
|
|
13180
|
+
PLUS_SIGN: 43,
|
|
13181
|
+
COMMA: 44,
|
|
13182
|
+
DASH: 45,
|
|
13183
|
+
DOT: 46,
|
|
13184
|
+
DIGIT_0: 48,
|
|
13185
|
+
DIGIT_1: 49,
|
|
13186
|
+
DIGIT_2: 50,
|
|
13187
|
+
DIGIT_3: 51,
|
|
13188
|
+
DIGIT_7: 55,
|
|
13189
|
+
DIGIT_9: 57,
|
|
13190
|
+
COLON: 58,
|
|
13191
|
+
EQUALS_SIGN: 61,
|
|
13192
|
+
LATIN_CAPITAL_A: 65,
|
|
13193
|
+
LATIN_CAPITAL_E: 69,
|
|
13194
|
+
LATIN_CAPITAL_F: 70,
|
|
13195
|
+
LATIN_CAPITAL_T: 84,
|
|
13196
|
+
LATIN_CAPITAL_U: 85,
|
|
13197
|
+
LATIN_CAPITAL_Z: 90,
|
|
13198
|
+
LEFT_BRACKET: 91,
|
|
13199
|
+
BACKSLASH: 92,
|
|
13200
|
+
RIGHT_BRACKET: 93,
|
|
13201
|
+
UNDERSCORE: 95,
|
|
13202
|
+
LATIN_SMALL_A: 97,
|
|
13203
|
+
LATIN_SMALL_B: 98,
|
|
13204
|
+
LATIN_SMALL_E: 101,
|
|
13205
|
+
LATIN_SMALL_F: 102,
|
|
13206
|
+
LATIN_SMALL_I: 105,
|
|
13207
|
+
LATIN_SMALL_L: 108,
|
|
13208
|
+
LATIN_SMALL_N: 110,
|
|
13209
|
+
LATIN_SMALL_O: 111,
|
|
13210
|
+
LATIN_SMALL_R: 114,
|
|
13211
|
+
LATIN_SMALL_S: 115,
|
|
13212
|
+
LATIN_SMALL_T: 116,
|
|
13213
|
+
LATIN_SMALL_U: 117,
|
|
13214
|
+
LATIN_SMALL_X: 120,
|
|
13215
|
+
LATIN_SMALL_Z: 122,
|
|
13216
|
+
LEFT_BRACE: 123,
|
|
13217
|
+
RIGHT_BRACE: 125,
|
|
13218
|
+
TILDE: 126,
|
|
13219
|
+
DELETE: 127,
|
|
13220
|
+
PAD: 128,
|
|
13221
|
+
SUPERSCRIPT_TWO: 178,
|
|
13222
|
+
SUPERSCRIPT_THREE: 179,
|
|
13223
|
+
SUPERSCRIPT_ONE: 185,
|
|
13224
|
+
VULGAR_FRACTION_ONE_QUARTER: 188,
|
|
13225
|
+
VULGAR_FRACTION_THREE_QUARTERS: 190,
|
|
13226
|
+
LATIN_CAPITAL_LETTER_A_WITH_GRAVE: 192,
|
|
13227
|
+
LATIN_CAPITAL_LETTER_O_WITH_DIAERESIS: 214,
|
|
13228
|
+
LATIN_CAPITAL_LETTER_O_WITH_STROKE: 216,
|
|
13229
|
+
LATIN_SMALL_LETTER_O_WITH_DIAERESIS: 246,
|
|
13230
|
+
LATIN_SMALL_LETTER_O_WITH_STROKE: 248,
|
|
13231
|
+
GREEK_SMALL_REVERSED_DOTTED_LUNATE_SIGMA_SYMBOL: 891,
|
|
13232
|
+
GREEK_CAPITAL_LETTER_YOT: 895,
|
|
13233
|
+
CP_1FFF: 8191,
|
|
13234
|
+
ZERO_WIDTH_NON_JOINER: 8204,
|
|
13235
|
+
ZERO_WIDTH_JOINER: 8205,
|
|
13236
|
+
UNDERTIE: 8255,
|
|
13237
|
+
CHARACTER_TIE: 8256,
|
|
13238
|
+
SUPERSCRIPT_ZERO: 8304,
|
|
13239
|
+
CP_218F: 8591,
|
|
13240
|
+
CIRCLED_DIGIT_ONE: 9312,
|
|
13241
|
+
NEGATIVE_CIRCLED_DIGIT_ZERO: 9471,
|
|
13242
|
+
GLAGOLITIC_CAPITAL_LETTER_AZU: 11264,
|
|
13243
|
+
CP_2FEF: 12271,
|
|
13244
|
+
IDEOGRAPHIC_COMMA: 12289,
|
|
13245
|
+
CP_D7FF: 55295,
|
|
13246
|
+
CP_E000: 57344,
|
|
13247
|
+
CJK_COMPATIBILITY_IDEOGRAPH_F900: 63744,
|
|
13248
|
+
ARABIC_LIGATURE_SALAAMUHU_ALAYNAA: 64975,
|
|
13249
|
+
ARABIC_LIGATURE_SALLA_USED_AS_KORANIC_STOP_SIGN_ISOLATED_FORM: 65008,
|
|
13250
|
+
REPLACEMENT_CHARACTER: 65533,
|
|
13251
|
+
LINEAR_B_SYLLABLE_B008_A: 65536,
|
|
13252
|
+
CP_EFFFF: 983039,
|
|
13253
|
+
CP_10FFFF: 1114111
|
|
13254
|
+
};
|
|
13255
|
+
var ESCAPES_1_0 = {
|
|
13256
|
+
[CodePoint.QUOTATION_MARK]: CodePoint.QUOTATION_MARK,
|
|
13257
|
+
[CodePoint.BACKSLASH]: CodePoint.BACKSLASH,
|
|
13258
|
+
[CodePoint.LATIN_SMALL_B]: CodePoint.BACKSPACE,
|
|
13259
|
+
[CodePoint.LATIN_SMALL_F]: CodePoint.FORM_FEED,
|
|
13260
|
+
[CodePoint.LATIN_SMALL_N]: CodePoint.LINE_FEED,
|
|
13261
|
+
[CodePoint.LATIN_SMALL_R]: CodePoint.CARRIAGE_RETURN,
|
|
13262
|
+
[CodePoint.LATIN_SMALL_T]: CodePoint.TABULATION
|
|
13263
|
+
};
|
|
13264
|
+
var ESCAPES_LATEST = {
|
|
13265
|
+
...ESCAPES_1_0,
|
|
13266
|
+
[CodePoint.LATIN_SMALL_E]: CodePoint.ESCAPE
|
|
13267
|
+
};
|
|
13268
|
+
var VALUE_KIND_VALUE = Symbol("VALUE_KIND_VALUE");
|
|
13269
|
+
var VALUE_KIND_INTERMEDIATE = Symbol("VALUE_KIND_INTERMEDIATE");
|
|
13270
|
+
var tomlKeys = {
|
|
13271
|
+
Program: ["body"],
|
|
13272
|
+
TOMLTopLevelTable: ["body"],
|
|
13273
|
+
TOMLTable: ["key", "body"],
|
|
13274
|
+
TOMLKeyValue: ["key", "value"],
|
|
13275
|
+
TOMLKey: ["keys"],
|
|
13276
|
+
TOMLArray: ["elements"],
|
|
13277
|
+
TOMLInlineTable: ["body"],
|
|
13278
|
+
TOMLBare: [],
|
|
13279
|
+
TOMLQuoted: [],
|
|
13280
|
+
TOMLValue: []
|
|
13281
|
+
};
|
|
13282
|
+
var KEYS2 = unionWith(tomlKeys);
|
|
13283
|
+
var getStaticTOMLValue = generateConvertTOMLValue((node2) => node2.value);
|
|
13284
|
+
function generateConvertTOMLValue(convertValue) {
|
|
13285
|
+
function resolveValue(node2, baseTable) {
|
|
13286
|
+
return resolver[node2.type](node2, baseTable);
|
|
13287
|
+
}
|
|
13288
|
+
const resolver = {
|
|
13289
|
+
Program(node2, baseTable = {}) {
|
|
13290
|
+
return resolveValue(node2.body[0], baseTable);
|
|
13291
|
+
},
|
|
13292
|
+
TOMLTopLevelTable(node2, baseTable = {}) {
|
|
13293
|
+
for (const body of node2.body)
|
|
13294
|
+
resolveValue(body, baseTable);
|
|
13295
|
+
return baseTable;
|
|
13296
|
+
},
|
|
13297
|
+
TOMLKeyValue(node2, baseTable = {}) {
|
|
13298
|
+
const value = resolveValue(node2.value);
|
|
13299
|
+
set(baseTable, resolveValue(node2.key), value);
|
|
13300
|
+
return baseTable;
|
|
13301
|
+
},
|
|
13302
|
+
TOMLTable(node2, baseTable = {}) {
|
|
13303
|
+
const table = getTable(baseTable, resolveValue(node2.key), node2.kind === "array");
|
|
13304
|
+
for (const body of node2.body)
|
|
13305
|
+
resolveValue(body, table);
|
|
13306
|
+
return baseTable;
|
|
13307
|
+
},
|
|
13308
|
+
TOMLArray(node2) {
|
|
13309
|
+
return node2.elements.map((e) => resolveValue(e));
|
|
13310
|
+
},
|
|
13311
|
+
TOMLInlineTable(node2) {
|
|
13312
|
+
const table = {};
|
|
13313
|
+
for (const body of node2.body)
|
|
13314
|
+
resolveValue(body, table);
|
|
13315
|
+
return table;
|
|
13316
|
+
},
|
|
13317
|
+
TOMLKey(node2) {
|
|
13318
|
+
return node2.keys.map((key) => resolveValue(key));
|
|
13319
|
+
},
|
|
13320
|
+
TOMLBare(node2) {
|
|
13321
|
+
return node2.name;
|
|
13322
|
+
},
|
|
13323
|
+
TOMLQuoted(node2) {
|
|
13324
|
+
return node2.value;
|
|
13325
|
+
},
|
|
13326
|
+
TOMLValue(node2) {
|
|
13327
|
+
return convertValue(node2);
|
|
13328
|
+
}
|
|
13329
|
+
};
|
|
13330
|
+
return (node2) => resolveValue(node2);
|
|
13331
|
+
}
|
|
13332
|
+
function getTable(baseTable, keys, array) {
|
|
13333
|
+
let target = baseTable;
|
|
13334
|
+
for (let index = 0;index < keys.length - 1; index++) {
|
|
13335
|
+
const key = keys[index];
|
|
13336
|
+
target = getNextTargetFromKey(target, key);
|
|
13337
|
+
}
|
|
13338
|
+
const lastKey = last(keys);
|
|
13339
|
+
const lastTarget = target[lastKey];
|
|
13340
|
+
if (lastTarget == null) {
|
|
13341
|
+
const tableValue$1 = {};
|
|
13342
|
+
target[lastKey] = array ? [tableValue$1] : tableValue$1;
|
|
13343
|
+
return tableValue$1;
|
|
13344
|
+
}
|
|
13345
|
+
if (isValue(lastTarget)) {
|
|
13346
|
+
const tableValue$1 = {};
|
|
13347
|
+
target[lastKey] = array ? [tableValue$1] : tableValue$1;
|
|
13348
|
+
return tableValue$1;
|
|
13349
|
+
}
|
|
13350
|
+
if (!array) {
|
|
13351
|
+
if (Array.isArray(lastTarget)) {
|
|
13352
|
+
const tableValue$1 = {};
|
|
13353
|
+
target[lastKey] = tableValue$1;
|
|
13354
|
+
return tableValue$1;
|
|
13355
|
+
}
|
|
13356
|
+
return lastTarget;
|
|
13357
|
+
}
|
|
13358
|
+
if (Array.isArray(lastTarget)) {
|
|
13359
|
+
const tableValue$1 = {};
|
|
13360
|
+
lastTarget.push(tableValue$1);
|
|
13361
|
+
return tableValue$1;
|
|
13362
|
+
}
|
|
13363
|
+
const tableValue = {};
|
|
13364
|
+
target[lastKey] = [tableValue];
|
|
13365
|
+
return tableValue;
|
|
13366
|
+
function getNextTargetFromKey(currTarget, key) {
|
|
13367
|
+
const nextTarget = currTarget[key];
|
|
13368
|
+
if (nextTarget == null) {
|
|
13369
|
+
const val = {};
|
|
13370
|
+
currTarget[key] = val;
|
|
13371
|
+
return val;
|
|
13372
|
+
}
|
|
13373
|
+
if (isValue(nextTarget)) {
|
|
13374
|
+
const val = {};
|
|
13375
|
+
currTarget[key] = val;
|
|
13376
|
+
return val;
|
|
13377
|
+
}
|
|
13378
|
+
let resultTarget = nextTarget;
|
|
13379
|
+
while (Array.isArray(resultTarget)) {
|
|
13380
|
+
const lastIndex = resultTarget.length - 1;
|
|
13381
|
+
const nextElement = resultTarget[lastIndex];
|
|
13382
|
+
if (isValue(nextElement)) {
|
|
13383
|
+
const val = {};
|
|
13384
|
+
resultTarget[lastIndex] = val;
|
|
13385
|
+
return val;
|
|
13386
|
+
}
|
|
13387
|
+
resultTarget = nextElement;
|
|
13388
|
+
}
|
|
13389
|
+
return resultTarget;
|
|
13390
|
+
}
|
|
13391
|
+
}
|
|
13392
|
+
function set(baseTable, keys, value) {
|
|
13393
|
+
let target = baseTable;
|
|
13394
|
+
for (let index = 0;index < keys.length - 1; index++) {
|
|
13395
|
+
const key = keys[index];
|
|
13396
|
+
const nextTarget = target[key];
|
|
13397
|
+
if (nextTarget == null) {
|
|
13398
|
+
const val = {};
|
|
13399
|
+
target[key] = val;
|
|
13400
|
+
target = val;
|
|
13401
|
+
} else if (isValue(nextTarget) || Array.isArray(nextTarget)) {
|
|
13402
|
+
const val = {};
|
|
13403
|
+
target[key] = val;
|
|
13404
|
+
target = val;
|
|
13405
|
+
} else
|
|
13406
|
+
target = nextTarget;
|
|
13407
|
+
}
|
|
13408
|
+
target[last(keys)] = value;
|
|
13409
|
+
}
|
|
13410
|
+
function isValue(value) {
|
|
13411
|
+
return typeof value !== "object" || value instanceof Date;
|
|
13412
|
+
}
|
|
13413
|
+
|
|
13414
|
+
// ../extract/src/configEvidenceParser.ts
|
|
13415
|
+
var import_yaml2 = __toESM(require_dist(), 1);
|
|
12319
13416
|
// ../extract/src/parser.ts
|
|
12320
|
-
import
|
|
13417
|
+
import * as WebTreeSitter from "web-tree-sitter";
|
|
12321
13418
|
import { existsSync } from "node:fs";
|
|
12322
13419
|
import { fileURLToPath } from "node:url";
|
|
13420
|
+
var treeSitterRuntime = WebTreeSitter;
|
|
13421
|
+
var Parser = treeSitterRuntime.default ?? treeSitterRuntime.Parser;
|
|
13422
|
+
if (!Parser) {
|
|
13423
|
+
throw new TypeError("web-tree-sitter runtime does not expose Parser");
|
|
13424
|
+
}
|
|
12323
13425
|
var parserInitPromise = null;
|
|
12324
13426
|
var parsedBytesSinceReset = 0;
|
|
12325
13427
|
var parserDead = false;
|
|
@@ -12329,9 +13431,13 @@ var createParserInstance = async () => {
|
|
|
12329
13431
|
const localWasm = resolveWasmPath("./wasm/tree-sitter.wasm");
|
|
12330
13432
|
const initOptions = existsSync(localWasm) ? { locateFile: (scriptName) => resolveWasmPath(`./wasm/${scriptName}`) } : undefined;
|
|
12331
13433
|
await Parser.init(initOptions);
|
|
13434
|
+
const LanguageRuntime = treeSitterRuntime.default?.Language ?? treeSitterRuntime.Language;
|
|
13435
|
+
if (!LanguageRuntime) {
|
|
13436
|
+
throw new TypeError("web-tree-sitter runtime does not expose Language after initialization");
|
|
13437
|
+
}
|
|
12332
13438
|
const parser = new Parser;
|
|
12333
|
-
const tsLanguage = await
|
|
12334
|
-
const tsxLanguage = await
|
|
13439
|
+
const tsLanguage = await LanguageRuntime.load(resolveWasmPath("./wasm/tree-sitter-typescript.wasm"));
|
|
13440
|
+
const tsxLanguage = await LanguageRuntime.load(resolveWasmPath("./wasm/tree-sitter-tsx.wasm"));
|
|
12335
13441
|
return { parser, tsLanguage, tsxLanguage };
|
|
12336
13442
|
};
|
|
12337
13443
|
var initParser = async () => {
|
|
@@ -12382,6 +13488,363 @@ var parseFile = async (source, isTsx) => {
|
|
|
12382
13488
|
return null;
|
|
12383
13489
|
}
|
|
12384
13490
|
};
|
|
13491
|
+
// src/commonJsModule.ts
|
|
13492
|
+
import ts2 from "typescript";
|
|
13493
|
+
|
|
13494
|
+
// src/typescriptAst.ts
|
|
13495
|
+
import ts from "typescript";
|
|
13496
|
+
var scriptKind = (filePath) => {
|
|
13497
|
+
const lower = filePath.toLowerCase();
|
|
13498
|
+
if (lower.endsWith(".tsx"))
|
|
13499
|
+
return ts.ScriptKind.TSX;
|
|
13500
|
+
if (lower.endsWith(".jsx"))
|
|
13501
|
+
return ts.ScriptKind.JSX;
|
|
13502
|
+
if (lower.endsWith(".js") || lower.endsWith(".mjs") || lower.endsWith(".cjs")) {
|
|
13503
|
+
return ts.ScriptKind.JS;
|
|
13504
|
+
}
|
|
13505
|
+
return ts.ScriptKind.TS;
|
|
13506
|
+
};
|
|
13507
|
+
var createEcmaScriptSourceFile = (source, filePath) => ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, scriptKind(filePath));
|
|
13508
|
+
var syntaxDiagnostics = (sourceFile) => {
|
|
13509
|
+
const diagnostics = sourceFile.parseDiagnostics ?? [];
|
|
13510
|
+
return diagnostics.map((diagnostic) => {
|
|
13511
|
+
const start = diagnostic.start ?? 0;
|
|
13512
|
+
const position = sourceFile.getLineAndCharacterOfPosition(start);
|
|
13513
|
+
return {
|
|
13514
|
+
code: "ecmascript-syntax-error",
|
|
13515
|
+
severity: "error",
|
|
13516
|
+
file: sourceFile.fileName,
|
|
13517
|
+
line: position.line + 1,
|
|
13518
|
+
column: position.character + 1
|
|
13519
|
+
};
|
|
13520
|
+
});
|
|
13521
|
+
};
|
|
13522
|
+
var nodeLocation = (sourceFile, node2) => {
|
|
13523
|
+
const start = sourceFile.getLineAndCharacterOfPosition(node2.getStart(sourceFile));
|
|
13524
|
+
const end = sourceFile.getLineAndCharacterOfPosition(node2.getEnd());
|
|
13525
|
+
return {
|
|
13526
|
+
line: start.line + 1,
|
|
13527
|
+
column: start.character + 1,
|
|
13528
|
+
endLine: end.line + 1
|
|
13529
|
+
};
|
|
13530
|
+
};
|
|
13531
|
+
var staticStringValue = (node2) => {
|
|
13532
|
+
if (!node2)
|
|
13533
|
+
return null;
|
|
13534
|
+
if (ts.isStringLiteral(node2) || ts.isNoSubstitutionTemplateLiteral(node2))
|
|
13535
|
+
return node2.text;
|
|
13536
|
+
return null;
|
|
13537
|
+
};
|
|
13538
|
+
|
|
13539
|
+
// src/commonJsModule.ts
|
|
13540
|
+
var requireCall = (node2) => ts2.isCallExpression(node2) && ts2.isIdentifier(node2.expression) && node2.expression.text === "require" ? node2 : null;
|
|
13541
|
+
var requireReference = (node2) => {
|
|
13542
|
+
const direct = requireCall(node2);
|
|
13543
|
+
if (direct) {
|
|
13544
|
+
const source = staticStringValue(direct.arguments[0]);
|
|
13545
|
+
return source ? { source, importedName: "*" } : null;
|
|
13546
|
+
}
|
|
13547
|
+
if (ts2.isPropertyAccessExpression(node2)) {
|
|
13548
|
+
const call = requireCall(node2.expression);
|
|
13549
|
+
const source = call ? staticStringValue(call.arguments[0]) : null;
|
|
13550
|
+
return source ? { source, importedName: node2.name.text } : null;
|
|
13551
|
+
}
|
|
13552
|
+
if (ts2.isElementAccessExpression(node2)) {
|
|
13553
|
+
const call = requireCall(node2.expression);
|
|
13554
|
+
const source = call ? staticStringValue(call.arguments[0]) : null;
|
|
13555
|
+
const importedName = staticStringValue(node2.argumentExpression);
|
|
13556
|
+
return source && importedName ? { source, importedName } : null;
|
|
13557
|
+
}
|
|
13558
|
+
return null;
|
|
13559
|
+
};
|
|
13560
|
+
var isModuleExports = (node2) => {
|
|
13561
|
+
if (ts2.isPropertyAccessExpression(node2) && ts2.isIdentifier(node2.expression) && node2.expression.text === "module" && node2.name.text === "exports")
|
|
13562
|
+
return true;
|
|
13563
|
+
return ts2.isElementAccessExpression(node2) && ts2.isIdentifier(node2.expression) && node2.expression.text === "module" && staticStringValue(node2.argumentExpression) === "exports";
|
|
13564
|
+
};
|
|
13565
|
+
var isExportsObject = (node2) => ts2.isIdentifier(node2) && node2.text === "exports" || isModuleExports(node2);
|
|
13566
|
+
var isUnsupportedExportMutationCall = (node2) => {
|
|
13567
|
+
if (ts2.isPropertyAccessExpression(node2.expression) && ts2.isIdentifier(node2.expression.expression) && node2.expression.expression.text === "Object" && ["assign", "defineProperties", "defineProperty"].includes(node2.expression.name.text) && node2.arguments[0] && isExportsObject(node2.arguments[0])) {
|
|
13568
|
+
return !(node2.expression.name.text === "defineProperty" && staticStringValue(node2.arguments[1]) === "__esModule");
|
|
13569
|
+
}
|
|
13570
|
+
return ts2.isIdentifier(node2.expression) && ["__createBinding", "__export", "__exportStar"].includes(node2.expression.text) && node2.arguments.some(isExportsObject);
|
|
13571
|
+
};
|
|
13572
|
+
var commonJsExportTarget = (node2) => {
|
|
13573
|
+
if (ts2.isPropertyAccessExpression(node2)) {
|
|
13574
|
+
if (ts2.isIdentifier(node2.expression) && node2.expression.text === "exports") {
|
|
13575
|
+
return { kind: "named", exportedName: node2.name.text };
|
|
13576
|
+
}
|
|
13577
|
+
if (isModuleExports(node2.expression)) {
|
|
13578
|
+
return { kind: "named", exportedName: node2.name.text };
|
|
13579
|
+
}
|
|
13580
|
+
if (isModuleExports(node2))
|
|
13581
|
+
return { kind: "whole" };
|
|
13582
|
+
}
|
|
13583
|
+
if (ts2.isElementAccessExpression(node2)) {
|
|
13584
|
+
const property = staticStringValue(node2.argumentExpression);
|
|
13585
|
+
if (ts2.isIdentifier(node2.expression) && node2.expression.text === "exports" && property) {
|
|
13586
|
+
return { kind: "named", exportedName: property };
|
|
13587
|
+
}
|
|
13588
|
+
if (isModuleExports(node2.expression) && property) {
|
|
13589
|
+
return { kind: "named", exportedName: property };
|
|
13590
|
+
}
|
|
13591
|
+
if (isModuleExports(node2))
|
|
13592
|
+
return { kind: "whole" };
|
|
13593
|
+
}
|
|
13594
|
+
return null;
|
|
13595
|
+
};
|
|
13596
|
+
var localReference = (expression, bindings) => {
|
|
13597
|
+
if (ts2.isIdentifier(expression)) {
|
|
13598
|
+
const binding = bindings.get(expression.text);
|
|
13599
|
+
if (binding) {
|
|
13600
|
+
return {
|
|
13601
|
+
source: binding.source,
|
|
13602
|
+
importedName: binding.importedName
|
|
13603
|
+
};
|
|
13604
|
+
}
|
|
13605
|
+
return { localName: expression.text };
|
|
13606
|
+
}
|
|
13607
|
+
if (ts2.isPropertyAccessExpression(expression) && ts2.isIdentifier(expression.expression)) {
|
|
13608
|
+
const binding = bindings.get(expression.expression.text);
|
|
13609
|
+
if (binding)
|
|
13610
|
+
return { source: binding.source, importedName: expression.name.text };
|
|
13611
|
+
}
|
|
13612
|
+
const required = requireReference(expression);
|
|
13613
|
+
return required ? { source: required.source, importedName: required.importedName } : null;
|
|
13614
|
+
};
|
|
13615
|
+
var syntheticDeclaration = (name, expression, sourceFile) => {
|
|
13616
|
+
const location = nodeLocation(sourceFile, expression);
|
|
13617
|
+
if (ts2.isFunctionExpression(expression) || ts2.isArrowFunction(expression)) {
|
|
13618
|
+
return {
|
|
13619
|
+
name,
|
|
13620
|
+
kind: "function",
|
|
13621
|
+
line: location.line,
|
|
13622
|
+
endLine: location.endLine,
|
|
13623
|
+
params: expression.parameters.map((parameter) => parameter.name.getText(sourceFile))
|
|
13624
|
+
};
|
|
13625
|
+
}
|
|
13626
|
+
if (ts2.isClassExpression(expression)) {
|
|
13627
|
+
return { name, kind: "class", line: location.line, endLine: location.endLine, params: [] };
|
|
13628
|
+
}
|
|
13629
|
+
if (ts2.isObjectLiteralExpression(expression) || ts2.isArrayLiteralExpression(expression) || ts2.isLiteralExpression(expression)) {
|
|
13630
|
+
return { name, kind: "variable", line: location.line, endLine: location.endLine, params: [] };
|
|
13631
|
+
}
|
|
13632
|
+
return null;
|
|
13633
|
+
};
|
|
13634
|
+
var pushExport = (result, exportedName, expression, line, bindings, sourceFile) => {
|
|
13635
|
+
const reference = localReference(expression, bindings);
|
|
13636
|
+
if (reference) {
|
|
13637
|
+
result.exports.push({ exportedName, ...reference, line });
|
|
13638
|
+
return true;
|
|
13639
|
+
}
|
|
13640
|
+
const synthetic = syntheticDeclaration(exportedName, expression, sourceFile);
|
|
13641
|
+
if (synthetic) {
|
|
13642
|
+
result.syntheticDeclarations.push(synthetic);
|
|
13643
|
+
result.exports.push({ exportedName, localName: exportedName, line });
|
|
13644
|
+
return true;
|
|
13645
|
+
}
|
|
13646
|
+
return false;
|
|
13647
|
+
};
|
|
13648
|
+
var appendUnsupportedExportDiagnostic = (result, sourceFile, node2) => {
|
|
13649
|
+
const location = nodeLocation(sourceFile, node2);
|
|
13650
|
+
if (result.diagnostics.some((diagnostic) => diagnostic.code === "dynamic-commonjs-require" && diagnostic.line === location.line && diagnostic.column === location.column))
|
|
13651
|
+
return;
|
|
13652
|
+
result.diagnostics.push({
|
|
13653
|
+
code: "unsupported-commonjs-export-expression",
|
|
13654
|
+
severity: "error",
|
|
13655
|
+
file: sourceFile.fileName,
|
|
13656
|
+
line: location.line,
|
|
13657
|
+
column: location.column
|
|
13658
|
+
});
|
|
13659
|
+
};
|
|
13660
|
+
var collectBindings = (sourceFile) => {
|
|
13661
|
+
const bindings = [];
|
|
13662
|
+
for (const statement of sourceFile.statements) {
|
|
13663
|
+
if (!ts2.isVariableStatement(statement))
|
|
13664
|
+
continue;
|
|
13665
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
13666
|
+
if (!declaration.initializer)
|
|
13667
|
+
continue;
|
|
13668
|
+
const line = nodeLocation(sourceFile, declaration).line;
|
|
13669
|
+
if (ts2.isIdentifier(declaration.name)) {
|
|
13670
|
+
const reference = requireReference(declaration.initializer);
|
|
13671
|
+
if (reference)
|
|
13672
|
+
bindings.push({ localName: declaration.name.text, ...reference, line });
|
|
13673
|
+
continue;
|
|
13674
|
+
}
|
|
13675
|
+
const direct = requireCall(declaration.initializer);
|
|
13676
|
+
const source = direct ? staticStringValue(direct.arguments[0]) : null;
|
|
13677
|
+
if (!source || !ts2.isObjectBindingPattern(declaration.name))
|
|
13678
|
+
continue;
|
|
13679
|
+
for (const element of declaration.name.elements) {
|
|
13680
|
+
if (!ts2.isIdentifier(element.name))
|
|
13681
|
+
continue;
|
|
13682
|
+
const importedName = element.propertyName?.getText(sourceFile) ?? element.name.text;
|
|
13683
|
+
bindings.push({ localName: element.name.text, source, importedName, line });
|
|
13684
|
+
}
|
|
13685
|
+
}
|
|
13686
|
+
}
|
|
13687
|
+
return bindings;
|
|
13688
|
+
};
|
|
13689
|
+
var collectDynamicDiagnostics = (sourceFile) => {
|
|
13690
|
+
const diagnostics = [];
|
|
13691
|
+
const visit = (node2) => {
|
|
13692
|
+
if (ts2.isCallExpression(node2) && ts2.isIdentifier(node2.expression) && node2.expression.text === "require") {
|
|
13693
|
+
if (staticStringValue(node2.arguments[0]) === null) {
|
|
13694
|
+
const location = nodeLocation(sourceFile, node2);
|
|
13695
|
+
diagnostics.push({
|
|
13696
|
+
code: "dynamic-commonjs-require",
|
|
13697
|
+
severity: "error",
|
|
13698
|
+
file: sourceFile.fileName,
|
|
13699
|
+
line: location.line,
|
|
13700
|
+
column: location.column
|
|
13701
|
+
});
|
|
13702
|
+
}
|
|
13703
|
+
}
|
|
13704
|
+
if (ts2.isCallExpression(node2) && isUnsupportedExportMutationCall(node2)) {
|
|
13705
|
+
const location = nodeLocation(sourceFile, node2);
|
|
13706
|
+
diagnostics.push({
|
|
13707
|
+
code: "unsupported-commonjs-export-form",
|
|
13708
|
+
severity: "error",
|
|
13709
|
+
file: sourceFile.fileName,
|
|
13710
|
+
line: location.line,
|
|
13711
|
+
column: location.column
|
|
13712
|
+
});
|
|
13713
|
+
}
|
|
13714
|
+
if (ts2.isBinaryExpression(node2) && node2.operatorToken.kind === ts2.SyntaxKind.EqualsToken) {
|
|
13715
|
+
if (ts2.isElementAccessExpression(node2.left)) {
|
|
13716
|
+
const isCommonJsTarget = ts2.isIdentifier(node2.left.expression) && node2.left.expression.text === "exports" || isModuleExports(node2.left.expression) || isModuleExports(node2.left);
|
|
13717
|
+
if (isCommonJsTarget && commonJsExportTarget(node2.left) === null) {
|
|
13718
|
+
const location = nodeLocation(sourceFile, node2.left);
|
|
13719
|
+
diagnostics.push({
|
|
13720
|
+
code: "dynamic-commonjs-export",
|
|
13721
|
+
severity: "error",
|
|
13722
|
+
file: sourceFile.fileName,
|
|
13723
|
+
line: location.line,
|
|
13724
|
+
column: location.column
|
|
13725
|
+
});
|
|
13726
|
+
}
|
|
13727
|
+
}
|
|
13728
|
+
}
|
|
13729
|
+
ts2.forEachChild(node2, visit);
|
|
13730
|
+
};
|
|
13731
|
+
visit(sourceFile);
|
|
13732
|
+
return diagnostics;
|
|
13733
|
+
};
|
|
13734
|
+
var analyzeCommonJsModule = (source, filePath) => {
|
|
13735
|
+
const sourceFile = createEcmaScriptSourceFile(source, filePath);
|
|
13736
|
+
const bindings = collectBindings(sourceFile);
|
|
13737
|
+
const bindingMap = new Map(bindings.map((binding) => [binding.localName, binding]));
|
|
13738
|
+
const result = {
|
|
13739
|
+
bindings,
|
|
13740
|
+
exports: [],
|
|
13741
|
+
wildcardSources: [],
|
|
13742
|
+
syntheticDeclarations: [],
|
|
13743
|
+
diagnostics: collectDynamicDiagnostics(sourceFile)
|
|
13744
|
+
};
|
|
13745
|
+
for (const statement of sourceFile.statements) {
|
|
13746
|
+
if (!ts2.isExpressionStatement(statement) || !ts2.isBinaryExpression(statement.expression))
|
|
13747
|
+
continue;
|
|
13748
|
+
const assignment = statement.expression;
|
|
13749
|
+
if (assignment.operatorToken.kind !== ts2.SyntaxKind.EqualsToken)
|
|
13750
|
+
continue;
|
|
13751
|
+
const target = commonJsExportTarget(assignment.left);
|
|
13752
|
+
if (!target)
|
|
13753
|
+
continue;
|
|
13754
|
+
const line = nodeLocation(sourceFile, assignment).line;
|
|
13755
|
+
if (target.kind === "named") {
|
|
13756
|
+
if (!pushExport(result, target.exportedName, assignment.right, line, bindingMap, sourceFile)) {
|
|
13757
|
+
appendUnsupportedExportDiagnostic(result, sourceFile, assignment.right);
|
|
13758
|
+
}
|
|
13759
|
+
continue;
|
|
13760
|
+
}
|
|
13761
|
+
const directRequire = requireReference(assignment.right);
|
|
13762
|
+
if (directRequire?.importedName === "*") {
|
|
13763
|
+
result.wildcardSources.push(directRequire.source);
|
|
13764
|
+
continue;
|
|
13765
|
+
}
|
|
13766
|
+
if (ts2.isObjectLiteralExpression(assignment.right)) {
|
|
13767
|
+
for (const property of assignment.right.properties) {
|
|
13768
|
+
if (ts2.isShorthandPropertyAssignment(property)) {
|
|
13769
|
+
pushExport(result, property.name.text, property.name, line, bindingMap, sourceFile);
|
|
13770
|
+
continue;
|
|
13771
|
+
}
|
|
13772
|
+
if (ts2.isPropertyAssignment(property)) {
|
|
13773
|
+
const name = property.name && (ts2.isIdentifier(property.name) || ts2.isStringLiteral(property.name)) ? property.name.text : null;
|
|
13774
|
+
if (name) {
|
|
13775
|
+
if (!pushExport(result, name, property.initializer, line, bindingMap, sourceFile)) {
|
|
13776
|
+
appendUnsupportedExportDiagnostic(result, sourceFile, property.initializer);
|
|
13777
|
+
}
|
|
13778
|
+
} else {
|
|
13779
|
+
appendUnsupportedExportDiagnostic(result, sourceFile, property);
|
|
13780
|
+
}
|
|
13781
|
+
continue;
|
|
13782
|
+
}
|
|
13783
|
+
if (ts2.isMethodDeclaration(property) && property.name && ts2.isIdentifier(property.name)) {
|
|
13784
|
+
const location = nodeLocation(sourceFile, property);
|
|
13785
|
+
result.syntheticDeclarations.push({
|
|
13786
|
+
name: property.name.text,
|
|
13787
|
+
kind: "function",
|
|
13788
|
+
line: location.line,
|
|
13789
|
+
endLine: location.endLine,
|
|
13790
|
+
params: property.parameters.map((parameter) => parameter.name.getText(sourceFile))
|
|
13791
|
+
});
|
|
13792
|
+
result.exports.push({
|
|
13793
|
+
exportedName: property.name.text,
|
|
13794
|
+
localName: property.name.text,
|
|
13795
|
+
line
|
|
13796
|
+
});
|
|
13797
|
+
continue;
|
|
13798
|
+
}
|
|
13799
|
+
appendUnsupportedExportDiagnostic(result, sourceFile, property);
|
|
13800
|
+
}
|
|
13801
|
+
continue;
|
|
13802
|
+
}
|
|
13803
|
+
if (ts2.isIdentifier(assignment.right)) {
|
|
13804
|
+
const binding = bindingMap.get(assignment.right.text);
|
|
13805
|
+
if (binding?.importedName === "*") {
|
|
13806
|
+
result.wildcardSources.push(binding.source);
|
|
13807
|
+
continue;
|
|
13808
|
+
}
|
|
13809
|
+
if (!pushExport(result, assignment.right.text, assignment.right, line, bindingMap, sourceFile)) {
|
|
13810
|
+
appendUnsupportedExportDiagnostic(result, sourceFile, assignment.right);
|
|
13811
|
+
}
|
|
13812
|
+
continue;
|
|
13813
|
+
}
|
|
13814
|
+
if (!pushExport(result, "default", assignment.right, line, bindingMap, sourceFile)) {
|
|
13815
|
+
appendUnsupportedExportDiagnostic(result, sourceFile, assignment.right);
|
|
13816
|
+
}
|
|
13817
|
+
}
|
|
13818
|
+
result.bindings.sort((left, right) => left.localName.localeCompare(right.localName));
|
|
13819
|
+
result.exports.sort((left, right) => left.exportedName.localeCompare(right.exportedName) || left.line - right.line);
|
|
13820
|
+
result.wildcardSources = [...new Set(result.wildcardSources)].sort();
|
|
13821
|
+
result.syntheticDeclarations.sort((left, right) => left.name.localeCompare(right.name));
|
|
13822
|
+
result.diagnostics.sort((left, right) => left.line - right.line || left.column - right.column);
|
|
13823
|
+
return result;
|
|
13824
|
+
};
|
|
13825
|
+
|
|
13826
|
+
// src/commonJsExportTrace.ts
|
|
13827
|
+
var traceCommonJsExports = async (input) => {
|
|
13828
|
+
const traced = [];
|
|
13829
|
+
for (const item of input.analysis.exports) {
|
|
13830
|
+
if (item.localName && input.localDeclarations.has(item.localName)) {
|
|
13831
|
+
traced.push({
|
|
13832
|
+
exportedName: item.exportedName,
|
|
13833
|
+
localName: item.localName,
|
|
13834
|
+
declarationFile: input.filePath
|
|
13835
|
+
});
|
|
13836
|
+
continue;
|
|
13837
|
+
}
|
|
13838
|
+
if (item.source && item.importedName) {
|
|
13839
|
+
traced.push(...await input.traceImported(item.source, item.importedName, item.exportedName));
|
|
13840
|
+
}
|
|
13841
|
+
}
|
|
13842
|
+
for (const source of input.analysis.wildcardSources) {
|
|
13843
|
+
traced.push(...await input.traceWildcard(source));
|
|
13844
|
+
}
|
|
13845
|
+
return traced;
|
|
13846
|
+
};
|
|
13847
|
+
|
|
12385
13848
|
// src/exportTracer.ts
|
|
12386
13849
|
var DECLARATION_TYPES = new Set([
|
|
12387
13850
|
"function_declaration",
|
|
@@ -12499,12 +13962,24 @@ var traceFile = async (filePath, fs, state) => {
|
|
|
12499
13962
|
state.inFlight.add(filePath);
|
|
12500
13963
|
state.files.add(filePath);
|
|
12501
13964
|
const source = await fs.readFile(filePath);
|
|
12502
|
-
const
|
|
13965
|
+
const commonJs = analyzeCommonJsModule(source, filePath);
|
|
13966
|
+
if (commonJs.diagnostics.length > 0)
|
|
13967
|
+
return [];
|
|
13968
|
+
const tree = await parseFile(source, isJsxLikePath(filePath));
|
|
12503
13969
|
if (!tree)
|
|
12504
13970
|
return [];
|
|
12505
13971
|
const root = tree.rootNode;
|
|
12506
13972
|
const localDeclarations = collectLocalDeclarations(root);
|
|
12507
13973
|
const importBindings = collectImportBindings(root);
|
|
13974
|
+
for (const declaration of commonJs.syntheticDeclarations) {
|
|
13975
|
+
localDeclarations.set(declaration.name, declaration.name);
|
|
13976
|
+
}
|
|
13977
|
+
for (const binding of commonJs.bindings) {
|
|
13978
|
+
importBindings.set(binding.localName, {
|
|
13979
|
+
source: binding.source,
|
|
13980
|
+
importedName: binding.importedName
|
|
13981
|
+
});
|
|
13982
|
+
}
|
|
12508
13983
|
const exportsList = [];
|
|
12509
13984
|
for (const node2 of root.namedChildren) {
|
|
12510
13985
|
if (node2.type !== "export_statement")
|
|
@@ -12576,6 +14051,16 @@ var traceFile = async (filePath, fs, state) => {
|
|
|
12576
14051
|
});
|
|
12577
14052
|
}
|
|
12578
14053
|
}
|
|
14054
|
+
exportsList.push(...await traceCommonJsExports({
|
|
14055
|
+
analysis: commonJs,
|
|
14056
|
+
filePath,
|
|
14057
|
+
localDeclarations,
|
|
14058
|
+
traceImported: (source2, importedName, exportedName) => traceImportedBinding(filePath, { source: source2, importedName }, exportedName, fs, state),
|
|
14059
|
+
traceWildcard: async (source2) => {
|
|
14060
|
+
const targetPath = await resolveImportSourcePath(filePath, source2, fs, state.resolver);
|
|
14061
|
+
return targetPath ? traceFile(targetPath, fs, state) : [];
|
|
14062
|
+
}
|
|
14063
|
+
}));
|
|
12579
14064
|
state.inFlight.delete(filePath);
|
|
12580
14065
|
return uniqueExports(exportsList);
|
|
12581
14066
|
})();
|
|
@@ -12727,7 +14212,7 @@ var appendTypeRelations = (relations, relationType, from, typeText, importBindin
|
|
|
12727
14212
|
}
|
|
12728
14213
|
};
|
|
12729
14214
|
var classifyVariable = (name, filePath) => {
|
|
12730
|
-
if (filePath.endsWith(".tsx") && /^[A-Z]/.test(name)) {
|
|
14215
|
+
if ((filePath.endsWith(".tsx") || filePath.endsWith(".jsx")) && /^[A-Z]/.test(name)) {
|
|
12731
14216
|
return "component" /* Component */;
|
|
12732
14217
|
}
|
|
12733
14218
|
return "variable" /* Variable */;
|
|
@@ -12887,6 +14372,146 @@ var findObjectTypeNodes = (node2) => {
|
|
|
12887
14372
|
return [];
|
|
12888
14373
|
};
|
|
12889
14374
|
|
|
14375
|
+
// src/staticCallRelations.ts
|
|
14376
|
+
import ts3 from "typescript";
|
|
14377
|
+
var callTarget = (expression, sourceFile) => {
|
|
14378
|
+
if (ts3.isIdentifier(expression))
|
|
14379
|
+
return expression.text === "require" ? null : expression.text;
|
|
14380
|
+
if (ts3.isPropertyAccessExpression(expression))
|
|
14381
|
+
return expression.getText(sourceFile).replace(/\s+/gu, "");
|
|
14382
|
+
if (ts3.isElementAccessExpression(expression)) {
|
|
14383
|
+
const property = staticStringValue(expression.argumentExpression);
|
|
14384
|
+
return property ? `${expression.expression.getText(sourceFile).replace(/\s+/gu, "")}.${property}` : null;
|
|
14385
|
+
}
|
|
14386
|
+
return null;
|
|
14387
|
+
};
|
|
14388
|
+
var rootIdentifier = (expression) => {
|
|
14389
|
+
let current = expression;
|
|
14390
|
+
while (ts3.isPropertyAccessExpression(current) || ts3.isElementAccessExpression(current)) {
|
|
14391
|
+
current = current.expression;
|
|
14392
|
+
}
|
|
14393
|
+
return ts3.isIdentifier(current) ? current.text : null;
|
|
14394
|
+
};
|
|
14395
|
+
var declarationName = (node2, sourceFile) => {
|
|
14396
|
+
if (ts3.isFunctionDeclaration(node2) && node2.name)
|
|
14397
|
+
return node2.name.text;
|
|
14398
|
+
if (ts3.isClassDeclaration(node2) && node2.name)
|
|
14399
|
+
return node2.name.text;
|
|
14400
|
+
if (ts3.isVariableDeclaration(node2) && ts3.isIdentifier(node2.name))
|
|
14401
|
+
return node2.name.text;
|
|
14402
|
+
if (ts3.isMethodDeclaration(node2) || ts3.isGetAccessorDeclaration(node2) || ts3.isSetAccessorDeclaration(node2)) {
|
|
14403
|
+
const parent = node2.parent;
|
|
14404
|
+
if (parent && ts3.isClassDeclaration(parent) && parent.name)
|
|
14405
|
+
return parent.name.text;
|
|
14406
|
+
return node2.name?.getText(sourceFile) ?? null;
|
|
14407
|
+
}
|
|
14408
|
+
return null;
|
|
14409
|
+
};
|
|
14410
|
+
var collectStaticCallRelations = (source, filePath, importBindings) => {
|
|
14411
|
+
const sourceFile = createEcmaScriptSourceFile(source, filePath);
|
|
14412
|
+
const relations = [];
|
|
14413
|
+
const visit = (node2, owner) => {
|
|
14414
|
+
const namedOwner = declarationName(node2, sourceFile) ?? owner;
|
|
14415
|
+
if (ts3.isCallExpression(node2) || ts3.isNewExpression(node2)) {
|
|
14416
|
+
const target = callTarget(node2.expression, sourceFile);
|
|
14417
|
+
if (target) {
|
|
14418
|
+
const root = rootIdentifier(node2.expression);
|
|
14419
|
+
const isExternal = root ? importBindings.get(root)?.isExternal ?? false : false;
|
|
14420
|
+
relations.push(createRelation("calls" /* Calls */, namedOwner, target, isExternal, nodeLocation(sourceFile, node2).line));
|
|
14421
|
+
}
|
|
14422
|
+
}
|
|
14423
|
+
ts3.forEachChild(node2, (child) => visit(child, namedOwner));
|
|
14424
|
+
};
|
|
14425
|
+
visit(sourceFile, filePath);
|
|
14426
|
+
const seen = new Set;
|
|
14427
|
+
return relations.sort((left, right) => (left.line ?? 0) - (right.line ?? 0) || left.from.localeCompare(right.from) || left.to.localeCompare(right.to)).filter((relation) => {
|
|
14428
|
+
const key = `${relation.from}\x00${relation.to}\x00${relation.line ?? 0}`;
|
|
14429
|
+
if (seen.has(key))
|
|
14430
|
+
return false;
|
|
14431
|
+
seen.add(key);
|
|
14432
|
+
return true;
|
|
14433
|
+
});
|
|
14434
|
+
};
|
|
14435
|
+
|
|
14436
|
+
// src/symbolExtractorImports.ts
|
|
14437
|
+
var esmImportParts = (node2, bindings, isExternal, statementTypeOnly) => {
|
|
14438
|
+
let hasValueImport = !statementTypeOnly;
|
|
14439
|
+
let hasTypeImport = statementTypeOnly;
|
|
14440
|
+
const clause = node2.namedChildren.find((child) => child.type === "import_clause");
|
|
14441
|
+
for (const part of clause?.namedChildren ?? []) {
|
|
14442
|
+
if (part.type === "identifier") {
|
|
14443
|
+
bindings.set(part.text, { isExternal, typeOnly: statementTypeOnly });
|
|
14444
|
+
continue;
|
|
14445
|
+
}
|
|
14446
|
+
if (part.type === "namespace_import") {
|
|
14447
|
+
const identifier = part.namedChildren.find((child) => child.type === "identifier");
|
|
14448
|
+
if (identifier)
|
|
14449
|
+
bindings.set(identifier.text, { isExternal, typeOnly: statementTypeOnly });
|
|
14450
|
+
continue;
|
|
14451
|
+
}
|
|
14452
|
+
if (part.type !== "named_imports")
|
|
14453
|
+
continue;
|
|
14454
|
+
for (const specifierNode of part.namedChildren.filter((child) => child.type === "import_specifier")) {
|
|
14455
|
+
const identifiers = specifierNode.namedChildren.filter((child) => child.type === "identifier" || child.type === "type_identifier").map((child) => child.text);
|
|
14456
|
+
const localName = identifiers[1] ?? identifiers[0];
|
|
14457
|
+
if (!localName)
|
|
14458
|
+
continue;
|
|
14459
|
+
const typeOnly = statementTypeOnly || specifierNode.text.trim().startsWith("type ");
|
|
14460
|
+
bindings.set(localName, { isExternal, typeOnly });
|
|
14461
|
+
hasValueImport ||= !typeOnly;
|
|
14462
|
+
hasTypeImport ||= typeOnly;
|
|
14463
|
+
}
|
|
14464
|
+
}
|
|
14465
|
+
return { hasValueImport, hasTypeImport };
|
|
14466
|
+
};
|
|
14467
|
+
var appendEsmImport = async (input) => {
|
|
14468
|
+
const specifierNode = input.node.namedChildren.find((child) => child.type === "string");
|
|
14469
|
+
if (!specifierNode)
|
|
14470
|
+
return;
|
|
14471
|
+
const specifier = specifierNode.text.replace(/^['"]/, "").replace(/['"]$/, "");
|
|
14472
|
+
const resolvedAlias = isRelativeModuleSpecifier(specifier) ? null : await resolveImportSourcePath(input.filePath, specifier, input.fs, input.resolver);
|
|
14473
|
+
const isExternal = !isRelativeModuleSpecifier(specifier) && resolvedAlias === null;
|
|
14474
|
+
const statementTypeOnly = input.node.text.startsWith("import type ");
|
|
14475
|
+
const parts = esmImportParts(input.node, input.bindings, isExternal, statementTypeOnly);
|
|
14476
|
+
if (parts.hasValueImport) {
|
|
14477
|
+
input.relations.push(createRelation("imports" /* Imports */, "", resolvedAlias ?? specifier, isExternal, getLine(input.node)));
|
|
14478
|
+
}
|
|
14479
|
+
if (parts.hasTypeImport) {
|
|
14480
|
+
input.relations.push(createRelation("imports_type" /* ImportsType */, "", resolvedAlias ?? specifier, isExternal, getLine(input.node)));
|
|
14481
|
+
}
|
|
14482
|
+
};
|
|
14483
|
+
var appendCommonJsImports = async (input) => {
|
|
14484
|
+
const recordedSources = new Set;
|
|
14485
|
+
for (const binding of input.commonJs.bindings) {
|
|
14486
|
+
const resolved = await resolveImportSourcePath(input.filePath, binding.source, input.fs, input.resolver);
|
|
14487
|
+
const isExternal = !isRelativeModuleSpecifier(binding.source) && resolved === null;
|
|
14488
|
+
input.bindings.set(binding.localName, { isExternal, typeOnly: false });
|
|
14489
|
+
if (recordedSources.has(binding.source))
|
|
14490
|
+
continue;
|
|
14491
|
+
recordedSources.add(binding.source);
|
|
14492
|
+
input.relations.push(createRelation("imports" /* Imports */, "", resolved ?? binding.source, isExternal, binding.line));
|
|
14493
|
+
}
|
|
14494
|
+
const remainingSources = [...new Set([
|
|
14495
|
+
...input.commonJs.wildcardSources,
|
|
14496
|
+
...input.commonJs.exports.flatMap((item) => item.source ? [item.source] : [])
|
|
14497
|
+
])].sort();
|
|
14498
|
+
for (const source of remainingSources) {
|
|
14499
|
+
if (recordedSources.has(source))
|
|
14500
|
+
continue;
|
|
14501
|
+
const resolved = await resolveImportSourcePath(input.filePath, source, input.fs, input.resolver);
|
|
14502
|
+
const isExternal = !isRelativeModuleSpecifier(source) && resolved === null;
|
|
14503
|
+
input.relations.push(createRelation("imports" /* Imports */, "", resolved ?? source, isExternal, input.commonJs.exports.find((item) => item.source === source)?.line ?? 1));
|
|
14504
|
+
}
|
|
14505
|
+
};
|
|
14506
|
+
var collectImportBindings2 = async (root, filePath, fs, resolver, relations, commonJs) => {
|
|
14507
|
+
const bindings = new Map;
|
|
14508
|
+
for (const node2 of root.namedChildren.filter((child) => child.type === "import_statement")) {
|
|
14509
|
+
await appendEsmImport({ node: node2, filePath, fs, resolver, bindings, relations });
|
|
14510
|
+
}
|
|
14511
|
+
await appendCommonJsImports({ commonJs, filePath, fs, resolver, bindings, relations });
|
|
14512
|
+
return bindings;
|
|
14513
|
+
};
|
|
14514
|
+
|
|
12890
14515
|
// src/symbolExtractorAnalyze.ts
|
|
12891
14516
|
var analyzeDeclaration = (node2, filePath, declarations, importBindings, relations) => {
|
|
12892
14517
|
if (node2.type === "lexical_declaration") {
|
|
@@ -12971,7 +14596,7 @@ var analyzeFunctionDeclaration = (node2, name, filePath, declarations, importBin
|
|
|
12971
14596
|
declarations.set(name, {
|
|
12972
14597
|
info: {
|
|
12973
14598
|
name,
|
|
12974
|
-
kind: "function" /* Function */,
|
|
14599
|
+
kind: isJsxLikePath(filePath) && /^[A-Z]/u.test(name) && containsJsx(node2) ? "component" /* Component */ : "function" /* Function */,
|
|
12975
14600
|
visibility: "internal" /* Internal */,
|
|
12976
14601
|
file: filePath,
|
|
12977
14602
|
line: getLine(node2),
|
|
@@ -13078,68 +14703,61 @@ var analyzeEnumDeclaration = (node2, name, symbolDoc, filePath, declarations) =>
|
|
|
13078
14703
|
}
|
|
13079
14704
|
});
|
|
13080
14705
|
};
|
|
13081
|
-
var
|
|
13082
|
-
const
|
|
13083
|
-
|
|
13084
|
-
const specifierNode = node2.namedChildren.find((child) => child.type === "string");
|
|
13085
|
-
if (!specifierNode)
|
|
14706
|
+
var appendCommonJsSyntheticDeclarations = (commonJs, filePath, declarations) => {
|
|
14707
|
+
for (const declaration of commonJs.syntheticDeclarations) {
|
|
14708
|
+
if (declarations.has(declaration.name))
|
|
13086
14709
|
continue;
|
|
13087
|
-
|
|
13088
|
-
|
|
13089
|
-
|
|
13090
|
-
|
|
13091
|
-
|
|
13092
|
-
|
|
13093
|
-
|
|
13094
|
-
|
|
13095
|
-
|
|
13096
|
-
if (part.type === "identifier") {
|
|
13097
|
-
bindings.set(part.text, { isExternal, typeOnly: statementTypeOnly });
|
|
13098
|
-
continue;
|
|
13099
|
-
}
|
|
13100
|
-
if (part.type === "namespace_import") {
|
|
13101
|
-
const identifier = part.namedChildren.find((child) => child.type === "identifier");
|
|
13102
|
-
if (identifier) {
|
|
13103
|
-
bindings.set(identifier.text, { isExternal, typeOnly: statementTypeOnly });
|
|
13104
|
-
}
|
|
13105
|
-
continue;
|
|
13106
|
-
}
|
|
13107
|
-
if (part.type !== "named_imports")
|
|
13108
|
-
continue;
|
|
13109
|
-
for (const specifierNode2 of part.namedChildren.filter((child) => child.type === "import_specifier")) {
|
|
13110
|
-
const identifiers = specifierNode2.namedChildren.filter((child) => child.type === "identifier" || child.type === "type_identifier").map((child) => child.text);
|
|
13111
|
-
const localName = identifiers[1] ?? identifiers[0];
|
|
13112
|
-
if (!localName)
|
|
13113
|
-
continue;
|
|
13114
|
-
const typeOnly = statementTypeOnly || specifierNode2.text.trim().startsWith("type ");
|
|
13115
|
-
bindings.set(localName, { isExternal, typeOnly });
|
|
13116
|
-
hasValueImport ||= !typeOnly;
|
|
13117
|
-
hasTypeImport ||= typeOnly;
|
|
14710
|
+
declarations.set(declaration.name, {
|
|
14711
|
+
info: {
|
|
14712
|
+
name: declaration.name,
|
|
14713
|
+
kind: declaration.kind === "function" ? isJsxLikePath(filePath) && /^[A-Z]/u.test(declaration.name) ? "component" /* Component */ : "function" /* Function */ : declaration.kind === "class" ? "class" /* Class */ : "variable" /* Variable */,
|
|
14714
|
+
visibility: "internal" /* Internal */,
|
|
14715
|
+
file: filePath,
|
|
14716
|
+
line: declaration.line,
|
|
14717
|
+
endLine: declaration.endLine,
|
|
14718
|
+
...declaration.params.length > 0 ? { params: declaration.params.map((name) => ({ name, type: null })) } : {}
|
|
13118
14719
|
}
|
|
13119
|
-
}
|
|
13120
|
-
if (hasValueImport) {
|
|
13121
|
-
relations.push(createRelation("imports" /* Imports */, "", relationTarget, isExternal, getLine(node2)));
|
|
13122
|
-
}
|
|
13123
|
-
if (hasTypeImport) {
|
|
13124
|
-
relations.push(createRelation("imports_type" /* ImportsType */, "", relationTarget, isExternal, getLine(node2)));
|
|
13125
|
-
}
|
|
14720
|
+
});
|
|
13126
14721
|
}
|
|
13127
|
-
return bindings;
|
|
13128
14722
|
};
|
|
13129
14723
|
var analyzeFile = async (filePath, fs, resolver = { mappings: [] }) => {
|
|
13130
14724
|
const source = await fs.readFile(filePath);
|
|
13131
|
-
const
|
|
14725
|
+
const sourceFile = createEcmaScriptSourceFile(source, filePath);
|
|
14726
|
+
const commonJs = analyzeCommonJsModule(source, filePath);
|
|
14727
|
+
const tree = await parseFile(source, isJsxLikePath(filePath));
|
|
13132
14728
|
if (!tree) {
|
|
14729
|
+
const diagnostics = syntaxDiagnostics(sourceFile);
|
|
14730
|
+
if (diagnostics.length === 0) {
|
|
14731
|
+
diagnostics.push({
|
|
14732
|
+
code: "ecmascript-parser-unsupported",
|
|
14733
|
+
severity: "error",
|
|
14734
|
+
file: filePath,
|
|
14735
|
+
line: 1,
|
|
14736
|
+
column: 1
|
|
14737
|
+
});
|
|
14738
|
+
}
|
|
14739
|
+
return {
|
|
14740
|
+
declarations: new Map,
|
|
14741
|
+
importBindings: new Map,
|
|
14742
|
+
relations: [],
|
|
14743
|
+
lines: countLines(source),
|
|
14744
|
+
disposition: "unsupported",
|
|
14745
|
+
diagnostics
|
|
14746
|
+
};
|
|
14747
|
+
}
|
|
14748
|
+
if (commonJs.diagnostics.length > 0) {
|
|
13133
14749
|
return {
|
|
13134
14750
|
declarations: new Map,
|
|
13135
14751
|
importBindings: new Map,
|
|
13136
14752
|
relations: [],
|
|
13137
|
-
lines: countLines(source)
|
|
14753
|
+
lines: countLines(source),
|
|
14754
|
+
disposition: "unsupported",
|
|
14755
|
+
diagnostics: commonJs.diagnostics
|
|
13138
14756
|
};
|
|
13139
14757
|
}
|
|
13140
14758
|
const root = tree.rootNode;
|
|
13141
14759
|
const relations = [];
|
|
13142
|
-
const importBindings = await collectImportBindings2(root, filePath, fs, resolver, relations);
|
|
14760
|
+
const importBindings = await collectImportBindings2(root, filePath, fs, resolver, relations, commonJs);
|
|
13143
14761
|
const declarations = new Map;
|
|
13144
14762
|
for (const relation of relations) {
|
|
13145
14763
|
if (relation.from === "") {
|
|
@@ -13158,11 +14776,15 @@ var analyzeFile = async (filePath, fs, resolver = { mappings: [] }) => {
|
|
|
13158
14776
|
analyzeDeclaration(declaration, filePath, declarations, importBindings, relations);
|
|
13159
14777
|
}
|
|
13160
14778
|
}
|
|
14779
|
+
appendCommonJsSyntheticDeclarations(commonJs, filePath, declarations);
|
|
14780
|
+
relations.push(...collectStaticCallRelations(source, filePath, importBindings));
|
|
13161
14781
|
return {
|
|
13162
14782
|
declarations,
|
|
13163
14783
|
importBindings,
|
|
13164
14784
|
relations,
|
|
13165
|
-
lines: countLines(source)
|
|
14785
|
+
lines: countLines(source),
|
|
14786
|
+
disposition: "analyzed",
|
|
14787
|
+
diagnostics: []
|
|
13166
14788
|
};
|
|
13167
14789
|
};
|
|
13168
14790
|
|
|
@@ -13243,21 +14865,38 @@ var extractSymbols = async (entries, fs, options) => {
|
|
|
13243
14865
|
}
|
|
13244
14866
|
const files = [...filePaths].sort().map((filePath) => ({
|
|
13245
14867
|
path: filePath,
|
|
13246
|
-
language: filePath
|
|
14868
|
+
language: ecmaScriptLanguage(filePath),
|
|
13247
14869
|
lines: analyses.get(filePath)?.lines ?? 0
|
|
13248
14870
|
}));
|
|
14871
|
+
const coverageFiles = files.map((file) => {
|
|
14872
|
+
const analysis = analyses.get(file.path);
|
|
14873
|
+
return {
|
|
14874
|
+
path: file.path,
|
|
14875
|
+
disposition: analysis?.disposition ?? "unsupported",
|
|
14876
|
+
diagnosticCodes: analysis?.diagnostics.map((diagnostic) => diagnostic.code) ?? [
|
|
14877
|
+
"ecmascript-analysis-missing"
|
|
14878
|
+
]
|
|
14879
|
+
};
|
|
14880
|
+
});
|
|
14881
|
+
const diagnostics = [...analyses.values()].flatMap((analysis) => analysis.diagnostics).sort((left, right) => left.file.localeCompare(right.file) || left.line - right.line || left.column - right.column);
|
|
13249
14882
|
return {
|
|
13250
14883
|
version: "2",
|
|
13251
14884
|
meta: {
|
|
13252
14885
|
extractedAt: new Date().toISOString(),
|
|
13253
14886
|
pluginId: options.pluginId,
|
|
13254
14887
|
commitHash: null,
|
|
13255
|
-
language:
|
|
14888
|
+
language: options.packageInfo.language
|
|
13256
14889
|
},
|
|
13257
14890
|
package: options.packageInfo,
|
|
13258
14891
|
files,
|
|
13259
14892
|
symbols,
|
|
13260
14893
|
relations,
|
|
14894
|
+
coverage: {
|
|
14895
|
+
tier: EXTRACT_TS_COVERAGE_TIER,
|
|
14896
|
+
capabilities: [...EXTRACT_TS_CAPABILITIES],
|
|
14897
|
+
files: coverageFiles,
|
|
14898
|
+
diagnostics
|
|
14899
|
+
},
|
|
13261
14900
|
stats: {
|
|
13262
14901
|
files: files.length,
|
|
13263
14902
|
lines: files.reduce((sum, file) => sum + file.lines, 0),
|
|
@@ -13271,8 +14910,10 @@ var extractSymbols = async (entries, fs, options) => {
|
|
|
13271
14910
|
// src/plugin.ts
|
|
13272
14911
|
class TypeScriptPlugin {
|
|
13273
14912
|
id = "c4a-extract-ts";
|
|
13274
|
-
languages = ["typescript", "tsx"];
|
|
14913
|
+
languages = ["typescript", "tsx", "javascript", "jsx"];
|
|
13275
14914
|
packageManagers = ["npm"];
|
|
14915
|
+
capabilities = [...EXTRACT_TS_CAPABILITIES];
|
|
14916
|
+
coverageTier = EXTRACT_TS_COVERAGE_TIER;
|
|
13276
14917
|
manifestTypes = ["package.json"];
|
|
13277
14918
|
#lastDetection = null;
|
|
13278
14919
|
canHandle(source) {
|
|
@@ -13297,20 +14938,20 @@ class TypeScriptPlugin {
|
|
|
13297
14938
|
}
|
|
13298
14939
|
}
|
|
13299
14940
|
// src/reactRouter.ts
|
|
13300
|
-
import * as
|
|
14941
|
+
import * as ts4 from "typescript";
|
|
13301
14942
|
function compact(value) {
|
|
13302
14943
|
return value.replace(/\s+/gu, " ").trim();
|
|
13303
14944
|
}
|
|
13304
14945
|
function scalarValue(node2) {
|
|
13305
14946
|
if (!node2)
|
|
13306
14947
|
return;
|
|
13307
|
-
if (
|
|
14948
|
+
if (ts4.isStringLiteralLike(node2) || ts4.isNoSubstitutionTemplateLiteral(node2))
|
|
13308
14949
|
return node2.text;
|
|
13309
|
-
if (
|
|
14950
|
+
if (ts4.isNumericLiteral(node2))
|
|
13310
14951
|
return Number(node2.text);
|
|
13311
|
-
if (node2.kind ===
|
|
14952
|
+
if (node2.kind === ts4.SyntaxKind.TrueKeyword)
|
|
13312
14953
|
return true;
|
|
13313
|
-
if (node2.kind ===
|
|
14954
|
+
if (node2.kind === ts4.SyntaxKind.FalseKeyword)
|
|
13314
14955
|
return false;
|
|
13315
14956
|
return;
|
|
13316
14957
|
}
|
|
@@ -13319,37 +14960,37 @@ function findDynamicImport(node2) {
|
|
|
13319
14960
|
const visit = (child) => {
|
|
13320
14961
|
if (result)
|
|
13321
14962
|
return;
|
|
13322
|
-
if (
|
|
14963
|
+
if (ts4.isCallExpression(child) && child.expression.kind === ts4.SyntaxKind.ImportKeyword && child.arguments[0] && ts4.isStringLiteralLike(child.arguments[0])) {
|
|
13323
14964
|
result = child.arguments[0].text;
|
|
13324
14965
|
return;
|
|
13325
14966
|
}
|
|
13326
|
-
|
|
14967
|
+
ts4.forEachChild(child, visit);
|
|
13327
14968
|
};
|
|
13328
14969
|
visit(node2);
|
|
13329
14970
|
return result;
|
|
13330
14971
|
}
|
|
13331
14972
|
function parseSource(source, filePath) {
|
|
13332
|
-
const sourceFile =
|
|
14973
|
+
const sourceFile = ts4.createSourceFile(filePath, source, ts4.ScriptTarget.Latest, true, filePath.endsWith(".tsx") ? ts4.ScriptKind.TSX : ts4.ScriptKind.TS);
|
|
13333
14974
|
const imports = new Map;
|
|
13334
14975
|
const constants2 = new Map;
|
|
13335
14976
|
for (const statement of sourceFile.statements) {
|
|
13336
|
-
if (
|
|
14977
|
+
if (ts4.isImportDeclaration(statement) && ts4.isStringLiteral(statement.moduleSpecifier)) {
|
|
13337
14978
|
const moduleSource = statement.moduleSpecifier.text;
|
|
13338
14979
|
const clause = statement.importClause;
|
|
13339
14980
|
if (clause?.name)
|
|
13340
14981
|
imports.set(clause.name.text, moduleSource);
|
|
13341
14982
|
const bindings = clause?.namedBindings;
|
|
13342
|
-
if (bindings &&
|
|
14983
|
+
if (bindings && ts4.isNamedImports(bindings)) {
|
|
13343
14984
|
for (const element of bindings.elements)
|
|
13344
14985
|
imports.set(element.name.text, moduleSource);
|
|
13345
14986
|
}
|
|
13346
|
-
if (bindings &&
|
|
14987
|
+
if (bindings && ts4.isNamespaceImport(bindings))
|
|
13347
14988
|
imports.set(bindings.name.text, moduleSource);
|
|
13348
14989
|
}
|
|
13349
|
-
if (!
|
|
14990
|
+
if (!ts4.isVariableStatement(statement))
|
|
13350
14991
|
continue;
|
|
13351
14992
|
for (const declaration of statement.declarationList.declarations) {
|
|
13352
|
-
if (!
|
|
14993
|
+
if (!ts4.isIdentifier(declaration.name) || !declaration.initializer)
|
|
13353
14994
|
continue;
|
|
13354
14995
|
const scalar = scalarValue(declaration.initializer);
|
|
13355
14996
|
if (scalar !== undefined)
|
|
@@ -13378,13 +15019,13 @@ function routeConditions(node2, sourceFile) {
|
|
|
13378
15019
|
let current = node2;
|
|
13379
15020
|
while (current?.parent) {
|
|
13380
15021
|
const parent = current.parent;
|
|
13381
|
-
if (
|
|
15022
|
+
if (ts4.isConditionalExpression(parent)) {
|
|
13382
15023
|
const condition = compact(parent.condition.getText(sourceFile));
|
|
13383
15024
|
conditions.push(current === parent.whenTrue ? condition : `!(${condition})`);
|
|
13384
|
-
} else if (
|
|
15025
|
+
} else if (ts4.isBinaryExpression(parent) && parent.operatorToken.kind === ts4.SyntaxKind.AmpersandAmpersandToken && current === parent.right) {
|
|
13385
15026
|
conditions.push(compact(parent.left.getText(sourceFile)));
|
|
13386
15027
|
}
|
|
13387
|
-
if (
|
|
15028
|
+
if (ts4.isFunctionLike(parent))
|
|
13388
15029
|
break;
|
|
13389
15030
|
current = parent;
|
|
13390
15031
|
}
|
|
@@ -13393,36 +15034,36 @@ function routeConditions(node2, sourceFile) {
|
|
|
13393
15034
|
function jsxAttributes(node2) {
|
|
13394
15035
|
const result = new Map;
|
|
13395
15036
|
for (const property of node2.attributes.properties)
|
|
13396
|
-
if (
|
|
15037
|
+
if (ts4.isJsxAttribute(property))
|
|
13397
15038
|
result.set(property.name.getText(), property);
|
|
13398
15039
|
return result;
|
|
13399
15040
|
}
|
|
13400
15041
|
function jsxExpression(attribute) {
|
|
13401
15042
|
const initializer = attribute?.initializer;
|
|
13402
|
-
return initializer &&
|
|
15043
|
+
return initializer && ts4.isJsxExpression(initializer) ? initializer.expression : undefined;
|
|
13403
15044
|
}
|
|
13404
15045
|
function jsxScalar(attribute, constants2) {
|
|
13405
15046
|
if (!attribute)
|
|
13406
15047
|
return;
|
|
13407
15048
|
if (!attribute.initializer)
|
|
13408
15049
|
return true;
|
|
13409
|
-
if (
|
|
15050
|
+
if (ts4.isStringLiteral(attribute.initializer))
|
|
13410
15051
|
return attribute.initializer.text;
|
|
13411
15052
|
const expression = jsxExpression(attribute);
|
|
13412
|
-
return scalarValue(expression) ?? (expression &&
|
|
15053
|
+
return scalarValue(expression) ?? (expression && ts4.isIdentifier(expression) ? constants2.get(expression.text) : undefined);
|
|
13413
15054
|
}
|
|
13414
15055
|
function descendantTags(node2) {
|
|
13415
15056
|
const tags = new Set;
|
|
13416
15057
|
const visit = (child) => {
|
|
13417
|
-
if (
|
|
13418
|
-
const opening =
|
|
15058
|
+
if (ts4.isJsxElement(child) || ts4.isJsxSelfClosingElement(child)) {
|
|
15059
|
+
const opening = ts4.isJsxElement(child) ? child.openingElement : child;
|
|
13419
15060
|
const tag = opening.tagName.getText();
|
|
13420
15061
|
if (child !== node2 && tag === "Route")
|
|
13421
15062
|
return;
|
|
13422
15063
|
if (!["Route", "Routes", "Suspense", "Fragment", "React.Fragment", "Navigate"].includes(tag))
|
|
13423
15064
|
tags.add(tag);
|
|
13424
15065
|
}
|
|
13425
|
-
|
|
15066
|
+
ts4.forEachChild(child, visit);
|
|
13426
15067
|
};
|
|
13427
15068
|
visit(node2);
|
|
13428
15069
|
return [...tags];
|
|
@@ -13432,8 +15073,8 @@ function navigateTarget(node2, sourceFile) {
|
|
|
13432
15073
|
const visit = (child) => {
|
|
13433
15074
|
if (target)
|
|
13434
15075
|
return;
|
|
13435
|
-
if (
|
|
13436
|
-
const opening =
|
|
15076
|
+
if (ts4.isJsxElement(child) || ts4.isJsxSelfClosingElement(child)) {
|
|
15077
|
+
const opening = ts4.isJsxElement(child) ? child.openingElement : child;
|
|
13437
15078
|
if (child !== node2 && opening.tagName.getText() === "Route")
|
|
13438
15079
|
return;
|
|
13439
15080
|
if (opening.tagName.getText() === "Navigate") {
|
|
@@ -13448,7 +15089,7 @@ function navigateTarget(node2, sourceFile) {
|
|
|
13448
15089
|
}
|
|
13449
15090
|
}
|
|
13450
15091
|
}
|
|
13451
|
-
|
|
15092
|
+
ts4.forEachChild(child, visit);
|
|
13452
15093
|
};
|
|
13453
15094
|
visit(node2);
|
|
13454
15095
|
return target;
|
|
@@ -13465,12 +15106,12 @@ function componentSource(component, imports) {
|
|
|
13465
15106
|
}
|
|
13466
15107
|
function objectProperty(object2, name) {
|
|
13467
15108
|
for (const property of object2.properties) {
|
|
13468
|
-
if (!
|
|
15109
|
+
if (!ts4.isPropertyAssignment(property) && !ts4.isShorthandPropertyAssignment(property))
|
|
13469
15110
|
continue;
|
|
13470
|
-
const key = property.name && (
|
|
15111
|
+
const key = property.name && (ts4.isIdentifier(property.name) || ts4.isStringLiteralLike(property.name)) ? property.name.text : undefined;
|
|
13471
15112
|
if (key !== name)
|
|
13472
15113
|
continue;
|
|
13473
|
-
return
|
|
15114
|
+
return ts4.isPropertyAssignment(property) ? property.initializer : property.name;
|
|
13474
15115
|
}
|
|
13475
15116
|
return;
|
|
13476
15117
|
}
|
|
@@ -13512,7 +15153,7 @@ function extractReactRouterRoutes(source, filePath, options = {}) {
|
|
|
13512
15153
|
};
|
|
13513
15154
|
const visitRouteObjects = (array, parentPath) => {
|
|
13514
15155
|
for (const element of array.elements) {
|
|
13515
|
-
if (!
|
|
15156
|
+
if (!ts4.isObjectLiteralExpression(element))
|
|
13516
15157
|
continue;
|
|
13517
15158
|
const index = scalarValue(objectProperty(element, "index")) === true;
|
|
13518
15159
|
const pathValue = scalarValue(objectProperty(element, "path"));
|
|
@@ -13528,13 +15169,13 @@ function extractReactRouterRoutes(source, filePath, options = {}) {
|
|
|
13528
15169
|
index,
|
|
13529
15170
|
...component ? { component } : {},
|
|
13530
15171
|
...typeof redirect === "string" ? { redirectTo: redirect } : {},
|
|
13531
|
-
...children &&
|
|
15172
|
+
...children && ts4.isArrayLiteralExpression(children) ? { children } : {}
|
|
13532
15173
|
});
|
|
13533
15174
|
}
|
|
13534
15175
|
};
|
|
13535
15176
|
const visit = (node2, parentPath) => {
|
|
13536
|
-
if (
|
|
13537
|
-
const opening =
|
|
15177
|
+
if (ts4.isJsxElement(node2) || ts4.isJsxSelfClosingElement(node2)) {
|
|
15178
|
+
const opening = ts4.isJsxElement(node2) ? node2.openingElement : node2;
|
|
13538
15179
|
if (opening.tagName.getText() === "Route") {
|
|
13539
15180
|
const attributes = jsxAttributes(opening);
|
|
13540
15181
|
const index = jsxScalar(attributes.get("index"), parsed.constants) === true;
|
|
@@ -13547,61 +15188,61 @@ function extractReactRouterRoutes(source, filePath, options = {}) {
|
|
|
13547
15188
|
const fullPath = joinRoutePath(parentPath, typeof pathValue === "string" ? pathValue : "", index);
|
|
13548
15189
|
const redirectTo = navigateTarget(candidateNode, parsed.sourceFile);
|
|
13549
15190
|
pushRoute({ node: node2, parentPath, path: typeof pathValue === "string" ? pathValue : "", index, ...component ? { component } : {}, candidates, ...redirectTo ? { redirectTo } : {} });
|
|
13550
|
-
if (
|
|
15191
|
+
if (ts4.isJsxElement(node2))
|
|
13551
15192
|
for (const child of node2.children)
|
|
13552
15193
|
visit(child, fullPath);
|
|
13553
15194
|
return;
|
|
13554
15195
|
}
|
|
13555
15196
|
}
|
|
13556
|
-
if (
|
|
15197
|
+
if (ts4.isCallExpression(node2)) {
|
|
13557
15198
|
const callee = node2.expression.getText(parsed.sourceFile);
|
|
13558
|
-
if ((callee === "createBrowserRouter" || callee === "createHashRouter" || callee === "useRoutes") && node2.arguments[0] &&
|
|
15199
|
+
if ((callee === "createBrowserRouter" || callee === "createHashRouter" || callee === "useRoutes") && node2.arguments[0] && ts4.isArrayLiteralExpression(node2.arguments[0])) {
|
|
13559
15200
|
visitRouteObjects(node2.arguments[0], mountPath);
|
|
13560
15201
|
}
|
|
13561
15202
|
}
|
|
13562
|
-
|
|
15203
|
+
ts4.forEachChild(node2, (child) => visit(child, parentPath));
|
|
13563
15204
|
};
|
|
13564
15205
|
visit(parsed.sourceFile, mountPath);
|
|
13565
15206
|
return routes.sort((left, right) => left.fullPath.localeCompare(right.fullPath) || left.location.startLine - right.location.startLine || left.location.startColumn - right.location.startColumn);
|
|
13566
15207
|
}
|
|
13567
15208
|
// src/moduleExports.ts
|
|
13568
|
-
import * as
|
|
15209
|
+
import * as ts5 from "typescript";
|
|
13569
15210
|
function exportedDeclarationName(statement) {
|
|
13570
|
-
const exported =
|
|
15211
|
+
const exported = ts5.canHaveModifiers(statement) && ts5.getModifiers(statement)?.some((modifier) => modifier.kind === ts5.SyntaxKind.ExportKeyword);
|
|
13571
15212
|
if (!exported)
|
|
13572
15213
|
return;
|
|
13573
|
-
if ((
|
|
15214
|
+
if ((ts5.isFunctionDeclaration(statement) || ts5.isClassDeclaration(statement) || ts5.isInterfaceDeclaration(statement) || ts5.isTypeAliasDeclaration(statement) || ts5.isEnumDeclaration(statement)) && statement.name) {
|
|
13574
15215
|
return statement.name.text;
|
|
13575
15216
|
}
|
|
13576
15217
|
return;
|
|
13577
15218
|
}
|
|
13578
15219
|
function extractTypeScriptModuleExports(source, filePath = "module.ts") {
|
|
13579
|
-
const sourceFile =
|
|
15220
|
+
const sourceFile = createEcmaScriptSourceFile(source, filePath);
|
|
13580
15221
|
const named = new Set;
|
|
13581
15222
|
const wildcard = new Set;
|
|
13582
15223
|
const targets = new Set;
|
|
13583
15224
|
for (const statement of sourceFile.statements) {
|
|
13584
|
-
if (
|
|
13585
|
-
const target = statement.moduleSpecifier &&
|
|
15225
|
+
if (ts5.isExportDeclaration(statement)) {
|
|
15226
|
+
const target = statement.moduleSpecifier && ts5.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : undefined;
|
|
13586
15227
|
if (target)
|
|
13587
15228
|
targets.add(target);
|
|
13588
15229
|
if (!statement.exportClause) {
|
|
13589
15230
|
if (target)
|
|
13590
15231
|
wildcard.add(target);
|
|
13591
|
-
} else if (
|
|
15232
|
+
} else if (ts5.isNamedExports(statement.exportClause)) {
|
|
13592
15233
|
for (const element of statement.exportClause.elements)
|
|
13593
15234
|
named.add(element.name.text);
|
|
13594
|
-
} else if (
|
|
15235
|
+
} else if (ts5.isNamespaceExport(statement.exportClause)) {
|
|
13595
15236
|
named.add(statement.exportClause.name.text);
|
|
13596
15237
|
}
|
|
13597
15238
|
continue;
|
|
13598
15239
|
}
|
|
13599
|
-
const
|
|
13600
|
-
if (
|
|
13601
|
-
named.add(
|
|
13602
|
-
if (
|
|
15240
|
+
const declarationName2 = exportedDeclarationName(statement);
|
|
15241
|
+
if (declarationName2)
|
|
15242
|
+
named.add(declarationName2);
|
|
15243
|
+
if (ts5.isVariableStatement(statement) && ts5.getModifiers(statement)?.some((modifier) => modifier.kind === ts5.SyntaxKind.ExportKeyword)) {
|
|
13603
15244
|
for (const declaration of statement.declarationList.declarations) {
|
|
13604
|
-
if (
|
|
15245
|
+
if (ts5.isIdentifier(declaration.name))
|
|
13605
15246
|
named.add(declaration.name.text);
|
|
13606
15247
|
}
|
|
13607
15248
|
}
|
|
@@ -13612,8 +15253,61 @@ function extractTypeScriptModuleExports(source, filePath = "module.ts") {
|
|
|
13612
15253
|
targets: [...targets].sort()
|
|
13613
15254
|
};
|
|
13614
15255
|
}
|
|
15256
|
+
function extractEcmaScriptModuleExports(source, filePath = "module.ts") {
|
|
15257
|
+
const esm = extractTypeScriptModuleExports(source, filePath);
|
|
15258
|
+
const sourceFile = createEcmaScriptSourceFile(source, filePath);
|
|
15259
|
+
const commonJs = analyzeCommonJsModule(source, filePath);
|
|
15260
|
+
const diagnostics = [
|
|
15261
|
+
...syntaxDiagnostics(sourceFile),
|
|
15262
|
+
...commonJs.diagnostics
|
|
15263
|
+
].map(({ code, line, column }) => ({ code, line, column }));
|
|
15264
|
+
if (diagnostics.length > 0) {
|
|
15265
|
+
return {
|
|
15266
|
+
named: [],
|
|
15267
|
+
wildcard: [],
|
|
15268
|
+
targets: [],
|
|
15269
|
+
coverageTier: EXTRACT_TS_COVERAGE_TIER,
|
|
15270
|
+
capabilities: [...EXTRACT_TS_CAPABILITIES],
|
|
15271
|
+
disposition: "unsupported",
|
|
15272
|
+
diagnostics
|
|
15273
|
+
};
|
|
15274
|
+
}
|
|
15275
|
+
return {
|
|
15276
|
+
named: [...new Set([
|
|
15277
|
+
...esm.named,
|
|
15278
|
+
...commonJs.exports.map((item) => item.exportedName)
|
|
15279
|
+
])].sort(),
|
|
15280
|
+
wildcard: [...new Set([...esm.wildcard, ...commonJs.wildcardSources])].sort(),
|
|
15281
|
+
targets: [...new Set([
|
|
15282
|
+
...esm.targets,
|
|
15283
|
+
...commonJs.bindings.map((binding) => binding.source),
|
|
15284
|
+
...commonJs.exports.flatMap((item) => item.source ? [item.source] : []),
|
|
15285
|
+
...commonJs.wildcardSources
|
|
15286
|
+
])].sort(),
|
|
15287
|
+
coverageTier: EXTRACT_TS_COVERAGE_TIER,
|
|
15288
|
+
capabilities: [...EXTRACT_TS_CAPABILITIES],
|
|
15289
|
+
disposition: "analyzed",
|
|
15290
|
+
diagnostics
|
|
15291
|
+
};
|
|
15292
|
+
}
|
|
15293
|
+
// src/evidenceAdapter.ts
|
|
15294
|
+
function typeScriptExtractionToEvidenceAdapterResult(extraction, invocation) {
|
|
15295
|
+
if (extraction.meta.pluginId !== "c4a-extract-ts") {
|
|
15296
|
+
throw new TypeError("TypeScript evidence adapter requires c4a-extract-ts output");
|
|
15297
|
+
}
|
|
15298
|
+
return extractionResultToEvidenceAdapterResult(extraction, invocation);
|
|
15299
|
+
}
|
|
15300
|
+
function typeScriptExtractionToEvidenceAdapterMaterialization(extraction, invocation) {
|
|
15301
|
+
return materializeIndexerEvidenceAdapterResult(typeScriptExtractionToEvidenceAdapterResult(extraction, invocation));
|
|
15302
|
+
}
|
|
13615
15303
|
export {
|
|
15304
|
+
typeScriptExtractionToEvidenceAdapterResult,
|
|
15305
|
+
typeScriptExtractionToEvidenceAdapterMaterialization,
|
|
13616
15306
|
extractTypeScriptModuleExports,
|
|
13617
15307
|
extractReactRouterRoutes,
|
|
13618
|
-
|
|
15308
|
+
extractEcmaScriptModuleExports,
|
|
15309
|
+
ecmaScriptLanguage,
|
|
15310
|
+
TypeScriptPlugin,
|
|
15311
|
+
EXTRACT_TS_COVERAGE_TIER,
|
|
15312
|
+
EXTRACT_TS_CAPABILITIES
|
|
13619
15313
|
};
|