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

Panic on invalid code #9140

Open
marvinhagemeister opened this issue Jul 4, 2024 · 1 comment
Open

Panic on invalid code #9140

marvinhagemeister opened this issue Jul 4, 2024 · 1 comment
Assignees
Labels
Milestone

Comments

@marvinhagemeister
Copy link
Contributor

Describe the bug

SWC panics when it encounters this particular source that is invalid JS. The error can be reproduced in the SWC playground.

Originally reported at denoland/deno#24417

Input code

https://fake.com

interface Fake {
}

Config

No response

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.6.7&code=H4sIAAAAAAAAA8soKSkottLXT0vMTtVLzs%2Fl4srMK0ktSktMTlVwA4opVHPVAgDVU9KdJAAAAA%3D%3D&config=H4sIAAAAAAAAA1WQPQ7CMAyFd05ReWZAHRi4AxMnsIJbBTU%2Fsh2JCvXuJOn%2FEiXfe8%2BO%2Fbs0DXzEwKP55Wt%2BRGQh3t6ZyOgVv5mAjpHEsI0K11VVKZJyokqmWQBF7klLiKS9te0SgCEEoYw7HIQW5qy33XhsaYKLTCJnY7Gi74ctf%2B7I6KUL7I6FmNDoAWRkXQysr5DYlELgo3vMtutu4uTVuqpj0uBQrYFFni7rWVuDC%2B9U%2F7RssGxpHvwOu2mdcZsHrDzXZF3f9Ae8XWptjQEAAA%3D%3D

SWC Info output

No response

Expected behavior

SWC should not panic

Actual behavior

No response

Version

1.6.8-nightly-20240704.3

Additional context

No response

@kdy1 kdy1 self-assigned this Jul 4, 2024
@kdy1 kdy1 added this to the Planned milestone Jul 4, 2024
@CPunisher
Copy link
Contributor

CPunisher commented Jul 12, 2024

From the AST of the code:

"body": [
    {
      "type": "LabeledStatement",
      "span": {
        "start": 0,
        "end": 36,
        "ctxt": 0
      },
      "label": {
        "type": "Identifier",
        "span": {
          "start": 0,
          "end": 5,
          "ctxt": 0
        },
        "value": "https",
        "optional": false
      },
      "body": {
        "type": "TsInterfaceDeclaration",
        "span": {
          "start": 18,
          "end": 36,
          "ctxt": 0
        },

The TsInterfaceDeclaration within the LabeledStatement cannot be removed during StripType, thus it will be visited and trigger an unreachable panic (Code).

I attempted to change unreachable_visit_mut_type!() to noop_visit_mut_type!(), but it triggered the standard_only_visit_mut!() panic(Code) of the RegExp Visitor(maybe other visitors).

Perhaps there are two possible solutions:

  1. Patch StripType to remove every TsInterfaceDeclaration. This is how tsc do, and its compilation result is:
https: ;
  1. Do not remove TsInterfaceDeclaration and find a way to resolve the subsequent panic. This may be how oxc do(no panic), and its compilation result is:
https: interface Fake {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants