Skip to content

Commit 78838fa

Browse files
committed
Merge branch 'master' of https://github.com/sveltejs/svelte into feature/preprocessor-sourcemaps
2 parents a0eb41f + c24b313 commit 78838fa

File tree

70 files changed

+707
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+707
-101
lines changed

.mocharc.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
module.exports = {
22
file: [
3-
'test/test.js'
3+
'test/test.ts'
4+
],
5+
require: [
6+
'sucrase/register'
47
]
58
};
69

710
// add coverage options when running 'npx c8 mocha'
811
if (process.env.NODE_V8_COVERAGE) {
9-
Object.assign(module.exports, {
10-
fullTrace: true,
11-
require: [
12-
'source-map-support/register'
13-
]
14-
});
12+
module.exports.fullTrace = true;
13+
module.exports.require.push('source-map-support/register');
1514
}

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Svelte changelog
22

3+
## 3.29.0
4+
5+
* Support `<slot slot="...">` ([#2079](https://github.com/sveltejs/svelte/issues/2079))
6+
* Fix unmounting components with a bidirectional transition with a delay ([#4954](https://github.com/sveltejs/svelte/issues/4954))
7+
* Add types to `get` function in `svelte/store` ([#5269](https://github.com/sveltejs/svelte/pull/5269))
8+
* Add a warning when a component looks like it's trying to use another component without beginning with a capital letter ([#5302](https://github.com/sveltejs/svelte/pull/5302))
9+
* Add `EventSource` to known globals ([#5463](https://github.com/sveltejs/svelte/issues/5463))
10+
* Fix compiler exception with `~`/`+` combinators and `{...spread}` attributes ([#5465](https://github.com/sveltejs/svelte/issues/5465))
11+
12+
## 3.28.0
13+
14+
* Add `{#key}` block for keying arbitrary content on an expression ([#1469](https://github.com/sveltejs/svelte/issues/1469))
15+
316
## 3.27.0
417

518
* Add `|nonpassive` event modifier, explicitly passing `passive: false` ([#2068](https://github.com/sveltejs/svelte/issues/2068))

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte",
3-
"version": "3.27.0",
3+
"version": "3.29.0",
44
"description": "Cybernetically enhanced web apps",
55
"module": "index.mjs",
66
"main": "index",

site/content/docs/02-template-syntax.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,33 @@ If you don't care about the pending state, you can also omit the initial block.
342342
{/await}
343343
```
344344

345+
### {#key ...}
346+
347+
```sv
348+
{#key expression}...{/key}
349+
```
350+
351+
Key blocks destroy and recreate their contents when the value of an expression changes.
352+
353+
---
354+
355+
This is useful if you want an element to play its transition whenever a value changes.
356+
357+
```sv
358+
{#key value}
359+
<div transition:fade>{value}</div>
360+
{/key}
361+
```
362+
363+
---
364+
365+
When used around components, this will cause them to be reinstantiated and reinitialised.
366+
367+
```sv
368+
{#key value}
369+
<Component />
370+
{/key}
371+
```
345372

346373
### {@html ...}
347374

src/compiler/compile/Component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,11 +664,13 @@ export default class Component {
664664
}
665665

666666
const writable = node.type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let');
667+
const imported = node.type.startsWith('Import');
667668

668669
this.add_var({
669670
name,
670671
initialised: instance_scope.initialised_declarations.has(name),
671-
writable
672+
writable,
673+
imported
672674
});
673675

674676
this.node_for_declaration.set(name, node);

src/compiler/compile/css/Selector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ function get_possible_element_siblings(node: INode, adjacent_only: boolean): Map
406406
let prev: INode = node;
407407
while (prev = prev.prev) {
408408
if (prev.type === 'Element') {
409-
if (!prev.attributes.find(attr => attr.name.toLowerCase() === 'slot')) {
409+
if (!prev.attributes.find(attr => attr.type === 'Attribute' && attr.name.toLowerCase() === 'slot')) {
410410
result.set(prev, NodeExist.Definitely);
411411
}
412412

src/compiler/compile/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { assign } from '../../runtime/internal/utils';
21
import Stats from '../Stats';
32
import parse from '../parse/index';
43
import render_dom from './render_dom/index';
@@ -69,7 +68,7 @@ function validate_options(options: CompileOptions, warnings: Warning[]) {
6968
}
7069

7170
export default function compile(source: string, options: CompileOptions = {}) {
72-
options = assign({ generate: 'dom', dev: false }, options);
71+
options = Object.assign({ generate: 'dom', dev: false }, options);
7372

7473
const stats = new Stats();
7574
const warnings = [];

src/compiler/compile/nodes/Element.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export default class Element extends Node {
186186

187187
case 'Attribute':
188188
case 'Spread':
189-
// special case
189+
// special case
190190
if (node.name === 'xmlns') this.namespace = node.value[0].data;
191191

192192
this.attributes.push(new Attribute(component, this, scope, node));
@@ -241,6 +241,13 @@ export default class Element extends Node {
241241
}
242242

243243
validate() {
244+
if (this.component.var_lookup.has(this.name) && this.component.var_lookup.get(this.name).imported) {
245+
this.component.warn(this, {
246+
code: 'component-name-lowercase',
247+
message: `<${this.name}> will be treated as an HTML element unless it begins with a capital letter`
248+
});
249+
}
250+
244251
if (a11y_distracting_elements.has(this.name)) {
245252
// no-distracting-elements
246253
this.component.warn(this, {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Expression from "./shared/Expression";
2+
import map_children from "./shared/map_children";
3+
import AbstractBlock from "./shared/AbstractBlock";
4+
5+
export default class KeyBlock extends AbstractBlock {
6+
type: "KeyBlock";
7+
8+
expression: Expression;
9+
10+
constructor(component, parent, scope, info) {
11+
super(component, parent, scope, info);
12+
13+
this.expression = new Expression(component, this, scope, info.expression);
14+
15+
this.children = map_children(component, this, scope, info.children);
16+
17+
this.warn_if_empty_block();
18+
}
19+
}

0 commit comments

Comments
 (0)