@octanejs/codemod 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
  }