circle-ir 4.23.0 → 4.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configs/sink-semantics.json +6 -0
- package/dist/analysis/config-loader.d.ts.map +1 -1
- package/dist/analysis/config-loader.js +18 -5
- package/dist/analysis/config-loader.js.map +1 -1
- package/dist/analysis/findings.d.ts +8 -1
- package/dist/analysis/findings.d.ts.map +1 -1
- package/dist/analysis/findings.js +67 -5
- package/dist/analysis/findings.js.map +1 -1
- package/dist/analysis/hono-env.d.ts +24 -0
- package/dist/analysis/hono-env.d.ts.map +1 -0
- package/dist/analysis/hono-env.js +105 -0
- package/dist/analysis/hono-env.js.map +1 -0
- package/dist/analysis/html/html-extractor.d.ts +6 -0
- package/dist/analysis/html/html-extractor.d.ts.map +1 -1
- package/dist/analysis/html/html-extractor.js +16 -0
- package/dist/analysis/html/html-extractor.js.map +1 -1
- package/dist/analysis/interprocedural.d.ts.map +1 -1
- package/dist/analysis/interprocedural.js +51 -2
- package/dist/analysis/interprocedural.js.map +1 -1
- package/dist/analysis/js-helper-return.d.ts +7 -0
- package/dist/analysis/js-helper-return.d.ts.map +1 -1
- package/dist/analysis/js-helper-return.js +165 -0
- package/dist/analysis/js-helper-return.js.map +1 -1
- package/dist/analysis/js-spawn-argv.d.ts +34 -0
- package/dist/analysis/js-spawn-argv.d.ts.map +1 -0
- package/dist/analysis/js-spawn-argv.js +156 -0
- package/dist/analysis/js-spawn-argv.js.map +1 -0
- package/dist/analysis/maven-declared.d.ts.map +1 -1
- package/dist/analysis/maven-declared.js +5 -1
- package/dist/analysis/maven-declared.js.map +1 -1
- package/dist/analysis/passes/cli-main-reflection-suppress-pass.d.ts +1 -1
- package/dist/analysis/passes/cli-main-reflection-suppress-pass.d.ts.map +1 -1
- package/dist/analysis/passes/cli-main-reflection-suppress-pass.js +3 -1
- package/dist/analysis/passes/cli-main-reflection-suppress-pass.js.map +1 -1
- package/dist/analysis/passes/cross-file-pass.d.ts.map +1 -1
- package/dist/analysis/passes/cross-file-pass.js +2 -1
- package/dist/analysis/passes/cross-file-pass.js.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.js +113 -2
- package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
- package/dist/analysis/passes/language-sources-pass.d.ts +15 -0
- package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
- package/dist/analysis/passes/language-sources-pass.js +1414 -33
- package/dist/analysis/passes/language-sources-pass.js.map +1 -1
- package/dist/analysis/passes/module-side-effect-pass.d.ts +9 -0
- package/dist/analysis/passes/module-side-effect-pass.d.ts.map +1 -1
- package/dist/analysis/passes/module-side-effect-pass.js +30 -3
- package/dist/analysis/passes/module-side-effect-pass.js.map +1 -1
- package/dist/analysis/passes/orphan-module-pass.d.ts +6 -1
- package/dist/analysis/passes/orphan-module-pass.d.ts.map +1 -1
- package/dist/analysis/passes/orphan-module-pass.js +6 -1
- package/dist/analysis/passes/orphan-module-pass.js.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.d.ts.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.js +2 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.js.map +1 -1
- package/dist/analysis/passes/scan-secrets-pass.d.ts +8 -0
- package/dist/analysis/passes/scan-secrets-pass.d.ts.map +1 -1
- package/dist/analysis/passes/scan-secrets-pass.js +78 -10
- package/dist/analysis/passes/scan-secrets-pass.js.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.d.ts +17 -0
- package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.js +687 -4
- package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.d.ts +19 -0
- package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.js +40 -1
- package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
- package/dist/analysis/require-entry-path.d.ts +4 -1
- package/dist/analysis/require-entry-path.d.ts.map +1 -1
- package/dist/analysis/require-entry-path.js +150 -7
- package/dist/analysis/require-entry-path.js.map +1 -1
- package/dist/analysis/rules.d.ts +7 -0
- package/dist/analysis/rules.d.ts.map +1 -1
- package/dist/analysis/rules.js +65 -0
- package/dist/analysis/rules.js.map +1 -1
- package/dist/analysis/sbom.d.ts +32 -4
- package/dist/analysis/sbom.d.ts.map +1 -1
- package/dist/analysis/sbom.js +57 -19
- package/dist/analysis/sbom.js.map +1 -1
- package/dist/analysis/taint-matcher.d.ts.map +1 -1
- package/dist/analysis/taint-matcher.js +85 -8
- package/dist/analysis/taint-matcher.js.map +1 -1
- package/dist/analysis/taint-propagation.d.ts +7 -0
- package/dist/analysis/taint-propagation.d.ts.map +1 -1
- package/dist/analysis/taint-propagation.js +84 -0
- package/dist/analysis/taint-propagation.js.map +1 -1
- package/dist/analysis/test-to-production-taint-gate.d.ts.map +1 -1
- package/dist/analysis/test-to-production-taint-gate.js +6 -2
- package/dist/analysis/test-to-production-taint-gate.js.map +1 -1
- package/dist/analyzer.d.ts +30 -5
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +93 -13
- package/dist/analyzer.js.map +1 -1
- package/dist/browser/circle-ir.js +11388 -8828
- package/dist/core/circle-ir-core.cjs +307 -27
- package/dist/core/circle-ir-core.js +307 -27
- package/dist/core/extractors/calls.d.ts.map +1 -1
- package/dist/core/extractors/calls.js +83 -1
- package/dist/core/extractors/calls.js.map +1 -1
- package/dist/core/extractors/meta.d.ts +3 -2
- package/dist/core/extractors/meta.d.ts.map +1 -1
- package/dist/core/extractors/meta.js +3 -2
- package/dist/core/extractors/meta.js.map +1 -1
- package/dist/core/extractors/runtime-registrations.js +5 -2
- package/dist/core/extractors/runtime-registrations.js.map +1 -1
- package/dist/core/extractors/types.d.ts +3 -2
- package/dist/core/extractors/types.d.ts.map +1 -1
- package/dist/core/extractors/types.js +22 -20
- package/dist/core/extractors/types.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/parser.d.ts +11 -6
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/core/parser.js +29 -5
- package/dist/core/parser.js.map +1 -1
- package/dist/core/partial-parse-recovery.d.ts +26 -0
- package/dist/core/partial-parse-recovery.d.ts.map +1 -0
- package/dist/core/partial-parse-recovery.js +129 -0
- package/dist/core/partial-parse-recovery.js.map +1 -0
- package/dist/graph/code-graph.d.ts +1 -0
- package/dist/graph/code-graph.d.ts.map +1 -1
- package/dist/graph/code-graph.js +1 -0
- package/dist/graph/code-graph.js.map +1 -1
- package/dist/graph/import-graph.d.ts +14 -4
- package/dist/graph/import-graph.d.ts.map +1 -1
- package/dist/graph/import-graph.js +72 -9
- package/dist/graph/import-graph.js.map +1 -1
- package/dist/graph-facts/dead-code.d.ts +2 -0
- package/dist/graph-facts/dead-code.d.ts.map +1 -1
- package/dist/graph-facts/dead-code.js +126 -1
- package/dist/graph-facts/dead-code.js.map +1 -1
- package/dist/graph-facts/index.d.ts +1 -1
- package/dist/graph-facts/index.d.ts.map +1 -1
- package/dist/graph-facts/index.js +1 -1
- package/dist/graph-facts/index.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/languages/plugins/javascript.d.ts.map +1 -1
- package/dist/languages/plugins/javascript.js +1 -1
- package/dist/languages/plugins/javascript.js.map +1 -1
- package/dist/languages/registry.d.ts.map +1 -1
- package/dist/languages/registry.js +12 -0
- package/dist/languages/registry.js.map +1 -1
- package/dist/navigation/index.d.ts +1 -1
- package/dist/navigation/index.d.ts.map +1 -1
- package/dist/navigation/index.js.map +1 -1
- package/dist/navigation/navigation-index.js +3 -1
- package/dist/navigation/navigation-index.js.map +1 -1
- package/dist/navigation/python-graph.d.ts +3 -1
- package/dist/navigation/python-graph.d.ts.map +1 -1
- package/dist/navigation/python-graph.js +236 -23
- package/dist/navigation/python-graph.js.map +1 -1
- package/dist/navigation/ts-call-edges.d.ts +18 -0
- package/dist/navigation/ts-call-edges.d.ts.map +1 -1
- package/dist/navigation/ts-call-edges.js +207 -18
- package/dist/navigation/ts-call-edges.js.map +1 -1
- package/dist/path-set/path-set.d.ts +5 -2
- package/dist/path-set/path-set.d.ts.map +1 -1
- package/dist/path-set/path-set.js +4 -1
- package/dist/path-set/path-set.js.map +1 -1
- package/dist/resolution/cross-file.d.ts +12 -0
- package/dist/resolution/cross-file.d.ts.map +1 -1
- package/dist/resolution/cross-file.js +357 -3
- package/dist/resolution/cross-file.js.map +1 -1
- package/dist/stable-ids/ts-parse-errors.d.ts +2 -0
- package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -1
- package/dist/stable-ids/ts-parse-errors.js +43 -1
- package/dist/stable-ids/ts-parse-errors.js.map +1 -1
- package/dist/types/config.d.ts +2 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/index.d.ts +74 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/docs/SPEC.md +1 -1
- package/package.json +2 -2
|
@@ -182,6 +182,7 @@ class Graph {
|
|
|
182
182
|
typeNodes = new Map();
|
|
183
183
|
/** Type decl id → direct supertypes (resolved decls). */
|
|
184
184
|
supers = new Map();
|
|
185
|
+
heritage = [];
|
|
185
186
|
/** Type decl id → direct subtypes. */
|
|
186
187
|
subs = new Map();
|
|
187
188
|
/** Declarations without a body: overload, interface and abstract signatures. */
|
|
@@ -201,6 +202,8 @@ class Graph {
|
|
|
201
202
|
tables;
|
|
202
203
|
pendingRoutes = [];
|
|
203
204
|
mounts = [];
|
|
205
|
+
/** Per-block name index (#1338): one scan per statement_block / for loop body. */
|
|
206
|
+
blockBindings = new WeakMap();
|
|
204
207
|
constructor(options) {
|
|
205
208
|
this.options = options;
|
|
206
209
|
this.maxInferred = options.maxInferred ?? 16;
|
|
@@ -263,6 +266,38 @@ class Graph {
|
|
|
263
266
|
this.subs.set(p.id, [self]);
|
|
264
267
|
}
|
|
265
268
|
}
|
|
269
|
+
this.emitClassHeritage();
|
|
270
|
+
}
|
|
271
|
+
/** Publish class heritage and reference edges for resolved `extends` / `implements`. */
|
|
272
|
+
emitClassHeritage() {
|
|
273
|
+
for (const [id, s] of this.supers) {
|
|
274
|
+
const decl = this.declById(id);
|
|
275
|
+
if (!decl || decl.kind !== 'type')
|
|
276
|
+
continue;
|
|
277
|
+
let extendsTarget;
|
|
278
|
+
if (s.extends && s.extends !== 'external') {
|
|
279
|
+
extendsTarget = { kind: 'in-tree', to: s.extends.id };
|
|
280
|
+
if (s.extends.id !== id)
|
|
281
|
+
this.references.push({ from: id, to: s.extends.id, site: s.site });
|
|
282
|
+
}
|
|
283
|
+
else if (s.extends === 'external' && s.extendsName) {
|
|
284
|
+
extendsTarget = { kind: 'external', name: s.extendsName, module: s.extendsModule ?? null };
|
|
285
|
+
}
|
|
286
|
+
const implementsIds = s.implements.map(i => i.id);
|
|
287
|
+
for (const to of implementsIds) {
|
|
288
|
+
if (to !== id)
|
|
289
|
+
this.references.push({ from: id, to, site: s.site });
|
|
290
|
+
}
|
|
291
|
+
if (extendsTarget || implementsIds.length > 0) {
|
|
292
|
+
this.heritage.push({
|
|
293
|
+
class: id,
|
|
294
|
+
extends: extendsTarget,
|
|
295
|
+
implements: implementsIds,
|
|
296
|
+
site: s.site,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
this.heritage.sort((a, b) => a.site.file < b.site.file ? -1 : a.site.file > b.site.file ? 1 : a.site.line - b.site.line || a.site.col - b.site.col);
|
|
266
301
|
}
|
|
267
302
|
sortedFiles() {
|
|
268
303
|
return [...this.files.values()].sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
@@ -439,6 +474,18 @@ class Graph {
|
|
|
439
474
|
}
|
|
440
475
|
return;
|
|
441
476
|
}
|
|
477
|
+
if (t === 'expression_statement') {
|
|
478
|
+
const expr = named(stmt)[0];
|
|
479
|
+
if (expr?.type === 'assignment_expression') {
|
|
480
|
+
const exportName = this.cjsExportName(expr.childForFieldName('left'));
|
|
481
|
+
if (exportName) {
|
|
482
|
+
const right = expr.childForFieldName('right');
|
|
483
|
+
const local = right?.type === 'identifier' ? right.text : exportName;
|
|
484
|
+
ctx.exports.set(exportName, local);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
442
489
|
if (t === 'lexical_declaration' || t === 'variable_declaration') {
|
|
443
490
|
for (const d of named(stmt)) {
|
|
444
491
|
if (d.type !== 'variable_declarator')
|
|
@@ -498,16 +545,34 @@ class Graph {
|
|
|
498
545
|
const ifaceExt = named(node).find(c => c.type === 'extends_type_clause');
|
|
499
546
|
if (ifaceExt)
|
|
500
547
|
implNodes.push(...named(ifaceExt));
|
|
548
|
+
const heritageSite = {
|
|
549
|
+
file: ctx.path,
|
|
550
|
+
line: (heritage ?? node).startPosition.row + 1,
|
|
551
|
+
col: (heritage ?? node).startPosition.column,
|
|
552
|
+
};
|
|
553
|
+
let extendsName;
|
|
554
|
+
let extendsModule;
|
|
501
555
|
if (extendsNodes[0]) {
|
|
502
556
|
const r = this.resolveTypeRef(ctx, extendsNodes[0]);
|
|
503
557
|
ext = r === null ? null : r;
|
|
558
|
+
if (r === 'external' && (extendsNodes[0].type === 'identifier' || extendsNodes[0].type === 'type_identifier')) {
|
|
559
|
+
extendsName = extendsNodes[0].text;
|
|
560
|
+
const binding = ctx.imports.get(extendsName);
|
|
561
|
+
extendsModule = binding ? binding.specifier : null;
|
|
562
|
+
}
|
|
504
563
|
}
|
|
505
564
|
for (const n of implNodes) {
|
|
506
565
|
const r = this.resolveTypeRef(ctx, n);
|
|
507
566
|
if (r && r !== 'external')
|
|
508
567
|
impls.push(r);
|
|
509
568
|
}
|
|
510
|
-
this.supers.set(decl.id, {
|
|
569
|
+
this.supers.set(decl.id, {
|
|
570
|
+
extends: ext,
|
|
571
|
+
implements: impls,
|
|
572
|
+
site: heritageSite,
|
|
573
|
+
extendsName,
|
|
574
|
+
extendsModule,
|
|
575
|
+
});
|
|
511
576
|
if (t !== 'interface_declaration')
|
|
512
577
|
this.decoratorEntries(ctx, node, decl);
|
|
513
578
|
}
|
|
@@ -646,6 +711,36 @@ class Graph {
|
|
|
646
711
|
return 'external';
|
|
647
712
|
}
|
|
648
713
|
// -- lexical scope ---------------------------------------------------------
|
|
714
|
+
/** Build once per block; answers every `localBinding` query for names in that block. */
|
|
715
|
+
blockBindingMap(block) {
|
|
716
|
+
let map = this.blockBindings.get(block);
|
|
717
|
+
if (map)
|
|
718
|
+
return map;
|
|
719
|
+
map = new Map();
|
|
720
|
+
for (const s of named(block)) {
|
|
721
|
+
if ((s.type === 'function_declaration' || s.type === 'generator_function_declaration')) {
|
|
722
|
+
const fnName = s.childForFieldName('name')?.text;
|
|
723
|
+
if (fnName)
|
|
724
|
+
map.set(fnName, { kind: 'fn', node: s });
|
|
725
|
+
}
|
|
726
|
+
if (s.type === 'lexical_declaration' || s.type === 'variable_declaration') {
|
|
727
|
+
for (const d of named(s)) {
|
|
728
|
+
if (d.type !== 'variable_declarator')
|
|
729
|
+
continue;
|
|
730
|
+
const pat = d.childForFieldName('name');
|
|
731
|
+
for (const nm of patternNames(pat))
|
|
732
|
+
map.set(nm, { kind: 'var', node: d });
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
if (block.type === 'for_in_statement') {
|
|
737
|
+
for (const nm of patternNames(block.childForFieldName('left'))) {
|
|
738
|
+
map.set(nm, { kind: 'param', node: block });
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
this.blockBindings.set(block, map);
|
|
742
|
+
return map;
|
|
743
|
+
}
|
|
649
744
|
/**
|
|
650
745
|
* The nearest binding of `name` inside the enclosing functions and blocks
|
|
651
746
|
* (module level excluded): a parameter, a variable declarator, or a nested
|
|
@@ -670,19 +765,9 @@ class Graph {
|
|
|
670
765
|
return { kind: 'param', node: n };
|
|
671
766
|
}
|
|
672
767
|
if (n.type === 'statement_block' || n.type === 'for_statement' || n.type === 'for_in_statement') {
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
}
|
|
677
|
-
if (s.type === 'lexical_declaration' || s.type === 'variable_declaration') {
|
|
678
|
-
for (const d of named(s)) {
|
|
679
|
-
if (d.type === 'variable_declarator' && patternNames(d.childForFieldName('name')).includes(name))
|
|
680
|
-
return { kind: 'var', node: d };
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
if (n.type === 'for_in_statement' && patternNames(n.childForFieldName('left')).includes(name))
|
|
685
|
-
return { kind: 'param', node: n };
|
|
768
|
+
const hit = this.blockBindingMap(n).get(name);
|
|
769
|
+
if (hit)
|
|
770
|
+
return hit;
|
|
686
771
|
}
|
|
687
772
|
}
|
|
688
773
|
return null;
|
|
@@ -912,6 +997,35 @@ class Graph {
|
|
|
912
997
|
this.fieldUses.push({ from, to: d.id, site });
|
|
913
998
|
}
|
|
914
999
|
// -- references (functions and classes used as values) ---------------------
|
|
1000
|
+
/** `exports.X` / `module.exports.X` on the left of an assignment → export name `X`. */
|
|
1001
|
+
cjsExportName(left) {
|
|
1002
|
+
if (!left || left.type !== 'member_expression')
|
|
1003
|
+
return null;
|
|
1004
|
+
const object = left.childForFieldName('object');
|
|
1005
|
+
const property = left.childForFieldName('property');
|
|
1006
|
+
if (!object || !property)
|
|
1007
|
+
return null;
|
|
1008
|
+
if (object.type === 'identifier' && object.text === 'exports')
|
|
1009
|
+
return property.text;
|
|
1010
|
+
if (object.type === 'member_expression') {
|
|
1011
|
+
const mod = object.childForFieldName('object');
|
|
1012
|
+
const prop = object.childForFieldName('property')?.text;
|
|
1013
|
+
if (mod?.type === 'identifier' && mod.text === 'module' && prop === 'exports')
|
|
1014
|
+
return property.text;
|
|
1015
|
+
}
|
|
1016
|
+
return null;
|
|
1017
|
+
}
|
|
1018
|
+
isCjsExportsReceiver(ctx, object) {
|
|
1019
|
+
if (object.type === 'identifier' && object.text === 'exports' && !this.localBinding(object, 'exports'))
|
|
1020
|
+
return true;
|
|
1021
|
+
if (object.type === 'member_expression') {
|
|
1022
|
+
const mod = object.childForFieldName('object');
|
|
1023
|
+
const prop = object.childForFieldName('property')?.text;
|
|
1024
|
+
if (mod?.type === 'identifier' && mod.text === 'module' && !this.localBinding(mod, 'module') && prop === 'exports')
|
|
1025
|
+
return true;
|
|
1026
|
+
}
|
|
1027
|
+
return false;
|
|
1028
|
+
}
|
|
915
1029
|
reference(ctx, node) {
|
|
916
1030
|
if (!node)
|
|
917
1031
|
return;
|
|
@@ -965,6 +1079,10 @@ class Graph {
|
|
|
965
1079
|
const cls = this.enclosingClass(ctx, node);
|
|
966
1080
|
return cls ? this.memberBodies(cls, name) : [];
|
|
967
1081
|
}
|
|
1082
|
+
if (this.isCjsExportsReceiver(ctx, object)) {
|
|
1083
|
+
const r = this.resolveExport(ctx, name, 0);
|
|
1084
|
+
return r.kind === 'decls' ? this.callables(r.decls) : [];
|
|
1085
|
+
}
|
|
968
1086
|
if (object.type === 'identifier' && !this.localBinding(object, object.text)) {
|
|
969
1087
|
const t = this.resolveLocal(ctx, object.text);
|
|
970
1088
|
if (t.kind === 'namespace') {
|
|
@@ -1339,6 +1457,19 @@ class Graph {
|
|
|
1339
1457
|
}
|
|
1340
1458
|
}
|
|
1341
1459
|
// -- React Native, Expo and Jest ---------------------------------------------
|
|
1460
|
+
/** Whether the package ships a Jest config file (preset-only setups may omit a `jest` dependency). */
|
|
1461
|
+
packageHasJestConfig(root) {
|
|
1462
|
+
const prefix = normalizePath(root);
|
|
1463
|
+
const pattern = /^jest\.config\.[cm]?[jt]s$/;
|
|
1464
|
+
for (const ctx of this.sortedFiles()) {
|
|
1465
|
+
if (prefix !== '' && !ctx.path.startsWith(prefix + '/'))
|
|
1466
|
+
continue;
|
|
1467
|
+
const rel = prefix === '' ? ctx.path : ctx.path.slice(prefix.length + 1);
|
|
1468
|
+
if (pattern.test(rel))
|
|
1469
|
+
return true;
|
|
1470
|
+
}
|
|
1471
|
+
return false;
|
|
1472
|
+
}
|
|
1342
1473
|
/** Files a tool loads by name or place, for the tools the package depends on. */
|
|
1343
1474
|
toolFileEntries(root, has) {
|
|
1344
1475
|
const rows = (this.tables.toolFiles ?? []).filter(r => has(r.dependencies));
|
|
@@ -1649,7 +1780,18 @@ class Graph {
|
|
|
1649
1780
|
if (next && Object.prototype.hasOwnProperty.call(deps, next.dependency))
|
|
1650
1781
|
this.nextFileRoutes(pkg.root);
|
|
1651
1782
|
this.scriptEntries(pkg.root, m.scripts);
|
|
1652
|
-
const has = (names) =>
|
|
1783
|
+
const has = (names) => {
|
|
1784
|
+
if (names.some(n => Object.prototype.hasOwnProperty.call(deps, n)))
|
|
1785
|
+
return true;
|
|
1786
|
+
if (names.includes('jest')) {
|
|
1787
|
+
if (Object.prototype.hasOwnProperty.call(deps, 'jest-expo'))
|
|
1788
|
+
return true;
|
|
1789
|
+
const jestEcosystem = Object.keys(deps).some(k => k === 'jest' || k === 'jest-expo' || k.startsWith('@jest/'));
|
|
1790
|
+
if (jestEcosystem && this.packageHasJestConfig(pkg.root))
|
|
1791
|
+
return true;
|
|
1792
|
+
}
|
|
1793
|
+
return false;
|
|
1794
|
+
};
|
|
1653
1795
|
this.toolFileEntries(pkg.root, has);
|
|
1654
1796
|
if (this.tables.expo && has(this.tables.expo.dependencies)) {
|
|
1655
1797
|
this.expoFileRoutes(pkg.root);
|
|
@@ -1796,7 +1938,7 @@ class Graph {
|
|
|
1796
1938
|
return;
|
|
1797
1939
|
}
|
|
1798
1940
|
if (fn.type === 'member_expression') {
|
|
1799
|
-
this.callMember(ctx, fn, edge, unresolved);
|
|
1941
|
+
this.callMember(ctx, fn, site, edge, unresolved);
|
|
1800
1942
|
return;
|
|
1801
1943
|
}
|
|
1802
1944
|
unresolved('<expr>', 'dynamic', `callee is a ${fn.type}`);
|
|
@@ -1887,7 +2029,35 @@ class Graph {
|
|
|
1887
2029
|
const t = this.resolveBinding(binding);
|
|
1888
2030
|
return t.kind === 'namespace' || t.kind === 'external' ? t : null;
|
|
1889
2031
|
}
|
|
1890
|
-
|
|
2032
|
+
/** Member bodies `recv.name` denotes (for `.bind` reference edges). */
|
|
2033
|
+
memberValueTargets(ctx, object, name) {
|
|
2034
|
+
if (object.type === 'this') {
|
|
2035
|
+
const cls = this.enclosingClass(ctx, object);
|
|
2036
|
+
return cls ? this.memberBodies(cls, name) : [];
|
|
2037
|
+
}
|
|
2038
|
+
if (object.type === 'identifier' && !this.localBinding(object, object.text)) {
|
|
2039
|
+
const t = this.resolveLocal(ctx, object.text);
|
|
2040
|
+
if (t.kind === 'namespace') {
|
|
2041
|
+
const m = this.resolveExport(t.ctx, name, 0);
|
|
2042
|
+
return m.kind === 'decls' ? this.callables(m.decls) : [];
|
|
2043
|
+
}
|
|
2044
|
+
const type = t.kind === 'decls' ? t.decls.find(d => d.kind === 'type') : undefined;
|
|
2045
|
+
if (type)
|
|
2046
|
+
return this.memberBodies(type, name);
|
|
2047
|
+
}
|
|
2048
|
+
const type = this.typeOf(ctx, object);
|
|
2049
|
+
return type && type !== 'external' ? this.memberBodies(type, name) : [];
|
|
2050
|
+
}
|
|
2051
|
+
memberReferenceAt(ctx, object, methodName, site) {
|
|
2052
|
+
const targets = this.memberValueTargets(ctx, object, methodName);
|
|
2053
|
+
if (targets.length === 0)
|
|
2054
|
+
return;
|
|
2055
|
+
const from = (ctx.locate(site.line, site.col) ?? ctx.module).id;
|
|
2056
|
+
for (const d of targets)
|
|
2057
|
+
if (d.id !== from)
|
|
2058
|
+
this.references.push({ from, to: d.id, site });
|
|
2059
|
+
}
|
|
2060
|
+
callMember(ctx, fn, site, edge, unresolved) {
|
|
1891
2061
|
const object = fn.childForFieldName('object');
|
|
1892
2062
|
const property = fn.childForFieldName('property');
|
|
1893
2063
|
if (!object || !property) {
|
|
@@ -1895,13 +2065,31 @@ class Graph {
|
|
|
1895
2065
|
return;
|
|
1896
2066
|
}
|
|
1897
2067
|
const name = property.text;
|
|
2068
|
+
if (name === 'call' || name === 'apply' || name === 'bind') {
|
|
2069
|
+
if (object.type === 'member_expression') {
|
|
2070
|
+
const recv = object.childForFieldName('object');
|
|
2071
|
+
const innerName = object.childForFieldName('property')?.text;
|
|
2072
|
+
if (recv && innerName) {
|
|
2073
|
+
if (name === 'bind')
|
|
2074
|
+
this.memberReferenceAt(ctx, recv, innerName, site);
|
|
2075
|
+
else
|
|
2076
|
+
this.resolveMemberCall(ctx, recv, innerName, edge, unresolved);
|
|
2077
|
+
return;
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
unresolved(name, 'unknown', 'receiver type unknown and no method of this name in the tree');
|
|
2081
|
+
return;
|
|
2082
|
+
}
|
|
1898
2083
|
if (property.type === 'private_property_identifier' && object.type !== 'this') {
|
|
1899
2084
|
unresolved(name, 'unknown', 'private member on another receiver');
|
|
1900
2085
|
return;
|
|
1901
2086
|
}
|
|
2087
|
+
this.resolveMemberCall(ctx, object, name, edge, unresolved);
|
|
2088
|
+
}
|
|
2089
|
+
resolveMemberCall(ctx, object, name, edge, unresolved) {
|
|
1902
2090
|
// `super.m()`
|
|
1903
2091
|
if (object.type === 'super') {
|
|
1904
|
-
const cls = this.enclosingClass(ctx,
|
|
2092
|
+
const cls = this.enclosingClass(ctx, object);
|
|
1905
2093
|
const sup = cls ? this.supers.get(cls.id)?.extends : null;
|
|
1906
2094
|
if (!sup || sup === 'external') {
|
|
1907
2095
|
unresolved(name, sup === 'external' ? 'external' : 'unknown', 'superclass method');
|
|
@@ -2064,6 +2252,7 @@ export async function buildTsCallGraph(files, options = {}) {
|
|
|
2064
2252
|
partial,
|
|
2065
2253
|
sites: graph.siteCount,
|
|
2066
2254
|
references: dedupe([...graph.references].sort((a, b) => bySite(a, b) || cmp(a.to, b.to)), r => `${r.from}>${r.to}@${r.site.file}:${r.site.line}:${r.site.col}`),
|
|
2255
|
+
heritage: [...graph.heritage],
|
|
2067
2256
|
fieldUses: dedupe([...graph.fieldUses].sort((a, b) => bySite(a, b) || cmp(a.to, b.to)), r => `${r.from}>${r.to}@${r.site.file}:${r.site.line}:${r.site.col}`),
|
|
2068
2257
|
imports: graph.importEdges(),
|
|
2069
2258
|
loads: dedupe([...graph.loadEdges].sort((a, b) => bySite(a, b) || cmp(a.to, b.to)), l => `${l.from}>${l.to}`),
|