@openrewrite/recipes-react 0.12.0 → 0.13.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.
Files changed (185) hide show
  1. package/dist/migration/change-component-prop-value.d.ts.map +1 -1
  2. package/dist/migration/change-component-prop-value.js +2 -2
  3. package/dist/migration/change-component-prop-value.js.map +1 -1
  4. package/dist/react-native/view-prop-types.d.ts.map +1 -1
  5. package/dist/react-native/view-prop-types.js +2 -2
  6. package/dist/react-native/view-prop-types.js.map +1 -1
  7. package/dist/react16/error-boundaries.d.ts.map +1 -1
  8. package/dist/react16/error-boundaries.js +2 -2
  9. package/dist/react16/error-boundaries.js.map +1 -1
  10. package/dist/react16/find-dom-node.d.ts.map +1 -1
  11. package/dist/react16/find-dom-node.js +2 -2
  12. package/dist/react16/find-dom-node.js.map +1 -1
  13. package/dist/react16/react-dom-factories.d.ts.map +1 -1
  14. package/dist/react16/react-dom-factories.js +2 -2
  15. package/dist/react16/react-dom-factories.js.map +1 -1
  16. package/dist/react16/react-prop-types.d.ts.map +1 -1
  17. package/dist/react16/react-prop-types.js +2 -2
  18. package/dist/react16/react-prop-types.js.map +1 -1
  19. package/dist/react16/react-to-react-dom.d.ts.map +1 -1
  20. package/dist/react16/react-to-react-dom.js +2 -2
  21. package/dist/react16/react-to-react-dom.js.map +1 -1
  22. package/dist/react16/replace-create-factory.d.ts.map +1 -1
  23. package/dist/react16/replace-create-factory.js +2 -2
  24. package/dist/react16/replace-create-factory.js.map +1 -1
  25. package/dist/react17/remove-event-persist.d.ts.map +1 -1
  26. package/dist/react17/remove-event-persist.js +2 -2
  27. package/dist/react17/remove-event-persist.js.map +1 -1
  28. package/dist/react17/rename-unsafe-lifecycles.d.ts.map +1 -1
  29. package/dist/react17/rename-unsafe-lifecycles.js +2 -2
  30. package/dist/react17/rename-unsafe-lifecycles.js.map +1 -1
  31. package/dist/react17/update-react-imports.d.ts.map +1 -1
  32. package/dist/react17/update-react-imports.js +2 -2
  33. package/dist/react17/update-react-imports.js.map +1 -1
  34. package/dist/react18/remove-unstable-batched-updates.d.ts.map +1 -1
  35. package/dist/react18/remove-unstable-batched-updates.js +2 -2
  36. package/dist/react18/remove-unstable-batched-updates.js.map +1 -1
  37. package/dist/react18/replace-reactdom-render.d.ts.map +1 -1
  38. package/dist/react18/replace-reactdom-render.js +2 -2
  39. package/dist/react18/replace-reactdom-render.js.map +1 -1
  40. package/dist/react18/replace-render-callback.d.ts.map +1 -1
  41. package/dist/react18/replace-render-callback.js +2 -2
  42. package/dist/react18/replace-render-callback.js.map +1 -1
  43. package/dist/react18/replace-unmount-component-at-node.d.ts.map +1 -1
  44. package/dist/react18/replace-unmount-component-at-node.js +2 -2
  45. package/dist/react18/replace-unmount-component-at-node.js.map +1 -1
  46. package/dist/react19/deprecated-react-types.d.ts.map +1 -1
  47. package/dist/react19/deprecated-react-types.js +2 -2
  48. package/dist/react19/deprecated-react-types.js.map +1 -1
  49. package/dist/react19/find-context-consumer.d.ts.map +1 -1
  50. package/dist/react19/find-context-consumer.js +2 -2
  51. package/dist/react19/find-context-consumer.js.map +1 -1
  52. package/dist/react19/find-deprecated-reactdom-apis.d.ts.map +1 -1
  53. package/dist/react19/find-deprecated-reactdom-apis.js +2 -2
  54. package/dist/react19/find-deprecated-reactdom-apis.js.map +1 -1
  55. package/dist/react19/find-element-ref.d.ts.map +1 -1
  56. package/dist/react19/find-element-ref.js +2 -2
  57. package/dist/react19/find-element-ref.js.map +1 -1
  58. package/dist/react19/find-legacy-context-api.d.ts.map +1 -1
  59. package/dist/react19/find-legacy-context-api.js +2 -2
  60. package/dist/react19/find-legacy-context-api.js.map +1 -1
  61. package/dist/react19/no-implicit-ref-callback-return.d.ts.map +1 -1
  62. package/dist/react19/no-implicit-ref-callback-return.js +2 -2
  63. package/dist/react19/no-implicit-ref-callback-return.js.map +1 -1
  64. package/dist/react19/remove-context-provider.d.ts.map +1 -1
  65. package/dist/react19/remove-context-provider.js +2 -2
  66. package/dist/react19/remove-context-provider.js.map +1 -1
  67. package/dist/react19/remove-forward-ref.d.ts.map +1 -1
  68. package/dist/react19/remove-forward-ref.js +2 -2
  69. package/dist/react19/remove-forward-ref.js.map +1 -1
  70. package/dist/react19/remove-prop-types.d.ts.map +1 -1
  71. package/dist/react19/remove-prop-types.js +2 -2
  72. package/dist/react19/remove-prop-types.js.map +1 -1
  73. package/dist/react19/remove-react-fc.d.ts.map +1 -1
  74. package/dist/react19/remove-react-fc.js +2 -2
  75. package/dist/react19/remove-react-fc.js.map +1 -1
  76. package/dist/react19/replace-act-import.d.ts.map +1 -1
  77. package/dist/react19/replace-act-import.js +1 -1
  78. package/dist/react19/replace-act-import.js.map +1 -1
  79. package/dist/react19/replace-default-props.d.ts.map +1 -1
  80. package/dist/react19/replace-default-props.js +2 -2
  81. package/dist/react19/replace-default-props.js.map +1 -1
  82. package/dist/react19/replace-react-shallow-renderer.d.ts.map +1 -1
  83. package/dist/react19/replace-react-shallow-renderer.js +2 -2
  84. package/dist/react19/replace-react-shallow-renderer.js.map +1 -1
  85. package/dist/react19/replace-reactdom-hydrate.d.ts.map +1 -1
  86. package/dist/react19/replace-reactdom-hydrate.js +2 -2
  87. package/dist/react19/replace-reactdom-hydrate.js.map +1 -1
  88. package/dist/react19/replace-string-ref.d.ts.map +1 -1
  89. package/dist/react19/replace-string-ref.js +2 -2
  90. package/dist/react19/replace-string-ref.js.map +1 -1
  91. package/dist/react19/replace-use-form-state.d.ts.map +1 -1
  92. package/dist/react19/replace-use-form-state.js +2 -2
  93. package/dist/react19/replace-use-form-state.js.map +1 -1
  94. package/dist/react19/scoped-jsx-namespace.d.ts.map +1 -1
  95. package/dist/react19/scoped-jsx-namespace.js +2 -2
  96. package/dist/react19/scoped-jsx-namespace.js.map +1 -1
  97. package/dist/react19/use-context-hook.d.ts.map +1 -1
  98. package/dist/react19/use-context-hook.js +2 -2
  99. package/dist/react19/use-context-hook.js.map +1 -1
  100. package/dist/react19/use-ref-required-initial.d.ts.map +1 -1
  101. package/dist/react19/use-ref-required-initial.js +2 -2
  102. package/dist/react19/use-ref-required-initial.js.map +1 -1
  103. package/dist/refactoring/class-to-functional.d.ts.map +1 -1
  104. package/dist/refactoring/class-to-functional.js +2 -2
  105. package/dist/refactoring/class-to-functional.js.map +1 -1
  106. package/dist/refactoring/create-class-to-es6.d.ts.map +1 -1
  107. package/dist/refactoring/create-class-to-es6.js +164 -32
  108. package/dist/refactoring/create-class-to-es6.js.map +1 -1
  109. package/dist/refactoring/create-element-to-jsx.d.ts.map +1 -1
  110. package/dist/refactoring/create-element-to-jsx.js +2 -2
  111. package/dist/refactoring/create-element-to-jsx.js.map +1 -1
  112. package/dist/refactoring/manual-bind-to-arrow.d.ts.map +1 -1
  113. package/dist/refactoring/manual-bind-to-arrow.js +2 -2
  114. package/dist/refactoring/manual-bind-to-arrow.js.map +1 -1
  115. package/dist/refactoring/pure-render-mixin.d.ts.map +1 -1
  116. package/dist/refactoring/pure-render-mixin.js +22 -16
  117. package/dist/refactoring/pure-render-mixin.js.map +1 -1
  118. package/dist/refactoring/sort-comp.d.ts.map +1 -1
  119. package/dist/refactoring/sort-comp.js +2 -2
  120. package/dist/refactoring/sort-comp.js.map +1 -1
  121. package/dist/search/find-hook-usage.d.ts.map +1 -1
  122. package/dist/search/find-hook-usage.js +2 -2
  123. package/dist/search/find-hook-usage.js.map +1 -1
  124. package/dist/search/find-prop-usage.d.ts.map +1 -1
  125. package/dist/search/find-prop-usage.js +2 -2
  126. package/dist/search/find-prop-usage.js.map +1 -1
  127. package/dist/search/find-react-component.d.ts.map +1 -1
  128. package/dist/search/find-react-component.js +2 -2
  129. package/dist/search/find-react-component.js.map +1 -1
  130. package/dist/search/find-server-rendering-usage.d.ts.map +1 -1
  131. package/dist/search/find-server-rendering-usage.js +2 -2
  132. package/dist/search/find-server-rendering-usage.js.map +1 -1
  133. package/dist/simplify-object-pattern-property.d.ts.map +1 -1
  134. package/dist/simplify-object-pattern-property.js +2 -2
  135. package/dist/simplify-object-pattern-property.js.map +1 -1
  136. package/dist/simplify-react-imports.d.ts.map +1 -1
  137. package/dist/simplify-react-imports.js +2 -2
  138. package/dist/simplify-react-imports.js.map +1 -1
  139. package/package.json +2 -2
  140. package/src/migration/change-component-prop-value.ts +4 -4
  141. package/src/react-native/view-prop-types.ts +4 -4
  142. package/src/react16/error-boundaries.ts +4 -4
  143. package/src/react16/find-dom-node.ts +5 -4
  144. package/src/react16/react-dom-factories.ts +5 -4
  145. package/src/react16/react-prop-types.ts +4 -5
  146. package/src/react16/react-to-react-dom.ts +4 -6
  147. package/src/react16/replace-create-factory.ts +4 -12
  148. package/src/react17/remove-event-persist.ts +4 -4
  149. package/src/react17/rename-unsafe-lifecycles.ts +4 -4
  150. package/src/react17/update-react-imports.ts +4 -4
  151. package/src/react18/remove-unstable-batched-updates.ts +4 -4
  152. package/src/react18/replace-reactdom-render.ts +5 -4
  153. package/src/react18/replace-render-callback.ts +4 -4
  154. package/src/react18/replace-unmount-component-at-node.ts +5 -4
  155. package/src/react19/deprecated-react-types.ts +4 -4
  156. package/src/react19/find-context-consumer.ts +4 -4
  157. package/src/react19/find-deprecated-reactdom-apis.ts +4 -4
  158. package/src/react19/find-element-ref.ts +4 -4
  159. package/src/react19/find-legacy-context-api.ts +4 -4
  160. package/src/react19/no-implicit-ref-callback-return.ts +4 -4
  161. package/src/react19/remove-context-provider.ts +5 -4
  162. package/src/react19/remove-forward-ref.ts +7 -4
  163. package/src/react19/remove-prop-types.ts +4 -4
  164. package/src/react19/remove-react-fc.ts +5 -4
  165. package/src/react19/replace-act-import.ts +3 -3
  166. package/src/react19/replace-default-props.ts +4 -4
  167. package/src/react19/replace-react-shallow-renderer.ts +4 -4
  168. package/src/react19/replace-reactdom-hydrate.ts +5 -4
  169. package/src/react19/replace-string-ref.ts +4 -4
  170. package/src/react19/replace-use-form-state.ts +5 -4
  171. package/src/react19/scoped-jsx-namespace.ts +4 -4
  172. package/src/react19/use-context-hook.ts +7 -4
  173. package/src/react19/use-ref-required-initial.ts +4 -4
  174. package/src/refactoring/class-to-functional.ts +4 -4
  175. package/src/refactoring/create-class-to-es6.ts +222 -37
  176. package/src/refactoring/create-element-to-jsx.ts +4 -4
  177. package/src/refactoring/manual-bind-to-arrow.ts +4 -4
  178. package/src/refactoring/pure-render-mixin.ts +30 -22
  179. package/src/refactoring/sort-comp.ts +4 -4
  180. package/src/search/find-hook-usage.ts +4 -4
  181. package/src/search/find-prop-usage.ts +4 -4
  182. package/src/search/find-react-component.ts +4 -4
  183. package/src/search/find-server-rendering-usage.ts +4 -4
  184. package/src/simplify-object-pattern-property.ts +4 -4
  185. package/src/simplify-react-imports.ts +4 -4
