Skip to content

[WIP] Unified attributes and bindings #380

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

Merged
merged 10 commits into from
Mar 17, 2017

Conversation

Rich-Harris
Copy link
Member

A realisation I've been gradually having: it makes sense to treat binding values (i.e. the foo in bind:value='foo' or bind:foo) the same way expressions are treated (i.e. {{foo}}). Doing so opens the door to a few things:

  • It makes it much easier to support <Widget :foo /> as shorthand for <Widget foo='{{foo}}'/>, as mentioned in Add spread for attributes #280 (comment)
  • We can more easily explore complex two-way bindings, like bind:value='options[key].value as discussed in this SO question (this is not a statement of intent at this stage, however)
  • The current system messily duplicates some of the logic in generator.contextualise
  • Using generator.contextualise will make sourcemap support much better

Technically this is a breaking change as it changes the AST format, but I think we can get away with it — I haven't heard of anyone using svelte.parse outside the context of svelte.compile. (I'll eat my words later if I have to.)

I've only done the first part so far — updating the parser and fixing all the tests broken by doing so. Next step is to refactor the binding code so that it uses generator.contextualise.

@Rich-Harris Rich-Harris merged commit ecf1413 into master Mar 17, 2017
@Rich-Harris Rich-Harris deleted the unified-attributes-and-bindings branch March 17, 2017 18:24
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.

1 participant