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: identifiers are not incorrectly scoped to state #1630

Merged
merged 17 commits into from
Nov 8, 2024

Conversation

liamdebeasi
Copy link
Contributor

@liamdebeasi liamdebeasi commented Nov 6, 2024

Description

https://builder-io.atlassian.net/browse/ENG-7338

Mitosis transforms identifiers that have the same name as state variables to have this. or state. prefixed where necessary. This causes issues with shadowed variables that are unrelated to state.

In the following example, the errors in foo have nothing to do with the errors defined in state.

const state = useStore({
  errors: {},
  foo(errors) {
    return errors;
  }
});

However, this is incorrectly prefixed with state. which causes runtime issues:

const state = useStore({
  errors: {},
  foo(state.errors) {
    return state.errors;
  }
});

This transformation is only needed when moving functions into state or when using useState. To fix this, I updated Mitosis to only transform state values that were set using useState or were function that got moved to state.

Make sure to follow the PR preparation steps in CONTRIBUTING.md before submitting your PR:

  • format the codebase: from the root, run yarn fmt:prettier.
  • update all snapshots (in core & CLI): from the root, run yarn test:update
  • add Changeset entry: from the root, run yarn g:changeset and follow the CLI instructions. Alternatively, use the Changeset Github Bot to create the file.

Copy link

changeset-bot bot commented Nov 6, 2024

🦋 Changeset detected

Latest commit: 6a0fc6b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@builder.io/mitosis Patch
@builder.io/mitosis-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

nx-cloud bot commented Nov 6, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 6a0fc6b. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 4 targets

Sent with 💌 from NxCloud.

@liamdebeasi liamdebeasi changed the title Eng 7338 fix: identifiers are not incorrectly scoped to state Nov 6, 2024
@liamdebeasi liamdebeasi marked this pull request as ready for review November 7, 2024 16:06
'@builder.io/mitosis': patch
---

identifiers are not incorrectly scoped to state
Copy link
Contributor

Choose a reason for hiding this comment

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

can we follow the changeset format here? what exactly got fixed, for which generators/parsers, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated in ed6b5f8

Let me know if you have other ideas for how to word this

@liamdebeasi liamdebeasi enabled auto-merge (squash) November 8, 2024 14:43
'@builder.io/mitosis': patch
---

shadowed variables in state methods are not scoped to state in all generators
Copy link
Contributor

Choose a reason for hiding this comment

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

[All] Fix: scope renaming of state methods to not include shadow variables
[Angular]: Update state.* -> this.* transform to new AST transform approach

@samijaber samijaber merged commit e9cfef0 into BuilderIO:main Nov 8, 2024
6 checks passed
@liamdebeasi liamdebeasi deleted the ENG-7338 branch November 8, 2024 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants