@octanejs/codemod 0.2.1 → 0.2.3

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.
@@ -45,8 +45,12 @@ export declare function mapReactImport(module: string, name: string, typeOnly: b
45
45
  module: string;
46
46
  name: string;
47
47
  } | null;
48
+ /** React-family hooks that need a compiled call site and the original ref allocator. */
49
+ export declare function isComputedReactHookOrRef(name: string): boolean;
50
+ /** Whether a React value type query can name an actual Octane export. */
51
+ export declare function hasOctaneValue(name: string): boolean;
48
52
  /** The Octane name for `React.<name>` in a type position. */
49
- export declare function mapQualifiedType(name: string): string | null;
53
+ export declare function mapQualifiedType(name: string, module: string, typeOf: boolean, typeArgumentCount: number): string | null;
50
54
  /** Built-in hooks whose omitted dependency list Octane infers. * */
51
55
  export declare const DEPENDENCY_HOOKS: Record<string, number>;
52
56
  /** `<input type>` values whose native `change` fires on commit, not per edit. */
package/dist/mappings.js CHANGED
@@ -94,7 +94,7 @@ const OCTANE_TYPES = new Set(('AllHTMLAttributes AnchorHTMLAttributes AnimationE
94
94
  'SVGAttributes SVGLineElementAttributes SVGProps SVGTextElementAttributes ScriptHTMLAttributes ' +
95
95
  'SelectHTMLAttributes SetStateAction SlotHTMLAttributes SourceHTMLAttributes StrictModeProps ' +
96
96
  'StyleHTMLAttributes SuspenseProps TableHTMLAttributes TdHTMLAttributes TextareaHTMLAttributes ' +
97
- 'ThHTMLAttributes TimeHTMLAttributes ToggleEvent ToggleEventHandler TouchEvent TouchEventHandler ' +
97
+ 'ThHTMLAttributes TimeHTMLAttributes ToggleEvent ToggleEventHandler Touch TouchEvent TouchEventHandler ' +
98
98
  'TrackHTMLAttributes TransitionEvent TransitionEventHandler UIEvent UIEventHandler ' +
99
99
  'VideoHTMLAttributes WebViewHTMLAttributes WheelEvent WheelEventHandler').split(' '));
100
100
  /**
@@ -303,14 +303,27 @@ export function mapReactImport(module, name, typeOnly) {
303
303
  }
304
304
  if (!typeOnly && OCTANE_VALUES.has(name))
305
305
  return { module: 'octane', name };
306
- if (OCTANE_TYPES.has(name))
306
+ if (OCTANE_TYPES.has(name) && (name !== 'Touch' || (module === 'react' && typeOnly)))
307
307
  return { module: 'octane', name };
308
308
  if (name in RENAMED_TYPES)
309
309
  return { module: 'octane', name: RENAMED_TYPES[name] };
310
310
  return null;
311
311
  }
312
+ /** React-family hooks that need a compiled call site and the original ref allocator. */
313
+ export function isComputedReactHookOrRef(name) {
314
+ return name === 'createRef' || (name.startsWith('use') && OCTANE_VALUES.has(name));
315
+ }
316
+ /** Whether a React value type query can name an actual Octane export. */
317
+ export function hasOctaneValue(name) {
318
+ return OCTANE_VALUES.has(name);
319
+ }
312
320
  /** The Octane name for `React.<name>` in a type position. */
313
- export function mapQualifiedType(name) {
321
+ export function mapQualifiedType(name, module, typeOf, typeArgumentCount) {
322
+ if (name === 'Touch' && (module !== 'react' || typeOf))
323
+ return null;
324
+ // OctaneElement only accepts props. The migration alias preserves an explicit element type.
325
+ if (name === 'ReactElement' && typeArgumentCount > 1)
326
+ return name;
314
327
  if (name in QUALIFIED_TYPE_PREFERENCES)
315
328
  return QUALIFIED_TYPE_PREFERENCES[name];
316
329
  if (OCTANE_TYPES.has(name))
@@ -111,6 +111,11 @@ type StaticSvgNode = {
111
111
  export declare function parseStaticSvg(source: string): {
112
112
  root: Record<string, string>;
113
113
  children: StaticSvgNode[];
114
+ title?: undefined;
115
+ } | {
116
+ root: Record<string, string>;
117
+ children: StaticSvgNode[];
118
+ title: string;
114
119
  } | null;
115
120
  export declare function parsePathSvg(source: string): {
116
121
  root: Record<string, string>;
package/dist/path-svg.js CHANGED
@@ -191,6 +191,7 @@ export function parseStaticSvg(source) {
191
191
  if (typeof source !== 'string')
192
192
  return null;
193
193
  let root = null;
194
+ let title;
194
195
  const children = [];
195
196
  const open = [];
196
197
  const definitions = new Map();
@@ -219,6 +220,20 @@ export function parseStaticSvg(source) {
219
220
  return null;
220
221
  open.push({ tag, children });
221
222
  }
223
+ else if (tag === 'title') {
224
+ if (parent?.tag !== 'svg' || children.length || title !== undefined || fields || selfClosing)
225
+ return null;
226
+ // Keep one literal text child. XML entities, markup, and line endings require loader rules.
227
+ const titleToken = /([^<&]+)<\/title>/uy;
228
+ titleToken.lastIndex = token.lastIndex;
229
+ const text = titleToken.exec(source);
230
+ if (!text ||
231
+ /\]\]>|[^\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/u.test(text[1]) ||
232
+ !text[1].trim())
233
+ return null;
234
+ title = text[1];
235
+ token.lastIndex = titleToken.lastIndex;
236
+ }
222
237
  else {
223
238
  if (!parent || !tag || !Object.prototype.hasOwnProperty.call(shapeAttributes, tag))
224
239
  return null;
@@ -284,13 +299,15 @@ export function parseStaticSvg(source) {
284
299
  new Set(references.map(({ id }) => id)).size === definitions.size &&
285
300
  references.every(({ id, target, rootRect }) => definitions.get(id) === target || (rootRect && definitions.get(id) === 'pattern')) &&
286
301
  space.test(source.slice(end))
287
- ? { root, children }
302
+ ? title === undefined
303
+ ? { root, children }
304
+ : { root, children, title }
288
305
  : null;
289
306
  }
290
307
  // Existing generated helpers expose this path-only result to their importers.
291
308
  export function parsePathSvg(source) {
292
309
  const svg = parseStaticSvg(source);
293
- return svg && svg.children.every((node) => node.tag === 'path')
310
+ return svg && svg.title === undefined && svg.children.every((node) => node.tag === 'path')
294
311
  ? { root: svg.root, paths: svg.children.map((node) => node.attributes) }
295
312
  : null;
296
313
  }