Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Parsing jsx text error #5

Closed
fanksy opened this issue Jun 23, 2024 · 7 comments
Closed

[Bug] Parsing jsx text error #5

fanksy opened this issue Jun 23, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@fanksy
Copy link

fanksy commented Jun 23, 2024

There is actually only one line break, but it is parsed as two line breaks

example:

import React from 'react';

function MyComponent() {
  return (
    <div>
      <p>Hello, this is JSX text!</p>
      <p>JSX allows us to write 
        HTML-like syntax in JavaScript.</p>
    </div>
  );
}

export default MyComponent;
Screenshot 2024-06-23 at 16 18 06
@caoccao
Copy link
Owner

caoccao commented Jun 23, 2024

Please double check your test code and leave a repo that can reproduce the issue.

@fanksy
Copy link
Author

fanksy commented Jun 23, 2024

@Test
    public void testAst() throws IOException, Swc4jCoreException {
        String script = "import React from 'react';\n" +
                "\n" +
                "function MyComponent() {\n" +
                "  return (\n" +
                "    <div>\n" +
                "      <p>Hello, this is JSX text!</p>\n" +
                "      <p>JSX allows us to write \n" +
                "        HTML-like syntax in JavaScript.</p>\n" +
                "    </div>\n" +
                "  );\n" +
                "}\n" +
                "\n" +
                "export default MyComponent;";
        Swc4j swc4j = new Swc4j();
        Swc4jTranspileOptions options = new Swc4jTranspileOptions()
                .setCaptureAst(true)
                .setMediaType(Swc4jMediaType.Jsx);
        Swc4jParseOutput parseOutput = swc4j.parse(script, options);
        assert  parseOutput != null;
    }

@fanksy
Copy link
Author

fanksy commented Jun 23, 2024

Please debug and check the jsx text node.

@caoccao
Copy link
Owner

caoccao commented Jun 26, 2024

It seems to be an SWC bug. Issue 9106 was filed.

@caoccao
Copy link
Owner

caoccao commented Jun 29, 2024

It's fixed in SWC. Please wait for the patch in the next couple of releases.

@caoccao
Copy link
Owner

caoccao commented Jul 13, 2024

The fix from SWC has been picked up. The new release will be published soon.

@caoccao caoccao self-assigned this Jul 14, 2024
@caoccao caoccao added the bug Something isn't working label Jul 14, 2024
@caoccao
Copy link
Owner

caoccao commented Jul 14, 2024

It's fixed in v0.10.0.

@caoccao caoccao closed this as completed Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants