MCPcopy Create free account
hub / github.com/ecomfe/tempad-dev / stringifyJSXComponent

Function stringifyJSXComponent

packages/extension/utils/component.ts:364–398  ·  view source on GitHub ↗
(
  component: DevComponent,
  indentLevel = 0,
  isInline?: (tag: string) => boolean
)

Source from the content-addressed store, hash-verified

362}
363
364function stringifyJSXComponent(
365 component: DevComponent,
366 indentLevel = 0,
367 isInline?: (tag: string) => boolean
368) {
369 return stringifyBaseComponent(
370 component,
371 (key, value) => {
372 if (EVENT_HANDLER_RE.test(key)) {
373 const callback = typeof value === 'string' ? value : '() => {}'
374 return `${key}="{${callback.trim()}}"`
375 }
376
377 if (typeof value === 'string') {
378 return `${key}="${escapeHTML(value).trim()}"`
379 }
380
381 if (typeof value === 'boolean') {
382 return value ? key : `${key}={false}`
383 }
384
385 if (typeof value === 'object' && value != null) {
386 const pruned = prune(value)
387 if (pruned == null) {
388 return ''
389 }
390 return `${key}={${stringify(pruned)}}`
391 }
392
393 return `${key}={${stringify(value)}}`
394 },
395 indentLevel,
396 isInline
397 )
398}
399
400type SerializeOptions = {
401 lang?: SupportedLang

Callers 1

stringifyComponentFunction · 0.85

Calls 4

escapeHTMLFunction · 0.90
pruneFunction · 0.90
stringifyFunction · 0.90
stringifyBaseComponentFunction · 0.85

Tested by

no test coverage detected