@openrewrite/recipes-react 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/migration/cra-to-vite/add-vite-config.d.ts +7 -0
- package/dist/migration/cra-to-vite/add-vite-config.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/add-vite-config.js +58 -1
- package/dist/migration/cra-to-vite/add-vite-config.js.map +1 -1
- package/dist/migration/cra-to-vite/cra-file-gate.d.ts +3 -0
- package/dist/migration/cra-to-vite/cra-file-gate.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/cra-file-gate.js +10 -0
- package/dist/migration/cra-to-vite/cra-file-gate.js.map +1 -0
- package/dist/migration/cra-to-vite/cra-runtime.d.ts +2 -0
- package/dist/migration/cra-to-vite/cra-runtime.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/cra-runtime.js +24 -0
- package/dist/migration/cra-to-vite/cra-runtime.js.map +1 -0
- package/dist/migration/cra-to-vite/cra-script.d.ts +8 -0
- package/dist/migration/cra-to-vite/cra-script.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/cra-script.js +82 -0
- package/dist/migration/cra-to-vite/cra-script.js.map +1 -0
- package/dist/migration/cra-to-vite/cra-to-vite.d.ts +2 -1
- package/dist/migration/cra-to-vite/cra-to-vite.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/cra-to-vite.js +23 -16
- package/dist/migration/cra-to-vite/cra-to-vite.js.map +1 -1
- package/dist/migration/cra-to-vite/cra-typecheck.d.ts +4 -0
- package/dist/migration/cra-to-vite/cra-typecheck.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/cra-typecheck.js +35 -0
- package/dist/migration/cra-to-vite/cra-typecheck.js.map +1 -0
- package/dist/migration/cra-to-vite/find-cra-config-blockers.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/find-cra-config-blockers.js +22 -29
- package/dist/migration/cra-to-vite/find-cra-config-blockers.js.map +1 -1
- package/dist/migration/cra-to-vite/index.d.ts +8 -2
- package/dist/migration/cra-to-vite/index.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/index.js +17 -2
- package/dist/migration/cra-to-vite/index.js.map +1 -1
- package/dist/migration/cra-to-vite/migrate-cra-package.d.ts +17 -0
- package/dist/migration/cra-to-vite/migrate-cra-package.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/migrate-cra-package.js +181 -0
- package/dist/migration/cra-to-vite/migrate-cra-package.js.map +1 -0
- package/dist/migration/cra-to-vite/migrate-cra-svg-imports.d.ts +9 -0
- package/dist/migration/cra-to-vite/migrate-cra-svg-imports.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/migrate-cra-svg-imports.js +66 -0
- package/dist/migration/cra-to-vite/migrate-cra-svg-imports.js.map +1 -0
- package/dist/migration/cra-to-vite/migrate-cra-tests-to-vitest.d.ts +49 -0
- package/dist/migration/cra-to-vite/migrate-cra-tests-to-vitest.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/migrate-cra-tests-to-vitest.js +506 -0
- package/dist/migration/cra-to-vite/migrate-cra-tests-to-vitest.js.map +1 -0
- package/dist/migration/cra-to-vite/move-public-index-html.d.ts +2 -0
- package/dist/migration/cra-to-vite/move-public-index-html.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/move-public-index-html.js +12 -7
- package/dist/migration/cra-to-vite/move-public-index-html.js.map +1 -1
- package/dist/migration/cra-to-vite/plan-cra-to-vite.d.ts +30 -0
- package/dist/migration/cra-to-vite/plan-cra-to-vite.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/plan-cra-to-vite.js +428 -0
- package/dist/migration/cra-to-vite/plan-cra-to-vite.js.map +1 -0
- package/dist/migration/cra-to-vite/prepare-cra-package.d.ts +15 -0
- package/dist/migration/cra-to-vite/prepare-cra-package.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/prepare-cra-package.js +100 -0
- package/dist/migration/cra-to-vite/prepare-cra-package.js.map +1 -0
- package/dist/migration/cra-to-vite/remove-cra-configuration.d.ts +12 -0
- package/dist/migration/cra-to-vite/remove-cra-configuration.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/remove-cra-configuration.js +85 -0
- package/dist/migration/cra-to-vite/remove-cra-configuration.js.map +1 -0
- package/dist/migration/cra-to-vite/rename-jsx-files.d.ts +20 -0
- package/dist/migration/cra-to-vite/rename-jsx-files.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/rename-jsx-files.js +220 -0
- package/dist/migration/cra-to-vite/rename-jsx-files.js.map +1 -0
- package/dist/migration/cra-to-vite/rename-process-env-react-app.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/rename-process-env-react-app.js +6 -3
- package/dist/migration/cra-to-vite/rename-process-env-react-app.js.map +1 -1
- package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.js +1 -1
- package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.js.map +1 -1
- package/dist/migration/cra-to-vite/replace-react-scripts-dependency.d.ts +11 -4
- package/dist/migration/cra-to-vite/replace-react-scripts-dependency.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/replace-react-scripts-dependency.js +47 -50
- package/dist/migration/cra-to-vite/replace-react-scripts-dependency.js.map +1 -1
- package/dist/migration/cra-to-vite/resolved-cra-dependency.d.ts +3 -0
- package/dist/migration/cra-to-vite/resolved-cra-dependency.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/resolved-cra-dependency.js +42 -0
- package/dist/migration/cra-to-vite/resolved-cra-dependency.js.map +1 -0
- package/dist/migration/cra-to-vite/scan-cra-projects.d.ts +13 -0
- package/dist/migration/cra-to-vite/scan-cra-projects.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/scan-cra-projects.js +52 -4
- package/dist/migration/cra-to-vite/scan-cra-projects.js.map +1 -1
- package/dist/migration/cra-to-vite/shared.d.ts +2 -15
- package/dist/migration/cra-to-vite/shared.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/shared.js +32 -130
- package/dist/migration/cra-to-vite/shared.js.map +1 -1
- package/dist/migration/cra-to-vite/svg-component.d.ts +5 -0
- package/dist/migration/cra-to-vite/svg-component.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/svg-component.js +60 -0
- package/dist/migration/cra-to-vite/svg-component.js.map +1 -0
- package/dist/migration/cra-to-vite/update-react-app-env-types.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/update-react-app-env-types.js +8 -2
- package/dist/migration/cra-to-vite/update-react-app-env-types.js.map +1 -1
- package/dist/migration/cra-to-vite/update-react-scripts-scripts.d.ts +3 -2
- package/dist/migration/cra-to-vite/update-react-scripts-scripts.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/update-react-scripts-scripts.js +28 -29
- package/dist/migration/cra-to-vite/update-react-scripts-scripts.js.map +1 -1
- package/dist/migration/cra-to-vite/update-tsconfig-for-vite.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/update-tsconfig-for-vite.js +4 -13
- package/dist/migration/cra-to-vite/update-tsconfig-for-vite.js.map +1 -1
- package/dist/react17/migrate-deprecated-lifecycles.js +1 -1
- package/dist/react17/migrate-deprecated-lifecycles.js.map +1 -1
- package/dist/react17/use-new-jsx-transform.d.ts.map +1 -1
- package/dist/react17/use-new-jsx-transform.js +30 -78
- package/dist/react17/use-new-jsx-transform.js.map +1 -1
- package/dist/react18/replace-reactdom-render.d.ts.map +1 -1
- package/dist/react18/replace-reactdom-render.js +16 -8
- package/dist/react18/replace-reactdom-render.js.map +1 -1
- package/dist/react18/replace-unmount-component-at-node.d.ts.map +1 -1
- package/dist/react18/replace-unmount-component-at-node.js +62 -20
- package/dist/react18/replace-unmount-component-at-node.js.map +1 -1
- package/dist/react19/replace-default-props.d.ts.map +1 -1
- package/dist/react19/replace-default-props.js +10 -13
- package/dist/react19/replace-default-props.js.map +1 -1
- package/dist/react19/replace-react-shallow-renderer.d.ts.map +1 -1
- package/dist/react19/replace-react-shallow-renderer.js +1 -6
- package/dist/react19/replace-react-shallow-renderer.js.map +1 -1
- package/dist/refactoring/create-class-to-es6.d.ts.map +1 -1
- package/dist/refactoring/create-class-to-es6.js +4 -7
- package/dist/refactoring/create-class-to-es6.js.map +1 -1
- package/dist/refactoring/create-element-to-jsx.d.ts.map +1 -1
- package/dist/refactoring/create-element-to-jsx.js +3 -4
- package/dist/refactoring/create-element-to-jsx.js.map +1 -1
- package/dist/refactoring/prop-types-to-typescript.js +2 -3
- package/dist/refactoring/prop-types-to-typescript.js.map +1 -1
- package/dist/refactoring/pure-render-mixin.d.ts.map +1 -1
- package/dist/refactoring/pure-render-mixin.js +3 -6
- package/dist/refactoring/pure-render-mixin.js.map +1 -1
- package/dist/testing/enzyme-constant-strings.d.ts +12 -0
- package/dist/testing/enzyme-constant-strings.d.ts.map +1 -0
- package/dist/testing/enzyme-constant-strings.js +101 -0
- package/dist/testing/enzyme-constant-strings.js.map +1 -0
- package/dist/testing/enzyme-host-components.d.ts +14 -0
- package/dist/testing/enzyme-host-components.d.ts.map +1 -0
- package/dist/testing/enzyme-host-components.js +248 -0
- package/dist/testing/enzyme-host-components.js.map +1 -0
- package/dist/testing/enzyme-portals.d.ts +38 -0
- package/dist/testing/enzyme-portals.d.ts.map +1 -0
- package/dist/testing/enzyme-portals.js +226 -0
- package/dist/testing/enzyme-portals.js.map +1 -0
- package/dist/testing/enzyme-selector-names.d.ts +9 -0
- package/dist/testing/enzyme-selector-names.d.ts.map +1 -0
- package/dist/testing/enzyme-selector-names.js +50 -0
- package/dist/testing/enzyme-selector-names.js.map +1 -0
- package/dist/testing/enzyme-to-react-testing-library.d.ts +80 -12
- package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -1
- package/dist/testing/enzyme-to-react-testing-library.js +447 -135
- package/dist/testing/enzyme-to-react-testing-library.js.map +1 -1
- package/dist/testing/enzyme-usage.d.ts.map +1 -1
- package/dist/testing/enzyme-usage.js +27 -4
- package/dist/testing/enzyme-usage.js.map +1 -1
- package/dist/testing/enzyme-wrapper-scope.d.ts +23 -8
- package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -1
- package/dist/testing/enzyme-wrapper-scope.js +291 -169
- package/dist/testing/enzyme-wrapper-scope.js.map +1 -1
- package/dist/util/java-recipe-proxy.d.ts +16 -0
- package/dist/util/java-recipe-proxy.d.ts.map +1 -0
- package/dist/util/java-recipe-proxy.js +85 -0
- package/dist/util/java-recipe-proxy.js.map +1 -0
- package/dist/util/module-imports.d.ts +13 -0
- package/dist/util/module-imports.d.ts.map +1 -0
- package/dist/util/module-imports.js +60 -0
- package/dist/util/module-imports.js.map +1 -0
- package/dist/util/react-class.d.ts +1 -0
- package/dist/util/react-class.d.ts.map +1 -1
- package/dist/util/react-class.js +3 -2
- package/dist/util/react-class.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +2 -1
- package/src/migration/cra-to-vite/add-vite-config.ts +53 -1
- package/src/migration/cra-to-vite/cra-file-gate.ts +8 -0
- package/src/migration/cra-to-vite/cra-runtime.ts +16 -0
- package/src/migration/cra-to-vite/cra-script.ts +61 -0
- package/src/migration/cra-to-vite/cra-to-vite.ts +25 -36
- package/src/migration/cra-to-vite/cra-typecheck.ts +33 -0
- package/src/migration/cra-to-vite/find-cra-config-blockers.ts +23 -28
- package/src/migration/cra-to-vite/index.ts +10 -2
- package/src/migration/cra-to-vite/migrate-cra-package.ts +127 -0
- package/src/migration/cra-to-vite/migrate-cra-svg-imports.ts +41 -0
- package/src/migration/cra-to-vite/migrate-cra-tests-to-vitest.ts +376 -0
- package/src/migration/cra-to-vite/move-public-index-html.ts +12 -7
- package/src/migration/cra-to-vite/plan-cra-to-vite.ts +283 -0
- package/src/migration/cra-to-vite/prepare-cra-package.ts +86 -0
- package/src/migration/cra-to-vite/remove-cra-configuration.ts +64 -0
- package/src/migration/cra-to-vite/rename-jsx-files.ts +155 -0
- package/src/migration/cra-to-vite/rename-process-env-react-app.ts +6 -3
- package/src/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.ts +1 -1
- package/src/migration/cra-to-vite/replace-react-scripts-dependency.ts +48 -54
- package/src/migration/cra-to-vite/resolved-cra-dependency.ts +41 -0
- package/src/migration/cra-to-vite/scan-cra-projects.ts +57 -6
- package/src/migration/cra-to-vite/shared.ts +35 -146
- package/src/migration/cra-to-vite/svg-component.ts +39 -0
- package/src/migration/cra-to-vite/update-react-app-env-types.ts +11 -4
- package/src/migration/cra-to-vite/update-react-scripts-scripts.ts +30 -41
- package/src/migration/cra-to-vite/update-tsconfig-for-vite.ts +6 -13
- package/src/react17/migrate-deprecated-lifecycles.ts +2 -2
- package/src/react17/use-new-jsx-transform.ts +30 -72
- package/src/react18/replace-reactdom-render.ts +17 -8
- package/src/react18/replace-unmount-component-at-node.ts +78 -32
- package/src/react19/replace-default-props.ts +11 -15
- package/src/react19/replace-react-shallow-renderer.ts +2 -7
- package/src/refactoring/create-class-to-es6.ts +6 -9
- package/src/refactoring/create-element-to-jsx.ts +4 -6
- package/src/refactoring/prop-types-to-typescript.ts +4 -4
- package/src/refactoring/pure-render-mixin.ts +4 -7
- package/src/testing/enzyme-constant-strings.ts +95 -0
- package/src/testing/enzyme-host-components.ts +287 -0
- package/src/testing/enzyme-portals.ts +279 -0
- package/src/testing/enzyme-selector-names.ts +59 -0
- package/src/testing/enzyme-to-react-testing-library.ts +584 -140
- package/src/testing/enzyme-usage.ts +29 -4
- package/src/testing/enzyme-wrapper-scope.ts +309 -151
- package/src/util/java-recipe-proxy.ts +81 -0
- package/src/util/module-imports.ts +60 -0
- package/src/util/react-class.ts +2 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {ExecutionContext, printer, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
|
|
2
|
-
import {JavaScriptVisitor, JS, raw, template, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
|
|
2
|
+
import {isObjectLiteral, JavaScriptVisitor, JS, raw, template, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
|
|
3
3
|
import {J} from "@openrewrite/rewrite/java";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -116,13 +116,11 @@ export class CreateElementToJsx extends Recipe {
|
|
|
116
116
|
if ((propsExpr as J.Identifier).simpleName === 'undefined') return '';
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const obj = propsExpr as J.NewClass;
|
|
122
|
-
if (!obj.body) return '';
|
|
119
|
+
if (isObjectLiteral(propsExpr)) {
|
|
120
|
+
if (!propsExpr.body) return '';
|
|
123
121
|
|
|
124
122
|
const attrs: string[] = [];
|
|
125
|
-
for (const stmt of
|
|
123
|
+
for (const stmt of propsExpr.body.statements) {
|
|
126
124
|
const s = stmt.element;
|
|
127
125
|
|
|
128
126
|
if (s.kind === JS.Kind.PropertyAssignment) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
|
|
2
|
-
import {isVendoredOrBundled, JavaScriptVisitor, JS, maybeAddImport, raw, template} from "@openrewrite/rewrite/javascript";
|
|
2
|
+
import {isObjectLiteral, isTypeScript, isVendoredOrBundled, JavaScriptVisitor, JS, maybeAddImport, raw, template} from "@openrewrite/rewrite/javascript";
|
|
3
3
|
import {emptySpace, J, singleSpace} from "@openrewrite/rewrite/java";
|
|
4
4
|
|
|
5
5
|
/** `PropTypes.<name>` validators with a fixed TypeScript type, and the `react` type each one needs. */
|
|
@@ -93,8 +93,8 @@ function isPropTypes(expr: J): boolean {
|
|
|
93
93
|
|
|
94
94
|
/** `name: type` / `name?: type` for each property of an object literal, or `undefined` if any is unsupported. */
|
|
95
95
|
function objectMembers(literal: J, reactTypes: Set<string>, names?: Set<string>): string[] | undefined {
|
|
96
|
-
if (literal
|
|
97
|
-
const body =
|
|
96
|
+
if (!isObjectLiteral(literal)) return undefined;
|
|
97
|
+
const body = literal.body;
|
|
98
98
|
if (!body) return undefined;
|
|
99
99
|
const members: string[] = [];
|
|
100
100
|
for (const statement of body.statements) {
|
|
@@ -247,7 +247,7 @@ export class PropTypesToTypeScript extends Recipe {
|
|
|
247
247
|
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
248
248
|
return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
|
|
249
249
|
override async visitJsCompilationUnit(cu: JS.CompilationUnit): Promise<J | undefined> {
|
|
250
|
-
if (
|
|
250
|
+
if (!isTypeScript(cu)) return cu;
|
|
251
251
|
|
|
252
252
|
const reactTypes = new Set<string>();
|
|
253
253
|
const plans: { index: number; propsName: string; source: string }[] = [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Cursor, ExecutionContext, findMarker, Marker, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
|
|
2
|
-
import {JavaScriptVisitor, JS, maybeRemoveImport, template, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
|
|
2
|
+
import {isObjectLiteral, JavaScriptVisitor, JS, maybeRemoveImport, template, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
|
|
3
3
|
import {J, TextComment} from "@openrewrite/rewrite/java";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -53,11 +53,8 @@ export class PureRenderMixin extends Recipe {
|
|
|
53
53
|
const args = m.arguments.elements;
|
|
54
54
|
if (args.length === 0) return m;
|
|
55
55
|
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
const specObj = specArg as J.NewClass;
|
|
60
|
-
if (!specObj.body) return m;
|
|
56
|
+
const specObj = args[0].element;
|
|
57
|
+
if (!isObjectLiteral(specObj) || !specObj.body) return m;
|
|
61
58
|
|
|
62
59
|
// Find the mixins property and check for PureRenderMixin
|
|
63
60
|
const mixinsInfo = this.findPureRenderMixin(specObj.body);
|
|
@@ -173,7 +170,7 @@ export class PureRenderMixin extends Recipe {
|
|
|
173
170
|
return React.addons.shallowCompare(this, nextProps, nextState);
|
|
174
171
|
}
|
|
175
172
|
}`.apply(specObj, new Cursor(specObj, this.cursor));
|
|
176
|
-
const method = obj
|
|
173
|
+
const method = obj && isObjectLiteral(obj) ? obj.body?.statements[0]?.element : undefined;
|
|
177
174
|
return method?.kind === J.Kind.MethodDeclaration ? method as J.MethodDeclaration : undefined;
|
|
178
175
|
}
|
|
179
176
|
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {JS} from "@openrewrite/rewrite/javascript";
|
|
2
|
+
import {isIdentifier, J} from "@openrewrite/rewrite/java";
|
|
3
|
+
import {Modules, Resolver} from "./enzyme-portals";
|
|
4
|
+
|
|
5
|
+
/** A string a `const` holds, as literal text and the names whose strings its template interpolates. */
|
|
6
|
+
export type ConstantParts = readonly ({text: string} | {name: string})[];
|
|
7
|
+
|
|
8
|
+
/** The `const` declarations of a source's top level that hold a string literal or a template of other names. */
|
|
9
|
+
export function constantStrings(cu: JS.CompilationUnit): Map<string, ConstantParts> {
|
|
10
|
+
const strings = new Map<string, ConstantParts>();
|
|
11
|
+
for (const {element} of cu.statements) {
|
|
12
|
+
const declarations = (element.kind === JS.Kind.ExportDeclaration ? (element as JS.ExportDeclaration).exportClause : element) as J | undefined;
|
|
13
|
+
if (declarations?.kind !== J.Kind.VariableDeclarations) continue;
|
|
14
|
+
const variables = declarations as J.VariableDeclarations;
|
|
15
|
+
if (!variables.modifiers.some(modifier => modifier.keyword === "const")) continue;
|
|
16
|
+
for (const {element: variable} of variables.variables) {
|
|
17
|
+
const name = variable.name;
|
|
18
|
+
const parts = variable.initializer && isIdentifier(name) ? stringParts(variable.initializer.element) : undefined;
|
|
19
|
+
if (parts && isIdentifier(name)) strings.set(name.simpleName, parts);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return strings;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** A string literal, or a template whose every interpolation is a bare name, as parts; anything else is not constant. */
|
|
26
|
+
export function stringParts(node: J): ConstantParts | undefined {
|
|
27
|
+
if (node.kind === J.Kind.Literal) return typeof (node as J.Literal).value === "string" ? [{text: (node as J.Literal).value as string}] : undefined;
|
|
28
|
+
if (node.kind !== JS.Kind.TemplateExpression) return undefined;
|
|
29
|
+
const template = node as JS.TemplateExpression;
|
|
30
|
+
const parts: ({text: string} | {name: string})[] = [];
|
|
31
|
+
const text = (literal: J.Literal) => typeof literal.value === "string" ? literal.value : undefined;
|
|
32
|
+
const head = text(template.head);
|
|
33
|
+
if (head === undefined) return undefined;
|
|
34
|
+
parts.push({text: head});
|
|
35
|
+
for (const {element: span} of template.spans) {
|
|
36
|
+
const tail = text(span.tail);
|
|
37
|
+
if (!isIdentifier(span.expression) || tail === undefined) return undefined;
|
|
38
|
+
parts.push({name: span.expression.simpleName}, {text: tail});
|
|
39
|
+
}
|
|
40
|
+
return parts;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The string `parts` evaluate to in the source at `path`, following each name to a `const` of that source, or
|
|
45
|
+
* through its imports and re-exports to one of the module it names, as {@link resolve} finds the module.
|
|
46
|
+
*/
|
|
47
|
+
export function evaluate(parts: ConstantParts, path: string, modules: Modules, resolve: Resolver, seen = new Set<string>()): string | undefined {
|
|
48
|
+
let value = "";
|
|
49
|
+
for (const part of parts) {
|
|
50
|
+
if ("text" in part) {
|
|
51
|
+
value += part.text;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const named = constantOf(path, part.name, modules, resolve, seen);
|
|
55
|
+
if (named === undefined) return undefined;
|
|
56
|
+
value += named;
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The string the binding `name` of the source at `path` holds, where it is a constant one. */
|
|
62
|
+
function constantOf(path: string, name: string, modules: Modules, resolve: Resolver, seen: Set<string>): string | undefined {
|
|
63
|
+
const key = `${path}#${name}`;
|
|
64
|
+
if (seen.has(key)) return undefined;
|
|
65
|
+
seen.add(key);
|
|
66
|
+
try {
|
|
67
|
+
const facts = modules.get(path);
|
|
68
|
+
if (!facts) return undefined;
|
|
69
|
+
const own = facts.strings.get(name);
|
|
70
|
+
if (own) return evaluate(own, path, modules, resolve, seen);
|
|
71
|
+
const imported = facts.imports.get(name) ?? facts.forwards.get(name);
|
|
72
|
+
if (imported) {
|
|
73
|
+
const target = resolve(path, imported.module);
|
|
74
|
+
return target === undefined ? undefined : exportedConstant(target, imported.name, modules, resolve, seen);
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
} finally {
|
|
78
|
+
seen.delete(key);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The string the export `name` of the source at `path` holds, through the names it forwards or re-exports. */
|
|
83
|
+
function exportedConstant(path: string, name: string, modules: Modules, resolve: Resolver, seen: Set<string>): string | undefined {
|
|
84
|
+
const facts = modules.get(path);
|
|
85
|
+
if (!facts) return undefined;
|
|
86
|
+
if (facts.strings.has(name) || facts.forwards.has(name)) return constantOf(path, name, modules, resolve, seen);
|
|
87
|
+
for (const {module, names} of facts.reExports) {
|
|
88
|
+
const exported = names === "*" ? name : names.get(name);
|
|
89
|
+
if (exported === undefined) continue;
|
|
90
|
+
const target = resolve(path, module);
|
|
91
|
+
const value = target === undefined ? undefined : exportedConstant(target, exported, modules, resolve, seen);
|
|
92
|
+
if (value !== undefined) return value;
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import {JS, JSX, namesReferencedWithin, walk} from "@openrewrite/rewrite/javascript";
|
|
2
|
+
import {Expression, isIdentifier, J, Type} from "@openrewrite/rewrite/java";
|
|
3
|
+
import {COMPONENT_BASES, unwrapBaseType} from "../util/react-class";
|
|
4
|
+
import {importBindings, namespaceImports, resolveRelative} from "../util/module-imports";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Each scanned JavaScript or TypeScript source mapped to the exports, `default` for the default
|
|
8
|
+
* export, of the components it declares that render host elements only. A source declaring none
|
|
9
|
+
* maps to an empty set, so that module resolution still stops at it.
|
|
10
|
+
*/
|
|
11
|
+
export type HostComponents = Map<string, ReadonlySet<string>>;
|
|
12
|
+
|
|
13
|
+
const NONE: ReadonlySet<string> = new Set();
|
|
14
|
+
|
|
15
|
+
/** A local name bound to an export of another source in the same repository. */
|
|
16
|
+
export interface ImportedExport {
|
|
17
|
+
path: string;
|
|
18
|
+
name: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Each renders what a JSX tag in the same file does not show, or, for the effects and refs, runs only
|
|
22
|
+
// in a full render: Enzyme's shallow renderer does not run `useEffect` or `useLayoutEffect`, attaches
|
|
23
|
+
// no ref, and does not parse `dangerouslySetInnerHTML` into elements that a selector can match.
|
|
24
|
+
const RENDERS_OTHERWISE = new Set(["createElement", "cloneElement", "createPortal", "lazy",
|
|
25
|
+
"useEffect", "useLayoutEffect", "useInsertionEffect", "ref", "dangerouslySetInnerHTML"]);
|
|
26
|
+
|
|
27
|
+
// React's hooks that behave alike in a shallow and a full render. Any other hook, such as a custom
|
|
28
|
+
// one declared elsewhere, may run an effect that this source does not show.
|
|
29
|
+
const SAME_IN_SHALLOW = new Set(["useState", "useReducer", "useMemo", "useCallback", "useRef", "useContext",
|
|
30
|
+
"useId", "useDebugValue", "useTransition", "useDeferredValue", "useSyncExternalStore"]);
|
|
31
|
+
|
|
32
|
+
const HOOK = /^use[A-Z0-9]/;
|
|
33
|
+
|
|
34
|
+
const FRAGMENT = new Set(["Fragment"]);
|
|
35
|
+
|
|
36
|
+
/** A lowercase tag is an intrinsic element and an empty one a fragment, which renders its children. */
|
|
37
|
+
function hostTag(tag: JSX.Tag): boolean {
|
|
38
|
+
const name = tag.openName.element;
|
|
39
|
+
if (name.kind === J.Kind.Empty) return true;
|
|
40
|
+
if (isIdentifier(name)) return /^[a-z]/.test(name.simpleName) || FRAGMENT.has(name.simpleName);
|
|
41
|
+
return reactMember(name, FRAGMENT);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function primitive(type: Type | undefined): boolean {
|
|
45
|
+
if (Type.isPrimitive(type)) return true;
|
|
46
|
+
return Type.isUnion(type) && type.bounds.length > 0 && type.bounds.every(primitive);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function rootName(node: Expression): string | undefined {
|
|
50
|
+
if (isIdentifier(node)) return node.simpleName;
|
|
51
|
+
if (node.kind === J.Kind.FieldAccess) return rootName((node as J.FieldAccess).target);
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Whether an expression a host element renders as a child holds no element of a component: a JSX
|
|
57
|
+
* tag, whose own name is checked separately, a primitive, a branch of either, a `map` whose
|
|
58
|
+
* callback is declared in the source, or a value that does not come from an import, such as a prop or
|
|
59
|
+
* `children`, which the rendering test supplies.
|
|
60
|
+
*/
|
|
61
|
+
function rendersAsHost(node: Expression, imports: ReadonlySet<string>): boolean {
|
|
62
|
+
switch (node.kind) {
|
|
63
|
+
case JS.Kind.JsxTag:
|
|
64
|
+
case J.Kind.Literal:
|
|
65
|
+
case J.Kind.Empty:
|
|
66
|
+
case JS.Kind.TemplateExpression:
|
|
67
|
+
return true;
|
|
68
|
+
case J.Kind.Parentheses:
|
|
69
|
+
return rendersAsHost((node as J.Parentheses<Expression>).tree.element, imports);
|
|
70
|
+
case J.Kind.Ternary: {
|
|
71
|
+
const ternary = node as J.Ternary;
|
|
72
|
+
return rendersAsHost(ternary.truePart.element, imports) && rendersAsHost(ternary.falsePart.element, imports);
|
|
73
|
+
}
|
|
74
|
+
case J.Kind.Binary: {
|
|
75
|
+
const binary = node as J.Binary;
|
|
76
|
+
// `condition && <tag />` renders the condition only where it is falsy
|
|
77
|
+
if (binary.operator.element === "And" as J.Binary.Type) return rendersAsHost(binary.right, imports);
|
|
78
|
+
return rendersAsHost(binary.left, imports) && rendersAsHost(binary.right, imports);
|
|
79
|
+
}
|
|
80
|
+
case JS.Kind.Binary:
|
|
81
|
+
return rendersAsHost((node as JS.Binary).left, imports) && rendersAsHost((node as JS.Binary).right, imports);
|
|
82
|
+
case J.Kind.Identifier:
|
|
83
|
+
case J.Kind.FieldAccess: {
|
|
84
|
+
const name = rootName(node);
|
|
85
|
+
return primitive((node as J.Identifier | J.FieldAccess).type) || (name !== undefined && !imports.has(name));
|
|
86
|
+
}
|
|
87
|
+
case J.Kind.MethodInvocation: {
|
|
88
|
+
const call = node as J.MethodInvocation;
|
|
89
|
+
// A callback declared elsewhere, imported or not, may return any element
|
|
90
|
+
return call.name.simpleName === "map" && call.select !== undefined && call.arguments.elements.every(({element}) =>
|
|
91
|
+
element.kind === JS.Kind.ArrowFunction && returnsAsHost((element as JS.ArrowFunction).lambda.body, imports)) ||
|
|
92
|
+
primitive(call.methodType?.returnType);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return primitive((node as Expression & {type?: Type}).type);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const FUNCTIONS = new Set<string>([JS.Kind.ArrowFunction, J.Kind.Lambda, J.Kind.MethodDeclaration, J.Kind.ClassDeclaration]);
|
|
99
|
+
|
|
100
|
+
/** Whether what a function returns renders as host elements: its expression body, or each `return` of its own. */
|
|
101
|
+
function returnsAsHost(body: J | undefined, imports: ReadonlySet<string>): boolean {
|
|
102
|
+
if (!body) return false;
|
|
103
|
+
if (body.kind !== J.Kind.Block) return rendersAsHost(body as Expression, imports);
|
|
104
|
+
let host = true;
|
|
105
|
+
walk(body, tree => {
|
|
106
|
+
if (!host || tree !== body && FUNCTIONS.has(tree.kind)) return false;
|
|
107
|
+
if (tree.kind === J.Kind.Return) {
|
|
108
|
+
const returned = (tree as J.Return).expression;
|
|
109
|
+
host = !returned || rendersAsHost(returned, imports);
|
|
110
|
+
}
|
|
111
|
+
return host;
|
|
112
|
+
});
|
|
113
|
+
return host;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Whether every element `node` creates, including any nested within it, is a host element or a
|
|
118
|
+
* fragment, and it calls nothing that creates elements otherwise.
|
|
119
|
+
*/
|
|
120
|
+
export function hostElementsOnly(node: J, imports: ReadonlySet<string>): boolean {
|
|
121
|
+
let host = true;
|
|
122
|
+
walk(node, tree => {
|
|
123
|
+
if (!host) return false;
|
|
124
|
+
if (tree.kind === J.Kind.Identifier && RENDERS_OTHERWISE.has((tree as J.Identifier).simpleName)) host = false;
|
|
125
|
+
if (tree.kind === J.Kind.MethodInvocation && HOOK.test((tree as J.MethodInvocation).name.simpleName) &&
|
|
126
|
+
!SAME_IN_SHALLOW.has((tree as J.MethodInvocation).name.simpleName)) host = false;
|
|
127
|
+
if (tree.kind === JS.Kind.JsxTag) {
|
|
128
|
+
const tag = tree as JSX.Tag;
|
|
129
|
+
host = hostTag(tag) && (tag.children ?? []).every(child =>
|
|
130
|
+
child.kind !== JS.Kind.JsxEmbeddedExpression || rendersAsHost((child as JSX.EmbeddedExpression).expression.element, imports));
|
|
131
|
+
}
|
|
132
|
+
return host;
|
|
133
|
+
});
|
|
134
|
+
return host;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function exportName(declaration: {modifiers: J.Modifier[]}, name: string): string | undefined {
|
|
138
|
+
const keywords = new Set(declaration.modifiers.map(modifier => modifier.keyword));
|
|
139
|
+
return keywords.has("export") ? keywords.has("default") ? "default" : name : undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Whether `node` is `React.<name>` for one of `names`. */
|
|
143
|
+
function reactMember(node: J | undefined, names: ReadonlySet<string>): boolean {
|
|
144
|
+
if (node?.kind !== J.Kind.FieldAccess) return false;
|
|
145
|
+
const access = node as J.FieldAccess;
|
|
146
|
+
return isIdentifier(access.target) && access.target.simpleName === "React" && names.has(access.name.element.simpleName);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Whether a class extends `Component` or `PureComponent`, bare or as a member of `React`, so that its `render` is its own. */
|
|
150
|
+
function reactBaseClass(declaration: J.ClassDeclaration): boolean {
|
|
151
|
+
const base = unwrapBaseType(declaration.extends?.element);
|
|
152
|
+
return base !== undefined && (isIdentifier(base) ? COMPONENT_BASES.has(base.simpleName) : reactMember(base, COMPONENT_BASES));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** A top-level declaration that can be a component, the export name it has, if any, and the body that renders it. */
|
|
156
|
+
function declaredComponent(statement: J): {name: string, exported?: string, renders?: J} | undefined {
|
|
157
|
+
if (statement.kind === J.Kind.MethodDeclaration) {
|
|
158
|
+
const method = statement as J.MethodDeclaration;
|
|
159
|
+
return {name: method.name.simpleName, renders: method.body, exported: exportName(method, method.name.simpleName)};
|
|
160
|
+
}
|
|
161
|
+
if (statement.kind === J.Kind.ClassDeclaration) {
|
|
162
|
+
const declaration = statement as J.ClassDeclaration;
|
|
163
|
+
if (!reactBaseClass(declaration)) return undefined;
|
|
164
|
+
const render = declaration.body.statements.map(({element}) => element).find(member =>
|
|
165
|
+
member.kind === J.Kind.MethodDeclaration && (member as J.MethodDeclaration).name.simpleName === "render") as J.MethodDeclaration | undefined;
|
|
166
|
+
return {name: declaration.name.simpleName, renders: render?.body, exported: exportName(declaration, declaration.name.simpleName)};
|
|
167
|
+
}
|
|
168
|
+
if (statement.kind === J.Kind.VariableDeclarations) {
|
|
169
|
+
const declaration = statement as J.VariableDeclarations;
|
|
170
|
+
const variable = declaration.variables.length === 1 ? declaration.variables[0].element : undefined;
|
|
171
|
+
if (!variable || !isIdentifier(variable.name) || variable.initializer?.element.kind !== JS.Kind.ArrowFunction) return undefined;
|
|
172
|
+
return {name: variable.name.simpleName, renders: (variable.initializer.element as JS.ArrowFunction).lambda.body,
|
|
173
|
+
exported: exportName(declaration, variable.name.simpleName)};
|
|
174
|
+
}
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Each export name of a source, with the body that renders it where it can be a component, without looking into any body. */
|
|
179
|
+
function componentExports(cu: JS.CompilationUnit): Map<string, J | undefined> {
|
|
180
|
+
const declared = new Map<string, J | undefined>();
|
|
181
|
+
const exported = new Map<string, J | undefined>();
|
|
182
|
+
for (const {element} of cu.statements) {
|
|
183
|
+
const component = declaredComponent(element);
|
|
184
|
+
if (!component) continue;
|
|
185
|
+
declared.set(component.name, component.renders);
|
|
186
|
+
if (component.exported) exported.set(component.exported, component.renders);
|
|
187
|
+
}
|
|
188
|
+
for (const {element} of cu.statements) {
|
|
189
|
+
if (element.kind === JS.Kind.ExportAssignment) {
|
|
190
|
+
const assignment = element as JS.ExportAssignment;
|
|
191
|
+
const expression = assignment.expression.element;
|
|
192
|
+
if (assignment.exportEquals) continue;
|
|
193
|
+
if (expression.kind === JS.Kind.ArrowFunction) exported.set("default", (expression as JS.ArrowFunction).lambda.body);
|
|
194
|
+
if (isIdentifier(expression) && declared.has(expression.simpleName)) exported.set("default", declared.get(expression.simpleName));
|
|
195
|
+
}
|
|
196
|
+
if (element.kind === JS.Kind.ExportDeclaration) {
|
|
197
|
+
const declaration = element as JS.ExportDeclaration;
|
|
198
|
+
if (declaration.moduleSpecifier || declaration.typeOnly.element || declaration.exportClause?.kind !== JS.Kind.NamedExports) continue;
|
|
199
|
+
for (const {element: specifier} of (declaration.exportClause as JS.NamedExports).elements.elements) {
|
|
200
|
+
if (specifier.kind !== JS.Kind.ExportSpecifier || (specifier as JS.ExportSpecifier).typeOnly.element) continue;
|
|
201
|
+
const named = (specifier as JS.ExportSpecifier).specifier;
|
|
202
|
+
if (isIdentifier(named) && declared.has(named.simpleName)) exported.set(named.simpleName, declared.get(named.simpleName));
|
|
203
|
+
if (named.kind === JS.Kind.Alias) {
|
|
204
|
+
const alias = named as JS.Alias;
|
|
205
|
+
const local = alias.propertyName.element;
|
|
206
|
+
if (isIdentifier(local) && declared.has(local.simpleName) && isIdentifier(alias.alias)) exported.set(alias.alias.simpleName, declared.get(local.simpleName));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return exported;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The exports of a source that are function or class components rendering host elements only, where
|
|
216
|
+
* the whole source creates no other element: a component it declares can then render no other.
|
|
217
|
+
* Components wrapped in a call, such as `memo`, `forwardRef`, or a higher-order component, are left out.
|
|
218
|
+
*/
|
|
219
|
+
export function hostComponentExports(cu: JS.CompilationUnit): ReadonlySet<string> {
|
|
220
|
+
// Most sources export no component, which the top-level statements alone show
|
|
221
|
+
const candidates = componentExports(cu);
|
|
222
|
+
if (candidates.size === 0) return NONE;
|
|
223
|
+
const bindings = importBindings(cu);
|
|
224
|
+
// A hook React declares behaves alike only where it is React's own
|
|
225
|
+
if (bindings.some(({local, module}) => HOOK.test(local) && module !== "react")) return NONE;
|
|
226
|
+
const imports = localNames(bindings, cu);
|
|
227
|
+
if (!hostElementsOnly(cu, imports)) return NONE;
|
|
228
|
+
// What a component returns is checked as a child is, since a helper may return any element
|
|
229
|
+
const exported = [...candidates].filter(([, renders]) => returnsAsHost(renders, imports)).map(([name]) => name);
|
|
230
|
+
return exported.length > 0 ? new Set(exported) : NONE;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Each local name a source binds with an import, including namespace imports. */
|
|
234
|
+
export function importedNames(cu: JS.CompilationUnit): ReadonlySet<string> {
|
|
235
|
+
return localNames(importBindings(cu), cu);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function localNames(bindings: ReturnType<typeof importBindings>, cu: JS.CompilationUnit): ReadonlySet<string> {
|
|
239
|
+
return new Set([...bindings.map(({local}) => local), ...namespaceImports(cu)]);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Each local name a source binds to an export of another scanned source. */
|
|
243
|
+
export function relativeImports(cu: JS.CompilationUnit, components: HostComponents): Map<string, ImportedExport> {
|
|
244
|
+
const imports = new Map<string, ImportedExport>();
|
|
245
|
+
for (const {local, name, module} of importBindings(cu)) {
|
|
246
|
+
const path = resolveRelative(cu.sourcePath, module, components);
|
|
247
|
+
if (path) imports.set(local, {path, name});
|
|
248
|
+
}
|
|
249
|
+
return imports;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Whether a prop value the test supplies is not an imported value, which may hold an element of a
|
|
254
|
+
* component. Unlike a child in {@link rendersAsHost}, any other expression passes: its own elements are checked by
|
|
255
|
+
* {@link hostElementsOnly}, and a prop the component does not render as a child cannot add an element.
|
|
256
|
+
*/
|
|
257
|
+
function suppliedByTest(node: Expression, testImports: ReadonlySet<string>): boolean {
|
|
258
|
+
const value = node.kind === JS.Kind.JsxEmbeddedExpression ? (node as JSX.EmbeddedExpression).expression.element : node;
|
|
259
|
+
if (value.kind !== J.Kind.Identifier && value.kind !== J.Kind.FieldAccess) return true;
|
|
260
|
+
const name = rootName(value);
|
|
261
|
+
return primitive((value as J.Identifier | J.FieldAccess).type) || name === undefined || !testImports.has(name);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Whether props that `setProps` passes a shallow wrapper hold no element of a component, which a full render would show as its DOM. */
|
|
265
|
+
export function propsRenderHostElements(props: Expression, testImports: ReadonlySet<string>): boolean {
|
|
266
|
+
return hostElementsOnly(props, testImports) && ![...namesReferencedWithin(props)].some(name => testImports.has(name));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Whether Enzyme's `shallow` renders the same host elements for `element` as a full render: it is a
|
|
271
|
+
* component of another source that renders host elements only, and receives no element of a
|
|
272
|
+
* component through its props or children, where `testImports` are the names the test imports.
|
|
273
|
+
*/
|
|
274
|
+
export function rendersHostElements(element: J, imports: ReadonlyMap<string, ImportedExport>, components: HostComponents,
|
|
275
|
+
testImports: ReadonlySet<string>): boolean {
|
|
276
|
+
if (element.kind !== JS.Kind.JsxTag) return false;
|
|
277
|
+
const tag = element as JSX.Tag;
|
|
278
|
+
const name = tag.openName.element;
|
|
279
|
+
if (!isIdentifier(name)) return false;
|
|
280
|
+
const source = imports.get(name.simpleName);
|
|
281
|
+
if (!source || !components.get(source.path)?.has(source.name)) return false;
|
|
282
|
+
return tag.attributes.every(({element: attribute}) => hostElementsOnly(attribute, testImports) && (
|
|
283
|
+
attribute.kind === JS.Kind.JsxSpreadAttribute ? suppliedByTest((attribute as JSX.SpreadAttribute).expression.element, testImports) :
|
|
284
|
+
attribute.kind !== JS.Kind.JsxAttribute || !(attribute as JSX.Attribute).value || suppliedByTest((attribute as JSX.Attribute).value!.element, testImports))) &&
|
|
285
|
+
(tag.children ?? []).every(child => hostElementsOnly(child, testImports) &&
|
|
286
|
+
(child.kind !== JS.Kind.JsxEmbeddedExpression || rendersAsHost((child as JSX.EmbeddedExpression).expression.element, testImports)));
|
|
287
|
+
}
|