@octanejs/codemod 0.2.1 → 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.
- package/README.md +97 -8
- package/dist/bin.js +2 -2
- package/dist/effect-receivers.d.ts +2 -0
- package/dist/effect-receivers.js +10 -0
- package/dist/expression-wrappers.d.ts +2 -0
- package/dist/expression-wrappers.js +19 -0
- package/dist/forwarded-props.d.ts +4 -1
- package/dist/forwarded-props.js +18 -3
- package/dist/local-react-hook.d.ts +7 -2
- package/dist/local-react-hook.js +99 -44
- package/dist/local-uses.d.ts +2 -0
- package/dist/local-uses.js +22 -0
- package/dist/mappings.d.ts +5 -1
- package/dist/mappings.js +16 -3
- package/dist/path-svg.d.ts +5 -0
- package/dist/path-svg.js +19 -2
- package/dist/project.js +868 -122
- package/dist/react-intl.d.ts +1 -1
- package/dist/react-intl.js +23 -3
- package/dist/react-island-sources.d.ts +26 -7
- package/dist/react-island-sources.js +614 -64
- package/dist/react-renderer.d.ts +2 -0
- package/dist/react-renderer.js +94 -0
- package/dist/scoped-store-contract.d.ts +6 -1
- package/dist/scoped-store-contract.js +199 -31
- package/dist/store-hook-uses.js +1 -20
- package/dist/store-inputs.js +3 -1
- package/dist/transform.d.ts +6 -0
- package/dist/transform.js +1922 -251
- package/dist/types.d.ts +24 -8
- package/package.json +4 -3
- package/src/path-svg.ts +20 -2
- package/templates/octane-path-svg.ts +4 -0
- package/templates/react-intl.tsrx +64 -11
package/dist/react-intl.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { TransformOptions } from './types.js';
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
/** Select whole named imports that the shared adapter can replace without changing renderer-owned values. */
|
|
4
|
-
export declare function intlImports(file: ts.SourceFile, importedText: TransformOptions['forwardedText'], checker: ts.TypeChecker, typeOf: (expression: ts.Expression) => ts.Type, isComponent: (functionNode: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression) => boolean, inReact: (element: ts.JsxElement | ts.JsxSelfClosingElement) => boolean, canPassToReact: (element: ts.JsxElement | ts.JsxSelfClosingElement) => boolean, returnedReceiver: (tag: ts.JsxOpeningLikeElement) => boolean, originalReact: () => boolean, unknownFormatter: (call: ts.CallExpression, method: string) => void): Set<ts.ImportSpecifier>;
|
|
4
|
+
export declare function intlImports(file: ts.SourceFile, importedText: TransformOptions['forwardedText'], checker: ts.TypeChecker, typeOf: (expression: ts.Expression) => ts.Type, isComponent: (functionNode: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression) => boolean, inReact: (element: ts.JsxElement | ts.JsxSelfClosingElement) => boolean, canPassToReact: (element: ts.JsxElement | ts.JsxSelfClosingElement) => boolean, returnedReceiver: (tag: ts.JsxOpeningLikeElement) => boolean, originalReact: () => boolean, reactHook: (callee: ts.Expression) => string | null, unknownFormatter: (call: ts.CallExpression, method: string) => void): Set<ts.ImportSpecifier>;
|
package/dist/react-intl.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { closedForwardedAttribute, forwardedProps, hasEval, hasPrototypeAccess, renderUses, } from './forwarded-props.js';
|
|
2
|
+
import { isWrapper } from './expression-wrappers.js';
|
|
2
3
|
import { localUses, portableArguments, scalar } from './local-uses.js';
|
|
3
4
|
import ts from 'typescript';
|
|
4
5
|
const scalarMethods = new Set([
|
|
@@ -11,8 +12,27 @@ const scalarMethods = new Set([
|
|
|
11
12
|
'formatDisplayName',
|
|
12
13
|
]);
|
|
13
14
|
const descriptor = new Set(['id', 'description', 'defaultMessage', 'ignoreTag']);
|
|
15
|
+
function isEagerFunction(node, reactHook) {
|
|
16
|
+
if (!(ts.isArrowFunction(node) || ts.isFunctionExpression(node)) ||
|
|
17
|
+
node.asteriskToken ||
|
|
18
|
+
node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword))
|
|
19
|
+
return false;
|
|
20
|
+
let expression = node;
|
|
21
|
+
while (isWrapper(expression.parent))
|
|
22
|
+
expression = expression.parent;
|
|
23
|
+
const call = expression.parent;
|
|
24
|
+
if (!ts.isCallExpression(call))
|
|
25
|
+
return false;
|
|
26
|
+
if (call.expression === expression)
|
|
27
|
+
return true;
|
|
28
|
+
if (call.arguments[0] !== expression || ts.isOptionalChain(call))
|
|
29
|
+
return false;
|
|
30
|
+
const hook = reactHook(call.expression);
|
|
31
|
+
return ((hook === 'useState' && call.arguments.length === 1) ||
|
|
32
|
+
(hook === 'useMemo' && call.arguments.length === 2 && !ts.isSpreadElement(call.arguments[1])));
|
|
33
|
+
}
|
|
14
34
|
/** Select whole named imports that the shared adapter can replace without changing renderer-owned values. */
|
|
15
|
-
export function intlImports(file, importedText, checker, typeOf, isComponent, inReact, canPassToReact, returnedReceiver, originalReact, unknownFormatter) {
|
|
35
|
+
export function intlImports(file, importedText, checker, typeOf, isComponent, inReact, canPassToReact, returnedReceiver, originalReact, reactHook, unknownFormatter) {
|
|
16
36
|
const candidates = file.statements.filter(ts.isImportDeclaration).flatMap((decl) => {
|
|
17
37
|
const named = decl.importClause?.namedBindings;
|
|
18
38
|
if (!ts.isStringLiteral(decl.moduleSpecifier) ||
|
|
@@ -176,11 +196,11 @@ export function intlImports(file, importedText, checker, typeOf, isComponent, in
|
|
|
176
196
|
if (!ts.isCallExpression(call) || call.expression !== access)
|
|
177
197
|
return false;
|
|
178
198
|
if (scalarMethods.has(access.name.text)) {
|
|
179
|
-
//
|
|
199
|
+
// React runs inline calls, memo calculators and lazy state initializers during render.
|
|
180
200
|
if (!owner.asteriskToken &&
|
|
181
201
|
!owner.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword) &&
|
|
182
202
|
ts.findAncestor(call, (node) => node === owner.body ||
|
|
183
|
-
ts.isFunctionLike(node) ||
|
|
203
|
+
(ts.isFunctionLike(node) && !isEagerFunction(node, reactHook)) ||
|
|
184
204
|
ts.isClassLike(node) ||
|
|
185
205
|
ts.isInterfaceDeclaration(node) ||
|
|
186
206
|
ts.isTypeNode(node)) === owner.body)
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
export declare function importsReactBridge(source: string): boolean;
|
|
2
|
+
/** Direct React class exports, including an alias in a local export list. */
|
|
3
|
+
export declare function reactClassExports(file: string, source: string): Set<string>;
|
|
4
|
+
/** Direct module-level const exports initialized by the real React context factory. */
|
|
5
|
+
export declare function retainedReactContextExports(file: string, source: string): Map<string, boolean>;
|
|
2
6
|
/** Original imported components handed to an authored React island. */
|
|
3
7
|
export declare function islandComponents(file: string, source: string, original: (module: string) => boolean): Promise<string[]>;
|
|
4
|
-
/** Runtime imports that an explicit
|
|
5
|
-
export declare function
|
|
6
|
-
line: number;
|
|
8
|
+
/** Runtime imports that an explicit React host returns directly. */
|
|
9
|
+
export declare function hostedComponents(file: string, source: string, bridge: 'octane/react' | 'octane/react/server', selected?: boolean): {
|
|
7
10
|
name: string;
|
|
8
11
|
module: string;
|
|
12
|
+
line: number;
|
|
9
13
|
}[];
|
|
10
|
-
/**
|
|
14
|
+
/** Imports rendered directly by a retained component. */
|
|
11
15
|
export declare function retainedReactComponentReturns(file: string, source: string): {
|
|
16
|
+
name: string;
|
|
17
|
+
module: string;
|
|
18
|
+
factory?: true;
|
|
19
|
+
lazy?: true;
|
|
12
20
|
line: number;
|
|
21
|
+
}[];
|
|
22
|
+
/** Named React factories returned by an otherwise retained function. */
|
|
23
|
+
export declare function retainedReactElementReturns(file: string, source: string): {
|
|
13
24
|
name: string;
|
|
14
25
|
module: string;
|
|
26
|
+
line: number;
|
|
15
27
|
}[];
|
|
16
28
|
/** Existing Octane roots that render a directly imported component body. */
|
|
17
29
|
export declare function octaneRootComponents(file: string, source: string): {
|
|
@@ -21,13 +33,20 @@ export declare function octaneRootComponents(file: string, source: string): {
|
|
|
21
33
|
line: number;
|
|
22
34
|
}[];
|
|
23
35
|
/** React server calls that render directly imported components. */
|
|
24
|
-
export declare function reactServerComponents(file: string, source: string, original: (module: 'react' | 'react/jsx-runtime') => boolean,
|
|
36
|
+
export declare function reactServerComponents(file: string, source: string, original: (module: 'react' | 'react/jsx-runtime') => boolean, selected?: boolean): {
|
|
25
37
|
module: string;
|
|
26
38
|
name: string;
|
|
27
39
|
line: number;
|
|
28
40
|
}[];
|
|
29
|
-
/** Local exports whose original body returns
|
|
30
|
-
export declare function
|
|
41
|
+
/** Local exports whose original body returns React JSX directly. */
|
|
42
|
+
export declare function directReactExports(file: string, source: string): {
|
|
43
|
+
intrinsics: Set<string>;
|
|
44
|
+
wrappers: Set<string>;
|
|
45
|
+
splitIntrinsicDefault: boolean;
|
|
46
|
+
mayExportThen: boolean;
|
|
47
|
+
};
|
|
48
|
+
/** Factories whose intrinsic JSX return survives as Octane JSX in the emitted file. */
|
|
49
|
+
export declare function migratedJsxFactories(file: string, source: string, emitted: string): Set<string>;
|
|
31
50
|
/** Inspect the emitted local export before assigning a reverse island to a server host. */
|
|
32
51
|
export declare function reverseIslandExports(file: string, source: string, original: (module: string) => boolean): Promise<Set<string>>;
|
|
33
52
|
/** Declaration-level type imports disappear even with verbatimModuleSyntax. */
|