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: 事件绑定JSX函数时,函数解析报错 #441

Merged
merged 4 commits into from
May 17, 2024

Conversation

gene9831
Copy link
Collaborator

@gene9831 gene9831 commented Apr 23, 2024

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

JS面板中,如果JS函数包含了JSX语法,绑定事件或者保存页面时可能会发生错误
image

原因:处理JS面板的函数过程中,会将函数转换成匿名函数,而babel jsx插件无法正确解析带JSX语法的匿名函数
解决方法:使用括号将匿名函数括起来,可以让babel jsx插件正常转换,转换完成后再去掉最外层的括号
解决方法:在绑定函数时,保留函数名,不转换成匿名函数

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@gene9831 gene9831 added bug Something isn't working ready_for_review This PR requires more reviews labels Apr 23, 2024
Copy link
Collaborator

@hexqi hexqi left a comment

Choose a reason for hiding this comment

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

这个问题有对应的issue吗,如果有,可以在描述里面加上 #issue编号 自动关联上

@gene9831 gene9831 changed the title fix: 转换JSX语法时,如果是JS匿名函数会导致转换失败 fix: 事件绑定JSX函数时,函数解析报错 May 14, 2024
@chilingling chilingling merged commit ffd0280 into opentiny:develop May 17, 2024
1 check passed
@gene9831 gene9831 deleted the fix/anonymous-function-jsx branch May 27, 2024 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready_for_review This PR requires more reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants