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 check for uninitialized condition in compound if block with static condition, needs_update and outros #4841

Merged

Conversation

dimfeld
Copy link
Contributor

@dimfeld dimfeld commented May 15, 2020

Fixes #4840

With a static if condition and both needs_update and outro support enabled on the if block, the check for condition (usually rendered as show_if in the generated code) is checked against -1 to see if the static function should be run, but the variable starts out uninitialized and so it doesn't get checked. This PR changes it to check for ${condition} == null instead, the same check used elsewhere in the file.

Here's an annotated example from the original REPL:

<script>
export let x;
function test() { return true; }
</script>

{#if test()} <!-- Static condition -->
    first
{:else if x} <!-- Turns on needs_update for the block -->
    second
{:else}
    <Component2 size=16 /> <!-- Include a component to enable outro handling -->
{/if}

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR relates to an outstanding issue, so please reference it in your PR, or create an explanatory one for discussion. In many cases features are absent for a reason.
  • This message body should clearly illustrate what problems it solves. If there are related issues, remember to reference them.
  • Ideally, include a test that fails without this PR but passes with it. PRs will only be merged once they pass CI. (Remember to npm run lint!)

Tests

  • Run the tests tests with npm test or yarn test)

@dimfeld dimfeld changed the title Fix check for uninitialized condition Fix check for uninitialized condition in compound if block with static condition, needs_update and outros May 15, 2020
@Conduitry Conduitry merged commit 81ade59 into sveltejs:master May 17, 2020
taylorzane pushed a commit to taylorzane/svelte that referenced this pull request Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants