@octanejs/codemod 0.2.0 → 0.2.2

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.
Files changed (40) hide show
  1. package/README.md +140 -12
  2. package/dist/bin.js +2 -2
  3. package/dist/effect-receivers.d.ts +14 -2
  4. package/dist/effect-receivers.js +171 -22
  5. package/dist/expression-wrappers.d.ts +2 -0
  6. package/dist/expression-wrappers.js +19 -0
  7. package/dist/forwarded-props.d.ts +4 -1
  8. package/dist/forwarded-props.js +18 -3
  9. package/dist/linked-state.d.ts +1 -1
  10. package/dist/linked-state.js +7 -3
  11. package/dist/local-react-hook.d.ts +13 -6
  12. package/dist/local-react-hook.js +316 -53
  13. package/dist/local-uses.d.ts +10 -1
  14. package/dist/local-uses.js +87 -5
  15. package/dist/mappings.d.ts +7 -1
  16. package/dist/mappings.js +21 -3
  17. package/dist/path-svg.d.ts +68 -4
  18. package/dist/path-svg.js +162 -56
  19. package/dist/project.js +1589 -147
  20. package/dist/react-intl.d.ts +1 -1
  21. package/dist/react-intl.js +43 -6
  22. package/dist/react-island-sources.d.ts +53 -0
  23. package/dist/react-island-sources.js +979 -0
  24. package/dist/react-renderer.d.ts +2 -0
  25. package/dist/react-renderer.js +94 -0
  26. package/dist/scoped-store-contract.d.ts +9 -2
  27. package/dist/scoped-store-contract.js +209 -33
  28. package/dist/store-hook-uses.d.ts +7 -5
  29. package/dist/store-hook-uses.js +218 -62
  30. package/dist/store-inputs.d.ts +9 -2
  31. package/dist/store-inputs.js +213 -16
  32. package/dist/strong.d.ts +2 -2
  33. package/dist/strong.js +72 -18
  34. package/dist/transform.d.ts +14 -0
  35. package/dist/transform.js +2856 -292
  36. package/dist/types.d.ts +40 -10
  37. package/package.json +4 -3
  38. package/src/path-svg.ts +183 -62
  39. package/templates/octane-path-svg.ts +5 -1
  40. package/templates/react-intl.tsrx +64 -11
@@ -1,4 +1,6 @@
1
1
  import ts from 'typescript';
2
+ /** A direct, unconsumed React DOM server stream and its later full-body read. */
3
+ export declare function unreadServerStream(wait: ts.AwaitExpression, declarationOf: (name: ts.Identifier) => ts.Declaration | null, uses: (name: ts.Identifier) => ts.Identifier[], original: (module: string) => boolean): boolean;
2
4
  /** The props object for a self-closing React element with closed literal attributes. */
3
5
  export declare function staticReactProps(element: ts.JsxSelfClosingElement): string | null;
4
6
  /** A React-owned value or renderer in an inline options object. */
@@ -1,4 +1,98 @@
1
1
  import ts from 'typescript';
