Merge branch 'master' into initialize-custom-elements-in-connected-callback

pull/5139/head
Christopher Mardell 5 years ago
commit f537cfe1d1

@ -1,5 +1,13 @@
# Svelte changelog
## Unreleased
* Prevent duplicate invalidation with certain two-way component bindings ([#3180](https://github.com/sveltejs/svelte/issues/3180), [#5117](https://github.com/sveltejs/svelte/issues/5117), [#5144](https://github.com/sveltejs/svelte/issues/5144))
* Fix reactivity when passing `$$props` to a `<slot>` ([#3364](https://github.com/sveltejs/svelte/issues/3364))
* Fix unneeded invalidation of `$$props` and `$$restProps` ([#4993](https://github.com/sveltejs/svelte/issues/4993), [#5118](https://github.com/sveltejs/svelte/issues/5118))
* Provide better compiler error message when mismatched tags are due to autoclosing of tags ([#5049](https://github.com/sveltejs/svelte/issues/5049))
* Fix `bind:group` when using contextual reference ([#5174](https://github.com/sveltejs/svelte/issues/5174))
## 3.24.0
* Support nullish coalescing (`??`) and optional chaining (`?.`) operators ([#1972](https://github.com/sveltejs/svelte/issues/1972))

6
package-lock.json generated

@ -2527,9 +2527,9 @@
}
},
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
"version": "4.17.19",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==",
"dev": true
},
"lodash.sortby": {

@ -53,6 +53,26 @@ To build the website, run `npm run sapper`. The output can be found in `__sapper
Tests can be run using `npm run test`.
## Linking `@sveltejs/site-kit` and `@sveltejs/site-repl`
This site depends on `@sveltejs/site-kit`, a collection of styles, components and icons used in common by *.svelte.dev websites, and `@sveltejs/site-repl`.
In order to work on features that depend on those packages, you need to [link](https://docs.npmjs.com/cli/link) their repositories:
- `cd <somewhere>`
- `git clone https://github.com/sveltejs/site-kit`
- `git clone https://github.com/sveltejs/svelte-repl`
- `cd <somewhere>/site-kit`
- `npm link`
- `cd <somewhere>/svelte-repl`
- `npm link`
- `cd <svelte-repo>/site`
- `npm link @sveltejs/site-kit`
- `npm link @sveltejs/svelte-repl`
## Translating the API docs
Anchors are automatically generated using headings in the documentation and by default (for the english language) they are latinised to make sure the URL is always conforming to RFC3986.

@ -30,7 +30,7 @@ Given that, what if the framework *didn't actually run in the browser*? What if,
Svelte is a new framework that does exactly that. You write your components using HTML, CSS and JavaScript (plus a few extra bits you can [learn in under 5 minutes](https://v2.svelte.dev/guide)), and during your build process Svelte compiles them into tiny standalone JavaScript modules. By statically analysing the component template, we can make sure that the browser does as little work as possible.
The [Svelte implementation of TodoMVC](http://svelte-todomvc.surge.sh/) weighs 3.6kb zipped. For comparison, React plus ReactDOM *without any app code* weighs about 45kb zipped. It takes about 10x as long for the browser just to evaluate React as it does for Svelte to be up and running with an interactive TodoMVC.
The [Svelte implementation of TodoMVC](https://svelte-todomvc.surge.sh/) weighs 3.6kb zipped. For comparison, React plus ReactDOM *without any app code* weighs about 45kb zipped. It takes about 10x as long for the browser just to evaluate React as it does for Svelte to be up and running with an interactive TodoMVC.
And once your app *is* up and running, according to [js-framework-benchmark](https://github.com/krausest/js-framework-benchmark) **Svelte is fast as heck**. It's faster than React. It's faster than Vue. It's faster than Angular, or Ember, or Ractive, or Preact, or Riot, or Mithril. It's competitive with Inferno, which is probably the fastest UI framework in the world, for now, because [Dominic Gannaway](https://twitter.com/trueadm) is a wizard. (Svelte is slower at removing elements. We're [working on it](https://github.com/sveltejs/svelte/issues/26).)

@ -5,7 +5,7 @@ author: Rich Harris
authorURL: https://twitter.com/Rich_Harris
---
> Quickstart for the impatient: [the Sapper docs](https://sapper.svelte.technology), and the [starter template](https://github.com/sveltejs/sapper-template)
> Quickstart for the impatient: [the Sapper docs](https://sapper.svelte.dev), and the [starter template](https://github.com/sveltejs/sapper-template)
If you had to list the characteristics of the perfect Node.js web application framework, you'd probably come up with something like this:
@ -47,9 +47,9 @@ What happens if we use the new model as a starting point?
## Introducing Sapper
<aside><p>The <a href="https://sapper.svelte.technology/docs#why-the-name-">name comes from</a> the term for combat engineers, and is also short for Svelte app maker</p></aside>
<aside><p>The <a href="https://sapper.svelte.dev/docs#Why_the_name">name comes from</a> the term for combat engineers, and is also short for Svelte app maker</p></aside>
[Sapper](https://sapper.svelte.technology) is the answer to that question. **Sapper is a Next.js-style framework that aims to meet the eleven criteria at the top of this article while dramatically reducing the amount of code that gets sent to the browser.** It's implemented as Express-compatible middleware, meaning it's easy to understand and customise.
[Sapper](https://sapper.svelte.dev) is the answer to that question. **Sapper is a Next.js-style framework that aims to meet the eleven criteria at the top of this article while dramatically reducing the amount of code that gets sent to the browser.** It's implemented as Express-compatible middleware, meaning it's easy to understand and customise.
The same 'hello world' app that took 204kb with React and Next weighs just 7kb with Sapper. That number is likely to fall further in the future as we explore the space of optimisation possibilities, such as not shipping any JavaScript *at all* for pages that aren't interactive, beyond the tiny Sapper runtime that handles client-side routing.

@ -74,8 +74,6 @@ This creates a new directory, `my-svelte-project`, adds files from the [sveltejs
In the `package.json` file, there is a section called `"scripts"`. These scripts define shortcuts for working with your application — `dev`, `build` and `start`. To launch your app in development mode, type the following:
> TODO update the template, it needs... some work
```bash
npm run dev
```

@ -0,0 +1,141 @@
---
title: Svelte <3 TypeScript
description: Typernetically enhanced web apps
author: Orta Therox
authorURL: https://twitter.com/orta
---
It's been by far the most requested feature for a while, and it's finally here: Svelte officially supports TypeScript.
We think it'll give you a much nicer development experience — one that also scales beautifully to larger Svelte code bases — regardless of whether you use TypeScript or JavaScript.
<figure>
<img alt="Screenshot of TypeScript in Svelte" src="media/svelte-ts.png">
<figcaption>Image of TypeScript + Svelte in VS Code (theme is <a href="https://marketplace.visualstudio.com/items?itemName=karyfoundation.theme-karyfoundation-themes">Kary Pro</a>.)</figcaption>
</figure>
## Try it now
You can start a new Svelte TypeScript project using the [normal template](https://github.com/sveltejs/template) and by running `node scripts/setupTypeScript.js` before you do anything else:
```bash
npx degit sveltejs/template svelte-typescript-app
cd svelte-typescript-app
node scripts/setupTypeScript.js
```
If you're a VS Code user, make sure you're using the (new) [official extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode), which replaces the popular extension by James Birtles.
Later in this blog post, we'll detail the individual steps involved in using TypeScript in an existing Svelte project.
## What does it mean to support TypeScript in Svelte?
TypeScript support in Svelte has been possible for a long time, but you had to mix a lot of disparate tools together and each project ran independently. Today, nearly all of these tools live under the Svelte organization and are maintained by a set of people who take responsibility over the whole pipeline and have common goals.
A week before COVID was declared a pandemic, [I pitched a consolidation](https://github.com/sveltejs/svelte/issues/4518) of the best Svelte tools and ideas from similar dev-ecosystems and provided a set of steps to get first class TypeScript support. Since then, many people have pitched in and written the code to get us there.
When we say that Svelte now supports TypeScript, we mean a few different things:
* You can use TypeScript inside your `<script>` blocks — just add the `lang="ts"` attribute
* Components with TypeScript can be type-checked with the `svelte-check` command
* You get autocompletion hints and type-checking as you're writing components, even in expressions inside markup
* TypeScript files understand the Svelte component API — no more red squiggles when you import a `.svelte` file into a `.ts` module
#### How does it work?
To understand the two main parts of TypeScript support, we'll compare it to the technique TypeScript uses to provide dev tools. There is a compiler `tsc` which you run on the command-line to convert `*.ts` to `*.js`, then there is a `TSServer` which is a node API that responds to requests from text editors. The `TSServer` is what provides all the JavaScript and TypeScript realtime introspection for editors while coding, and it has most of the compiler's code inside it.
For Svelte, we have the Svelte compiler, and now we have the [`svelte-language-server`](https://github.com/sveltejs/language-tools/tree/master/packages/language-server#svelte-language-server) which responds to text editor calls via the [Language Server Protocol standard](https://microsoft.github.io//language-server-protocol/overviews/lsp/overview/). First class TypeScript support means that _both_ of these two systems do a good job of handling TypeScript code.
The Svelte compiler support for TypeScript is handled by [Christian Kaisermann](https://github.com/kaisermann)'s [`svelte-preprocess`](https://github.com/sveltejs/svelte-preprocess#svelte-preprocess) which is now an official Svelte project.
For the editor level, we took inspiration from [Pine's](https://github.com/octref) work in the [Vue](https://vuejs.org) ecosystem via [Vetur](https://github.com/vuejs/vetur). Vetur provides an [LSP](https://github.com/vuejs/vetur/blob/master/server), a VS Code extension and a [CLI](https://github.com/vuejs/vetur/blob/master/vti). Svelte now also has an [LSP](https://github.com/sveltejs/language-tools/blob/master/packages/language-server), a [VS Code extension](https://github.com/sveltejs/language-tools/blob/master/packages/svelte-vscode) and a [CLI](https://github.com/sveltejs/language-tools/blob/master/packages/svelte-check).
#### `*.svelte` Introspection
For the official Svelte VS Code extension, we built off the foundations which [James Birtles](https://github.com/UnwrittenFun) has created in [`UnwrittenFun/svelte-vscode`](https://github.com/UnwrittenFun/svelte-vscode) and [`UnwrittenFun/svelte-language-server`](https://github.com/UnwrittenFun/svelte-language-server/).
[Simon Holthausen](https://github.com/dummdidumm) and [Lyu, Wei-Da](https://github.com/jasonlyu123) have done great work improving the JavaScript and TypeScript introspection, including integrating [@halfnelson](https://github.com/halfnelson)'s [svelte2tsx](https://github.com/sveltejs/language-tools/tree/master/packages/svelte2tsx#svelte2tsx) which powers understanding the props on components in your codebase.
## Adding TypeScript to an existing project
Before getting started, add the dependencies:
```bash
npm install --save-dev @tsconfig/svelte typescript svelte-preprocess svelte-check
```
##### 1. Compiling TypeScript
You first need to set up [`svelte-preprocess`](https://github.com/sveltejs/svelte-preprocess#svelte-preprocess), which passes the contents of your `<script lang="ts">` blocks through the TypeScript compiler.
In a Rollup project, that would look like this — note that we also need to install `@rollup/plugin-typescript` so that Rollup can handle `.ts` files:
```diff
+ import autoPreprocess from 'svelte-preprocess';
+ import typescript from '@rollup/plugin-typescript';
export default {
...,
plugins: [
svelte({
+ preprocess: autoPreprocess()
}),
+ typescript({ sourceMap: !production })
]
}
```
[Full instructions for other environments here](https://github.com/sveltejs/svelte-preprocess#usage).
To configure TypeScript, you will need to create a `tsconfig.json` in the root of your project:
```json
{
"extends": "@tsconfig/svelte/tsconfig.json",
"include": ["src/**/*", "src/node_modules"],
"exclude": ["node_modules/*", "__sapper__/*", "public/*"],
}
```
Your `include`/`exclude` may differ per project — these are defaults that should work across most Svelte projects.
##### 2. Editor Support
Any editor [using an LSP](https://langserver.org/#implementations-client) can be supported. The [VS Code](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) extension has been our primary focus, but there is work in progress [on Atom](https://github.com/sveltejs/language-tools/pull/160), and Vim via [coc-svelte](https://github.com/coc-extensions/coc-svelte) has been updated with the latest LSP.
These editor extensions will improve your coding experience even if you only use JavaScript. The editor won't offer errors, but it will offer inference and refactoring tools. You can [add `// @check-js`](https://www.staging-typescript.org/docs/handbook/intro-to-js-ts.html) to the top of a `<script>` tag using JavaScript to get better error messages with no infra changes.
To switch a `<script>` to use TypeScript, use `<script lang="ts">` and that should be it. Hopefully you won't be seeing an ocean of red squiggles.
##### 3. CI Checks
Having red squiggles is great, well, kinda. On the long run though, you want to be able to verify that there are no errors in your code. To verify your project is error free, you can use the CLI tool [`svelte-check`](https://www.npmjs.com/package/svelte-check). It acts like an editor asking for errors against all of your `.svelte` files.
You can add the dependency to your project and then add it to CI.
```bash
npx svelte-check
Loading svelte-check in workspace: /Users/ortatherox/dev/svelte/example-app
Getting Svelte diagnostics...
====================================
/Users/ortatherox/dev/svelte/example-app/src/App.svelte:3:2
Error: Type '123' is not assignable to type 'string'. (ts)
====================================
svelte-check found 1 error
error Command failed with exit code 1.
```
## What about TypeScript in Sapper projects?
Watch this space!
## How can I contribute?
We're so glad you asked. The work is happening in the [sveltejs/language-tools](https://github.com/sveltejs/language-tools) repo and in the [#language-tools](https://discord.gg/enV6v8K) channel in the Svelte Discord. If you'd like to report issues, submit fixes, or help out with extensions for new editors and so on, that's where you can find us. See you there!

@ -773,7 +773,7 @@ Actions are functions that are called when an element is created. They can retur
---
An action can have parameters. If the returned value has an `update` method, it will be called whenever those parameters change, immediately after Svelte has applied updates to the markup.
An action can have a parameter. If the returned value has an `update` method, it will be called whenever that parameter changes, immediately after Svelte has applied updates to the markup.
> Don't worry about the fact that we're redeclaring the `foo` function for every component instance — Svelte will hoist any functions that don't depend on local state out of the component definition.

@ -16,16 +16,10 @@
$: remaining = todos.filter(t => !t.done).length;
</script>
<style>
.done {
opacity: 0.4;
}
</style>
<h1>Todos</h1>
{#each todos as todo}
<div class:done={todo.done}>
<div>
<input
type=checkbox
bind:checked={todo.done}
@ -34,6 +28,7 @@
<input
placeholder="What needs to be done?"
bind:value={todo.text}
disabled={todo.done}
>
</div>
{/each}

@ -2,6 +2,6 @@
question: I'm new to Svelte. Where should I start?
---
We think the best way to get started is playing through the interactive [Tutorial](https://svelte.dev/tutorial). Each step there is mainly focused on one specific aspect and is easy to follow. You'll be editing and running real Svelte components right in your browser.
We think the best way to get started is playing through the interactive [Tutorial](tutorial). Each step there is mainly focused on one specific aspect and is easy to follow. You'll be editing and running real Svelte components right in your browser.
Five to ten minutes should be enough to get you up and running. An hour and a half should get you through the entire tutorial.

@ -0,0 +1,32 @@
---
question: How do I document my components?
---
In editors which use the Svelte Language Server you can document Components, functions and exports using specially formatted comments.
````svelte
<script>
/** What should we call the user? */
export let name = 'world';
</script>
<!--
@component
Here's some documentation for this component.
It will show up on hover.
- You can use markdown here.
- You can also use code blocks here.
- Usage:
```tsx
<main name="Arethra">
```
-->
<main>
<h1>
Hello, {name}
</h1>
</main>
````
Note: The `@component` is necessary in the HTML comment which describes your component.

@ -14,7 +14,7 @@ It's useful for things like this folder tree view, where folders can contain *ot
{/if}
```
...but that's impossible, because a file can't import itself. Instead, we use `<svelte:self>`:
...but that's impossible, because a module can't import itself. Instead, we use `<svelte:self>`:
```html
{#if file.type === 'folder'}
@ -22,4 +22,4 @@ It's useful for things like this folder tree view, where folders can contain *ot
{:else}
<File {...file}/>
{/if}
```
```

@ -1281,9 +1281,9 @@
}
},
"@sveltejs/site-kit": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@sveltejs/site-kit/-/site-kit-1.2.0.tgz",
"integrity": "sha512-C7puq+1so3fKPPZAnQJQlKfyCG6FsnSSFSS2LRIhWD8VK2FL5j8Eq7DIKSxUvWbGw1AsxnzO3dIHJWPB7fwjKg==",
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/@sveltejs/site-kit/-/site-kit-1.2.1.tgz",
"integrity": "sha512-5AhOCBcproHF5UbmuOIB9CiyAmG6BXOr2G4EjeeDz/tyo9myfnRKIgJSy26q8Zlw6TOlwxhzcAgvL5sgZF+IsA==",
"dev": true,
"requires": {
"@sindresorhus/slugify": "^0.9.1",
@ -2404,9 +2404,9 @@
}
},
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
"version": "4.17.19",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==",
"dev": true
},
"lodash.deburr": {

@ -36,7 +36,7 @@
"@babel/preset-env": "^7.6.0",
"@babel/runtime": "^7.6.0",
"@sindresorhus/slugify": "^0.9.1",
"@sveltejs/site-kit": "^1.2.0",
"@sveltejs/site-kit": "^1.2.1",
"@sveltejs/svelte-repl": "^0.2.0",
"degit": "^2.1.4",
"dotenv": "^8.1.0",

@ -137,6 +137,15 @@
top: calc((var(--h3) - 24px) / 2);
}
.post :global(a) {
padding: 0;
transition: none;
}
.post :global(a):not(:hover) {
border: none;
}
@media (max-width: 768px) {
.post :global(.anchor) {
transform: scale(0.6);

@ -8,6 +8,18 @@ function formatPubdate(str) {
return `${d} ${months[+m]} ${y} 12:00 +0000`;
}
function escapeHTML(html) {
const chars = {
'"' : 'quot',
"'": '#39',
'&': 'amp',
'<' : 'lt',
'>' : 'gt'
};
return html.replace(/["'&<>]/g, c => `&${chars[c]};`);
}
const rss = `
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
@ -23,9 +35,9 @@ const rss = `
</image>
${get_posts().filter(post => !post.metadata.draft).map(post => `
<item>
<title>${post.metadata.title}</title>
<title>${escapeHTML(post.metadata.title)}</title>
<link>https://svelte.dev/blog/${post.slug}</link>
<description>${post.metadata.description}</description>
<description>${escapeHTML(post.metadata.description)}</description>
<pubDate>${formatPubdate(post.metadata.pubdate)}</pubDate>
</item>
`).join('')}

@ -227,6 +227,7 @@ export default app;` });
padding: .6rem var(--side-nav);
background-color: var(--second);
color: white;
white-space: nowrap;
}
.icon {

@ -1,6 +1,7 @@
import { langs } from '@sveltejs/site-kit/utils/markdown.js';
import PrismJS from 'prismjs';
import 'prismjs/components/prism-bash';
import 'prismjs/components/prism-diff';
import 'prism-svelte';
export function highlight(source, lang) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

@ -41,7 +41,8 @@ export default class Binding extends Node {
this.raw_expression = JSON.parse(JSON.stringify(info.expression));
const { name } = get_object(this.expression.node);
this.is_contextual = scope.names.has(name);
this.is_contextual = Array.from(this.expression.references).some(name => scope.names.has(name));
// make sure we track this as a mutable ref
if (scope.is_let(name)) {
@ -49,7 +50,7 @@ export default class Binding extends Node {
code: 'invalid-binding',
message: 'Cannot bind to a variable declared with the let: directive'
});
} else if (this.is_contextual) {
} else if (scope.names.has(name)) {
if (scope.is_await(name)) {
component.error(this, {
code: 'invalid-binding',

@ -24,7 +24,7 @@ export default class Expression {
component: Component;
owner: Owner;
node: any;
references: Set<string>;
references: Set<string> = new Set();
dependencies: Set<string> = new Set();
contextual_dependencies: Set<string> = new Set();
@ -50,7 +50,7 @@ export default class Expression {
this.template_scope = template_scope;
this.owner = owner;
const { dependencies, contextual_dependencies } = this;
const { dependencies, contextual_dependencies, references } = this;
let { map, scope } = create_scopes(info);
this.scope = scope;
@ -75,6 +75,7 @@ export default class Expression {
if (is_reference(node, parent)) {
const { name, nodes } = flatten_reference(node);
references.add(name);
if (scope.has(name)) return;

@ -420,7 +420,7 @@ export default function dom(
${component.partly_hoisted}
${set && b`$$self.$set = ${set};`}
${set && b`$$self.$$set = ${set};`}
${capture_state && b`$$self.$capture_state = ${capture_state};`}

@ -468,7 +468,7 @@ export default class InlineComponentWrapper extends Wrapper {
${name} = null;
}
} else if (${switch_value}) {
${updates.length && b`${name}.$set(${name_changes});`}
${updates.length > 0 && b`${name}.$set(${name_changes});`}
}
`);

@ -7,6 +7,7 @@ import { b, p, x } from 'code-red';
import { sanitize } from '../../../utils/names';
import add_to_set from '../../utils/add_to_set';
import get_slot_data from '../../utils/get_slot_data';
import { is_reserved_keyword } from '../../utils/reserved_keywords';
import Expression from '../../nodes/shared/Expression';
import is_dynamic from './shared/is_dynamic';
import { Identifier, ObjectExpression } from 'estree';
@ -94,11 +95,7 @@ export default class SlotWrapper extends Wrapper {
}
});
const dynamic_dependencies = Array.from(attribute.dependencies).filter(name => {
if (this.node.scope.is_let(name)) return true;
const variable = renderer.component.var_lookup.get(name);
return is_dynamic(variable);
});
const dynamic_dependencies = Array.from(attribute.dependencies).filter((name) => this.is_dependency_dynamic(name));
if (dynamic_dependencies.length > 0) {
changes.properties.push(p`${attribute.name}: ${renderer.dirty(dynamic_dependencies)}`);
@ -157,17 +154,10 @@ export default class SlotWrapper extends Wrapper {
b`@transition_out(${slot_or_fallback}, #local);`
);
const is_dependency_dynamic = name => {
if (name === '$$scope') return true;
if (this.node.scope.is_let(name)) return true;
const variable = renderer.component.var_lookup.get(name);
return is_dynamic(variable);
};
const dynamic_dependencies = Array.from(this.dependencies).filter(is_dependency_dynamic);
const dynamic_dependencies = Array.from(this.dependencies).filter((name) => this.is_dependency_dynamic(name));
const fallback_dynamic_dependencies = has_fallback
? Array.from(this.fallback.dependencies).filter(is_dependency_dynamic)
? Array.from(this.fallback.dependencies).filter((name) => this.is_dependency_dynamic(name))
: [];
const slot_update = b`
@ -201,4 +191,12 @@ export default class SlotWrapper extends Wrapper {
b`if (${slot_or_fallback}) ${slot_or_fallback}.d(detaching);`
);
}
is_dependency_dynamic(name: string) {
if (name === '$$scope') return true;
if (this.node.scope.is_let(name)) return true;
if (is_reserved_keyword(name)) return true;
const variable = this.renderer.component.var_lookup.get(name);
return is_dynamic(variable);
}
}

@ -2,7 +2,6 @@ import EachBlock from "../../../nodes/EachBlock";
import InlineComponentWrapper from "../InlineComponent";
import ElementWrapper from "../Element";
import Binding from "../../../nodes/Binding";
import get_object from "../../../utils/get_object";
export default function mark_each_block_bindings(
parent: ElementWrapper | InlineComponentWrapper,
@ -10,9 +9,12 @@ export default function mark_each_block_bindings(
) {
// we need to ensure that the each block creates a context including
// the list and the index, if they're not otherwise referenced
const object = get_object(binding.expression.node).name;
const each_block = parent.node.scope.get_owner(object);
(each_block as EachBlock).has_binding = true;
binding.expression.references.forEach(name => {
const each_block = parent.node.scope.get_owner(name);
if (each_block) {
(each_block as EachBlock).has_binding = true;
}
});
if (binding.name === "group") {
// for `<input bind:group={} >`, we make sure that all the each blocks creates context with `index`

@ -8,6 +8,12 @@ import error from '../utils/error';
type ParserState = (parser: Parser) => (ParserState | void);
interface LastAutoClosedTag {
tag: string;
reason: string;
depth: number;
}
export class Parser {
readonly template: string;
readonly filename?: string;
@ -20,6 +26,7 @@ export class Parser {
css: Style[] = [];
js: Script[] = [];
meta_tags = {};
last_auto_closed_tag?: LastAutoClosedTag;
constructor(template: string, options: ParserOptions) {
if (typeof template !== 'string') {

@ -133,11 +133,15 @@ export default function tag(parser: Parser) {
// close any elements that don't have their own closing tags, e.g. <div><p></div>
while (parent.name !== name) {
if (parent.type !== 'Element')
if (parent.type !== 'Element') {
const message = parser.last_auto_closed_tag && parser.last_auto_closed_tag.tag === name
? `</${name}> attempted to close <${name}> that was already automatically closed by <${parser.last_auto_closed_tag.reason}>`
: `</${name}> attempted to close an element that was not open`;
parser.error({
code: `invalid-closing-tag`,
message: `</${name}> attempted to close an element that was not open`
message
}, start);
}
parent.end = start;
parser.stack.pop();
@ -148,10 +152,19 @@ export default function tag(parser: Parser) {
parent.end = parser.index;
parser.stack.pop();
if (parser.last_auto_closed_tag && parser.stack.length < parser.last_auto_closed_tag.depth) {
parser.last_auto_closed_tag = null;
}
return;
} else if (closing_tag_omitted(parent.name, name)) {
parent.end = start;
parser.stack.pop();
parser.last_auto_closed_tag = {
tag: parent.name,
reason: name,
depth: parser.stack.length,
};
}
const unique_names: Set<string> = new Set();

@ -1,6 +1,6 @@
import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler';
import { current_component, set_current_component } from './lifecycle';
import { blank_object, is_function, run, run_all, noop } from './utils';
import { blank_object, is_empty, is_function, run, run_all, noop } from './utils';
import { children, detach } from './dom';
import { transition_in } from './transitions';
@ -33,6 +33,7 @@ interface T$$ {
context: Map<any, any>;
on_mount: any[];
on_destroy: any[];
skip_bound: boolean;
}
export function bind(component, name, callback) {
@ -120,7 +121,8 @@ export function init(component, options, instance, create_fragment, not_equal, p
// everything else
callbacks: blank_object(),
dirty
dirty,
skip_bound: false
};
let ready = false;
@ -129,7 +131,7 @@ export function init(component, options, instance, create_fragment, not_equal, p
? instance(component, prop_values, (i, ret, ...rest) => {
const value = rest.length ? rest[0] : ret;
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
if ($$.bound[i]) $$.bound[i](value);
if (!$$.skip_bound && $$.bound[i]) $$.bound[i](value);
if (ready) make_dirty(component, i);
}
return ret;
@ -166,6 +168,7 @@ export let SvelteElement;
if (typeof HTMLElement === 'function') {
SvelteElement = class extends HTMLElement {
$$: T$$;
$$set?: ($$props: any) => void;
constructor() {
super();
this.attachShadow({ mode: 'open' });
@ -221,19 +224,25 @@ if (typeof HTMLElement === 'function') {
};
}
$set(obj) {
if (this.$$initialProps && obj) {
for (const attr of Object.getOwnPropertyNames(obj)) {
this.$$initialProps[attr] = obj[attr];
$set($$props) {
if (this.$$initialProps && $$props) {
for (const attr of Object.getOwnPropertyNames($$props)) {
this.$$initialProps[attr] = $$props[attr];
}
return;
}
if (this.$$set && !is_empty($$props)) {
this.$$.skip_bound = true;
this.$$set($$props);
this.$$.skip_bound = false;
}
// overridden by instance, if it has props
}
};
}
export class SvelteComponent {
$$: T$$;
$$set?: ($$props: any) => void;
$destroy() {
destroy_component(this, 1);
@ -250,7 +259,11 @@ export class SvelteComponent {
};
}
$set() {
// overridden by instance, if it has props
$set($$props) {
if (this.$$set && !is_empty($$props)) {
this.$$.skip_bound = true;
this.$$set($$props);
this.$$.skip_bound = false;
}
}
}

@ -42,6 +42,10 @@ export function not_equal(a, b) {
return a != a ? b == b : a !== b;
}
export function is_empty(obj) {
return Object.keys(obj).length === 0;
}
export function validate_store(store, name) {
if (store != null && typeof store.subscribe !== 'function') {
throw new Error(`'${name}' is not a store with a 'subscribe' method`);

@ -55,7 +55,7 @@ function instance($$self, $$props, $$invalidate) {
let { bar } = $$props;
const foo_function = () => handleFoo(bar);
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("bar" in $$props) $$invalidate(0, bar = $$props.bar);
};

@ -52,7 +52,7 @@ function instance($$self, $$props, $$invalidate) {
$$invalidate(0, open);
}
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("open" in $$props) $$invalidate(0, open = $$props.open);
};

@ -46,7 +46,7 @@ function instance($$self, $$props, $$invalidate) {
$$invalidate(1, h);
}
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("w" in $$props) $$invalidate(0, w = $$props.w);
if ("h" in $$props) $$invalidate(1, h = $$props.h);
};

@ -68,7 +68,7 @@ function instance($$self, $$props, $$invalidate) {
$$invalidate(0, files);
}
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("files" in $$props) $$invalidate(0, files = $$props.files);
};

@ -118,7 +118,7 @@ function instance($$self, $$props, $$invalidate) {
let { $$slots = {}, $$scope } = $$props;
validate_slots("Component", $$slots, []);
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("prop" in $$props) $$subscribe_prop($$invalidate(0, prop = $$props.prop));
if ("alias" in $$props) $$invalidate(1, realName = $$props.alias);
};

@ -48,7 +48,7 @@ function create_fragment(ctx) {
function instance($$self, $$props, $$invalidate) {
let { foo = 42 } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("foo" in $$props) $$invalidate(0, foo = $$props.foo);
};

@ -12,7 +12,7 @@ function instance($$self, $$props, $$invalidate) {
return x * 3;
}
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("x" in $$props) $$invalidate(0, x = $$props.x);
};

@ -47,7 +47,7 @@ function create_fragment(ctx) {
function instance($$self, $$props, $$invalidate) {
let { bar } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("bar" in $$props) $$invalidate(0, bar = $$props.bar);
};

@ -79,7 +79,7 @@ function instance($$self, $$props, $$invalidate) {
let { $$slots = {}, $$scope } = $$props;
validate_slots("Component", $$slots, []);
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("name" in $$props) $$invalidate(0, name = $$props.name);
};

@ -183,7 +183,7 @@ function instance($$self, $$props, $$invalidate) {
let { $$slots = {}, $$scope } = $$props;
validate_slots("Component", $$slots, []);
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("things" in $$props) $$invalidate(0, things = $$props.things);
if ("foo" in $$props) $$invalidate(1, foo = $$props.foo);
if ("bar" in $$props) $$invalidate(2, bar = $$props.bar);

@ -175,7 +175,7 @@ function instance($$self, $$props, $$invalidate) {
let { $$slots = {}, $$scope } = $$props;
validate_slots("Component", $$slots, []);
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("things" in $$props) $$invalidate(0, things = $$props.things);
if ("foo" in $$props) $$invalidate(1, foo = $$props.foo);
};

@ -104,7 +104,7 @@ function create_fragment(ctx) {
function instance($$self, $$props, $$invalidate) {
let { createElement } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("createElement" in $$props) $$invalidate(0, createElement = $$props.createElement);
};

@ -10,7 +10,7 @@ function instance($$self, $$props, $$invalidate) {
alert(JSON.stringify(data()));
});
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("foo" in $$props) $$invalidate(0, foo = $$props.foo);
};

@ -76,7 +76,7 @@ function instance($$self, $$props, $$invalidate) {
let { $$slots = {}, $$scope } = $$props;
validate_slots("Component", $$slots, []);
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("foo" in $$props) $$invalidate(0, foo = $$props.foo);
};

@ -106,7 +106,7 @@ function instance($$self, $$props, $$invalidate) {
let { d } = $$props;
let { e } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("a" in $$props) $$invalidate(0, a = $$props.a);
if ("b" in $$props) $$invalidate(1, b = $$props.b);
if ("c" in $$props) $$invalidate(2, c = $$props.c);

@ -152,7 +152,7 @@ function instance($$self, $$props, $$invalidate) {
let { time } = $$props;
let { foo } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("comments" in $$props) $$invalidate(0, comments = $$props.comments);
if ("elapsed" in $$props) $$invalidate(1, elapsed = $$props.elapsed);
if ("time" in $$props) $$invalidate(2, time = $$props.time);

@ -128,7 +128,7 @@ function foo(node, animation, params) {
function instance($$self, $$props, $$invalidate) {
let { things } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("things" in $$props) $$invalidate(0, things = $$props.things);
};

@ -97,7 +97,7 @@ function create_fragment(ctx) {
function instance($$self, $$props, $$invalidate) {
let { things } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("things" in $$props) $$invalidate(0, things = $$props.things);
};

@ -88,7 +88,7 @@ function create_fragment(ctx) {
function instance($$self, $$props, $$invalidate) {
let { foo } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("foo" in $$props) $$invalidate(0, foo = $$props.foo);
};

@ -66,7 +66,7 @@ function create_fragment(ctx) {
function instance($$self, $$props, $$invalidate) {
let { foo } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("foo" in $$props) $$invalidate(0, foo = $$props.foo);
};

@ -44,7 +44,7 @@ function instance($$self, $$props, $$invalidate) {
let { x } = $$props;
let { y } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("color" in $$props) $$invalidate(0, color = $$props.color);
if ("x" in $$props) $$invalidate(1, x = $$props.x);
if ("y" in $$props) $$invalidate(2, y = $$props.y);

@ -37,7 +37,7 @@ function create_fragment(ctx) {
function instance($$self, $$props, $$invalidate) {
let { data } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("data" in $$props) $$invalidate(0, data = $$props.data);
};

@ -37,7 +37,7 @@ function create_fragment(ctx) {
function instance($$self, $$props, $$invalidate) {
let { color } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("color" in $$props) $$invalidate(0, color = $$props.color);
};

@ -54,7 +54,7 @@ function instance($$self, $$props, $$invalidate) {
let { key } = $$props;
let { value } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("style" in $$props) $$invalidate(0, style = $$props.style);
if ("key" in $$props) $$invalidate(1, key = $$props.key);
if ("value" in $$props) $$invalidate(2, value = $$props.value);

@ -49,7 +49,7 @@ function instance($$self, $$props, $$invalidate) {
$$invalidate(0, files);
}
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("files" in $$props) $$invalidate(0, files = $$props.files);
};

@ -60,7 +60,7 @@ function instance($$self, $$props, $$invalidate) {
$$invalidate(0, value);
}
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("value" in $$props) $$invalidate(0, value = $$props.value);
};

@ -53,7 +53,7 @@ function instance($$self, $$props, $$invalidate) {
$$invalidate(0, foo);
}
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("foo" in $$props) $$invalidate(0, foo = $$props.foo);
};

@ -173,7 +173,7 @@ function instance($$self, $$props, $$invalidate) {
$$invalidate(10, ended);
}
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("buffered" in $$props) $$invalidate(0, buffered = $$props.buffered);
if ("seekable" in $$props) $$invalidate(1, seekable = $$props.seekable);
if ("played" in $$props) $$invalidate(2, played = $$props.played);

@ -167,7 +167,7 @@ function instance($$self, $$props, $$invalidate) {
let { f } = $$props;
let Component;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("a" in $$props) $$invalidate(0, a = $$props.a);
if ("b" in $$props) $$invalidate(1, b = $$props.b);
if ("c" in $$props) $$invalidate(2, c = $$props.c);

@ -6,7 +6,7 @@ function instance($$self, $$props, $$invalidate) {
let a;
let b;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("x" in $$props) $$invalidate(0, x = $$props.x);
};

@ -5,7 +5,7 @@ function instance($$self, $$props, $$invalidate) {
let { a = 1 } = $$props;
let { b = 2 } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("a" in $$props) $$invalidate(0, a = $$props.a);
if ("b" in $$props) $$invalidate(1, b = $$props.b);
};

@ -50,7 +50,7 @@ function create_fragment(ctx) {
function instance($$self, $$props, $$invalidate) {
let { current } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("current" in $$props) $$invalidate(0, current = $$props.current);
};

@ -67,7 +67,7 @@ function instance($$self, $$props, $$invalidate) {
let { url } = $$props;
let { slug } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("url" in $$props) $$invalidate(0, url = $$props.url);
if ("slug" in $$props) $$invalidate(1, slug = $$props.slug);
};

@ -22,7 +22,7 @@ function create_fragment(ctx) {
function instance($$self, $$props, $$invalidate) {
let { custom } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("custom" in $$props) $$invalidate(0, custom = $$props.custom);
};

@ -124,7 +124,7 @@ function instance($$self, $$props, $$invalidate) {
let { x } = $$props;
let { y } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("x" in $$props) $$invalidate(0, x = $$props.x);
if ("y" in $$props) $$invalidate(1, y = $$props.y);
};

@ -102,7 +102,7 @@ function create_fragment(ctx) {
function instance($$self, $$props, $$invalidate) {
let { num = 1 } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("num" in $$props) $$invalidate(0, num = $$props.num);
};

@ -243,7 +243,7 @@ function instance($$self, $$props, $$invalidate) {
let { d } = $$props;
let { e } = $$props;
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("a" in $$props) $$invalidate(0, a = $$props.a);
if ("b" in $$props) $$invalidate(1, b = $$props.b);
if ("c" in $$props) $$invalidate(2, c = $$props.c);

@ -93,7 +93,7 @@ function instance($$self, $$props, $$invalidate) {
$$invalidate(3, offsetWidth);
}
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("currentTime" in $$props) $$invalidate(0, currentTime = $$props.currentTime);
if ("videoHeight" in $$props) $$invalidate(1, videoHeight = $$props.videoHeight);
if ("videoWidth" in $$props) $$invalidate(2, videoWidth = $$props.videoWidth);

@ -78,7 +78,7 @@ function instance($$self, $$props, $$invalidate) {
$$invalidate(0, y = window.pageYOffset)
}
$$self.$set = $$props => {
$$self.$$set = $$props => {
if ("y" in $$props) $$invalidate(0, y = $$props.y);
};

@ -0,0 +1,10 @@
{
"code": "invalid-closing-tag",
"message": "</p> attempted to close an element that was not open",
"pos": 38,
"start": {
"character": 38,
"column": 0,
"line": 5
}
}

@ -0,0 +1,10 @@
{
"code": "invalid-closing-tag",
"message": "</p> attempted to close <p> that was already automatically closed by <pre>",
"pos": 24,
"start": {
"character": 24,
"column": 0,
"line": 3
}
}

@ -0,0 +1,87 @@
export default {
html: `
<label><input type="checkbox" value="x"> x</label>
<label><input type="checkbox" value="y"> y</label>
<label><input type="checkbox" value="z"> z</label>
<p></p>
<label><input type="checkbox" value="x"> x</label>
<label><input type="checkbox" value="y"> y</label>
<label><input type="checkbox" value="z"> z</label>
<p></p>
<label><input type="checkbox" value="x"> x</label>
<label><input type="checkbox" value="y"> y</label>
<label><input type="checkbox" value="z"> z</label>
<p></p>
`,
async test({ assert, component, target, window }) {
const inputs = target.querySelectorAll('input');
assert.equal(inputs[0].checked, false);
assert.equal(inputs[1].checked, false);
assert.equal(inputs[2].checked, false);
assert.equal(inputs[3].checked, false);
assert.equal(inputs[4].checked, false);
assert.equal(inputs[5].checked, false);
assert.equal(inputs[6].checked, false);
assert.equal(inputs[7].checked, false);
assert.equal(inputs[8].checked, false);
const event = new window.Event('change');
inputs[2].checked = true;
await inputs[2].dispatchEvent(event);
assert.htmlEqual(target.innerHTML, `
<label><input type="checkbox" value="x"> x</label>
<label><input type="checkbox" value="y"> y</label>
<label><input type="checkbox" value="z"> z</label>
<p>z</p>
<label><input type="checkbox" value="x"> x</label>
<label><input type="checkbox" value="y"> y</label>
<label><input type="checkbox" value="z"> z</label>
<p></p>
<label><input type="checkbox" value="x"> x</label>
<label><input type="checkbox" value="y"> y</label>
<label><input type="checkbox" value="z"> z</label>
<p></p>
`);
inputs[4].checked = true;
await inputs[4].dispatchEvent(event);
assert.htmlEqual(target.innerHTML, `
<label><input type="checkbox" value="x"> x</label>
<label><input type="checkbox" value="y"> y</label>
<label><input type="checkbox" value="z"> z</label>
<p>z</p>
<label><input type="checkbox" value="x"> x</label>
<label><input type="checkbox" value="y"> y</label>
<label><input type="checkbox" value="z"> z</label>
<p>y</p>
<label><input type="checkbox" value="x"> x</label>
<label><input type="checkbox" value="y"> y</label>
<label><input type="checkbox" value="z"> z</label>
<p></p>
`);
inputs[5].checked = true;
await inputs[5].dispatchEvent(event);
assert.htmlEqual(target.innerHTML, `
<label><input type="checkbox" value="x"> x</label>
<label><input type="checkbox" value="y"> y</label>
<label><input type="checkbox" value="z"> z</label>
<p>z</p>
<label><input type="checkbox" value="x"> x</label>
<label><input type="checkbox" value="y"> y</label>
<label><input type="checkbox" value="z"> z</label>
<p>y, z</p>
<label><input type="checkbox" value="x"> x</label>
<label><input type="checkbox" value="y"> y</label>
<label><input type="checkbox" value="z"> z</label>
<p></p>
`);
}
};

@ -0,0 +1,22 @@
<script>
const values = ['x', 'y', 'z'];
const list = {
a: [],
b: [],
c: [],
};
</script>
{#each Object.keys(list) as key}
{#each values as value}
<label>
<input
type='checkbox'
bind:group={list[key]}
value={value}
/>
{value}
</label>
{/each}
<p>{list[key].join(', ')}</p>
{/each}

@ -0,0 +1,5 @@
<script>
export let value = '';
</script>
<input bind:value />

@ -0,0 +1,61 @@
export default {
html: `
<input />
<input />
<div></div>
`,
async test({ assert, component, target, window }) {
let count = 0;
component.callback = () => {
count++;
};
const [input1, input2] = target.querySelectorAll("input");
input1.value = "1";
await input1.dispatchEvent(new window.Event("input"));
assert.htmlEqual(
target.innerHTML,
`
<input />
<input />
<div>1</div>
`
);
assert.equal(input1.value, "1");
assert.equal(input2.value, "1");
assert.equal(count, 1);
input2.value = "123";
await input2.dispatchEvent(new window.Event("input"));
assert.htmlEqual(
target.innerHTML,
`
<input />
<input />
<div>123</div>
`
);
assert.equal(input1.value, "123");
assert.equal(input2.value, "123");
assert.equal(count, 2);
input1.value = "456";
await input1.dispatchEvent(new window.Event("input"));
assert.htmlEqual(
target.innerHTML,
`
<input />
<input />
<div>456</div>
`
);
assert.equal(input1.value, "456");
assert.equal(input2.value, "456");
assert.equal(count, 3);
},
};

@ -0,0 +1,18 @@
<script>
import { writable } from 'svelte/store';
import Input from './Input.svelte';
let value = writable({ value: '' });
export let callback = () => {};
value.subscribe(() => {
callback();
})
</script>
<input bind:value={$value.value} />
<Input bind:value={$value.value}/>
<div>{$value.value}</div>

@ -0,0 +1,6 @@
<script>
export let id;
export let callback;
$: $$props, callback(id);
</script>

@ -0,0 +1,30 @@
let callbacks = [];
export default {
props: {
callback: (value) => callbacks.push(value),
val1: "1",
val2: "2",
},
before_test() {
callbacks = [];
},
async test({ assert, component, target }) {
assert.equal(callbacks.length, 2);
assert.equal(JSON.stringify(callbacks), '["1","2"]');
component.val1 = "3";
assert.equal(callbacks.length, 3);
assert.equal(JSON.stringify(callbacks), '["1","2","1"]');
component.val1 = "4";
assert.equal(callbacks.length, 4);
assert.equal(JSON.stringify(callbacks), '["1","2","1","1"]');
component.val2 = "5";
assert.equal(callbacks.length, 5);
assert.equal(JSON.stringify(callbacks), '["1","2","1","1","2"]');
},
};

@ -0,0 +1,8 @@
<script>
import Comp from './Comp.svelte';
export let callback;
export let val1, val2;
</script>
<Comp id="1" {callback} value={val1} />
<Comp id="2" {callback} value={val2} />

@ -0,0 +1,21 @@
export default {
html: `
<h1>hi</h1>
<button>Change</button>
`,
async test({ assert, component, target, window }) {
const btn = target.querySelector("button");
const clickEvent = new window.MouseEvent("click");
await btn.dispatchEvent(clickEvent);
assert.htmlEqual(
target.innerHTML,
`
<h1>changed</h1>
<button>Change</button>
`
);
},
};

@ -0,0 +1,13 @@
<script>
import Comp from './Comp.svelte'
let p = "hi"
</script>
<Comp someprop={p} let:props>
<h1>
{props.someprop}
</h1>
</Comp>
<button on:click={()=> p = "changed"}>Change
</button>
Loading…
Cancel
Save