@@ -1,6 +1,6 @@
1
- import {emptyMarkers, ExecutionContext, findMarker, printer, randomId, Recipe, TreeVisitor} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, JS, raw, template} from "@openrewrite/rewrite/javascript";
3
- import {J} from "@openrewrite/rewrite/java";
1
+ import {Cursor, emptyMarkers, ExecutionContext, findMarker, Marker, printer, randomId, Recipe, Tree, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
+ import {compilationUnitOf, JavaScriptVisitor, JS, maybeBind, maybeUnbind, moduleBindings, raw, template, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
+ import {Comment, J, TextComment} from "@openrewrite/rewrite/java";
4
4
 
5
5
  const LIFECYCLE_METHODS = new Set([
6
6
  'render',
@@ -13,6 +13,9 @@ const LIFECYCLE_METHODS = new Set([
13
13
  'getDerivedStateFromProps', 'getDerivedStateFromError',
14
14
  ]);
15
15
 
16
+ /** The properties of a spec that become static fields of the class. */
17
+ const STATIC_PROPERTIES = new Set(['childContextTypes', 'contextTypes', 'displayName', 'propTypes']);
18
+
16
19
  /** The methods a `createClass` component has and a `React.Component` doesn't, as react-codemod lists them. */
17
20
  const CREATE_CLASS_METHODS = new Set(['getDOMNode', 'isMounted', 'replaceProps', 'replaceState', 'setProps']);
18
21
 
@@ -25,8 +28,11 @@ const SEMICOLON_KIND = "org.openrewrite.java.marker.Semicolon";
25
28
  * - `getInitialState()` → class property `state = {...}`
26
29
  * - `getDefaultProps()` → `static defaultProps = {...}`
27
30
  * - Static properties (propTypes, contextTypes) → class statics
31
+ * - `displayName` → `static displayName`, unless it is the class's name
28
32
  * - Auto-binding of methods → arrow function class fields
29
33
  * - Lifecycle methods and render → regular class methods
34
+ * - A `createReactClass()` component extends the `Component` of the `react` the file binds, or binds one, and the
35
+ * `create-react-class` import goes where nothing else uses it
30
36
  * - Skips conversion if mixins are present, or a member it has no conversion for, such as
31
37
  * `render: function() {}` or `statics`
32
38
  *
@@ -38,7 +44,7 @@ export class CreateClassToES6 extends Recipe {
38
44
  readonly description: string = "Converts `React.createClass()` and `createReactClass()` calls to ES6 class syntax.";
39
45
 
40
46
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
41
- return new class extends JavaScriptVisitor<ExecutionContext> {
47
+ return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
42
48
  private convertedClassIds = new Set<string>();
43
49
 
44
50
  private stripSemicolonFromConverted(statements: any[]): { modified: boolean, statements: any[] } {
@@ -116,22 +122,36 @@ export class CreateClassToES6 extends Recipe {
116
122
  if (await mentions(specObj.body, CREATE_CLASS_METHODS)) return vd;
117
123
 
118
124
  // Build transformed class members
119
- const members = await this.transformMembers(vd, specObj.body, ctx);
125
+ const members = await this.transformMembers(componentName, vd, specObj.body, ctx);
120
126
  if (!members) return vd;
121
127
 
122
128
  // Construct class declaration using template
129
+ const component = this.componentClass(methodInv);
130
+ if (!component) return vd;
123
131
  const classDecl = this.isExported(vd) ?
124
- await template`export class ${raw(componentName)} extends React.Component {}`.apply(vd, this.cursor) :
125
- await template`class ${raw(componentName)} extends React.Component {}`.apply(vd, this.cursor);
132
+ await template`export class ${raw(componentName)} extends ${raw(component)} {}`.apply(vd, this.cursor) :
133
+ await template`class ${raw(componentName)} extends ${raw(component)} {}`.apply(vd, this.cursor);
126
134
  if (!classDecl) return vd;
135
+ if (!methodInv.select) {
136
+ maybeUnbind(this, 'create-react-class');
137
+ }
127
138
 
128
139
  // Splice transformed members into class body
129
140
  const cd = classDecl as J.ClassDeclaration;
141
+ const end = specObj.body.end;
142
+ const last = members[members.length - 1];
130
143
  const result = {
131
144
  ...cd,
132
145
  body: {
133
146
  ...cd.body,
134
- statements: members
147
+ statements: members,
148
+ // The comments after the spec's last member stay ahead of the class's closing brace, on a line of
149
+ // their own where that member ends with a line comment
150
+ end: end.comments.length === 0 ? cd.body.end : {
151
+ ...end,
152
+ whitespace: last && /\n[ \t]*$/.test(spaceText(last.after)) ? '' : end.whitespace,
153
+ comments: end.comments.map((c, i) => i < end.comments.length - 1 ? c : {...c, suffix: cd.body.end.whitespace})
154
+ }
135
155
  }
136
156
  } as any as J.ClassDeclaration;
137
157
 
@@ -153,6 +173,24 @@ export class CreateClassToES6 extends Recipe {
153
173
  return false;
154
174
  }
155
175
 
176
+ /**
177
+ * What the class extends: `React.Component` for `React.createClass`, and for `createReactClass` the `Component`
178
+ * of the `react` the file binds, or of one it binds here, or `undefined` where it can't bind one.
179
+ */
180
+ private componentClass(createClass: J.MethodInvocation): string | undefined {
181
+ const bindings = moduleBindings(this);
182
+ // A script that calls `createReactClass` has it and React as globals, as create-react-class's UMD build does
183
+ if (createClass.select || bindings.moduleSystem === 'none') return 'React.Component';
184
+ const react = bindings.bindingOf('react');
185
+ // A class can't extend what an `import type` binds
186
+ if (react !== undefined && !importsTypeOnly(compilationUnitOf(this), react)) return `${react}.Component`;
187
+ const component = maybeBind(this, {module: 'react', member: 'Component', onlyIfReferenced: false});
188
+ if (component !== undefined) return component;
189
+ // An AMD block binds a whole module, not one of its members
190
+ const module = maybeBind(this, {module: 'react', onlyIfReferenced: false});
191
+ return module === undefined ? undefined : `${module}.Component`;
192
+ }
193
+
156
194
  private isExported(vd: J.VariableDeclarations): boolean {
157
195
  return vd.modifiers.some(m => m.keyword === 'export');
158
196
  }
@@ -177,26 +215,30 @@ export class CreateClassToES6 extends Recipe {
177
215
  }
178
216
 
179
217
  /** The members of the class, or `undefined` when the spec holds one that has no conversion here. */
180
- private async transformMembers(declaration: J.VariableDeclarations, body: J.Block, ctx: ExecutionContext): Promise<any[] | undefined> {
218
+ private async transformMembers(componentName: string, declaration: J.VariableDeclarations, body: J.Block, ctx: ExecutionContext): Promise<any[] | undefined> {
181
219
  const members: any[] = [];
182
220
 
183
- for (const stmt of body.statements) {
221
+ for (const [i, stmt] of body.statements.entries()) {
184
222
  const s = stmt.element;
185
223
  // A converted member keeps the comments and indentation it had in the spec
186
224
  const prefix = s.prefix;
225
+ // Whether a line comment the converted member ends with can end without a line break of its own
226
+ const lineFollows = i === body.statements.length - 1 ?
227
+ body.end.comments.length === 0 || body.end.whitespace.includes('\n') :
228
+ stmt.after.whitespace.includes('\n') || body.statements[i + 1].element.prefix.whitespace.includes('\n');
187
229
 
188
230
  if (s.kind === J.Kind.MethodDeclaration) {
189
231
  const method = s as J.MethodDeclaration;
190
232
  const name = method.name.simpleName;
191
233
 
192
234
  if (name === 'getInitialState') {
193
- const stateInit = await this.convertGetInitialState(method, prefix, ctx);
235
+ const stateInit = await this.convertGetInitialState(stmt, method, lineFollows, ctx);
194
236
  if (!stateInit) return undefined;
195
- members.push({...stmt, element: stateInit});
237
+ members.push(stateInit);
196
238
  } else if (name === 'getDefaultProps') {
197
- const defaultProps = await this.convertGetDefaultProps(method, declaration, prefix);
239
+ const defaultProps = await this.convertGetDefaultProps(stmt, method, declaration, lineFollows);
198
240
  if (!defaultProps) return undefined;
199
- members.push({...stmt, element: defaultProps});
241
+ members.push(defaultProps);
200
242
  } else if (LIFECYCLE_METHODS.has(name)) {
201
243
  members.push(stmt);
202
244
  } else {
@@ -208,11 +250,11 @@ export class CreateClassToES6 extends Recipe {
208
250
  const prop = s as JS.PropertyAssignment;
209
251
  const keyName = this.getPropertyKeyName(prop);
210
252
 
211
- if (keyName === 'propTypes' || keyName === 'contextTypes' || keyName === 'childContextTypes') {
212
- const staticProp = await this.convertToStaticProperty(prop, keyName, declaration, prefix);
253
+ if (keyName !== undefined && STATIC_PROPERTIES.has(keyName)) {
254
+ const staticProp = await this.convertToStaticProperty(stmt, prop, keyName, declaration, lineFollows);
213
255
  if (!staticProp) return undefined;
214
- members.push({...stmt, element: staticProp});
215
- } else if (keyName !== 'displayName') {
256
+ members.push(staticProp);
257
+ } else {
216
258
  // `render: function() {}`, `statics` and other properties don't belong in a class body as they are
217
259
  return undefined;
218
260
  }
@@ -221,10 +263,20 @@ export class CreateClassToES6 extends Recipe {
221
263
  }
222
264
  }
223
265
 
224
- return members;
266
+ return members.map((member, i) => {
267
+ // A class body has no commas, so the spec's trailing comma goes
268
+ const markers = member.markers.markers.filter((m: Marker) => m.kind !== J.Markers.TrailingComma);
269
+ // and a field ends with a semicolon where the member after it starts on the same line
270
+ const semicolon = member.element.kind === J.Kind.VariableDeclarations && i < members.length - 1 &&
271
+ !(spaceText(member.after) + spaceText(members[i + 1].element.prefix)).includes('\n');
272
+ return !semicolon && markers.length === member.markers.markers.length ? member : {
273
+ ...member,
274
+ markers: {...member.markers, markers: semicolon ? [...markers, {kind: SEMICOLON_KIND, id: randomId()}] : markers}
275
+ };
276
+ });
225
277
  }
226
278
 
227
- private async convertGetInitialState(method: J.MethodDeclaration, prefix: any, ctx: ExecutionContext): Promise<J | undefined> {
279
+ private async convertGetInitialState(stmt: J.RightPadded<J>, method: J.MethodDeclaration, lineFollows: boolean, ctx: ExecutionContext): Promise<J.RightPadded<J> | undefined> {
228
280
  if (!method.body) return undefined;
229
281
  const stmts = method.body.statements;
230
282
  if (stmts.length !== 1) return undefined;
@@ -236,14 +288,10 @@ export class CreateClassToES6 extends Recipe {
236
288
  if (!returnStmt.expression) return undefined;
237
289
 
238
290
  const result = await template`state = ${returnStmt.expression}`.apply(method, this.cursor);
239
- const field = result && classField(result);
240
- if (field && prefix) {
241
- return {...(field as any), prefix};
242
- }
243
- return field;
291
+ return result && inPlaceOf(stmt, classField(result), returnStmt.expression, lineFollows);
244
292
  }
245
293
 
246
- private async convertGetDefaultProps(method: J.MethodDeclaration, declaration: J.VariableDeclarations, prefix: any): Promise<J | undefined> {
294
+ private async convertGetDefaultProps(stmt: J.RightPadded<J>, method: J.MethodDeclaration, declaration: J.VariableDeclarations, lineFollows: boolean): Promise<J.RightPadded<J> | undefined> {
247
295
  if (!method.body) return undefined;
248
296
  const stmts = method.body.statements;
249
297
  if (stmts.length !== 1) return undefined;
@@ -254,7 +302,7 @@ export class CreateClassToES6 extends Recipe {
254
302
  const returnStmt = firstStmt as J.Return;
255
303
  if (!returnStmt.expression) return undefined;
256
304
 
257
- return this.staticField('defaultProps', returnStmt.expression, declaration, prefix);
305
+ return this.staticField('defaultProps', returnStmt.expression, stmt, declaration, lineFollows);
258
306
  }
259
307
 
260
308
  private async convertToArrowProperty(method: J.MethodDeclaration, prefix: any, ctx: ExecutionContext): Promise<J | undefined> {
@@ -306,26 +354,24 @@ export class CreateClassToES6 extends Recipe {
306
354
 
307
355
 
308
356
 
309
- private async convertToStaticProperty(prop: JS.PropertyAssignment, name: string, declaration: J.VariableDeclarations, prefix: any): Promise<J | undefined> {
357
+ private async convertToStaticProperty(stmt: J.RightPadded<J>, prop: JS.PropertyAssignment, name: string, declaration: J.VariableDeclarations, lineFollows: boolean): Promise<J.RightPadded<J> | undefined> {
310
358
  // A shorthand `propTypes` stands for `propTypes: propTypes`
311
- return this.staticField(name, prop.initializer ?? prop.name.element, declaration, prefix);
359
+ return this.staticField(name, prop.initializer ?? prop.name.element, stmt, declaration, lineFollows);
312
360
  }
313
361
 
314
362
  /**
315
- * The field `static name = value` as the parser makes it, which a template parses only inside a class, so it
316
- * takes the field from a class laid out where the converted class replaces `declaration`.
363
+ * The field `static name = value` that takes the place of the spec's `member`, as the parser makes it, which a
364
+ * template parses only inside a class, so it takes the field from a class laid out where the converted class
365
+ * replaces `declaration`.
317
366
  */
318
- private async staticField(name: string, value: J, declaration: J.VariableDeclarations, prefix: any): Promise<J | undefined> {
367
+ private async staticField(name: string, value: J, member: J.RightPadded<J>, declaration: J.VariableDeclarations, lineFollows: boolean): Promise<J.RightPadded<J> | undefined> {
319
368
  const cls = await template`class C {
320
369
  static ${raw(name)} = ${value}
321
370
  }`.apply(declaration, this.cursor);
322
371
  const field = cls?.kind === J.Kind.ClassDeclaration ? (cls as J.ClassDeclaration).body.statements[0]?.element : undefined;
323
- if (field && prefix) {
324
- return {...(field as any), prefix};
325
- }
326
- return field;
372
+ return field && inPlaceOf(member, field, value, lineFollows);
327
373
  }
328
- }();
374
+ }());
329
375
  }
330
376
  }
331
377
 
@@ -358,6 +404,145 @@ function classField(tree: J): J {
358
404
  } as any as J.VariableDeclarations;
359
405
  }
360
406
 
407
+ /**
408
+ * The `field` a template made of `value` in the place of the spec's `member`: with the member's prefix, with the value
409
+ * laid out as the spec has it, moved with the line it starts on to the line the member starts on, and with the comments
410
+ * the member holds around the value before and after it.
411
+ */
412
+ async function inPlaceOf(member: J.RightPadded<J>, field: J, value: J, lineFollows: boolean): Promise<J.RightPadded<J>> {
413
+ const prefix = member.element.prefix;
414
+ const variable = field.kind === J.Kind.VariableDeclarations ? (field as J.VariableDeclarations).variables[0] : undefined;
415
+ const initializer = variable?.element.initializer;
416
+ const around = await surroundings(member.element, value);
417
+ if (!variable || !initializer || !around) {
418
+ return {...member, element: {...field, prefix}};
419
+ }
420
+ const from = around.line;
421
+ const to = indentation(prefix);
422
+ const shift = (text: string) => from === undefined || to === undefined ? text : shiftLines(text, from, to);
423
+ const lineStart = to === undefined ? undefined : (/\r\n/.test(prefix.whitespace) ? '\r\n' : '\n') + to;
424
+ // A value the template put in parentheses, or one on a line whose indentation isn't known, keeps the template's layout
425
+ const laidOut = initializer.element.id !== value.id || (from === undefined) !== (to === undefined) ? initializer.element : {
426
+ ...(from === undefined || to === undefined ? value : await reindent(value, from, to)),
427
+ prefix: {...initializer.element.prefix, comments: value.prefix.comments}
428
+ };
429
+ // The comments before the value go on lines of their own above the field
430
+ const before = around.before.flatMap(space => space.comments)
431
+ .map(c => ({...shiftComment(c, shift), suffix: lineStart ?? shift(c.suffix)}));
432
+ // and those after it follow the field, ahead of what the member had before the comma that followed it
433
+ const after = around.after.flatMap((space, i) => space.comments.map((c, j) => {
434
+ const next = j < space.comments.length - 1 ? '' : around.after[i + 1]?.whitespace;
435
+ // The last one ends the line where a line comment would take in what follows
436
+ const suffix = next !== undefined ? shift(c.suffix + next) :
437
+ ((c as TextComment).multiline || lineFollows ? '' : lineStart ?? '\n') + member.after.whitespace;
438
+ return {...shiftComment(c, shift), suffix};
439
+ }));
440
+ return {
441
+ ...member,
442
+ element: {
443
+ ...field,
444
+ prefix: {...prefix, comments: [...prefix.comments, ...before]},
445
+ variables: [{...variable, element: {...variable.element, initializer: {...initializer, element: laidOut}}}]
446
+ } as J.VariableDeclarations,
447
+ after: after.length === 0 ? member.after :
448
+ {...member.after, whitespace: shift(around.after[0].whitespace), comments: [...after, ...member.after.comments]}
449
+ };
450
+ }
451
+
452
+ /** What `member` holds besides `value` and its own prefix. */
453
+ interface Surroundings {
454
+ /** The indentation of the line `value` starts on, unless `member` starts no line before it. */
455
+ line?: string
456
+ /** The whitespace with comments in it before `value`. */
457
+ before: J.Space[]
458
+ /** The whitespace with comments in it after `value`. */
459
+ after: J.Space[]
460
+ }
461
+
462
+ /** What `member` holds besides `value` and its own prefix, or `undefined` when `value` isn't in it. */
463
+ async function surroundings(member: J, value: J): Promise<Surroundings | undefined> {
464
+ const around: Surroundings = {before: [], after: []};
465
+ let found = false;
466
+ await new class extends JavaScriptVisitor<void> {
467
+ override async visit<R extends J>(tree: Tree, p: void, parent?: Cursor): Promise<R | undefined> {
468
+ if (tree !== value) {
469
+ return super.visit<R>(tree, p, parent);
470
+ }
471
+ around.line = indentation(value.prefix) ?? around.line;
472
+ found = true;
473
+ return tree as R;
474
+ }
475
+
476
+ override async visitSpace(space: J.Space, p: void): Promise<J.Space> {
477
+ if (!found) {
478
+ around.line = indentation(space) ?? around.line;
479
+ }
480
+ if (space !== member.prefix && space.comments.length > 0) {
481
+ (found ? around.after : around.before).push(space);
482
+ }
483
+ return space;
484
+ }
485
+ }().visit(member, undefined);
486
+ return found ? around : undefined;
487
+ }
488
+
489
+ /** The indentation of the last line `space` starts, or `undefined` when it holds no line break. */
490
+ function indentation(space: J.Space): string | undefined {
491
+ const text = spaceText(space);
492
+ const lineBreak = text.lastIndexOf('\n');
493
+ return lineBreak < 0 ? undefined : /^[ \t]*/.exec(text.substring(lineBreak + 1))![0];
494
+ }
495
+
496
+ /** The text the whitespace and comments of `space` print. */
497
+ function spaceText(space: J.Space): string {
498
+ return space.whitespace + space.comments.map(c => {
499
+ const comment = c as TextComment;
500
+ return (comment.multiline ? `/*${comment.text}*/` : `//${comment.text}`) + c.suffix;
501
+ }).join('');
502
+ }
503
+
504
+ /** The tree with each line it spans that is indented by `from` indented by `to` instead. */
505
+ async function reindent<T extends J>(tree: T, from: string, to: string): Promise<T> {
506
+ if (from === to) return tree;
507
+ const shift = (text: string) => shiftLines(text, from, to);
508
+ const shiftSpace = (space: J.Space): J.Space => ({
509
+ ...space,
510
+ whitespace: shift(space.whitespace),
511
+ comments: space.comments.map(c => ({...shiftComment(c, shift), suffix: shift(c.suffix)}))
512
+ });
513
+ return await new class extends JavaScriptVisitor<void> {
514
+ override async visitSpace(space: J.Space, p: void): Promise<J.Space> {
515
+ return shiftSpace(space);
516
+ }
517
+
518
+ // A trailing comma keeps the whitespace after it
519
+ protected override async visitMarker<M extends Marker>(marker: M, p: void): Promise<M> {
520
+ const suffix = (marker as any).suffix;
521
+ return suffix?.kind === J.Kind.Space ? {...marker, suffix: shiftSpace(suffix)} : marker;
522
+ }
523
+ }().visit(tree, undefined) as T;
524
+ }
525
+
526
+ /** The text with each line after its first that is indented by `from` indented by `to` instead. */
527
+ function shiftLines(text: string, from: string, to: string): string {
528
+ return text.split('\n').map((line, i) => i > 0 && line.startsWith(from) ? to + line.substring(from.length) : line).join('\n');
529
+ }
530
+
531
+ /** The comment with `shift` applied to the lines its text spans, as only a block comment's can. */
532
+ function shiftComment(comment: Comment, shift: (text: string) => string): Comment {
533
+ return (comment as TextComment).multiline ? {...comment, text: shift((comment as TextComment).text)} as TextComment : comment;
534
+ }
535
+
536
+ /** Whether the file binds `name` with an `import type`, as its default or namespace import. */
537
+ function importsTypeOnly(cu: JS.CompilationUnit | undefined, name: string): boolean {
538
+ return cu?.statements.some(({element}) => {
539
+ const clause = element.kind === JS.Kind.Import ? (element as JS.Import).importClause : undefined;
540
+ const namespace = clause?.namedBindings?.kind === JS.Kind.Alias ? (clause.namedBindings as JS.Alias).alias : undefined;
541
+ return clause?.typeOnly === true && [clause.name?.element, namespace]
542
+ .some(id => id?.kind === J.Kind.Identifier && (id as J.Identifier).simpleName === name);
543
+ }) ?? false;
544
+ }
545
+
361
546
  /** Whether the method declares the TypeScript parameter `this`. */
362
547
  function declaresThis(method: J.MethodDeclaration): boolean {
363
548
  const first = method.parameters.elements[0]?.element;
@@ -1,5 +1,5 @@
1
- import {ExecutionContext, printer, Recipe, TreeVisitor} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, JS, raw, template} from "@openrewrite/rewrite/javascript";
1
+ import {ExecutionContext, printer, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
+ import {JavaScriptVisitor, JS, raw, template, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
 
5
5
  /**
@@ -33,7 +33,7 @@ export class CreateElementToJsx extends Recipe {
33
33
  readonly description: string = "Converts `React.createElement()` calls to JSX syntax for improved readability.";
34
34
 
35
35
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
36
- return new class extends JavaScriptVisitor<ExecutionContext> {
36
+ return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
37
37
  override async visitMethodInvocation(method: J.MethodInvocation, ctx: ExecutionContext): Promise<J | undefined> {
38
38
  let m = await super.visitMethodInvocation(method, ctx) as J.MethodInvocation;
39
39
 
@@ -195,6 +195,6 @@ export class CreateElementToJsx extends Recipe {
195
195
 
196
196
  return parts.join('');
197
197
  }
198
- }();
198
+ }());
199
199
  }
200
200
  }
@@ -1,5 +1,5 @@
1
- import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor} from "@openrewrite/rewrite/javascript";
1
+ import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
+ import {JavaScriptVisitor, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
 
5
5
  /**
@@ -34,7 +34,7 @@ export class ManualBindToArrow extends Recipe {
34
34
  readonly description: string = "Converts `this.method = this.method.bind(this)` in constructors to class field arrow function syntax.";
35
35
 
36
36
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
37
- return new class extends JavaScriptVisitor<ExecutionContext> {
37
+ return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
38
38
  private boundMethods = new Set<string>();
39
39
 
40
40
  override async visitClassDeclaration(classDecl: J.ClassDeclaration, ctx: ExecutionContext): Promise<J | undefined> {
@@ -134,6 +134,6 @@ export class ManualBindToArrow extends Recipe {
134
134
 
135
135
  return m;
136
136
  }
137
- }();
137
+ }());
138
138
  }
139
139
  }
@@ -1,6 +1,6 @@
1
- import {Cursor, ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, JS, maybeRemoveImport, template} from "@openrewrite/rewrite/javascript";
3
- import {J} from "@openrewrite/rewrite/java";
1
+ import {Cursor, ExecutionContext, findMarker, Marker, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
+ import {JavaScriptVisitor, JS, maybeRemoveImport, template, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
+ import {J, TextComment} from "@openrewrite/rewrite/java";
4
4
 
5
5
  /**
6
6
  * Removes `PureRenderMixin` from `React.createClass` components and replaces it
@@ -33,7 +33,7 @@ export class PureRenderMixin extends Recipe {
33
33
  readonly description: string = "Removes `PureRenderMixin` from `React.createClass` mixins and adds an explicit `shouldComponentUpdate` method.";
34
34
 
35
35
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
36
- return new class extends JavaScriptVisitor<ExecutionContext> {
36
+ return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
37
37
  private transformed = false;
38
38
 
39
39
  override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
@@ -66,9 +66,6 @@ export class PureRenderMixin extends Recipe {
66
66
  // Check that shouldComponentUpdate doesn't already exist
67
67
  if (this.hasShouldComponentUpdate(specObj.body)) return m;
68
68
 
69
- // Get member indent from existing members
70
- const memberIndent = this.getMemberIndent(specObj.body);
71
-
72
69
  // A spec written with function properties alone gets no method shorthand
73
70
  if (!this.hasMethod(specObj.body)) return m;
74
71
 
@@ -79,8 +76,7 @@ export class PureRenderMixin extends Recipe {
79
76
  const newStatements = this.buildNewStatements(
80
77
  specObj.body.statements,
81
78
  mixinsInfo,
82
- scuMethod,
83
- memberIndent
79
+ scuMethod
84
80
  );
85
81
 
86
82
  this.transformed = true;
@@ -181,18 +177,10 @@ export class PureRenderMixin extends Recipe {
181
177
  return method?.kind === J.Kind.MethodDeclaration ? method as J.MethodDeclaration : undefined;
182
178
  }
183
179
 
184
- private getMemberIndent(body: J.Block): any {
185
- for (const stmt of body.statements) {
186
- if (stmt.element?.prefix) return stmt.element.prefix;
187
- }
188
- return undefined;
189
- }
190
-
191
180
  private buildNewStatements(
192
181
  statements: any[],
193
182
  mixinsInfo: { stmtIndex: number; isOnlyMixin: boolean },
194
- scuMethod: J,
195
- indent: any
183
+ scuMethod: J
196
184
  ): any[] {
197
185
  const result: any[] = [];
198
186
  let scuInserted = false;
@@ -243,7 +231,7 @@ export class PureRenderMixin extends Recipe {
243
231
  (s as J.MethodDeclaration).name.simpleName === 'render') {
244
232
  const scuStmt = {
245
233
  ...statements[i],
246
- element: indent ? {...(scuMethod as any), prefix: indent} : scuMethod
234
+ element: {...scuMethod, prefix: lineOf(s.prefix)}
247
235
  };
248
236
  result.push(scuStmt);
249
237
  scuInserted = true;
@@ -256,12 +244,32 @@ export class PureRenderMixin extends Recipe {
256
244
  const lastStmt = statements[statements.length - 1];
257
245
  result.push({
258
246
  ...lastStmt,
259
- element: indent ? {...(scuMethod as any), prefix: indent} : scuMethod
247
+ element: {...scuMethod, prefix: lineOf(lastStmt.element.prefix)}
260
248
  });
261
249
  }
262
250
 
263
- return result;
251
+ // The spec's trailing comma follows the member that now comes last, and no other
252
+ const trailingComma = findMarker(statements[statements.length - 1], J.Markers.TrailingComma);
253
+ return result.map((stmt, i) => {
254
+ const wanted = i === result.length - 1 ? trailingComma : undefined;
255
+ if (findMarker(stmt, J.Markers.TrailingComma) === wanted) return stmt;
256
+ const markers = stmt.markers.markers.filter((m: Marker) => m.kind !== J.Markers.TrailingComma);
257
+ return {...stmt, markers: {...stmt.markers, markers: wanted ? [...markers, wanted] : markers}};
258
+ });
264
259
  }
265
- }();
260
+ }());
266
261
  }
267
262
  }
263
+
264
+ /**
265
+ * A prefix of its own for a member next to the one `prefix` belongs to: the line break and indentation of the line that
266
+ * member starts on, without its comments.
267
+ */
268
+ function lineOf(prefix: J.Space): J.Space {
269
+ const text = prefix.whitespace + prefix.comments.map(c => {
270
+ const comment = c as TextComment;
271
+ return (comment.multiline ? `/*${comment.text}*/` : `//${comment.text}`) + c.suffix;
272
+ }).join('');
273
+ const lineStart = /\r?\n[ \t]*(?=[^\n]*$)/.exec(text);
274
+ return {kind: J.Kind.Space, comments: [], whitespace: lineStart ? lineStart[0] : prefix.whitespace};
275
+ }
@@ -1,5 +1,5 @@
1
- import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor} from "@openrewrite/rewrite/javascript";
1
+ import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
+ import {JavaScriptVisitor, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
 
5
5
  const LIFECYCLE_METHODS = [
@@ -49,7 +49,7 @@ export class SortComp extends Recipe {
49
49
  readonly description: string = "Reorders React component methods to follow the recommended lifecycle ordering convention.";
50
50
 
51
51
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
52
- return new class extends JavaScriptVisitor<ExecutionContext> {
52
+ return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
53
53
  override async visitClassDeclaration(classDecl: J.ClassDeclaration, ctx: ExecutionContext): Promise<J | undefined> {
54
54
  let cd = await super.visitClassDeclaration(classDecl, ctx) as J.ClassDeclaration;
55
55
 
@@ -130,6 +130,6 @@ export class SortComp extends Recipe {
130
130
  // 4: everything else
131
131
  return 400;
132
132
  }
133
- }();
133
+ }());
134
134
  }
135
135
  }
@@ -1,5 +1,5 @@
1
- import {Column, DataTable, ExecutionContext, foundSearchResult, Recipe, TreeVisitor} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
1
+ import {Column, DataTable, ExecutionContext, foundSearchResult, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
+ import {JavaScriptVisitor, JS, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {isIdentifier, J} from "@openrewrite/rewrite/java";
4
4
 
5
5
  const BUILT_IN_HOOKS = new Set([
@@ -72,7 +72,7 @@ export class FindHookUsage extends Recipe {
72
72
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
73
73
  const dataTable = this.dataTable;
74
74
 
75
- return new class extends JavaScriptVisitor<ExecutionContext> {
75
+ return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
76
76
  private filePath = "";
77
77
  private componentStack: string[] = [];
78
78
  private conditionalDepth = 0;
@@ -221,6 +221,6 @@ export class FindHookUsage extends Recipe {
221
221
  }
222
222
  return null;
223
223
  }
224
- }();
224
+ }());
225
225
  }
226
226
  }
@@ -1,5 +1,5 @@
1
- import {Column, DataTable, ExecutionContext, foundSearchResult, Option, Recipe, TreeVisitor} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, JS, JSX} from "@openrewrite/rewrite/javascript";
1
+ import {Column, DataTable, ExecutionContext, foundSearchResult, Option, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
+ import {JavaScriptVisitor, JS, JSX, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {Expression, isIdentifier, J} from "@openrewrite/rewrite/java";
4
4
 
5
5
  class FindPropUsageRow {
@@ -70,7 +70,7 @@ export class FindPropUsage extends Recipe {
70
70
  const filterProp = this.propName;
71
71
  const dataTable = this.dataTable;
72
72
 
73
- return new class extends JavaScriptVisitor<ExecutionContext> {
73
+ return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
74
74
  private filePath = "";
75
75
 
76
76
  override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
@@ -171,6 +171,6 @@ export class FindPropUsage extends Recipe {
171
171
  }
172
172
  return "";
173
173
  }
174
- }();
174
+ }());
175
175
  }
176
176
  }
@@ -1,5 +1,5 @@
1
- import {Column, DataTable, ExecutionContext, foundSearchResult, Option, Recipe, TreeVisitor} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, JS, JSX} from "@openrewrite/rewrite/javascript";
1
+ import {Column, DataTable, ExecutionContext, foundSearchResult, Option, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
+ import {JavaScriptVisitor, JS, JSX, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {Expression, isIdentifier, J} from "@openrewrite/rewrite/java";
4
4
 
5
5
  class FindReactComponentRow {
@@ -69,7 +69,7 @@ export class FindReactComponent extends Recipe {
69
69
  const importPathFilter = this.importPath;
70
70
  const dataTable = this.dataTable;
71
71
 
72
- return new class extends JavaScriptVisitor<ExecutionContext> {
72
+ return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
73
73
  // Track component aliases within the current file
74
74
  private aliases = new Map<string, { importPath: string; isDefault: boolean; alias: string }>();
75
75
  private filePath = "";
@@ -249,6 +249,6 @@ export class FindReactComponent extends Recipe {
249
249
  const regex = new RegExp("^" + pattern.replace(/\*/g, ".*") + "$");
250
250
  return regex.test(actual);
251
251
  }
252
- }();
252
+ }());
253
253
  }
254
254
  }