2
+ import { REACT_MODULES } from './mappings.js';
3
+ import { inTypeNode } from './local-uses.js';
4
+ function constantStatement(decl) {
5
+ if (ts.isVariableDeclaration(decl) &&
6
+ ts.isVariableDeclarationList(decl.parent) &&
7
+ ts.isVariableStatement(decl.parent.parent) &&
8
+ (decl.parent.flags & ts.NodeFlags.BlockScoped) === ts.NodeFlags.Const &&
9
+ decl.parent.declarations.length === 1)
10
+ return decl.parent.parent;
11
+ }
12
+ /** A direct, unconsumed React DOM server stream and its later full-body read. */
13
+ export function unreadServerStream(wait, declarationOf, uses, original) {
14
+ const access = wait.expression;
15
+ if (!ts.isPropertyAccessExpression(access) ||
16
+ access.name.text !== 'allReady' ||
17
+ !ts.isExpressionStatement(wait.parent) ||
18
+ !ts.isBlock(wait.parent.parent) ||
19
+ ts.isOptionalChain(access) ||
20
+ !ts.isIdentifier(access.expression))
21
+ return false;
22
+ const stream = declarationOf(access.expression);
23
+ if (!stream || !ts.isVariableDeclaration(stream) || !ts.isIdentifier(stream.name))
24
+ return false;
25
+ const statement = constantStatement(stream);
26
+ const initializer = stream.initializer;
27
+ if (statement?.parent !== wait.parent.parent ||
28
+ statement.end > wait.pos ||
29
+ !initializer ||
30
+ !ts.isAwaitExpression(initializer) ||
31
+ !ts.isCallExpression(initializer.expression) ||
32
+ ts.isOptionalChain(initializer.expression) ||
33
+ !initializer.expression.arguments.length ||
34
+ initializer.expression.arguments.some(ts.isSpreadElement) ||
35
+ !ts.isIdentifier(initializer.expression.expression))
36
+ return false;
37
+ const refs = uses(stream.name).filter((ref) => !inTypeNode(ref));
38
+ if (refs.length !== 2 || refs[0] !== access.expression)
39
+ return false;
40
+ const response = refs[1].parent;
41
+ if (!ts.isNewExpression(response) ||
42
+ response.arguments?.length !== 1 ||
43
+ !ts.isIdentifier(response.expression) ||
44
+ response.expression.text !== 'Response' ||
45
+ declarationOf(response.expression))
46
+ return false;
47
+ const text = response.parent;
48
+ if (!ts.isPropertyAccessExpression(text) ||
49
+ text.name.text !== 'text' ||
50
+ !ts.isCallExpression(text.parent) ||
51
+ ts.isOptionalChain(text.parent) ||
52
+ text.parent.arguments.length ||
53
+ !ts.isAwaitExpression(text.parent.parent))
54
+ return false;
55
+ const read = ts.findAncestor(text.parent.parent, (node) => ts.isStatement(node) || ts.isFunctionLike(node));
56
+ if (read?.parent !== statement.parent || read.pos < wait.parent.end)
57
+ return false;
58
+ const factory = declarationOf(initializer.expression.expression);
59
+ if (!factory)
60
+ return false;
61
+ let module;
62
+ if (ts.isImportSpecifier(factory)) {
63
+ const clause = factory.parent.parent;
64
+ if (factory.isTypeOnly || clause.isTypeOnly || clause.parent.attributes)
65
+ return false;
66
+ if ((factory.propertyName ?? factory.name).text !== 'renderToReadableStream')
67
+ return false;
68
+ module = clause.parent.moduleSpecifier;
69
+ }
70
+ else if (ts.isBindingElement(factory) && ts.isObjectBindingPattern(factory.parent)) {
71
+ const key = factory.propertyName ?? factory.name;
72
+ const binding = factory.parent.parent;
73
+ const load = ts.isVariableDeclaration(binding) && constantStatement(binding);
74
+ const init = load && binding.initializer;
75
+ if (!load ||
76
+ load.parent !== statement.parent ||
77
+ load.end > statement.pos ||
78
+ factory.parent.elements.length !== 1 ||
79
+ factory.initializer ||
80
+ factory.dotDotDotToken ||
81
+ !ts.isIdentifier(key) ||
82
+ key.text !== 'renderToReadableStream' ||
83
+ !init ||
84
+ !ts.isAwaitExpression(init) ||
85
+ !ts.isCallExpression(init.expression) ||
86
+ init.expression.expression.kind !== ts.SyntaxKind.ImportKeyword ||
87
+ init.expression.arguments.length !== 1)
88
+ return false;
89
+ module = init.expression.arguments[0];
90
+ }
91
+ return (!!module &&
92
+ ts.isStringLiteral(module) &&
93
+ REACT_MODULES[module.text] === 'octane/server' &&
94
+ original(module.text));
95
+ }
2
96
  /** The props object for a self-closing React element with closed literal attributes. */
3
97
  export function staticReactProps(element) {
4
98
  if (element.typeArguments)
@@ -7,7 +7,14 @@ export interface ScopedStoreHookPlan {
7
7
  /** Checks a store factory against its original, renderer-independent declaration. */
8
8
  isSharedExport(module: string, imported: string, from: string): boolean;
9
9
  }
10
- declare function runtime(s: ts.ImportDeclaration | ts.ExportDeclaration): boolean;
10
+ interface ScopedStoreHookContract {
11
+ plan?: ScopedStoreHookPlan;
12
+ /** Every normal return from the verified original export reaches a React hook. */
13
+ requiresReact(): boolean;
14
+ }
15
+ declare function runtime(s: ts.ImportDeclaration | ts.ExportDeclaration, verbatim?: boolean): boolean;
11
16
  export { runtime as hasRuntimeDependency };
17
+ /** Audit every executable target of a bare dependency, including browser and server conditions. */
18
+ export declare function runtimeTargets(spec: string, resolved: string, from: string, unconditional?: boolean): string[];
12
19
  /** Read linked, authored packages only. All output belongs to the consuming project. */
13
- export declare function createScopedStorePlanner(outputDir: string, contextBridge: string, compilerOptions?: ts.CompilerOptions): (specifier: string, importedName: string, importer: string) => ScopedStoreHookPlan | null;
20
+ export declare function createScopedStorePlanner(outputDir: string, contextBridge: string, compilerOptions?: ts.CompilerOptions): (specifier: string, importedName: string, importer: string) => ScopedStoreHookContract | null;
@@ -3,6 +3,8 @@ import fs from 'node:fs';
3
3
  import { createRequire } from 'node:module';
4
4
  import path from 'node:path';
5
5
  import ts from 'typescript';
6
+ import { skipWrappers } from './expression-wrappers.js';
7
+ import { namedRuntimeImport, safeSetupLiteral } from './local-react-hook.js';
6
8
  // The application's React compiler must not synthesize dispatcher calls in Octane hooks.
7
9
  const nativeDirective = "'use no memo';\n";
8
10
  const hooks = new Set([
@@ -30,9 +32,11 @@ function relative(from, to) {
30
32
  const spec = path.relative(path.dirname(from), to).split(path.sep).join('/').replace(/\.ts$/, '');
31
33
  return spec.startsWith('../') || spec.startsWith('./') ? spec : './' + spec;
32
34
  }
33
- function runtime(s) {
35
+ function runtime(s, verbatim = false) {
34
36
  if ((ts.isImportDeclaration(s) ? s.importClause : s)?.isTypeOnly)
35
37
  return false;
38
+ if (verbatim)
39
+ return true;
36
40
  const bindings = ts.isExportDeclaration(s)
37
41
  ? s.exportClause
38
42
  : s.importClause?.name
@@ -70,8 +74,10 @@ function manifest(file) {
70
74
  }
71
75
  }
72
76
  /** Audit every executable target of a bare dependency, including browser and server conditions. */
73
- function runtimeTargets(spec, resolved, from) {
77
+ export function runtimeTargets(spec, resolved, from, unconditional = false) {
74
78
  if (spec.startsWith('.')) {
79
+ if (unconditional)
80
+ return [];
75
81
  const executable = installed(spec, from);
76
82
  return executable && executable !== resolved ? [resolved, executable] : [resolved];
77
83
  }
@@ -86,6 +92,8 @@ function runtimeTargets(spec, resolved, from) {
86
92
  if (pkg.browser)
87
93
  return [];
88
94
  if (!pkg.exports) {
95
+ if (unconditional)
96
+ return [];
89
97
  if (subpath !== '.')
90
98
  return [resolved];
91
99
  return [
@@ -115,6 +123,8 @@ function runtimeTargets(spec, resolved, from) {
115
123
  wildcard = subpath.slice(start.length, subpath.length - end.length);
116
124
  branch = map[key];
117
125
  }
126
+ if (unconditional && typeof branch !== 'string')
127
+ return [];
118
128
  const leaves = (v) => {
119
129
  if (typeof v === 'string')
120
130
  return v.startsWith('./') ? [path.resolve(dir, v.replaceAll('*', wildcard))] : [];
@@ -259,7 +269,15 @@ function modulePlan(pkg, project, entry, candidates, link, options, outputDir, b
259
269
  if (!neutral.size)
260
270
  return null;
261
271
  const contextReaders = new Set();
262
- function discover(sf, files, seen, shared) {
272
+ function localExportBody(item, sf) {
273
+ const edge = item.parent.parent;
274
+ if (edge.isTypeOnly || edge.attributes || edge.moduleSpecifier || item.isTypeOnly)
275
+ return;
276
+ return checker
277
+ .getExportSpecifierLocalTargetSymbol(item)
278
+ ?.declarations?.find((d) => ts.isFunctionDeclaration(d) && !!d.body && d.parent === sf);
279
+ }
280
+ function discover(sf, files, seen, shared, localExports) {
263
281
  if (seen.has(sf.fileName))
264
282
  return true;
265
283
  if (!owned(sf.fileName) || !sourceFile.test(sf.fileName) || sf.isDeclarationFile)
@@ -331,6 +349,15 @@ function modulePlan(pkg, project, entry, candidates, link, options, outputDir, b
331
349
  }
332
350
  continue;
333
351
  }
352
+ if (ts.isExportDeclaration(s) &&
353
+ s.exportClause &&
354
+ ts.isNamedExports(s.exportClause) &&
355
+ s.exportClause.elements.some((item) => !item.isTypeOnly) &&
356
+ s.exportClause.elements.every((item) => item.isTypeOnly || localExportBody(item, sf))) {
357
+ for (const item of s.exportClause.elements)
358
+ localExports.add(item);
359
+ continue;
360
+ }
334
361
  if (!ts.isImportDeclaration(s) ||
335
362
  !s.importClause ||
336
363
  s.attributes ||
@@ -416,7 +443,7 @@ function modulePlan(pkg, project, entry, candidates, link, options, outputDir, b
416
443
  !named ||
417
444
  !ts.isNamedImports(named) ||
418
445
  !named.elements.every((x) => x.isTypeOnly || /^use[A-Z0-9]/.test((x.propertyName ?? x.name).text)) ||
419
- !discover(child, files, seen, shared))
446
+ !discover(child, files, seen, shared, localExports))
420
447
  return false;
421
448
  for (const x of named.elements) {
422
449
  const sym = checker.getSymbolAtLocation(x.name);
@@ -484,7 +511,9 @@ function modulePlan(pkg, project, entry, candidates, link, options, outputDir, b
484
511
  valid = false;
485
512
  return;
486
513
  }
487
- if (!ts.isIdentifier(node) || ts.isImportSpecifier(node.parent))
514
+ if (!ts.isIdentifier(node) ||
515
+ ts.isImportSpecifier(node.parent) ||
516
+ localExports.has(node.parent))
488
517
  return;
489
518
  const sym = ts.isShorthandPropertyAssignment(node.parent)
490
519
  ? checker.getShorthandAssignmentValueSymbol(node.parent)
@@ -544,7 +573,18 @@ function modulePlan(pkg, project, entry, candidates, link, options, outputDir, b
544
573
  files.set(out, code.slice(0, start) + nativeDirective + code.slice(start));
545
574
  return true;
546
575
  }
547
- function readsContext(fn, seen, files) {
576
+ function forwardedCall(fn, unwrap) {
577
+ if (fn.body?.statements.length !== 1)
578
+ return;
579
+ const [only] = fn.body.statements;
580
+ const expression = ts.isReturnStatement(only) ? only.expression : undefined;
581
+ if (!expression)
582
+ return;
583
+ const call = unwrap ? skipWrappers(expression) : expression;
584
+ if (ts.isCallExpression(call) && ts.isIdentifier(call.expression))
585
+ return call;
586
+ }
587
+ function readsContext(fn, seen, files, unwrap = false) {
548
588
  const symbol = fn.name && checker.getSymbolAtLocation(fn.name);
549
589
  if (!symbol || !fn.body || !files.has(output(fn.getSourceFile())) || seen.has(symbol))
550
590
  return false;
@@ -552,16 +592,139 @@ function modulePlan(pkg, project, entry, candidates, link, options, outputDir, b
552
592
  return true;
553
593
  seen.add(symbol);
554
594
  // A thin exported forwarding hook may share another hook's contextual read.
555
- const [only] = fn.body.statements;
556
- if (fn.body.statements.length !== 1 ||
557
- !ts.isReturnStatement(only) ||
558
- !only.expression ||
559
- !ts.isCallExpression(only.expression) ||
560
- !ts.isIdentifier(only.expression.expression))
595
+ const forward = forwardedCall(fn, unwrap);
596
+ if (!forward)
561
597
  return false;
562
- const called = referenced(checker, only.expression.expression);
598
+ const called = referenced(checker, forward.expression);
563
599
  const body = called?.declarations?.find((d) => ts.isFunctionDeclaration(d) && !!d.body);
564
- return !!body && readsContext(body, seen, files);
600
+ return !!body && readsContext(body, seen, files, unwrap);
601
+ }
602
+ function reachesReact(fn, seen = new Set()) {
603
+ if (!fn.body ||
604
+ seen.has(fn) ||
605
+ fn.parameters.some((param) => {
606
+ if (!ts.isIdentifier(param.name))
607
+ return true;
608
+ if (!param.initializer)
609
+ return false;
610
+ const value = skipWrappers(param.initializer);
611
+ return (!safeSetupLiteral(value, checker) &&
612
+ !(ts.isObjectLiteralExpression(value) && value.properties.length === 0));
613
+ }) ||
614
+ installed('react', fn.getSourceFile().fileName) !== installed('react', entry))
615
+ return false;
616
+ function dispatch(expression) {
617
+ const call = skipWrappers(expression);
618
+ if (!ts.isCallExpression(call) ||
619
+ ts.isOptionalChain(call) ||
620
+ !ts.isIdentifier(call.expression))
621
+ return false;
622
+ const binding = namedRuntimeImport(call.expression, checker);
623
+ // The arguments of an ordinary call run before the call can return.
624
+ return ((binding?.module === 'react' && hooks.has(binding.name)) || call.arguments.some(dispatch));
625
+ }
626
+ // Every entered branch must call React before it can return. Only simple setup
627
+ // statements and if arms without an else can continue to the next statement.
628
+ function setup(body) {
629
+ for (const statement of body.statements) {
630
+ if (ts.isReturnStatement(statement) || ts.isExpressionStatement(statement))
631
+ return !!statement.expression && dispatch(statement.expression);
632
+ if (ts.isIfStatement(statement) &&
633
+ !statement.elseStatement &&
634
+ ts.isBlock(statement.thenStatement) &&
635
+ setup(statement.thenStatement))
636
+ continue;
637
+ if (!ts.isVariableStatement(statement) ||
638
+ (statement.declarationList.flags & ts.NodeFlags.BlockScoped) !== ts.NodeFlags.Const ||
639
+ statement.declarationList.declarations.length !== 1)
640
+ return false;
641
+ const { initializer } = statement.declarationList.declarations[0];
642
+ if (initializer && dispatch(initializer))
643
+ return true;
644
+ }
645
+ return false;
646
+ }
647
+ if (setup(fn.body))
648
+ return true;
649
+ const call = forwardedCall(fn, true);
650
+ if (!call || ts.isOptionalChain(call))
651
+ return false;
652
+ // The module audit already rules out reassignment and async or generator
653
+ // helpers. An imported alias alone does not identify the runtime module.
654
+ const target = checker
655
+ .getSymbolAtLocation(call.expression)
656
+ ?.declarations?.find((declaration) => ts.isFunctionDeclaration(declaration) &&
657
+ !!declaration.body &&
658
+ declaration.parent === fn.parent);
659
+ seen.add(fn);
660
+ return !!target && reachesReact(target, seen);
661
+ }
662
+ function localExportName(symbol, fn) {
663
+ if (fn.name?.text === symbol.name &&
664
+ fn.modifiers?.some((mod) => mod.kind === ts.SyntaxKind.ExportKeyword))
665
+ return fn.name;
666
+ const alias = symbol.declarations?.find((item) => ts.isExportSpecifier(item) && localExportBody(item, fn.getSourceFile()) === fn);
667
+ return alias?.name;
668
+ }
669
+ function originalExportName(sf, name, fn, depth = 0) {
670
+ if (depth === 5)
671
+ return false;
672
+ const exported = exports(sf).find((item) => item.name === name);
673
+ if (!exported || !identity(exported).declarations?.includes(fn))
674
+ return false;
675
+ if (fn.parent === sf)
676
+ return localExportName(exported, fn)?.text ?? false;
677
+ const reexports = sf.statements
678
+ .filter(ts.isExportDeclaration)
679
+ .filter((edge) => !edge.isTypeOnly);
680
+ const named = reexports.filter(({ exportClause }) => exportClause &&
681
+ ts.isNamedExports(exportClause) &&
682
+ exportClause.elements.some((item) => !item.isTypeOnly && item.name.text === name));
683
+ // ESM resolves an explicit export before consulting any star exports.
684
+ const edges = named.length ? named : reexports.filter((edge) => !edge.exportClause);
685
+ // A barrel with multiple candidate exports does not prove which implementation runs.
686
+ if (edges.length !== 1)
687
+ return false;
688
+ const edge = edges[0];
689
+ if (edge.attributes || !edge.moduleSpecifier)
690
+ return false;
691
+ const specifier = request(edge.moduleSpecifier);
692
+ if (!specifier || (!specifier.startsWith('./') && !specifier.startsWith('../')))
693
+ return false;
694
+ const stem = path.resolve(path.dirname(sf.fileName), specifier);
695
+ if (fs.existsSync(path.join(stem, 'package.json')))
696
+ return false;
697
+ const next = target(specifier, sf.fileName);
698
+ if (!next || !owned(next) || fs.realpathSync(next) !== next || !sourceFile.test(next))
699
+ return false;
700
+ const executable = installed(specifier, sf.fileName);
701
+ if (executable && executable !== next)
702
+ return false;
703
+ const candidates = new Set([stem]);
704
+ for (const prefix of [stem, path.join(stem, 'index')])
705
+ for (const suffix of ['', ...(options.moduleSuffixes ?? [])])
706
+ for (const extension of [
707
+ '.ts',
708
+ '.tsx',
709
+ '.tsrx',
710
+ '.js',
711
+ '.jsx',
712
+ '.mjs',
713
+ '.mts',
714
+ '.cjs',
715
+ '.cts',
716
+ '.json',
717
+ ])
718
+ candidates.add(prefix + suffix + extension);
719
+ if ([...candidates].some((file) => file !== next && fs.statSync(file, { throwIfNoEntry: false })?.isFile()))
720
+ return false;
721
+ const child = program.getSourceFile(next);
722
+ if (!child)
723
+ return false;
724
+ const binding = edge.exportClause && ts.isNamedExports(edge.exportClause)
725
+ ? edge.exportClause.elements.find((item) => !item.isTypeOnly && item.name.text === name)
726
+ : undefined;
727
+ return originalExportName(child, binding?.propertyName?.text ?? name, fn, depth + 1);
565
728
  }
566
729
  const sharedExports = new Map();
567
730
  function isSharedExport(module, imported, from) {
@@ -587,36 +750,49 @@ function modulePlan(pkg, project, entry, candidates, link, options, outputDir, b
587
750
  const result = new Map();
588
751
  return (requested) => {
589
752
  if (!result.has(requested)) {
590
- let plan = null;
753
+ let contract = null;
591
754
  const ex = exportsOfRoot.find((s) => s.name === requested), sym = ex && identity(ex);
592
755
  const fn = sym?.declarations?.find((s) => ts.isFunctionDeclaration(s) && !!s.body);
593
756
  if (fn?.name && /^use[A-Z0-9]/.test(fn.name.text)) {
594
757
  const sf = fn.getSourceFile(), files = new Map();
595
758
  const shared = new Set();
596
- if (discover(sf, files, new Set(), shared) &&
597
- shared.size &&
598
- readsContext(fn, new Set(), files)) {
759
+ const localExports = new Set();
760
+ if (discover(sf, files, new Set(), shared, localExports) && shared.size) {
761
+ contract = {
762
+ requiresReact: () => readsContext(fn, new Set(), files, true) &&
763
+ originalExportName(root, requested, fn) !== false &&
764
+ reachesReact(fn),
765
+ };
766
+ }
767
+ const hasLocalExports = localExports.size > 0;
768
+ const name = hasLocalExports && contract ? originalExportName(root, requested, fn) : fn.name.text;
769
+ if (contract && name && readsContext(fn, new Set(), files)) {
599
770
  const raw = output(sf), entry = raw.replace(/-impl\.ts$/, '.ts');
600
- const bound = exports(sf).flatMap((sym) => {
601
- const impl = identity(sym).declarations?.find((d) => ts.isFunctionDeclaration(d) && !!d.body);
602
- return impl &&
603
- impl.getSourceFile() === sf &&
604
- impl.name &&
771
+ const bound = exports(sf).flatMap((symbol) => {
772
+ const impl = identity(symbol).declarations?.find((d) => ts.isFunctionDeclaration(d) && !!d.body);
773
+ if (!impl || impl.getSourceFile() !== sf)
774
+ return [];
775
+ const key = hasLocalExports ? localExportName(symbol, impl) : impl.name;
776
+ return key &&
777
+ ts.isIdentifier(key) &&
778
+ /^use[A-Z0-9]/.test(key.text) &&
605
779
  readsContext(impl, new Set(), files)
606
- ? [impl.name.text]
780
+ ? [key.text]
607
781
  : [];
608
782
  });
609
- const code = [
610
- `import { bindStoreHook } from ${JSON.stringify(relative(entry, shim))};`,
611
- `import * as implementations from ${JSON.stringify(relative(entry, raw))};`,
612
- ...bound.map((name) => `export const ${name} = bindStoreHook(implementations.${name});`),
613
- '',
614
- ].join('\n');
615
- files.set(entry, nativeDirective + code);
616
- plan = { entry, name: fn.name.text, files, isSharedExport };
783
+ if (bound.includes(name)) {
784
+ const code = [
785
+ `import { bindStoreHook } from ${JSON.stringify(relative(entry, shim))};`,
786
+ `import * as implementations from ${JSON.stringify(relative(entry, raw))};`,
787
+ ...bound.map((name) => `export const ${name} = bindStoreHook(implementations.${name});`),
788
+ '',
789
+ ].join('\n');
790
+ files.set(entry, nativeDirective + code);
791
+ contract.plan = { entry, name, files, isSharedExport };
792
+ }
617
793
  }
618
794
  }
619
- result.set(requested, plan);
795
+ result.set(requested, contract);
620
796
  }
621
797
  return result.get(requested) ?? null;
622
798
  };
@@ -1,18 +1,20 @@
1
+ import { localUses } from './local-uses.js';
2
+ import type { StoreInputCheck } from './store-inputs.js';
1
3
  import ts from 'typescript';
2
- type SharedInput = (module: string, name: string) => boolean | 'opaque';
3
4
  type ResultCheck = {
4
5
  item: ts.ImportSpecifier;
5
- imported: SharedInput;
6
+ imported: StoreInputCheck;
6
7
  known: Map<ts.Expression, boolean>;
7
8
  descriptors: (elements: ts.JsxSelfClosingElement[]) => boolean;
8
9
  unchangedHelper?: (module: string, name: string) => boolean;
10
+ retainedArgument?: (module: string, name: string) => boolean;
9
11
  };
10
- /** Bare SVG default imports can switch from a component to an asset URL for a .tsrx issuer. */
11
- export declare function isBareSvgTag(tag: ts.JsxTagNameExpression, checker: ts.TypeChecker, imports: Set<ts.Node>): boolean;
12
+ /** A bare SVG's default export can switch from a component to an asset URL for a .tsrx issuer. */
13
+ export declare function isBareSvgTag(tag: ts.JsxTagNameExpression, checker: ts.TypeChecker, imports: Set<ts.Node>, uses: ReturnType<typeof localUses>): boolean;
12
14
  /**
13
15
  * A store can contain React elements or objects that carry them. Follow the
14
16
  * result of each direct hook call through local bindings to where it is used.
15
17
  * A condition or discarded method result is safe even with no project types.
16
18
  */
17
- export declare function storeHookUses(file: ts.SourceFile, checker: ts.TypeChecker, isComponent: (fn: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression) => boolean, typeOf: (node: ts.Node) => ts.Type): (item: ts.ImportSpecifier, imported: SharedInput, descriptors: ResultCheck["descriptors"], unchangedHelper?: ResultCheck["unchangedHelper"]) => boolean;
19
+ export declare function storeHookUses(file: ts.SourceFile, checker: ts.TypeChecker, isComponent: (fn: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression) => boolean, typeOf: (node: ts.Node) => ts.Type): (item: ts.ImportSpecifier, imported: StoreInputCheck, descriptors: ResultCheck["descriptors"], unchangedHelper?: ResultCheck["unchangedHelper"], retainedArgument?: ResultCheck["retainedArgument"]) => boolean;
18
20
  export {};