@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
@@ -15,13 +15,20 @@ export function scalar(type) {
15
15
  ts.TypeFlags.Null |
16
16
  ts.TypeFlags.Undefined));
17
17
  }
18
- function localSymbol(checker, id) {
18
+ export function localSymbol(checker, id) {
19
19
  return ts.isShorthandPropertyAssignment(id.parent) && id.parent.name === id
20
20
  ? checker.getShorthandAssignmentValueSymbol(id.parent)
21
21
  : ts.isExportSpecifier(id.parent)
22
22
  ? checker.getExportSpecifierLocalTargetSymbol(id.parent)
23
23
  : checker.getSymbolAtLocation(id);
24
24
  }
25
+ /** A type query reads only the type. Class heritage reads the actual value. */
26
+ export function inTypeNode(node) {
27
+ let parent = node.parent;
28
+ while (ts.isQualifiedName(parent))
29
+ parent = parent.parent;
30
+ return ts.isTypeNode(parent) && !ts.isExpressionWithTypeArguments(parent);
31
+ }
25
32
  function isMember(node) {
26
33
  return ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node);
27
34
  }
@@ -185,12 +192,14 @@ function localWrites(file, checker) {
185
192
  }
186
193
  // Visit the storage locations a local reference may name, including a binding's
187
194
  // initializer and subsequent assignments. Unknown computed keys match any field.
