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

FIX bundler parsing error should not panic #11

Merged
merged 4 commits into from
Apr 8, 2024
Merged

Conversation

Charlie-XIAO
Copy link
Contributor

@Charlie-XIAO Charlie-XIAO commented Apr 6, 2024

Fixes #9.

This PR attempts to emit the parsing error in a formatted way instead of panicking (which is clearly wrong). The rendered error message of the reproducer in #9 should now look like this (no color, but formatted):

image

I've also added a corresponding widget to test-widgets.

/cc @Xinyu-Li-123 Can you give a review and confirm if this works?

@Charlie-XIAO Charlie-XIAO added the bug Something isn't working label Apr 7, 2024
@Xinyu-Li-123
Copy link
Contributor

I have tested your changes locally. It works for other bugs, but Deskulpt still crashes if there are duplicated export default statements. Below is a minimal example to reproduce this crash

const React = window.__DESKULPT__.defaultDeps.React;
const options = {
  year: "numeric",
  month: "short",
  day: "numeric",
  hour: "numeric",
  minute: "numeric",
};


function Clock() {
  const [time, setTime] = React.useState(new Date().toLocaleString("en", options));

  function updateTime() {
    setTime(new Date().toLocaleTimeString("en", options));
  }
  setInterval(updateTime, 10000);

  return <h3>{time}</h3>;
}

const FOO = 1;
export default FOO;

export default {
  render: () => <Clock />,
};

The error message is as follows

thread 'main' panicked at C:\Users\Eiger\.cargo\registry\src\index.crates.io-6f17d22bba15001f\swc_bundler-0.225.17\src\inline.rs:49:13:
internal error: entered unreachable code: Multiple identifiers equivalent up to span hygiene found: default#8        
First = default#5
Second = default#5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[0408/132929.720:ERROR:window_impl.cc(121)] Failed to unregister class Chrome_WidgetWin_0. Error = 0

@Charlie-XIAO
Copy link
Contributor Author

Charlie-XIAO commented Apr 8, 2024

This is not the same issue: this one is an internal SWC error that cannot be recovered :(

@Xinyu-Li-123
Copy link
Contributor

So should we merge this pr but open a new issue about this bug?

@Charlie-XIAO
Copy link
Contributor Author

Charlie-XIAO commented Apr 8, 2024

I opened swc-project/swc#8824 upstream. Hopefully it will get fixed there, and a simple update of dependencies will fix the issue. AFAIK this PR should not be blocked by that.

Copy link
Contributor

@Xinyu-Li-123 Xinyu-Li-123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR fixes the bug that Deskulpt will crash once there is a syntax error in widget source code.

@Xinyu-Li-123 Xinyu-Li-123 enabled auto-merge (squash) April 8, 2024 07:46
@Xinyu-Li-123 Xinyu-Li-123 merged commit 8df31e8 into main Apr 8, 2024
4 checks passed
@Xinyu-Li-123 Xinyu-Li-123 deleted the bundle-syntax-err branch April 8, 2024 07:58
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

Successfully merging this pull request may close these issues.

BUG Deskulpt can't handle syntax error in widget js code
2 participants