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

Syntax changes #1318

Closed
Rich-Harris opened this issue Apr 5, 2018 · 125 comments
Closed

Syntax changes #1318

Rich-Harris opened this issue Apr 5, 2018 · 125 comments

Comments

@Rich-Harris
Copy link
Member

Rich-Harris commented Apr 5, 2018

Update 12 April

Most of these decisions are fairly settled at this point — you can see a summary here.

Original issue follows:


I've referred to this obliquely in other issues, Gitter, etc, but haven't quite got to the point of starting a proper discussion about it.

Essentially, for version 2 I'd like to move away from the Mustache-esque template syntax to something a bit lighter and more modern, which boils down to using one curly brace instead of two:

<h1 class={myClass}>Hello {name}!</h1>

The success of JSX has proved that the second curly is unnecessary. Moreover, a lot of people — particularly those who have been exposed to React — have a visceral negative reaction to double curlies, many of them assuming that it brings with it all the limitations of crusty old languages like Mustache and Handlebars, where you can't use arbitrary JavaScript in expressions.

We would also put an end to this sort of thing — component properties being typecast — at the same time. (See #657).

Quoted attributes

At present, Svelte allows you to quote attributes and properties for the sake of your syntax highlighter:

<Widget x={{y < z ? }}>this generally breaks highlighting</Widget>
<Widget x="{{y < z ? }}">this generally breaks highlighting</Widget>

I'd suggest that we keep that behaviour, so as not to force people to adopt additional tooling (which doesn't yet exist anyway). The same goes for directive arguments — these would be unchanged.

Control flow

It's less clear what to do about if/else/elseif, each, and await/then/catch. We could of course do this...

{#if foo}
  <p>foo!</p>
{else}
  <p>not foo!</p>
{/if}

...though part of me feels like we're just continuing to accept the premise of Handlebars, and that there's a more natural approach waiting to be discovered. Just for the sake of argument:

#if (foo) {
  <p>foo!</p>
} else if (bar) {
  <p>bar!</p>
} else {
  <p>neither foo nor bar!</p>
}

<ul>
  #each (cats as cat) {
    <li><a target='_blank' href={cat.video}>{cat.name}</a></li>
  }
</ul>

#await (promise) {
  <p>wait for it...</p>
} then (answer) {
  <p>the answer is {answer}!</p>
} catch (error) {
  <p>well that's odd</p>
}

Maybe that makes you want to barf, I don't know. But I'd be very interested to hear everyone's ideas.

Keyed each blocks

I'm in favour of replacing @name with by name, as discussed in #703 — it has some clear advantages.

Triples

Triples could arguably be unchanged — if anything, the increased distinction between {text} and {{{html}}} is a good thing. Or we could go in a totally different direction like <{html}>. Eager to hear thoughts.

Static tags

#364 — briefly discussed, but never acted upon: the idea of adding syntax for declaring tags static, as a way of saying to the compiler 'this will never change after the initial render, don't worry about generating update code'. Would be nice if whatever choices we make preserve that possibility.

Escaping

