@octanejs/codemod 0.1.2 → 0.1.4
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 +21 -5
- package/package.json +4 -3
- package/src/bin.js +18 -2
- package/src/index.d.ts +4 -0
- package/src/mappings.js +13 -0
- package/src/project.js +178 -2
- package/src/transform.js +190 -46
package/README.md
CHANGED
|
@@ -10,8 +10,9 @@ npx @octanejs/codemod src --dry-run # report only
|
|
|
10
10
|
npx @octanejs/codemod src --strong # also make modules Strong where possible
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
The codemod adds each binding the migrated code imports to `package.json`, at
|
|
14
|
+
the version in its catalog. Then run `npx @octanejs/cli init` to swap the
|
|
15
|
+
bundler plugin and `tsconfig` over to Octane and install the dependencies.
|
|
15
16
|
|
|
16
17
|
> **Prototype.** The rewrites below are tested, and every migrated module is
|
|
17
18
|
> compiled by the Octane compiler before it is written, but the rule set is
|
|
@@ -27,6 +28,7 @@ dependencies over to Octane.
|
|
|
27
28
|
| `imports` | React libraries with a binding (`@tanstack/react-query`, ...) | `@octanejs/*` |
|
|
28
29
|
| `imports` | `@radix-ui/react-<primitive>` (`import * as DialogPrimitive from '@radix-ui/react-dialog'`) | that primitive's namespace of `@octanejs/radix` (`import { Dialog as DialogPrimitive } from '@octanejs/radix'`) |
|
|
29
30
|
| `imports` | `@tanstack/react-table`, `@tanstack/react-hotkeys`, `@tanstack/react-pacer` | TanStack's own `@tanstack/octane-*` adapters, with `Octane` for `React` in type names |
|
|
31
|
+
| `imports` | `jsx`, `jsxs` from `react/jsx-runtime`, passed to a JSX runtime consumer such as `hast-util-to-jsx-runtime` | a local `jsx` that calls `createElement` with the key in its props |
|
|
30
32
|
| `template-component` | `function C() { …; return <div /> }` | `function C() @{ …; <div /> }` |
|
|
31
33
|
| `template-if` | `{a ? <A /> : <B />}`, `{a > 0 && <A />}` (also through a `const`) | `@if (a) { <A /> } @else { <B /> }` |
|
|
32
34
|
| `template-if` | `if (a) return <A />; …; return <B />` in a component | `@if (a) { <A /> } @else { …; <B /> }` |
|
|
@@ -38,8 +40,8 @@ dependencies over to Octane.
|
|
|
38
40
|
| `descriptor-children` | a component that clones or inspects `children` (`render={children}`, `cloneElement`, `Children.only`) | `descriptorChildren(…)`, so callers pass elements as React does |
|
|
39
41
|
| `context-provider` | `<Ctx.Provider value>` | `<Ctx value>` |
|
|
40
42
|
| `context-consumer` | `<Ctx.Consumer>{(v) => …}</Ctx.Consumer>` | `@{ const v = useContext(Ctx); … }` |
|
|
41
|
-
| `native-text-change` | `onChange` on a text `<input>` / `<textarea
|
|
42
|
-
| `native-text-change` | `function Input({ ...props }) { return <input {...props} /> }` | `function Input({ onChange, ...props }) @{ <input onInput={onChange} {...props} /> }` |
|
|
43
|
+
| `native-text-change` | `onChange` on a text `<input>` / `<textarea>`, or on Base UI's `Input` / `Field.Control`, which render one | `onInput` (native `change` fires on blur) |
|
|
44
|
+
| `native-text-change` | `function Input({ ...props }) { return <input {...props} /> }`, also when a nested `const { a, ...rest } = props` reaches the field | `function Input({ onChange, ...props }) @{ <input onInput={onChange} {...props} /> }` |
|
|
43
45
|
| `event-object` | `e.nativeEvent`, `e.persist()`, `e.target` on a control, also through a component typed for one | `e`, removed, `e.currentTarget` |
|
|
44
46
|
| `class-attribute` | `className` on an HTML element | `class` |
|
|
45
47
|
| `legacy-root` | `ReactDOM.render(el, c)` | `createRoot(c).render(el)` |
|
|
@@ -64,6 +66,10 @@ Every module with JSX becomes `.tsrx`, entries and helpers without a component
|
|
|
64
66
|
included, so Strong mode can reach all of them; one that was JavaScript gains
|
|
65
67
|
`// @ts-nocheck`, so it stays as unchecked as it was. Every import of a renamed
|
|
66
68
|
module, dynamic imports and `index.html` entry scripts included, is updated.
|
|
69
|
+
So is each string elsewhere in the project that is exactly a renamed module's
|
|
70
|
+
path, from its own file or from the project root, such as Vite's
|
|
71
|
+
`server.warmup.clientFiles: ['./src/main.tsx']`: the `module-paths` rule.
|
|
72
|
+
Globs and paths without an extension stay as they are.
|
|
67
73
|
|
|
68
74
|
## Strong mode
|
|
69
75
|
|
|
@@ -88,10 +94,20 @@ has React and React DOM 19.2 or newer in the React 19 series, a component of tha
|
|
|
88
94
|
its own React root through `ReactCompat` if its element gives React nothing
|
|
89
95
|
Octane renders: text children and props without elements. The package's hooks
|
|
90
96
|
and contexts, and its components that take Octane children or render
|
|
91
|
-
callbacks, are reported where they are used.
|
|
97
|
+
callbacks, are reported where they are used. Each such component is wrapped
|
|
98
|
+
in a local `NoOctanePort`, which throws the reported error where the component
|
|
99
|
+
would render, so the page names the package instead of failing deep in
|
|
100
|
+
Octane's renderer. Once you have checked that nothing Octane renders reaches
|
|
101
|
+
it, such as a spread of props whose `children` no caller passes, swap the
|
|
102
|
+
wrapper for `ReactCompat`. **No Octane port** lists each such
|
|
92
103
|
package with the modules that import it, the elements hosted in islands, and
|
|
93
104
|
the uses that need a port.
|
|
94
105
|
|
|
106
|
+
A patch the project applies to a React package the codemod replaces, through
|
|
107
|
+
`patchedDependencies` (pnpm, Bun) or `patches/` (patch-package), patches the
|
|
108
|
+
React package, not its binding. **Dependencies** names each one, to port by
|
|
109
|
+
hand.
|
|
110
|
+
|
|
95
111
|
## Options
|
|
96
112
|
|
|
97
113
|
| Flag | |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/codemod",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.22.2"
|
|
@@ -39,8 +39,9 @@
|
|
|
39
39
|
"./package.json": "./package.json"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@octanejs/cli": "0.3.
|
|
43
|
-
"
|
|
42
|
+
"@octanejs/cli": "0.3.3",
|
|
43
|
+
"@tsrx/oxc": "0.23.0",
|
|
44
|
+
"octane": "0.16.7",
|
|
44
45
|
"picocolors": "^1.1.1",
|
|
45
46
|
"typescript": "^5.9.3"
|
|
46
47
|
},
|
package/src/bin.js
CHANGED
|
@@ -99,7 +99,21 @@ if (findings.length > 0) {
|
|
|
99
99
|
}
|
|
100
100
|
if (result.packages.length > 0) {
|
|
101
101
|
process.stdout.write(`\n${colors.bold('Dependencies')}\n`);
|
|
102
|
-
|
|
102
|
+
const ranges = new Map(result.dependencies.map(({ name, range }) => [name, range]));
|
|
103
|
+
for (const { from, to } of result.packages) {
|
|
104
|
+
const range = ranges.get(to);
|
|
105
|
+
process.stdout.write(` ${from} → ${to}${range ? colors.dim(` ${range}`) : ''}\n`);
|
|
106
|
+
}
|
|
107
|
+
if (ranges.size > 0) {
|
|
108
|
+
process.stdout.write(
|
|
109
|
+
colors.dim(` ${dryRun ? 'Would add' : 'Added'} ${ranges.size} to package.json\n`),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
for (const { name, patch } of result.patched) {
|
|
113
|
+
process.stdout.write(
|
|
114
|
+
` ${colors.yellow('warning')} ${name} is patched by ${patch}, which does not apply to its binding: port the patch there.\n`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
103
117
|
}
|
|
104
118
|
if (result.missing.length > 0) {
|
|
105
119
|
process.stdout.write(
|
|
@@ -127,7 +141,9 @@ const summary = [
|
|
|
127
141
|
].filter(Boolean);
|
|
128
142
|
process.stdout.write(`\n${summary.join(', ')}${dryRun ? colors.dim(' (dry run)') : ''}\n`);
|
|
129
143
|
if (changed.length > 0 && !dryRun) {
|
|
130
|
-
|
|
144
|
+
// A project outside this directory is named in full, not by `../` steps.
|
|
145
|
+
const relative = path.relative(process.cwd(), result.root);
|
|
146
|
+
const root = relative.startsWith('..') ? result.root : relative || '.';
|
|
131
147
|
process.stdout.write(
|
|
132
148
|
colors.dim(`Next: run \`npx @octanejs/cli init\` in ${root} to wire Octane into the build.\n`),
|
|
133
149
|
);
|
package/src/index.d.ts
CHANGED
|
@@ -69,6 +69,10 @@ interface CodemodResult {
|
|
|
69
69
|
root: string;
|
|
70
70
|
files: FileResult[];
|
|
71
71
|
packages: { from: string; to: string }[];
|
|
72
|
+
/** Bindings added to package.json, which the project did not declare. */
|
|
73
|
+
dependencies: { name: string; range: string }[];
|
|
74
|
+
/** Patches of replaced React packages, which do not reach their bindings. */
|
|
75
|
+
patched: { name: string; patch: string }[];
|
|
72
76
|
missing: (Unported & { modules: number })[];
|
|
73
77
|
html: string[];
|
|
74
78
|
compiler: string | null;
|
package/src/mappings.js
CHANGED
|
@@ -414,3 +414,16 @@ export const TEXT_INPUT_TYPES = new Set([
|
|
|
414
414
|
'email',
|
|
415
415
|
'number',
|
|
416
416
|
]);
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Library components that render a text `<input>` and hand it the `onChange`
|
|
420
|
+
* they receive, by the module that exports each: React fires that per edit, as
|
|
421
|
+
* on the element itself.
|
|
422
|
+
*
|
|
423
|
+
* @type {Record<string, string[]>}
|
|
424
|
+
*/
|
|
425
|
+
export const TEXT_FIELD_COMPONENTS = {
|
|
426
|
+
'@base-ui/react': ['Input', 'Field.Control'],
|
|
427
|
+
'@base-ui/react/input': ['Input'],
|
|
428
|
+
'@base-ui/react/field': ['Field.Control'],
|
|
429
|
+
};
|
package/src/project.js
CHANGED
|
@@ -40,6 +40,10 @@ import { transformModule } from './transform.js';
|
|
|
40
40
|
* @property {FileResult[]} files
|
|
41
41
|
* @property {{ from: string, to: string }[]} packages React packages the
|
|
42
42
|
* migrated code now imports as Octane bindings
|
|
43
|
+
* @property {{ name: string, range: string }[]} dependencies the bindings
|
|
44
|
+
* added to package.json, which the project did not declare yet
|
|
45
|
+
* @property {{ name: string, patch: string }[]} patched patches the project
|
|
46
|
+
* applies to replaced React packages, which do not reach their bindings
|
|
43
47
|
* @property {Missing[]} missing React packages the code imports that have no
|
|
44
48
|
* Octane port, and how it uses them
|
|
45
49
|
* @property {string[]} html entry pages whose script reference was updated
|
|
@@ -195,12 +199,44 @@ export async function runCodemod(paths, options = {}) {
|
|
|
195
199
|
});
|
|
196
200
|
}
|
|
197
201
|
|
|
202
|
+
// Configs and scripts name modules by path too, such as Vite's
|
|
203
|
+
// `server.warmup.clientFiles`, including those outside the migrated paths.
|
|
204
|
+
const byFile = new Map(results.map((result) => [path.join(root, result.file), result]));
|
|
205
|
+
for (const file of collect(root, (name) => SOURCE.test(name))) {
|
|
206
|
+
if (renames.has(file)) continue;
|
|
207
|
+
const result = byFile.get(file);
|
|
208
|
+
const paths = rewriteModulePaths(
|
|
209
|
+
result?.code ?? fs.readFileSync(file, 'utf8'),
|
|
210
|
+
file,
|
|
211
|
+
root,
|
|
212
|
+
renames,
|
|
213
|
+
);
|
|
214
|
+
if (!paths) continue;
|
|
215
|
+
const rules = { ...result?.rules, 'module-paths': paths.count };
|
|
216
|
+
if (result) Object.assign(result, { code: paths.code, changed: true, rules });
|
|
217
|
+
else {
|
|
218
|
+
const name = path.relative(root, file);
|
|
219
|
+
results.push({
|
|
220
|
+
file: name,
|
|
221
|
+
output: name,
|
|
222
|
+
changed: true,
|
|
223
|
+
rules,
|
|
224
|
+
notes: [],
|
|
225
|
+
strong: null,
|
|
226
|
+
strongFixes: [],
|
|
227
|
+
diagnostics: [],
|
|
228
|
+
code: paths.code,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
198
233
|
const html = rewriteEntryPages(
|
|
199
234
|
root,
|
|
200
235
|
paths.map((entry) => path.resolve(entry)),
|
|
201
236
|
renames,
|
|
202
237
|
options.write !== false,
|
|
203
238
|
);
|
|
239
|
+
const dependencies = addBindings(root, packages, options.write !== false);
|
|
204
240
|
if (options.write !== false) {
|
|
205
241
|
for (const result of results) {
|
|
206
242
|
if (!result.changed) continue;
|
|
@@ -213,6 +249,8 @@ export async function runCodemod(paths, options = {}) {
|
|
|
213
249
|
root,
|
|
214
250
|
files: results,
|
|
215
251
|
packages: [...packages].map(([from, to]) => ({ from, to })),
|
|
252
|
+
dependencies,
|
|
253
|
+
patched: patchedPackages(root, packages),
|
|
216
254
|
missing: [...missing.values()].sort((a, b) => a.name.localeCompare(b.name)),
|
|
217
255
|
html,
|
|
218
256
|
compiler: compiler?.from ?? null,
|
|
@@ -486,13 +524,114 @@ function catalogName(specifier) {
|
|
|
486
524
|
function unportedName(specifier, from) {
|
|
487
525
|
if (specifier.startsWith('.') || specifier.startsWith('/') || catalogName(specifier) !== null)
|
|
488
526
|
return null;
|
|
489
|
-
const
|
|
490
|
-
const root = specifier.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
|
|
527
|
+
const root = packageName(specifier);
|
|
491
528
|
// Any package's `/react` entry renders with React (`@tanstack/markdown/react`).
|
|
492
529
|
if (/\/react(?:\/|$)/.test(specifier.slice(root.length))) return specifier;
|
|
493
530
|
return rendersWithReact(root, from) ? root : null;
|
|
494
531
|
}
|
|
495
532
|
|
|
533
|
+
/**
|
|
534
|
+
* The package a bare specifier imports from: `@pierre/diffs` for
|
|
535
|
+
* `@pierre/diffs/react`.
|
|
536
|
+
*
|
|
537
|
+
* @param {string} specifier
|
|
538
|
+
*/
|
|
539
|
+
function packageName(specifier) {
|
|
540
|
+
return specifier
|
|
541
|
+
.split('/')
|
|
542
|
+
.slice(0, specifier.startsWith('@') ? 2 : 1)
|
|
543
|
+
.join('/');
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Add the bindings the migrated code imports to the project's package.json,
|
|
548
|
+
* each at its catalog version and in the field that lists the React package it
|
|
549
|
+
* replaces. TanStack publishes its Octane adapters outside the catalog, so
|
|
550
|
+
* those take `latest`.
|
|
551
|
+
*
|
|
552
|
+
* @param {string} root
|
|
553
|
+
* @param {Map<string, string>} packages
|
|
554
|
+
* @param {boolean} write
|
|
555
|
+
* @returns {CodemodResult['dependencies']}
|
|
556
|
+
*/
|
|
557
|
+
function addBindings(root, packages, write) {
|
|
558
|
+
const file = path.join(root, 'package.json');
|
|
559
|
+
if (!fs.existsSync(file)) return [];
|
|
560
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
561
|
+
const manifest = JSON.parse(text);
|
|
562
|
+
const fields = ['dependencies', 'devDependencies', 'peerDependencies'];
|
|
563
|
+
/** @type {CodemodResult['dependencies']} */
|
|
564
|
+
const added = [];
|
|
565
|
+
for (const [from, to] of packages) {
|
|
566
|
+
if (fields.some((field) => manifest[field]?.[to] !== undefined)) continue;
|
|
567
|
+
const version = DATA.bindings.find((binding) => binding.name === to)?.version;
|
|
568
|
+
const range = version ? `^${version}` : 'latest';
|
|
569
|
+
const field = manifest.devDependencies?.[packageName(from)]
|
|
570
|
+
? 'devDependencies'
|
|
571
|
+
: 'dependencies';
|
|
572
|
+
manifest[field] = Object.fromEntries(
|
|
573
|
+
Object.entries({ ...manifest[field], [to]: range }).sort(([a], [b]) => a.localeCompare(b)),
|
|
574
|
+
);
|
|
575
|
+
added.push({ name: to, range });
|
|
576
|
+
}
|
|
577
|
+
if (write && added.length > 0) {
|
|
578
|
+
const indent = /^[ \t]+/m.exec(text)?.[0] ?? ' ';
|
|
579
|
+
fs.writeFileSync(file, JSON.stringify(manifest, null, indent) + '\n');
|
|
580
|
+
}
|
|
581
|
+
return added;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* The patches a project applies to the React packages the migration replaces,
|
|
586
|
+
* which stop applying once the code imports the binding instead: pnpm's and
|
|
587
|
+
* Bun's `patchedDependencies`, in package.json or pnpm-workspace.yaml, and
|
|
588
|
+
* patch-package's `patches/name+version.patch`. They live where the project
|
|
589
|
+
* installs, so each directory up from `root` is read until a lockfile.
|
|
590
|
+
*
|
|
591
|
+
* @param {string} root
|
|
592
|
+
* @param {Map<string, string>} packages
|
|
593
|
+
* @returns {CodemodResult['patched']}
|
|
594
|
+
*/
|
|
595
|
+
function patchedPackages(root, packages) {
|
|
596
|
+
const replaced = new Set([...packages.keys()].map(packageName));
|
|
597
|
+
/** @type {CodemodResult['patched']} */
|
|
598
|
+
const patched = [];
|
|
599
|
+
for (let dir = root; ; dir = path.dirname(dir)) {
|
|
600
|
+
const read = (/** @type {string} */ name) => {
|
|
601
|
+
const file = path.join(dir, name);
|
|
602
|
+
return fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : null;
|
|
603
|
+
};
|
|
604
|
+
const manifest = JSON.parse(read('package.json') ?? '{}');
|
|
605
|
+
/** @type {[string, string][]} `name@version` and its patch */
|
|
606
|
+
const declared = Object.entries({
|
|
607
|
+
...manifest.pnpm?.patchedDependencies,
|
|
608
|
+
...manifest.patchedDependencies,
|
|
609
|
+
});
|
|
610
|
+
const workspace =
|
|
611
|
+
/^patchedDependencies:[ \t]*\r?\n((?:[ \t]+.*\r?\n?)*)/m.exec(
|
|
612
|
+
read('pnpm-workspace.yaml') ?? '',
|
|
613
|
+
)?.[1] ?? '';
|
|
614
|
+
for (const [, , key, , patch] of workspace.matchAll(
|
|
615
|
+
/^[ \t]+(["']?)(.+?)\1:[ \t]*(["']?)(.+?)\3[ \t]*$/gm,
|
|
616
|
+
)) {
|
|
617
|
+
declared.push([key, patch]);
|
|
618
|
+
}
|
|
619
|
+
const patches = path.join(dir, 'patches');
|
|
620
|
+
for (const name of fs.existsSync(patches) ? fs.readdirSync(patches) : []) {
|
|
621
|
+
const match = /^((?:@[^+]+\+)?[^+]+)\+[^+]+\.patch$/.exec(name);
|
|
622
|
+
if (match) declared.push([match[1].replace('+', '/'), `patches/${name}`]);
|
|
623
|
+
}
|
|
624
|
+
for (const [key, patch] of declared) {
|
|
625
|
+
const name = key.replace(/(?!^)@[^@]*$/, '');
|
|
626
|
+
if (replaced.has(name))
|
|
627
|
+
patched.push({ name, patch: path.relative(root, path.join(dir, patch)) });
|
|
628
|
+
}
|
|
629
|
+
const installed = ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock', 'bun.lock', 'bun.lockb'];
|
|
630
|
+
if (installed.some((name) => fs.existsSync(path.join(dir, name))) || path.dirname(dir) === dir)
|
|
631
|
+
return patched;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
496
635
|
/**
|
|
497
636
|
* Whether a package renders through React: it declares `react` as a peer or
|
|
498
637
|
* dependency when installed, or its name says so when it is not. A package
|
|
@@ -542,6 +681,43 @@ function rewriteEntryPages(root, targets, renames, write) {
|
|
|
542
681
|
return updated;
|
|
543
682
|
}
|
|
544
683
|
|
|
684
|
+
/**
|
|
685
|
+
* Point the exact path strings in a module that keeps its name at the modules
|
|
686
|
+
* renamed to `.tsrx`. A path resolves from the module or, as Vite resolves its
|
|
687
|
+
* options, from the root; a glob or an extensionless path stays.
|
|
688
|
+
*
|
|
689
|
+
* @param {string} code
|
|
690
|
+
* @param {string} file
|
|
691
|
+
* @param {string} root
|
|
692
|
+
* @param {Map<string, string>} renames
|
|
693
|
+
* @returns {{ code: string, count: number } | null}
|
|
694
|
+
*/
|
|
695
|
+
function rewriteModulePaths(code, file, root, renames) {
|
|
696
|
+
const sf = ts.createSourceFile(file, code, ts.ScriptTarget.Latest);
|
|
697
|
+
/** @type {ts.StringLiteralLike[]} */
|
|
698
|
+
const paths = [];
|
|
699
|
+
const visit = (/** @type {ts.Node} */ node) => {
|
|
700
|
+
if (
|
|
701
|
+
ts.isStringLiteralLike(node) &&
|
|
702
|
+
SOURCE.test(node.text) &&
|
|
703
|
+
[path.dirname(file), root].some((dir) => renames.has(path.join(dir, node.text)))
|
|
704
|
+
) {
|
|
705
|
+
paths.push(node);
|
|
706
|
+
}
|
|
707
|
+
ts.forEachChild(node, visit);
|
|
708
|
+
};
|
|
709
|
+
visit(sf);
|
|
710
|
+
if (paths.length === 0) return null;
|
|
711
|
+
let next = code;
|
|
712
|
+
for (const node of paths.reverse()) {
|
|
713
|
+
// The extension ends the literal, just before its closing quote.
|
|
714
|
+
const end = node.getEnd() - 1;
|
|
715
|
+
const start = node.getStart(sf);
|
|
716
|
+
next = next.slice(0, start) + next.slice(start, end).replace(SOURCE, '.tsrx') + next.slice(end);
|
|
717
|
+
}
|
|
718
|
+
return { code: next, count: paths.length };
|
|
719
|
+
}
|
|
720
|
+
|
|
545
721
|
/**
|
|
546
722
|
* The HTML pages a Vite or CRA app keeps beside its sources: those in the
|
|
547
723
|
* root, `public/`, `src/`, and each migrated directory.
|
package/src/transform.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
DEPENDENCY_HOOKS,
|
|
4
4
|
RADIX_TYPES,
|
|
5
5
|
REACT_MODULES,
|
|
6
|
+
TEXT_FIELD_COMPONENTS,
|
|
6
7
|
TEXT_INPUT_TYPES,
|
|
7
8
|
UNSUPPORTED_VALUES,
|
|
8
9
|
mapPackageExport,
|
|
@@ -78,6 +79,8 @@ const LITERAL_NEWLINE = '\u0000NL\u0000';
|
|
|
78
79
|
|
|
79
80
|
const TEMPLATE = { template: true };
|
|
80
81
|
const PLAIN = { template: false };
|
|
82
|
+
/** The local component that wraps an element no island can host and throws its `error`. */
|
|
83
|
+
const NO_PORT = 'NoOctanePort';
|
|
81
84
|
|
|
82
85
|
/** Rule names, as reported. */
|
|
83
86
|
const RULE = {
|
|
@@ -208,6 +211,45 @@ function skipParens(node) {
|
|
|
208
211
|
return node;
|
|
209
212
|
}
|
|
210
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Whether `node` wraps an expression only for grouping or the type checker.
|
|
216
|
+
*
|
|
217
|
+
* @param {ts.Node} node
|
|
218
|
+
* @returns {node is ts.ParenthesizedExpression | ts.AsExpression | ts.SatisfiesExpression | ts.NonNullExpression | ts.TypeAssertion}
|
|
219
|
+
*/
|
|
220
|
+
function isWrapper(node) {
|
|
221
|
+
return (
|
|
222
|
+
ts.isParenthesizedExpression(node) ||
|
|
223
|
+
ts.isAsExpression(node) ||
|
|
224
|
+
ts.isSatisfiesExpression(node) ||
|
|
225
|
+
ts.isNonNullExpression(node) ||
|
|
226
|
+
ts.isTypeAssertionExpression(node)
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @param {ts.Expression} node
|
|
232
|
+
* @returns {ts.Expression}
|
|
233
|
+
*/
|
|
234
|
+
function skipWrappers(node) {
|
|
235
|
+
while (isWrapper(node)) node = node.expression;
|
|
236
|
+
return node;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* The declaration as a rest binding, `rest` in `{ a, ...rest }`, or null.
|
|
241
|
+
*
|
|
242
|
+
* @param {ts.Declaration | null} declaration
|
|
243
|
+
*/
|
|
244
|
+
function asRest(declaration) {
|
|
245
|
+
return declaration &&
|
|
246
|
+
ts.isBindingElement(declaration) &&
|
|
247
|
+
declaration.dotDotDotToken &&
|
|
248
|
+
ts.isObjectBindingPattern(declaration.parent)
|
|
249
|
+
? declaration
|
|
250
|
+
: null;
|
|
251
|
+
}
|
|
252
|
+
|
|
211
253
|
/** @param {ts.Node} node */
|
|
212
254
|
function isJsx(node) {
|
|
213
255
|
return ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node);
|
|
@@ -642,6 +684,8 @@ class ModuleTransform {
|
|
|
642
684
|
this.unported = new Map();
|
|
643
685
|
/** @type {Set<ts.JsxElement | ts.JsxSelfClosingElement>} Elements to host in a `ReactCompat` island. */
|
|
644
686
|
this.islands = new Set();
|
|
687
|
+
/** @type {Map<ts.Node, string>} Elements no island can host, with the error each throws where it renders. */
|
|
688
|
+
this.unrenderable = new Map();
|
|
645
689
|
/** @type {ts.ImportDeclaration[]} Placeholder index -> import declaration. */
|
|
646
690
|
this.importSlots = [];
|
|
647
691
|
this.hasJsx = false;
|
|
@@ -658,6 +702,12 @@ class ModuleTransform {
|
|
|
658
702
|
code = this.finishImports(code);
|
|
659
703
|
code = code.replace(/^[ \t]*\u0000DROP\u0000[ \t]*\r?\n/gm, '').replaceAll(DROP, '');
|
|
660
704
|
code = code.replaceAll(LITERAL_NEWLINE, '\n');
|
|
705
|
+
if (this.unrenderable.size > 0) {
|
|
706
|
+
const [props, result] = this.isTypeScript()
|
|
707
|
+
? [': { error: string; children?: unknown }', ': never']
|
|
708
|
+
: ['', ''];
|
|
709
|
+
code = `${code.trimEnd()}\n\nfunction ${NO_PORT}({ error }${props})${result} {\n${this.indentUnit}throw new Error(error);\n}\n`;
|
|
710
|
+
}
|
|
661
711
|
const tsrx =
|
|
662
712
|
this.template || (this.target === 'tsrx' && (this.hasJsx || /\.[jt]sx$/.test(this.filename)));
|
|
663
713
|
if (tsrx) code = code.replace(/^\/\*\*\s*@jsxImportSource\s+\S+\s*\*\/[ \t]*\r?\n/m, '');
|
|
@@ -859,7 +909,9 @@ class ModuleTransform {
|
|
|
859
909
|
const parent = member.parent;
|
|
860
910
|
const block = (/** @type {string} */ message) => {
|
|
861
911
|
port.blocked++;
|
|
862
|
-
|
|
912
|
+
const error = `${message} \`${port.name}\` has no Octane port.`;
|
|
913
|
+
this.note(RULE.bindings, 'error', member, error);
|
|
914
|
+
return error;
|
|
863
915
|
};
|
|
864
916
|
if (
|
|
865
917
|
(ts.isJsxOpeningElement(parent) || ts.isJsxSelfClosingElement(parent)) &&
|
|
@@ -867,17 +919,18 @@ class ModuleTransform {
|
|
|
867
919
|
) {
|
|
868
920
|
const element = ts.isJsxOpeningElement(parent) ? parent.parent : parent;
|
|
869
921
|
if (this.inIsland(element)) return;
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
`\`<${text}>\` can render in a \`ReactCompat\` island only with React and React DOM 19.2 or newer in the React 19 series.`,
|
|
877
|
-
);
|
|
878
|
-
} else {
|
|
922
|
+
const reason = !this.hostsInReact(element)
|
|
923
|
+
? `\`<${text}>\` takes children or props that Octane renders, which cannot cross into a React island.`
|
|
924
|
+
: this.options.reactCompat
|
|
925
|
+
? null
|
|
926
|
+
: `\`<${text}>\` can render in a \`ReactCompat\` island only with React and React DOM 19.2 or newer in the React 19 series.`;
|
|
927
|
+
if (reason === null) {
|
|
879
928
|
port.islands++;
|
|
880
929
|
this.islands.add(element);
|
|
930
|
+
} else {
|
|
931
|
+
// Octane fails on a React component deep in its renderer, naming
|
|
932
|
+
// neither it nor its package, so it throws this error there instead.
|
|
933
|
+
this.unrenderable.set(element, block(reason));
|
|
881
934
|
}
|
|
882
935
|
} else if (ts.isCallExpression(parent) && parent.expression === member) {
|
|
883
936
|
if (/^use[A-Z0-9]/.test(name))
|
|
@@ -965,16 +1018,7 @@ class ModuleTransform {
|
|
|
965
1018
|
* @param {ts.Expression} expression
|
|
966
1019
|
*/
|
|
967
1020
|
planDescriptorChildren(expression) {
|
|
968
|
-
|
|
969
|
-
while (
|
|
970
|
-
ts.isParenthesizedExpression(value) ||
|
|
971
|
-
ts.isAsExpression(value) ||
|
|
972
|
-
ts.isSatisfiesExpression(value) ||
|
|
973
|
-
ts.isNonNullExpression(value) ||
|
|
974
|
-
ts.isTypeAssertionExpression(value)
|
|
975
|
-
) {
|
|
976
|
-
value = value.expression;
|
|
977
|
-
}
|
|
1021
|
+
const value = skipWrappers(expression);
|
|
978
1022
|
const component = this.childrenOwner(value);
|
|
979
1023
|
if (!component) return;
|
|
980
1024
|
// `memo(…)` and `forwardRef(…)` wrap it; the declaration holds the call.
|
|
@@ -1105,7 +1149,11 @@ class ModuleTransform {
|
|
|
1105
1149
|
* @param {ts.JsxOpeningLikeElement} element
|
|
1106
1150
|
*/
|
|
1107
1151
|
takesChange(element) {
|
|
1108
|
-
if (
|
|
1152
|
+
if (
|
|
1153
|
+
!/^(?:input|textarea)$/.test(element.tagName.getText(this.sf)) &&
|
|
1154
|
+
!this.isTextFieldComponent(element)
|
|
1155
|
+
)
|
|
1156
|
+
return false;
|
|
1109
1157
|
if (attributeOf(element, 'onChange') || attributeOf(element, 'onInput')) return false;
|
|
1110
1158
|
const type = attributeOf(element, 'type')?.initializer;
|
|
1111
1159
|
return !type || !ts.isStringLiteral(type) || TEXT_INPUT_TYPES.has(type.text);
|
|
@@ -1126,23 +1174,18 @@ class ModuleTransform {
|
|
|
1126
1174
|
// Props whose type has no `onChange` have none to pass on.
|
|
1127
1175
|
const type = this.projectType(spread.expression)?.type;
|
|
1128
1176
|
if (type && !(type.flags & ts.TypeFlags.Any) && !type.getProperty('onChange')) continue;
|
|
1129
|
-
const
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
: null;
|
|
1139
|
-
// A pattern that names `onChange` leaves none in the rest.
|
|
1140
|
-
const pattern = /** @type {ts.ObjectBindingPattern | undefined} */ (rest?.parent);
|
|
1141
|
-
if (
|
|
1142
|
-
pattern?.elements.some((e) => (e.propertyName ?? e.name).getText(this.sf) === 'onChange')
|
|
1143
|
-
) {
|
|
1144
|
-
continue;
|
|
1177
|
+
const expression = skipWrappers(spread.expression);
|
|
1178
|
+
let rest = ts.isIdentifier(expression) ? asRest(this.declarationOf(expression)) : null;
|
|
1179
|
+
// `const { style, ...native } = props` hands on what `props` holds:
|
|
1180
|
+
// follow it to where the component receives `onChange`, so every field
|
|
1181
|
+
// spread from it gets it.
|
|
1182
|
+
while (rest && !this.namesChange(rest.parent)) {
|
|
1183
|
+
const source = this.restSource(rest);
|
|
1184
|
+
if (!source) break;
|
|
1185
|
+
rest = source;
|
|
1145
1186
|
}
|
|
1187
|
+
// A pattern that names `onChange` leaves none in the rest.
|
|
1188
|
+
if (rest && this.namesChange(rest.parent)) continue;
|
|
1146
1189
|
if (
|
|
1147
1190
|
rest &&
|
|
1148
1191
|
!this.checker.resolveName('onChange', spread, ts.SymbolFlags.Value, false) &&
|
|
@@ -1172,12 +1215,26 @@ class ModuleTransform {
|
|
|
1172
1215
|
const visit = (/** @type {ts.Node} */ node) => {
|
|
1173
1216
|
if (!only) return;
|
|
1174
1217
|
if (ts.isIdentifier(node) && node !== rest.name && this.declarationOf(node) === rest) {
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1218
|
+
/** @type {ts.Node} */
|
|
1219
|
+
let read = node;
|
|
1220
|
+
while (isWrapper(read.parent)) read = read.parent;
|
|
1221
|
+
const parent = read.parent;
|
|
1222
|
+
if (ts.isJsxSpreadAttribute(parent)) {
|
|
1223
|
+
only = this.takesChange(parent.parent.parent);
|
|
1224
|
+
} else if (
|
|
1225
|
+
ts.isVariableDeclaration(parent) &&
|
|
1226
|
+
parent.initializer === read &&
|
|
1227
|
+
ts.isObjectBindingPattern(parent.name)
|
|
1228
|
+
) {
|
|
1229
|
+
// A destructuring hands `onChange` on to its own rest, if it has one.
|
|
1230
|
+
const inner = asRest(parent.name.elements.find((e) => e.dotDotDotToken) ?? null);
|
|
1231
|
+
only = !this.namesChange(parent.name) && (!inner || this.onlySpreadOntoFields(inner));
|
|
1232
|
+
} else {
|
|
1233
|
+
only =
|
|
1234
|
+
ts.isPropertyAccessExpression(parent) &&
|
|
1235
|
+
parent.expression === read &&
|
|
1180
1236
|
parent.name.text !== 'onChange';
|
|
1237
|
+
}
|
|
1181
1238
|
}
|
|
1182
1239
|
ts.forEachChild(node, visit);
|
|
1183
1240
|
};
|
|
@@ -1185,6 +1242,47 @@ class ModuleTransform {
|
|
|
1185
1242
|
return only;
|
|
1186
1243
|
}
|
|
1187
1244
|
|
|
1245
|
+
/**
|
|
1246
|
+
* The rest binding a destructuring into `rest`'s pattern reads, or null:
|
|
1247
|
+
* `props` for `native` in `const { style, ...native } = props`.
|
|
1248
|
+
*
|
|
1249
|
+
* @param {ts.BindingElement} rest
|
|
1250
|
+
*/
|
|
1251
|
+
restSource(rest) {
|
|
1252
|
+
const declaration = rest.parent.parent;
|
|
1253
|
+
if (!ts.isVariableDeclaration(declaration) || !declaration.initializer) return null;
|
|
1254
|
+
const source = skipWrappers(declaration.initializer);
|
|
1255
|
+
return ts.isIdentifier(source) ? asRest(this.declarationOf(source)) : null;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* Whether a destructuring takes `onChange` out by name.
|
|
1260
|
+
*
|
|
1261
|
+
* @param {ts.ObjectBindingPattern | ts.ArrayBindingPattern} pattern
|
|
1262
|
+
*/
|
|
1263
|
+
namesChange(pattern) {
|
|
1264
|
+
return pattern.elements.some(
|
|
1265
|
+
(e) => ts.isBindingElement(e) && (e.propertyName ?? e.name).getText(this.sf) === 'onChange',
|
|
1266
|
+
);
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
/**
|
|
1270
|
+
* Whether `element` is a library component that renders a text `<input>`,
|
|
1271
|
+
* such as Base UI's `Input`, imported by name or through a namespace.
|
|
1272
|
+
*
|
|
1273
|
+
* @param {ts.JsxOpeningLikeElement} element
|
|
1274
|
+
*/
|
|
1275
|
+
isTextFieldComponent(element) {
|
|
1276
|
+
/** @type {ts.Node} */
|
|
1277
|
+
let root = element.tagName;
|
|
1278
|
+
while (ts.isPropertyAccessExpression(root)) root = root.expression;
|
|
1279
|
+
const entry = this.importOf(root);
|
|
1280
|
+
if (!entry) return false;
|
|
1281
|
+
const [, ...members] = element.tagName.getText(this.sf).split('.');
|
|
1282
|
+
const name = (entry.namespace ? members : [entry.imported, ...members]).join('.');
|
|
1283
|
+
return TEXT_FIELD_COMPONENTS[entry.module]?.includes(name) ?? false;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1188
1286
|
/**
|
|
1189
1287
|
* The declaration a name refers to.
|
|
1190
1288
|
*
|
|
@@ -1468,8 +1566,25 @@ class ModuleTransform {
|
|
|
1468
1566
|
const island = this.require('octane/react', 'ReactCompat', false);
|
|
1469
1567
|
return `<${island}>${this.span(node, node.getStart(this.sf), node.end, PLAIN)}</${island}>`;
|
|
1470
1568
|
}
|
|
1569
|
+
// An earlier run's wrapper goes: each run decides again whether its
|
|
1570
|
+
// element throws or renders in an island.
|
|
1571
|
+
if (ts.isJsxElement(node) && node.openingElement.tagName.getText(this.sf) === NO_PORT) {
|
|
1572
|
+
const element = node.children.find(
|
|
1573
|
+
(child) => ts.isJsxElement(child) || ts.isJsxSelfClosingElement(child),
|
|
1574
|
+
);
|
|
1575
|
+
if (element) return this.emit(element, ctx);
|
|
1576
|
+
}
|
|
1577
|
+
const error = this.unrenderable.get(node);
|
|
1578
|
+
if (error !== undefined) {
|
|
1579
|
+
const element =
|
|
1580
|
+
(ts.isJsxElement(node) ? this.rewriteElement(node, ctx) : null) ??
|
|
1581
|
+
this.span(node, node.getStart(this.sf), node.end, ctx);
|
|
1582
|
+
return `<${NO_PORT} error="${error}">${element}</${NO_PORT}>`;
|
|
1583
|
+
}
|
|
1471
1584
|
if (ts.isJsxElement(node)) return this.rewriteElement(node, ctx);
|
|
1472
1585
|
if (ts.isJsxExpression(node) && ctx.template) return this.rewriteHole(node);
|
|
1586
|
+
// So does its `NoOctanePort`, which `run` adds back while one still throws.
|
|
1587
|
+
if (ts.isFunctionDeclaration(node) && node.name?.text === NO_PORT) return DROP;
|
|
1473
1588
|
if (
|
|
1474
1589
|
ts.isFunctionDeclaration(node) ||
|
|
1475
1590
|
ts.isFunctionExpression(node) ||
|
|
@@ -1780,6 +1895,8 @@ class ModuleTransform {
|
|
|
1780
1895
|
};
|
|
1781
1896
|
/** React specifiers with no Octane export stay on React, for a person. */
|
|
1782
1897
|
const kept = new Map();
|
|
1898
|
+
/** @type {string[]} Locals of React's `jsx` factories, which a JSX runtime consumer calls. */
|
|
1899
|
+
const factories = [];
|
|
1783
1900
|
for (const node of this.importSlots) {
|
|
1784
1901
|
const module = /** @type {ts.StringLiteral} */ (node.moduleSpecifier).text;
|
|
1785
1902
|
const clause = node.importClause;
|
|
@@ -1802,6 +1919,11 @@ class ModuleTransform {
|
|
|
1802
1919
|
add(mapped.module, mapped.name, local, typeOnly || !this.valueUses.has(local));
|
|
1803
1920
|
continue;
|
|
1804
1921
|
}
|
|
1922
|
+
if (/^react\/jsx-(?:dev-)?runtime$/.test(module) && /^jsx(?:s|DEV)?$/.test(imported)) {
|
|
1923
|
+
add('octane', 'createElement', 'createElement', false);
|
|
1924
|
+
factories.push(local);
|
|
1925
|
+
continue;
|
|
1926
|
+
}
|
|
1805
1927
|
this.note(
|
|
1806
1928
|
RULE.unsupported,
|
|
1807
1929
|
'error',
|
|
@@ -1837,6 +1959,20 @@ class ModuleTransform {
|
|
|
1837
1959
|
}
|
|
1838
1960
|
for (const [module, specs] of kept)
|
|
1839
1961
|
lines.push(`import { ${specs.join(', ')} } from ${quote(module)};`);
|
|
1962
|
+
if (factories.length > 0) {
|
|
1963
|
+
// React's runtime takes the key apart from the props; Octane's
|
|
1964
|
+
// `createElement` reads it from them.
|
|
1965
|
+
const params = this.isTypeScript()
|
|
1966
|
+
? 'type: Parameters<typeof createElement>[0], props: Record<string, unknown>, key?: string | number'
|
|
1967
|
+
: 'type, props, key';
|
|
1968
|
+
const [first, ...rest] = factories;
|
|
1969
|
+
lines.push(
|
|
1970
|
+
`function ${first}(${params}) {`,
|
|
1971
|
+
`${this.indentUnit}return createElement(type, key === undefined ? props : { ...props, key });`,
|
|
1972
|
+
'}',
|
|
1973
|
+
...rest.map((local) => `const ${local} = ${first};`),
|
|
1974
|
+
);
|
|
1975
|
+
}
|
|
1840
1976
|
|
|
1841
1977
|
// In a script, `declare module` declares the module instead of adding to
|
|
1842
1978
|
// it: a module whose only import was `import 'react'` stays a module, and
|
|
@@ -2375,13 +2511,17 @@ class ModuleTransform {
|
|
|
2375
2511
|
const found = this.parameterOf(node);
|
|
2376
2512
|
if (!found) return false;
|
|
2377
2513
|
// Unannotated, the project's types still name a handler a component
|
|
2378
|
-
// passes on to a control: `<Input onChange={(e) => …}>`.
|
|
2514
|
+
// passes on to a control: `<Input onChange={(e) => …}>`. A library may
|
|
2515
|
+
// wrap the event (Base UI's `BaseUIEvent<ChangeEvent<…>>`); its first
|
|
2516
|
+
// type argument is still the element the handler is attached to.
|
|
2379
2517
|
const inferred = found.param.type ? null : this.projectType(found.param);
|
|
2380
2518
|
const type =
|
|
2381
2519
|
found.param.type?.getText(this.sf) ??
|
|
2382
2520
|
(inferred ? inferred.checker.typeToString(inferred.type) : '');
|
|
2383
2521
|
if (
|
|
2384
|
-
|
|
2522
|
+
/\b(?:Change|Form|Focus)Event<\s*(?:HTML(?:Input|TextArea|Select)Element\s*\|?\s*)+[,>]/.test(
|
|
2523
|
+
type,
|
|
2524
|
+
)
|
|
2385
2525
|
)
|
|
2386
2526
|
return true;
|
|
2387
2527
|
const attribute = this.handlerAttribute(found.fn);
|
|
@@ -2436,6 +2576,9 @@ class ModuleTransform {
|
|
|
2436
2576
|
const element = node.parent;
|
|
2437
2577
|
const tag = element.tagName.getText(this.sf);
|
|
2438
2578
|
const intrinsic = /^[a-z]/.test(tag);
|
|
2579
|
+
// A library text field takes `onInput` for `onChange` as `<input>` does;
|
|
2580
|
+
// its other props are its own.
|
|
2581
|
+
const textField = !intrinsic && this.isTextFieldComponent(element);
|
|
2439
2582
|
const spread = node.properties.some(ts.isJsxSpreadAttribute);
|
|
2440
2583
|
const attributes = node.properties;
|
|
2441
2584
|
|
|
@@ -2465,13 +2608,14 @@ class ModuleTransform {
|
|
|
2465
2608
|
const line = this.source.slice(this.source.lastIndexOf('\n', start - 1), start);
|
|
2466
2609
|
out += 'onInput={onChange}' + (/^\n[ \t]*$/.test(line) ? line : ' ');
|
|
2467
2610
|
}
|
|
2468
|
-
if (!ts.isJsxAttribute(attribute) || !intrinsic) {
|
|
2611
|
+
if (!ts.isJsxAttribute(attribute) || !(intrinsic || textField)) {
|
|
2469
2612
|
out += this.emit(attribute, PLAIN);
|
|
2470
2613
|
continue;
|
|
2471
2614
|
}
|
|
2472
2615
|
const name = attribute.name.getText(this.sf);
|
|
2473
2616
|
if (
|
|
2474
2617
|
name === 'className' &&
|
|
2618
|
+
intrinsic &&
|
|
2475
2619
|
this.target === 'tsrx' &&
|
|
2476
2620
|
!attributeOf(element, 'class') &&
|
|
2477
2621
|
!spread
|
|
@@ -2517,7 +2661,7 @@ class ModuleTransform {
|
|
|
2517
2661
|
isTextEntry(element) {
|
|
2518
2662
|
const tag = element.tagName.getText(this.sf);
|
|
2519
2663
|
if (tag === 'textarea') return true;
|
|
2520
|
-
if (tag !== 'input') return false;
|
|
2664
|
+
if (tag !== 'input' && !this.isTextFieldComponent(element)) return false;
|
|
2521
2665
|
const type = attributeOf(element, 'type');
|
|
2522
2666
|
if (!type) return true;
|
|
2523
2667
|
const value = type.initializer;
|