188
- function locations(node, path, writing, match, initial, unbound) {
195
+ function locations(node, path, writing, match, initial, unbound, leaf) {
189
196
  const states = new Map();
190
197
  const activeReturns = new Set();
191
198
  const joinedReturns = new Map();
192
199
  let returnVisits = 0;
193
200
  function trace(node, path, frame) {
201
+ if (leaf?.(node))
202
+ return true;
194
203
  if (isWrapper(node))
195
204
  return trace(node.expression, path, frame);
196
205
  if (isMember(node)) {
@@ -201,6 +210,9 @@ function localWrites(file, checker) {
201
210
  return node.arguments.some((arg, i) => (i === 0 || path.length > 0) && trace(arg, path, frame));
202
211
  }
203
212
  if (ts.isCallExpression(node)) {
213
+ // The value query can reach a local call even in a file without indexed member writes.
214
+ if (leaf && !calls.targets.has(node))
215
+ calls.scan(node);
204
216
  const fn = calls.targets.get(node);
205
217
  if (fn && !activeReturns.has(node)) {
206
218
  const joined = frame === null || ++returnVisits > MAX_CALL_CONTEXTS;
@@ -222,6 +234,11 @@ function localWrites(file, checker) {
222
234
  }
223
235
  if (ts.isConditionalExpression(node))
224
236
  return trace(node.whenTrue, path, frame) || trace(node.whenFalse, path, frame);
237
+ if (leaf &&
238
+ ts.isBinaryExpression(node) &&
239
+ (node.operatorToken.kind === ts.SyntaxKind.CommaToken ||
240
+ node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken))
241
+ return trace(node.right, path, frame);
225
242
  if (isLogical(node))
226
243
  return trace(node.left, path, frame) || trace(node.right, path, frame);
227
244
  if ((path.length || !writing) && ts.isArrayLiteralExpression(node)) {
@@ -567,8 +584,8 @@ function localWrites(file, checker) {
567
584
  const value = selected(d.initializer, [key]);
568
585
  return !!value && scalar(checker.getTypeAtLocation(skipWrappers(value)));
569
586
  }
570
- function memberSources(node, visit, frame, selectionPath) {
571
- if (!members.size || (!selectionPath && !consumingUse(node)))
587
+ function memberSources(node, visit, frame, selectionPath, leaf) {
588
+ if (!members.size || (!selectionPath && !leaf && !consumingUse(node)))
572
589
  return false;
573
590
  return locations(node, selectionPath ?? [], false, (root, read, instance) => !!members
574
591
  .get(root)
@@ -587,7 +604,7 @@ function localWrites(file, checker) {
587
604
  return false;
588
605
  const origin = sourcePath(selection, read.slice(path.length), false);
589
606
  return visit(source, sourceFrame === undefined ? frame : sourceFrame, origin);
590
- }), frame);
607
+ }), frame, undefined, leaf);
591
608
  }
592
609
  function record(target, source, selection) {
593
610
  if (ts.isIdentifier(target)) {
@@ -782,6 +799,11 @@ function localWrites(file, checker) {
782
799
  bindingStep,
783
800
  arguments: argumentSources,
784
801
  bindings,
802
+ values: (node, selection, imported, leaf) => {
803
+ const trace = (value, frame, path = []) => locations(value, path, false, imported, frame, undefined, leaf);
804
+ return (trace(node, undefined, selection) ||
805
+ memberSources(node, trace, undefined, selection.length ? selection : undefined, leaf));
806
+ },
785
807
  members: memberSources,
786
808
  hasMemberWrite: (name) => (members.size > 0 || mutationOnly.size > 0) &&
787
809
  locations(name, [], false, (root) => members.has(root) || mutationOnly.has(root)),
@@ -887,6 +909,41 @@ export function walkLocalValues(root, checker, inspect) {
887
909
  }
888
910
  return walk(root);
889
911
  }
912
+ /** Follow the bindings that can supply a value or a selected part of it. */
913
+ export function valueReads(value, checker, selection, binding, leaf) {
914
+ return localWrites(value.getSourceFile(), checker).values(value, selection, binding, leaf);
915
+ }
916
+ export function transportedValue(value, checker, selection, imported, jsx) {
917
+ return valueReads(value, checker, selection, (symbol, path) => {
918
+ const item = symbol.declarations?.[0];
919
+ if (!item)
920
+ return false;
921
+ let clause;
922
+ let name;
923
+ if (ts.isImportSpecifier(item) && !item.isTypeOnly) {
924
+ clause = item.parent.parent;
925
+ name = (item.propertyName ?? item.name).text;
926
+ }
927
+ else if (ts.isImportClause(item) && item.name) {
928
+ clause = item;
929
+ name = 'default';
930
+ }
931
+ else if (ts.isNamespaceImport(item) && path.length) {
932
+ clause = item.parent;
933
+ [name, ...path] = path;
934
+ }
935
+ else
936
+ return false;
937
+ const statement = clause.parent;
938
+ return (name !== undefined &&
939
+ !clause.isTypeOnly &&
940
+ !statement.attributes &&
941
+ ts.isStringLiteral(statement.moduleSpecifier) &&
942
+ imported(statement.moduleSpecifier.text, name, path));
943
+ }, (node) => !!jsx &&
944
+ (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node)) &&
945
+ jsx());
946
+ }
890
947
  export function portableArguments(checker, typeOf) {
891
948
  function argument(expr, imported) {
892
949
  if (ts.isParenthesizedExpression(expr) ||
@@ -950,6 +1007,9 @@ export function portableArguments(checker, typeOf) {
950
1007
  return (expr, imported) => {
951
1008
  if (!argument(expr, imported))
952
1009
  return false;
1010
+ if (imported &&
1011
+ transportedValue(expr, checker, [], (module, name, selection) => imported(module, name, selection) === 'reject'))
1012
+ return false;
953
1013
  let safe = clean.get(expr);
954
1014
  if (safe === undefined) {
955
1015
  safe = !walkLocalValues(expr, checker, (n) => ts.isJsxElement(n) || ts.isJsxSelfClosingElement(n) || ts.isJsxFragment(n)
@@ -967,6 +1027,28 @@ export function componentTagOrExport(ref) {
967
1027
  ? p.tagName === ref
968
1028
  : ts.isExportSpecifier(p) || ts.isExportAssignment(p);
969
1029
  }
1030
+ /** Lexical context reads allowed by the retained Provider advisory. */
1031
+ export function unchangedContextProviderUse(ref, isReactContextRead) {
1032
+ if (inTypeNode(ref) || componentTagOrExport(ref))
1033
+ return true;
1034
+ const member = ref.parent;
1035
+ if (ts.isCallExpression(member)) {
1036
+ return (!ts.isOptionalChain(member) &&
1037
+ member.arguments[0] === ref &&
1038
+ member.arguments.length === 1 &&
1039
+ isReactContextRead(member.expression));
1040
+ }
1041
+ if (!ts.isPropertyAccessExpression(member) || member.expression !== ref)
1042
+ return false;
1043
+ const use = member.parent;
1044
+ return (((ts.isJsxOpeningElement(use) ||
1045
+ ts.isJsxSelfClosingElement(use) ||
1046
+ ts.isJsxClosingElement(use)) &&
1047
+ use.tagName === member) ||
1048
+ (member.name.text === 'displayName' &&
1049
+ ((ts.isVariableDeclaration(use) && use.initializer === member) ||
1050
+ (ts.isReturnStatement(use) && use.expression === member))));
1051
+ }
970
1052
  export function localUses(file, checker) {
971
1053
  const refs = new Map();
972
1054
  function visit(node) {
@@ -16,6 +16,8 @@ export declare const RADIX_TYPES: Set<string>;
16
16
  * `@octanejs/radix` serves as namespaces.
17
17
  */
18
18
  export declare const PORTED_PACKAGES: Record<string, string>;
19
+ /** The React entry points that the bounded Motion binding serves from its root. */
20
+ export declare function isReactMotion(module: string): module is "framer-motion" | "motion/react";
19
21
  /**
20
22
  * The `@octanejs/radix` namespace a Radix package's imports become, or null.
21
23
  * `@radix-ui/react-slot` has none: its exports are the binding's own.
@@ -43,8 +45,12 @@ export declare function mapReactImport(module: string, name: string, typeOnly: b
43
45
  module: string;
44
46
  name: string;
45
47
  } | null;
48
+ /** React-family hooks that need a compiled call site and the original ref allocator. */
49
+ export declare function isComputedReactHookOrRef(name: string): boolean;
50
+ /** Whether a React value type query can name an actual Octane export. */
51
+ export declare function hasOctaneValue(name: string): boolean;
46
52
  /** The Octane name for `React.<name>` in a type position. */
47
- export declare function mapQualifiedType(name: string): string | null;
53
+ export declare function mapQualifiedType(name: string, module: string, typeOf: boolean, typeArgumentCount: number): string | null;
48
54
  /** Built-in hooks whose omitted dependency list Octane infers. * */
49
55
  export declare const DEPENDENCY_HOOKS: Record<string, number>;
50
56
  /** `<input type>` values whose native `change` fires on commit, not per edit. */
package/dist/mappings.js CHANGED
@@ -94,7 +94,7 @@ const OCTANE_TYPES = new Set(('AllHTMLAttributes AnchorHTMLAttributes AnimationE
94
94
  'SVGAttributes SVGLineElementAttributes SVGProps SVGTextElementAttributes ScriptHTMLAttributes ' +
95
95
  'SelectHTMLAttributes SetStateAction SlotHTMLAttributes SourceHTMLAttributes StrictModeProps ' +
96
96
  'StyleHTMLAttributes SuspenseProps TableHTMLAttributes TdHTMLAttributes TextareaHTMLAttributes ' +
97
- 'ThHTMLAttributes TimeHTMLAttributes ToggleEvent ToggleEventHandler TouchEvent TouchEventHandler ' +
97
+ 'ThHTMLAttributes TimeHTMLAttributes ToggleEvent ToggleEventHandler Touch TouchEvent TouchEventHandler ' +
98
98
  'TrackHTMLAttributes TransitionEvent TransitionEventHandler UIEvent UIEventHandler ' +
99
99
  'VideoHTMLAttributes WebViewHTMLAttributes WheelEvent WheelEventHandler').split(' '));
100
100
  /**
@@ -214,9 +214,14 @@ const TANSTACK_ADAPTERS = {
214
214
  export const PORTED_PACKAGES = {
215
215
  '@floating-ui/react-dom': '@octanejs/floating-ui/react-dom',
216
216
  '@tanstack/react-start': '@octanejs/tanstack-start',
217
+ 'motion/react': '@octanejs/motion',
217
218
  ...Object.fromEntries(Object.keys(TANSTACK_ADAPTERS).map((name) => [name, name.replace('/react-', '/octane-')])),
218
219
  ...Object.fromEntries([...RADIX_PACKAGES.keys()].map((name) => [name, '@octanejs/radix'])),
219
220
  };
221
+ /** The React entry points that the bounded Motion binding serves from its root. */
222
+ export function isReactMotion(module) {
223
+ return module === 'framer-motion' || module === 'motion/react';
224
+ }
220
225
  /**
221
226
  * The `@octanejs/radix` namespace a Radix package's imports become, or null.
222
227
  * `@radix-ui/react-slot` has none: its exports are the binding's own.
@@ -298,14 +303,27 @@ export function mapReactImport(module, name, typeOnly) {
298
303
  }
299
304
  if (!typeOnly && OCTANE_VALUES.has(name))
300
305
  return { module: 'octane', name };
301
- if (OCTANE_TYPES.has(name))
306
+ if (OCTANE_TYPES.has(name) && (name !== 'Touch' || (module === 'react' && typeOnly)))
302
307
  return { module: 'octane', name };
303
308
  if (name in RENAMED_TYPES)
304
309
  return { module: 'octane', name: RENAMED_TYPES[name] };
305
310
  return null;
306
311
  }
312
+ /** React-family hooks that need a compiled call site and the original ref allocator. */
313
+ export function isComputedReactHookOrRef(name) {
314
+ return name === 'createRef' || (name.startsWith('use') && OCTANE_VALUES.has(name));
315
+ }
316
+ /** Whether a React value type query can name an actual Octane export. */
317
+ export function hasOctaneValue(name) {
318
+ return OCTANE_VALUES.has(name);
319
+ }
307
320
  /** The Octane name for `React.<name>` in a type position. */
308
- export function mapQualifiedType(name) {
321
+ export function mapQualifiedType(name, module, typeOf, typeArgumentCount) {
322
+ if (name === 'Touch' && (module !== 'react' || typeOf))
323
+ return null;
324
+ // OctaneElement only accepts props. The migration alias preserves an explicit element type.
325
+ if (name === 'ReactElement' && typeArgumentCount > 1)
326
+ return name;
309
327
  if (name in QUALIFIED_TYPE_PREFERENCES)
310
328
  return QUALIFIED_TYPE_PREFERENCES[name];
311
329
  if (OCTANE_TYPES.has(name))
@@ -14,13 +14,25 @@ declare const shapeAttributes: {
14
14
  opacity: RegExp;
15
15
  };
16
16
  rect: {
17
- fill: RegExp;
17
+ rx: RegExp;
18
+ ry: RegExp;
19
+ transform: RegExp;
18
20
  x: RegExp;
19
21
  y: RegExp;
20
22
  width: RegExp;
21
23
  height: RegExp;
22
- rx: RegExp;
23
- ry: RegExp;
24
+ fill: RegExp;
25
+ stroke: RegExp;
26
+ 'stroke-width': RegExp;
27
+ 'stroke-linecap': RegExp;
28
+ 'stroke-linejoin': RegExp;
29
+ opacity: RegExp;
30
+ };
31
+ circle: {
32
+ cx: RegExp;
33
+ cy: RegExp;
34
+ r: RegExp;
35
+ fill: RegExp;
24
36
  stroke: RegExp;
25
37
  'stroke-width': RegExp;
26
38
  'stroke-linecap': RegExp;
@@ -30,6 +42,8 @@ declare const shapeAttributes: {
30
42
  g: {
31
43
  transform: RegExp;
32
44
  'clip-path': RegExp;
45
+ mask: RegExp;
46
+ filter: RegExp;
33
47
  };
34
48
  defs: {};
35
49
  clipPath: {
@@ -41,6 +55,51 @@ declare const shapeAttributes: {
41
55
  height: RegExp;
42
56
  patternUnits: RegExp;
43
57
  };
58
+ linearGradient: {
59
+ id: RegExp;
60
+ gradientUnits: RegExp;
61
+ x1: RegExp;
62
+ y1: RegExp;
63
+ x2: RegExp;
64
+ y2: RegExp;
65
+ };
66
+ stop: {
67
+ offset: RegExp;
68
+ 'stop-color': RegExp;
69
+ 'stop-opacity': RegExp;
70
+ };
71
+ mask: {
72
+ maskUnits: RegExp;
73
+ style: RegExp;
74
+ x: RegExp;
75
+ y: RegExp;
76
+ width: RegExp;
77
+ height: RegExp;
78
+ id: RegExp;
79
+ };
80
+ filter: {
81
+ filterUnits: RegExp;
82
+ 'color-interpolation-filters': RegExp;
83
+ x: RegExp;
84
+ y: RegExp;
85
+ width: RegExp;
86
+ height: RegExp;
87
+ id: RegExp;
88
+ };
89
+ feFlood: {
90
+ 'flood-opacity': RegExp;
91
+ result: RegExp;
92
+ };
93
+ feBlend: {
94
+ in: RegExp;
95
+ in2: RegExp;
96
+ mode: RegExp;
97
+ result: RegExp;
98
+ };
99
+ feGaussianBlur: {
100
+ stdDeviation: RegExp;
101
+ result: RegExp;
102
+ };
44
103
  };
45
104
  export declare function svgDataAttribute(name: string): name is `data-${string}`;
46
105
  type StaticSvgNode = {
@@ -48,10 +107,15 @@ type StaticSvgNode = {
48
107
  attributes: Record<string, string>;
49
108
  children: StaticSvgNode[];
50
109
  };
51
- /** Read authored geometry with a single local clip or paint definition. */
110
+ /** Read authored geometry with bounded local paint and effect definitions. */
52
111
  export declare function parseStaticSvg(source: string): {
53
112
  root: Record<string, string>;
54
113
  children: StaticSvgNode[];
114
+ title?: undefined;
115
+ } | {
116
+ root: Record<string, string>;
117
+ children: StaticSvgNode[];
118
+ title: string;
55
119
  } | null;
56
120
  export declare function parsePathSvg(source: string): {
57
121
  root: Record<string, string>;