If you needed a literal { character in your markup, you could always do {'{'}. (This is how it's done in React.) Or you could do &#123;, which is pleasingly easy to remember. Does there need to be some method of escaping beyond that?

Migrating

All this stuff should come with an simple, completely automated way to upgrade an existing template. There could be a CLI tool, and the REPL would detect old templates and show an 'upgrade' button.


Obviously we shouldn't rush into anything. But changes like these are best made earlier on in a project's lifecycle, so I'm eager to hear what people think so that we can start making some progress. Thanks!

@ansarizafar
Copy link

All Ideas presented here are very reasonable. Particularly I like Static Tags and control flow syntax changes the most.

@PaulMaly
Copy link
Contributor

PaulMaly commented Apr 5, 2018

Actually, I feel no pain with current, mustache-like, syntax. Maybe because I work with it in Ractive and worked even before Ractive.

But I always thought that if Svelte will change its syntax to something new, it will more look like ES6 Template Literals:

<h1 class="${myClass}">Hello {name}!</h1>

But in this case, we need to decide which syntax will be for blocks:

${if foo}
  <p>foo!</p>
{else}
  <p>not foo!</p>
{/if}

If there are any serious reasons to not use this standard, well, then it's completely up-to-you.

Btw, I also personally like Dust-syntax: https://github.com/linkedin/dustjs/wiki/Dust-Tutorial

@dxlbnl
Copy link
Contributor

dxlbnl commented Apr 5, 2018

I like it, single/double braces sometimes trips when switching between svelte and react.
I'm unsure about what to think of the control flow syntax, but I think I like the style closest to js the most.
using curly braces to denote blocks feels most natural. But maybe not in html style templating.

@jacwright
Copy link
Contributor

the limitations of crusty old languages like Mustache and Handlebars, where you can't use arbitrary JavaScript in expressions

Currently you can't use arbitrary JavaScript expressions everywhere you would like to. We could simplify the compiler code by having one expression parsing path instead of each directive and binding using it's own. For example, transitions require an object literal when it could be desirable to use a member, setting the options on data. There are issues to solve, such as methods being pulled from helpers in bindings but pulled from the public component API in events. However, this is a digression from the topic of this issue and should be discussed in more depth elsewhere if it has any merit. My apologies.

For the rest:

  • 👍 for keeping quoted attributes right now
  • 👍 for {#if} and 👎 for #if { which I find very hard to read/follow in HTML, esp with the other parts: } else { and }
  • 👍 for triple curlies for unescaped HTML
  • 👍 for using "by name" in keyed blocks
  • FWIW I'm not sure static tags should use single brackets (<div>[Something]</div>) because brackets are not uncommon in HTML designs. Even double brackets are used to decorate navigation. I've never done this or encouraged it, but I know of websites that do. Using CSS ::before and ::after to add [ ] could be a workaround though, so on second thought maybe that will be ok for that use-case. Still, it is more commonly used than curly braces, something to consider.

@TehShrike
Copy link
Member

Exciting stuff! 😃 I'm positive on these changes, and excited about decreasing the curlies.

The #if (foo) { syntax seems fine to me, but no strong preference for it versus the current syntax. I'm not currently capable of imagining something superior and new, but I'll keep my eyes open.

Is there any reason not to use backslashes to escape curlies? \{

Maybe going down the route of any escape characters at all would be confusing, and people would start expecting things like \n to work.

@tomcon
Copy link

tomcon commented Apr 5, 2018

  1. Curly: Go from two down to one throughout Svelte. Easier to understand and clear for v2 imo
  2. Keyed each blocks: prefer "key name" rather than "by name". Shows purpose clearly
  3. Triples: as is
  4. Static tags: @TehShrike suggestion at component level seems good,
    otherwise [[wontChange]] or maybe even simply enclosing in backticks {`wontChange`}?
    looking forward to it!

@Rich-Harris
Copy link
Member Author

I always thought that if Svelte will change its syntax to something new, it will more look like ES6 Template Literals:

I wondered about that. But as you mention, the control flow makes it tricky, because it's not really a template literal — it's a DSL. I thought perhaps it's better to have something that's explicitly different, than something a bit 'uncanny valley'.

👍 for {#if} and 👎 for #if {

Am by no means wedded to that second idea — I came up with it more or less as I was typing it. Just want us to have a think about whether there is a better solution than {#if ...}, and if there isn't then that's fine too.

Is there any reason not to use backslashes to escape curlies? \{

I had the same question earlier and googled 'react escape curly braces' and landed here: facebook/react#1545. Feels like a slippery slope.

Re static tags, I'm not suggesting that they should be part of these initial changes, just that we don't prevent ourselves from doing it in future. Static-ifying stuff at a component level could be done, but it doesn't address this sort of thing:

{{#each dynamicList as item}}
  <p>[[item.name]]</p>
{{/each}}

Tag-level and component-level aren't mutually exclusive though, we could do them independently.

@thgh
Copy link
Contributor

thgh commented Apr 5, 2018

Things that I miss most from Vue:

<!-- Bind expression to attribute with `:` -->
<h1 class="some-static-class">Hello!</h1>
<h1 :class="someClassExpression">Hello!</h1>

<!-- Bind event handler with `@` and pass event as first param. -->
<h1 @click="greet">Hello!</h1>

<!-- Event handler options -->
<button @click.prevent="greet">Hello!</button>
<:Window @keydown.esc="close"></:Window>

What bothers me most from Svelte:

<!-- I want to bind the value of this custom input just like I would bind to normal input -->
<input bind:value="query" /> <!-- works -->
<search-input bind:value="query" /> <!-- doesn't work :/ -->

Proposal for double binding:

<search-input ::value="query" />

For templating, I don't mind the handlebars. It's familiar for Vue and Angular users. I have never regretted keeping logic in my templates to a minimum. So I don't agree with the "visceral negative reaction" argument.

@RyanZim
Copy link

RyanZim commented Apr 5, 2018

IDK about doubles vs. singles, but #if (foo) { looks horrible to me. Triples are fine as they are IMO.

@PaulMaly
Copy link
Contributor

PaulMaly commented Apr 5, 2018

@Rich-Harris I've an idea, why not use a unified scheme for all things:

{:sign[:key][:expression]}

For example:

<h1 class="{=myClass}">Hello {=name}!</h1>

Control flow

{#if foo}
  <p>foo!</p>
{:else}
  <p>not foo!</p>
{/if}

<ul>
  {#each cats as cat}
    <li><a href="{=cat.video}">{=cat.name}</a></li>
  {/each}
</ul>

{#await promise}
  <p>wait for it...</p>
{:then answer}
  <p>the answer is {answer}!</p>
{:catch error}
  <p>well that's odd</p>
{/await}

Keyed each blocks

<ul>
  {#each cats as cat, key}
    <li><a target='_blank' href="{=cat.video}">{=cat.name}</a></li>
  {/each}
</ul>

Triples

<div>{&html}</div>

Static tags

<div>{~text}</div>

Escaping
Seems, using obligatory signs parser able to ignore brackets without appropriate sign after that.

Possible signs:
{= } - escaped interpolation
{& } - unescaped interpolation
{~ } - static interpolation

{# } - start of block
{: } - sub-block
{/ } - end of block

Most likely, the signs have to be others, it's just an example. The main ideas - use single scheme with the equal parsing rules:

  1. use single brackets
  2. start sign is signaled about what will be it's parsed
  3. following expression depends on sign

As I could imagine, the unified scheme should simplify parsing. Correct me if I'm wrong.

p/s Sorry for verboseness, you said that you're very interested to hear everyone's ideas.

@burningTyger
Copy link
Contributor

single curlies are fine with me. As for the blocks I'd prefer {#if ... style. Yet I like vue's v-if= attribute style a bit better. It's more concise and you don't actually need another set of closing directives.

@Conduitry
Copy link
Member

I like the single curlies for interpolation. Using them for {#if} etc. also seems fine to me. The other #if { syntax does indeed make me barf a little for some reason. I don't have strong opinions about triple tags, those can stay at three braces probably.

For static tags, iirc Angular 1.something introduced one-time bindings, where the value inside the {{ }}s would begin with a colon. So {{:foo}} would cease updating in the document once foo had a non-undefined value. I like this a bit better than square brackets, which it seems will make escaping a bit more of a hassle. (I don't tend to use brackets or braces too much in regular old html, but I probably use square brackets more.)

As for escaping: For some reason I wasn't thinking about the &#123; possibility. I think that works well enough, and doesn't produce the additional unnecessary code that {{'{'}} does. I think just mentioning that in the docs would suffice.

@jacwright
Copy link
Contributor

I've used if and each attributes in frameworks. It simplifies the syntax, but I've really enjoyed Svelte's blocks not being element-bound. Plenty of times I've had to add a <span> tag to employ an if, but with Svelte I don't need to.

I like @PaulMaly's idea, but I would like it if the "default" sign was = to simplify. Anything that isn't an escaped interpolation would require a sign. And you could use = if you wanted to be explicit.

@Conduitry
Copy link
Member

I just gave @PaulMaly's suggestions a proper re-read, and they are interesting. I like the succinctness but I'm also concerned about this resulting in punctuation salad. (Insert Perl joke here.) Perhaps some middle ground - which I realize is unhelpfully vague.

@PaulMaly
Copy link
Contributor

PaulMaly commented Apr 5, 2018

@jacwright @Conduitry Thanks,

I would like it if the "default" sign was = to simplify. Anything that isn't an escaped interpolation would require a sign. And you could use = if you wanted to be explicit.

Agree. I just tried to show the main idea. But, if obligatory using of signs would help with a literal { characters without any workarounds I think it reasonable price too.

I like the succinctness but I'm also concerned about this resulting in punctuation salad. (Insert Perl joke here.) Perhaps some middle ground - which I realize is unhelpfully vague.

Yep, it's just a number ideas but seems we already have some of those things like {#if ...} and {/if}. So maybe it's just some kind of unification.

@trbrc
Copy link
Contributor

trbrc commented Apr 5, 2018

I applaud the effort to simplify things for 2.0! The current syntax feels sprawling and ad hoc.

The general approach that @PaulMaly suggested looks like a good idea to me. You can remember a simple rule like "everything inside curlies is Svelte specific stuff", and then look up details as needed as you go.

The specifics are of course infinitely bikesheddable. To reduce punctuation salad, maybe common interpolation could simply be {myVar}, and special cases could be marked with readable words like {unescape myVar} and {static myVar}. It is easier to google "svelte js unescape" than "svelte js {&" or "svelte js {{{".

I think blocks could also be simplified to just use reserved words, like {if condition1} <A /> {elseif condition2} <B /> {endif} or similar. If additional punctuation is needed for syntactic disambiguation or clarity, it might be a good idea to harmonize it with directives and special components too, which are currently marked with colon. So maybe {:if condition}, {:static myVar}, etc.

On the general topic of simplifying syntax in a breaking way, I would like to recall #878 and #1069. Remove the poorly motivated special syntax for declaring dependencies of computed properties, so the <script> tag just uses standard, valid Javascript. It is an unnecessary gotcha that you can't use higher order functions or simple references in this part of the component.

@shancarter
Copy link

+1 for new control flow #if {...

+1 for <{html}>

@arxpoetica
Copy link
Member

arxpoetica commented Apr 6, 2018

Oh man...

Please, please, PLEASE keep the normal quotation inline as you mention above regarding tooling: <foo bar="{baz}"> etc. It really drives me batty when our syntax actually does start to resemble something too far afield from native HTML.

Can we also bikeshed on stuff like <:Window/> tags, etc? That little colon after an opening brace doesn't parse well with many current tooling systems. I know you like it's easily identifiable difference from "normal" HTML for good easy to distinguish reasons. But why not just capitalize and call these components reserved?

<Window/>

The parser can throw an error if one uses a reserved component namespace.

I too like @PaulMaly's notation as well as the recommendation elsewhere to allow {=foo} and {foo} as the same.

@arxpoetica
Copy link
Member

Oh, also, I agree:

👍 for {#if} and 👎 for #if {

@ansarizafar
Copy link

ansarizafar commented Apr 6, 2018

I think blocks could also be simplified to just use reserved words, like {if condition1} {elseif condition2} {endif} or similar.

To reduce punctuation salad, maybe common interpolation could simply be {myVar}, and special cases could be marked with readable words like {unescape myVar} and {static myVar}.

I like these ideas. We can also consider this #1322 for V2.

@subpx
Copy link

subpx commented Apr 6, 2018

What happens when a new framework becomes really popular and starts using double curlies?

@PaulMaly
Copy link
Contributor

PaulMaly commented Apr 6, 2018

Can we also bikeshed on stuff like <:Window/> tags, etc? That little colon after an opening brace doesn't parse well with many current tooling systems. I know you like it's easily identifiable difference from "normal" HTML for good easy to distinguish reasons. But why not just capitalize and call these components reserved?

👍+1

Btw, we already have one reserved tag: <slot>. It looks like very similar - special, reserved tag.

@stalkerg
Copy link
Contributor

stalkerg commented Apr 6, 2018

For my opinion Mustache syntax, it's ok and makes changes this only by taste reasons it's a bad idea.
We only begun made collections of components, I don't want to think about porting all this.
If we talk about syntax I like more http://www.makotemplates.org/ way or maybe ES6 template strings syntax. %if expression: and %endif is the best 👍

@opus131
Copy link

opus131 commented Apr 6, 2018

Would it be possible to make the templating engine pluggable, so that the community could write e.g. a svelte-jsx or svelte-lithtml adapter?

@stalkerg
Copy link
Contributor

stalkerg commented Apr 6, 2018

Would it be possible to make the templating engine pluggable, so that the community could write e.g. a svelte-jsx or svelte-lithtml adapter?

If I remember right too many things locked on the internal handwritten parser. For real good approach, we can use something like Flex/Bison but I don't know about JS in this case.

@hperrin
Copy link
Contributor

hperrin commented Apr 6, 2018

Since we already have special "HTML" tags like <:Window>, would it be reasonable to make all control structures into special tags?

<:if myVar>
  <span>Something</span>
<:else />
  <span>Something else</span>
</:if>
<ul>
  <:each myArray as el>
    <li>{el}</li>
  </:each>
</ul>

That makes a clear distinction between things that control the DOM structure (<:thing>) and things that output text ({thing}).

It also has the benefit of being quite readable in editors:
screen shot 2018-04-06 at 9 06 16 am

@Rich-Harris
Copy link
Member Author

Oh my, I wasn't expecting so much feedback! Thanks everyone, this is fantastic.

@hperrin's idea is pretty cool. You get auto-completion as a nice bonus! The self-closing <:else /> is a bit awkward though, and the same would be true for <:await...> — I wonder if it should be like this instead:

<:if myArray.length>
  <ul>
    <:each myArray as el, i>
      <li>{el}</li>
    </:each>
  </ul>

  <:else>
    Nothing in the array
  </:else>
</:if>

<:await promise>
  <p>loading...</p>

  <:then value>
    <p>the value is {value}</p>
  </:then>

  <:catch error>
    <p>oops! {error.message}</p>
  </:catch>
</:await>

Maybe it's too weird having else (and elseif) inside if, and maybe it would interact badly with certain tooling (@arxpoetica can you be more specific on that point?). Curious to hear what people think.

@arxpoetica

It really drives me batty when our syntax actually does start to resemble something too far afield from native HTML

I don't totally follow this point — <input type=range min=0 max=100 > is valid HTML — the quotes are entirely optional for attributes without spaces as of HTML5 😀

@thgh the Svelte equivalent for those Vue idioms is this — I'm not sure I understand what the drawbacks are? (These are more flexible and explicit IMHO, and barely any extra characters.)

<h1 class="some-static-class">Hello!</h1>
<h1 class={{someClassExpression}}>Hello!</h1>
<h1 on:click="greet(event)">Hello!</h1>

For the event modifier stuff see #1088. Bindings on custom elements is something we should support, I don't think we currently have an issue for it though.

@PaulMaly that's a really strong proposal, thanks. Agree with the other comments the {= is probably unnecessary and could just be {. @trbrc makes a great point about searchability.

@opus131

Would it be possible to make the templating engine pluggable, so that the community could write e.g. a svelte-jsx or svelte-lithtml adapter?

In theory yes. The compiler really only needs the source string and an AST. If we properly formalised and documented the Svelte AST format, then we could allow anyone to build their own parser. I think the costs of doing so are more human than technical though — having a single canonical template language is better from the point of view of documentation, tutorials, Stack Overflow, shareable components, etc.


So, consolidating everyone's input so far, my read is that the current front-runner is something like this...

  • {expression} — replaces {{expression}}
  • {#if expression} — replaces {{#if expression}}
  • {:else} — replaces {{else}}
  • {/if} — replaces {{/if}}

...with the following possible additions:

  • {static expression} (though this doesn't allow static if/each/await expressions)
  • {unescape expression} — replaces {{{expression}}}. Or maybe {html expression}?

But a last minute challenger has entered the race:

<:if foo>
  <p>foo!</p>
</:if>

@hperrin
Copy link
Contributor

hperrin commented Apr 6, 2018

Regarding static tags, we could use another special tag:

<:Static>
  Hello, {user.name}. Even if you update your name, I'll still call you by the old one!
</:Static>

Also, -1 for <{html}>. (It will definitely confuse editors.)
+1 for keeping {{{html}}}

@jacwright
Copy link
Contributor

Regarding @hperrin's suggestion, the simple case works for HTML parsing in browsers. Will more complex expressions hurt that at all?

<:if myHelper() !== some.value && foo.bar.length>
  Foo is true!
<:else />
  Foo is false. :(
</:if>

I like it. But I'm leaning to {#if}, possibly because it stands apart more, possibly because I'm more used to that syntax in Svelte.

@RyanZim
Copy link

RyanZim commented Apr 6, 2018

I'm personally not a huge fan of <:if..., for two reasons:

  1. I forsee this highlighting very poorly in some editors.
  2. It doesn't stand out from the rest of the template; it's a conditional, not an element.

@Rich-Harris
Copy link
Member Author

@arxpoetica

What's the shorthand for one-way vs. two-way binding? Or is that still a thing?

Two-way is unchanged — <input bind:value> or <input bind:value='name'>. One way has changed:

<!-- before -->
<Foo bar={{bar}} />
<Foo :bar /> <!-- shorthand equivalent -->

<!-- after -->
<Foo bar={bar} />
<Foo {bar} /> <!-- shorthand equivalent -->

@PaulMaly as soon as humanly possible. Going to do as much work on it this weekend as time allows.

@jamesbirtles
Copy link
Contributor

@Rich-Harris it needs a bit of a cleanup (and decoupling from vscode). I can shove it up on GitHub once I have done this

@arxpoetica
Copy link
Member

What about:

<input bind:value={name}>
<input bind:{value}>

For some consistency?

@Rich-Harris
Copy link
Member Author

The format for directives is type:name=value or type:name where no value is necessary (i.e. refs, or shorthand bindings). In the case of bindings, it's something like

bind:expression1=expression2

Conceptually, this is like doing a = b in a reactive language. If it were this instead...

bind:expression1={expression2}

...then it's sort of like saying a = (whateverTheValueOfBIsRightNow) — let's say a = 42 — we're binding expression1 to the evaluation of expression2, rather than expression2 itself. Put another way, as I'm visualising data flowing through my components, I find it helpful to think of {...} as read-only windows onto reactively evaluated expressions, because in general expressions are read-only.

Probably not articulating myself very well here, but tl;dr is I think bind:value=name and bind:value are more logical.

@jacwright
Copy link
Contributor

After looking at the syntax as it stands now, I like it. I think the shorthand example should be updated to the example you provided a few comments up this page @Rich-Harris. It makes it more clear.

The one piece that feels confusing to me is they keyed array syntax.
{#each cats as cat key cat.name}
Perhaps with good syntax highlighting it will be better, but right now there are too many plain words that it is harder to understand. I'm not sure the solution. Perhaps one of these?

{#each cats as cat, key={cat.name}}
{#each cats as cat, @cat.name}

@Rich-Harris
Copy link
Member Author

@jacwright I was waiting to see if anyone would bring that up... I kind of had the same feeling about key. Adding punctuation back is definitely a possibility. The comma might be excessive if you also had an index:

{#each cats as cat, i, key={cat.name}}

I'll throw a few more options on the table:

{#each cats as cat, i @cat.name}
{#each cats as cat, i | cat.name}
{#each cats as cat, i {cat.name}}
{#each cats as (cat, i) {cat.name}}
{#each cats as cat, i (cat.name)}
{#each cats as cat, i (key = cat.name)}

I think I prefer options that don't involve the }} curlies butting up against each other. None of them leap out as the 'obviously correct' answer ahead of the others, as far as I can see, though some are easier to type than others. Thoughts welcome!

@arxpoetica
Copy link
Member

tl;dr is I think bind:value=name and bind:value are more logical

Makes sense

@TehShrike
Copy link
Member

I like {#each cats as cat, i, key={cat.name}} because I like to think of cat.name as an expression, but "no touching curlies" does seem like a good priority.

Beyond that, I lean towards {#each cats as cat, i @cat.name}

@arxpoetica
Copy link
Member

As long as I can do index as well as i.

Multiple cursor selection in various IDEs (cmd + d) can be really cumbersome when trying to select single letters because the letter I will be all over, whereas index is far more specific and each cursor selection will jump to the right thing.

@hperrin
Copy link
Contributor

hperrin commented Apr 14, 2018

{For each cat in cats where cat is identified by name}
  <span>{cat's name}</span>
{.}

Personally, I've always been fond of the syntax of the English language.

@hperrin
Copy link
Contributor

hperrin commented Apr 14, 2018

My vote is for:

{#each cats as cat, i (cat.name)}

The parens still imply that it's an expression, and no double curlies. And, it could support a space in that expression, unlike @cat.name.

Imagine {#each cats as cat, i (cat.items[i % 2])}
vs {#each cats as cat, i @cat.items[i % 2]}.

@Rich-Harris
Copy link
Member Author

Think I agree with @hperrin. I'll start implementing {#each list as item, index (keyExpression)}. The only place it might look a bit weird is if you wanted to use the item as the key expression —

{#each words as word (word)}
  <p>{word}</p>
{/each}

— but I suspect that'd be true of whatever we chose.

Rich-Harris added a commit that referenced this issue Apr 14, 2018
@Rich-Harris
Copy link
Member Author

Alright, this is implemented in 1.61. You can opt in with parser: 'v2', and use svelte-upgrade to update existing components. Thanks everyone!

@andreujuanc
Copy link

Personally I find odd the use of {:else}

I think it can be a source of bugs for developers.

{else} can't be because of new bindings.
{#else} gonna look weird. Buy I would prefer this one since pound is already use for flow control.

@PaulMaly
Copy link
Contributor

@andreujuanc Why do you think it’ll be a source of bugs? What difference between this syntax change and any other?

@antonheryanto
Copy link

i think its should be candidate for dev mode to catch possible user mistake

@andreujuanc
Copy link

I think it's a change, and people are used to the prev version. I can be wrong, but muscle memory sometimes is hard to beat.

Another point against it, it's that the character is relatively smaller and less visible than pound, so eyeballing syntax might be tricky.
but hey I again. I can be wrong.

I do understand the use of it. I get the benefits. But something tells me that it's odd.

On the other hand for example I find AMAZING and well thought all the other changes.

@PaulMaly
Copy link
Contributor

I just think that these problems are common for any syntax changes. Not just for this one.

@constgen
Copy link

I leave this here for an inspiration Marko & NodeJS: STREAMING, ASYNC AND UI COMPONENTS! OH MY!

@PaulMaly
Copy link
Contributor

@constgen Basically, nothing new. I use all these things even with Ractive. One more bicycle.

@constgen
Copy link

I like declarative conditionals, loops, asyncs, etc.

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

No branches or pull requests