Upgrade your Svelte templates for version 2
Clone or download
Latest commit ff71523 Jul 16, 2018
Permalink
Failed to load latest commit information.
src upgrade: swap clorox for turbocolor Jul 16, 2018
test -> v1.0.16 Apr 21, 2018
.gitignore shorthand properties Apr 13, 2018
.travis.yml initial commit Apr 12, 2018
CHANGELOG.md -> v1.0.16 Apr 21, 2018
LICENSE initial commit Apr 12, 2018
README.md document store method call syntax change Apr 19, 2018
appveyor.yml initial commit Apr 12, 2018
bin add a CLI Apr 13, 2018
package.json upgrade: swap clorox for turbocolor Jul 16, 2018
rollup.config.js add a CLI Apr 13, 2018
yarn.lock -> v1.0.1 Apr 13, 2018

README.md

svelte-upgrade

Upgrade your Svelte templates for compatibility with version 2.

To update all the templates in the src directory:

npx svelte-upgrade v2 src

To update an individual component:

npx svelte-upgrade v2 MyComponent.html

To specify a different output location, instead of writing in place, use the --output (or -o) flag.

If files will be overwritten, you'll be prompted for confirmation. Use --force or -f to bypass the prompt.

Configuring the compiler

Prior to the release of Svelte v2, it is possible to opt in to the new syntax by passing the parser: 'v2' option to the compiler, either directly or via your rollup-plugin-svelte or svelte-loader options.

Svelte v2 syntax changes

Single-curly tags

<!-- before -->
<div class="item {{active ? 'highlighted' : ''}}">
  {{name}}
</div>

<!-- after -->
<div class="item {active ? 'highlighted' : ''}">
  {name}
</div>

Control flow

<!-- before -->
{{#if foo}}
  <p>foo</p>
{{elseif bar}}
  <p>bar</p>
{{else}}
  <p>neither foo nor bar</p>
{{/if}}

<!-- after -->
{#if foo}
  <p>foo</p>
{:elseif bar}
  <p>bar</p>
{:else}
  <p>neither foo nor bar</p>
{/if}

Keyed each blocks

<!-- before -->
<ul>
  {{#each cats as cat @name}}
    <li><a target='_blank' href={{cat.video}}>{{cat.name}}</a></li>
  {{/each}}
</ul>

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

Built-in elements

<!-- before -->
<:Window on:resize='handleResize()'/>

<!-- after -->
<svelte:window on:resize='handleResize()'/>

Dynamic components

<!-- before -->
<:Component {Thing}/>

<!-- after -->
<svelte:component this={Thing}/>

Shorthand properties

<!-- before -->
<Foo :bar/>

<!-- after -->
<Foo {bar}/>

HTML

<!-- before -->
<div class='blog-post'>
  {{{post.content}}}
</div>

<!-- after -->
<div class='blog-post'>
  {@html post.content}
</div>

Store methods in event handlers

<!-- before -->
<button on:click="store.set({ clicked: true })">click me</button>

<!-- after -->
<button on:click="$set({ clicked: true })">click me</button>

License

LIL