{resultLinkTitle}
{resultLinkTitle} {resultLinkTitle}

How to use swc to make ast restore be code segment

24 Views Asked by At

My code segment is this:

<>
    <Divider orientation="left">{resultLinkTitle}</Divider>
    <Intension />
    <Form form={form} name="auditForm" ref={auditFormRef}>
      <Form.Item label="files">
        <Button type="link" onClick={() => handleDownLoadFile(aduitInfo?.fileUrl)}>
          download
        </Button>
      </Form.Item>
    </Form>
  </>

then I use swc.parse to get ast. But I cannot get the original code with swc.printSync. It returns an error unknown variant 'JSXElement', expected 'Module' or 'Script'. How can I solve this?

How do I get the original code with swc.

1

There are 1 best solutions below

0
Shemea Xu On

I know what hapend. It's not a data struct like swc.Program. I should create it like this:

{
  type: 'Module',
  span: { start: 0, end: 100, ctxt:0 },
  body: [...]
}