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

Allow slot names to be numbers #5481

Merged
merged 1 commit into from Apr 25, 2017
Merged

Conversation

posva
Copy link
Member

@posva posva commented Apr 21, 2017

Closes #5480

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

@posva
Copy link
Member Author

posva commented Apr 21, 2017

So flow is complaining about the name value being undefined inside of the if but I don't see how that's possible...
Edit: tried to search for an existing issue in flow but no luck

@yyx990803
Copy link
Member

Well let's just make it name: any

@posva
Copy link
Member Author

posva commented Apr 22, 2017

@yyx990803 That won't change the error, I should have posted it to make it clearer:

src/core/instance/render-helpers/resolve-slots.js:22
 22:       const slot = (slots[name] || (slots[name] = []))
                         ^^^^^^^^^^^ access of computed property/element. Computed property cannot be accessed with
 22:       const slot = (slots[name] || (slots[name] = []))
                               ^^^^ possibly uninitialized variable

@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Apr 24, 2017

I guess this is caused by flow's wrong flow analysis. name is declared in outer block, not in the name = child.data.slot check expression. In this case, flow might be confused about whether name will be changed.

Changing to this will work

    if ((child.context === context || child.functionalContext === context) &&
        child.data && child.data.slot != null) {
      const name = child.data.slot
}

@yyx990803 yyx990803 merged commit 380e988 into vuejs:dev Apr 25, 2017
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.

v-for with named slot (via v-for index) skips first item for 0-based indices
4 participants